Esempio n. 1
1
 /**
  * 
  * @return booleam
  */
 public function ping()
 {
     if (!imap_ping($this->connect)) {
         $this->connect();
     }
     return true;
 }
Esempio n. 2
0
 public function pingMailbox()
 {
     if (!imap_ping($this->mbox)) {
         return $this->reconnect();
     }
     return true;
 }
 /**
  * Ping the connection
  *
  * @return bool
  */
 public function ping()
 {
     //init the catching
     $this->exceptionThrower->start();
     $success = imap_ping($this->mailbox);
     $this->exceptionThrower->stop();
     return $success;
 }
Esempio n. 4
0
 function open()
 {
     //echo $this->serverstr;
     if ($this->mbox && imap_ping($this->mbox)) {
         return $this->mbox;
     }
     $this->mbox = @imap_open($this->serverstr, $this->username, $this->password);
     return $this->mbox;
 }
Esempio n. 5
0
	/**
	 * Get IMAP mailbox connection stream
	 * @param bool $forceConnection Initialize connection if it's not initialized
	 * @return null|resource
	 */
	public function getImapStream($forceConnection = true) {
		if($forceConnection) {
			if($this->imapStream && (!is_resource($this->imapStream) || !imap_ping($this->imapStream))) {
				$this->disconnect();
				$this->imapStream = null;
			}
			if(!$this->imapStream) {
				$this->imapStream = $this->initImapStream();
			}
		}
		return $this->imapStream;
	}
Esempio n. 6
0
 /**
  * Get IMAP mailbox connection stream
  * @param bool $forceConnection Initialize connection if it's not initialized
  * @return null|resource
  */
 public function get_imap_stream($force_connection = true)
 {
     static $imap_stream;
     if ($force_connection) {
         if ($imap_stream && (!is_resource($imap_stream) || !imap_ping($imap_stream))) {
             $this->disconnect();
             $imap_stream = null;
         }
         if (!$imap_stream) {
             $imap_stream = $this->_init_imap_stream();
         }
     }
     return $imap_stream;
 }
function emailListener()
{
    //$output = "<script>console.log( 'just got in' );</script>";
    //echo $output;
    $connection = establishConnection();
    $dbConn = establishDBConnection();
    //$output = "<script>console.log( 'set up connection' );</script>";
    //$dbConn->query("INSERT INTO away_mentor (userID, tiStamp) VALUES (99897, NOW())");//test the db connection
    //echo $output;//develop thread/loop
    $messagestatus = "UNSEEN";
    $countTo24 = 0;
    while (true) {
        echo "in check loop";
        $emails = imap_search($connection, $messagestatus);
        if ($emails) {
            rsort($emails);
            foreach ($emails as $email_number) {
                echo "in email loop";
                $header = imap_headerinfo($connection, $email_number);
                $message = imap_fetchbody($connection, $email_number, 1.1);
                if ($message == "") {
                    $message = imap_fetchbody($connection, $email_number, 1);
                }
                $emailaddress = substr($header->senderaddress, stripos($header->senderaddress, "<") + 1, stripos($header->senderaddress, ">") - (stripos($header->senderaddress, ">") + 1));
                if (!detectOOOmessage($header->subject, $message, $emailaddress)) {
                    detectB00message($header->subject, $emailaddress);
                }
                imap_delete($connection, 1);
                //this might bug out but should delete the top message that was just parsed
            }
        }
        sleep(600);
        //do check every 10 minutes
        $countTo24 = $countTo24 + 1;
        if ($countTo24 >= 144) {
            $countTo24 = 0;
            $dbConn->query("DELETE FROM away_mentor WHERE tiStamp <= DATE_ADD(CURRENT_DATE, INTERVAL -1 DAY)");
            //delete mentors that have been away for more than 24 hours from the away list
            //$command = Yii::app()->db->createCommand();
            //   $command->delete('away_mentor', 'tiStamp <= DATE_ADD(CURRENT_DATE , INTERVAL -1 DAY )');//this might bug the hell out deletes mentors on the away list that were put on over 24 hours ago
        }
        if (!imap_ping($connection)) {
            $connection = establishConnection();
        }
    }
}
Esempio n. 8
0
 /**
  * Helper to re-initialize the folder to speed things up
  * Remember what folder is currently open and only change if necessary
  *
  * @param string        $folderid       id of the folder
  * @param boolean       $force          re-open the folder even if currently opened
  *
  * @access protected
  * @return boolean      if folder is opened
  */
 protected function imap_reopen_folder($folderid, $force = false)
 {
     // if the stream is not alive, we open it again
     if (!@imap_ping($this->mbox)) {
         $this->mbox = @imap_open($this->server, $this->username, $this->password, OP_HALFOPEN);
         $this->mboxFolder = "";
     }
     // to see changes, the folder has to be reopened!
     if ($this->mboxFolder != $folderid || $force) {
         $s = @imap_reopen($this->mbox, $this->server . $folderid);
         // TODO throw status exception
         if (!$s) {
             ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->imap_reopen_folder('%s'): failed to change folder: %s", $folderid, implode(", ", imap_errors())));
             return false;
         }
         $this->mboxFolder = $folderid;
     }
     return true;
 }
Esempio n. 9
0
 /**
  * Check if the stream is connected
  *
  * @return bool
  */
 protected function isConnected()
 {
     return $this->isConfigured() && $this->imapStream && is_resource($this->imapStream) && @imap_ping($this->imapStream);
 }
Esempio n. 10
0
 /**
  * Checks connection state and if not connected, reconnects
  */
 public function checkConnection()
 {
     if (!imap_ping($this->stream)) {
         $this->reconnect();
     }
 }
Esempio n. 11
0
<?php

echo "Checking with no parameters\n";
imap_ping();
echo "Checking with incorrect parameter type\n";
imap_ping('');
imap_ping(false);
 /**
  * The main method we use to parse an IMAP inbox.
  */
 public function run()
 {
     // $instance must be initialized before we go on!
     if (self::$instance === false) {
         return false;
     }
     // If safe mode isn't on, then let's set the execution time to unlimited
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
     // Try to connect
     $connect = $this->connect();
     if (!$connect) {
         return false;
     }
     // Total duration we should keep the IMAP stream alive for in seconds
     $duration = bp_rbe_get_execution_time();
     bp_rbe_log('--- Keep alive for ' . $duration / 60 . ' minutes ---');
     bp_rbe_remove_imap_lock();
     // Mark the current timestamp, mark the future time when we should close the IMAP connection;
     // Do our parsing until $future > $now; re-mark the timestamp at end of loop... rinse and repeat!
     for ($now = time(), $future = time() + $duration; $future > $now; $now = time()) {
         // Get number of messages
         $message_count = imap_num_msg($this->connection);
         // If there are messages in the inbox, let's start parsing!
         if ($message_count != 0) {
             // According to this:
             // http://www.php.net/manual/pl/function.imap-headerinfo.php#95012
             // This speeds up rendering the email headers... could be wrong
             imap_headers($this->connection);
             bp_rbe_log('- Checking inbox -');
             // Loop through each email message
             for ($i = 1; $i <= $message_count; ++$i) {
                 // flush object cache if necessary
                 //
                 // we only flush the cache if the default object cache is in use
                 // why? b/c the default object cache is only meant for single page loads and
                 // since RBE runs in the background, we need to flush the object cache so WP
                 // will do a direct DB query for the next data fetch
                 if (!wp_using_ext_object_cache()) {
                     wp_cache_flush();
                 }
                 self::$html = false;
                 $content = self::body_parser($this->connection, $i);
                 $headers = $this->get_mail_headers($this->connection, $i);
                 $data = array('headers' => $headers, 'to_email' => BP_Reply_By_Email_Parser::get_header($headers, 'To'), 'from_email' => BP_Reply_By_Email_Parser::get_header($headers, 'From'), 'content' => $content, 'is_html' => self::$html, 'subject' => imap_utf8(BP_Reply_By_Email_Parser::get_header($headers, 'Subject')));
                 $parser = BP_Reply_By_Email_Parser::init($data, $i);
                 if (is_wp_error($parser)) {
                     //do_action( 'bp_rbe_imap_no_match', $this->connection, $i, $headers, $parser->get_error_code() );
                     do_action('bp_rbe_no_match', $parser, $data, $i, $this->connection);
                 }
                 // do something during the loop
                 // we mark the message for deletion here via this hook
                 do_action('bp_rbe_imap_loop', $this->connection, $i);
                 // unset some variables at the end of the loop
                 unset($content, $headers, $data, $parser);
             }
             // do something after the loop
             do_action('bp_rbe_imap_after_loop', $this->connection);
         }
         // stop the loop if necessary
         if (bp_rbe_should_stop()) {
             if ($this->close()) {
                 bp_rbe_log('--- Manual termination of connection confirmed! Kaching! ---');
             } else {
                 bp_rbe_log('--- Error - invalid connection during manual termination ---');
             }
             remove_action('shutdown', 'bp_rbe_spawn_inbox_check');
             exit;
         }
         // Give IMAP server a break
         sleep(10);
         // If the IMAP connection is down, reconnect
         if (!imap_ping($this->connection)) {
             bp_rbe_log('-- IMAP connection is down, attempting to reconnect... --');
             if (bp_rbe_is_connecting(array('clearcache' => true))) {
                 bp_rbe_log('--- RBE is already attempting to connect - stopping connection attempt ---');
                 continue;
             }
             // add lock marker before connecting
             bp_rbe_add_imap_lock();
             // attempt to reconnect
             $reopen = BP_Reply_By_Email_Connect::init(array('reconnect' => true), $this->connection);
             if ($reopen) {
                 bp_rbe_log('-- Reconnection successful! --');
             } else {
                 bp_rbe_log('-- Reconnection failed! :( --');
                 bp_rbe_log('Cannot connect: ' . imap_last_error());
                 // cleanup RBE after failure
                 bp_rbe_cleanup();
                 remove_action('shutdown', 'bp_rbe_spawn_inbox_check');
                 exit;
             }
         }
         // Unset some variables to clear some memory
         unset($message_count);
     }
     if ($this->close()) {
         bp_rbe_log('--- Closing current connection automatically ---');
     } else {
         bp_rbe_log('--- Invalid connection during close time ---');
     }
     // autoconnect is off
     if (1 !== (int) bp_rbe_get_setting('keepaliveauto', array('refetch' => true))) {
         remove_action('shutdown', 'bp_rbe_spawn_inbox_check');
         // sleep a bit before autoconnecting again
     } else {
         sleep(5);
     }
     exit;
 }
Esempio n. 13
0
 protected function check_mailbox()
 {
     imap_ping($this->conn);
     $count = imap_num_msg($this->conn);
     common_log(LOG_INFO, "Found {$count} messages");
     if ($count > 0) {
         $handler = new IMAPMailHandler();
         for ($i = 1; $i <= $count; $i++) {
             $rawmessage = imap_fetchheader($this->conn, $count, FT_PREFETCHTEXT) . imap_body($this->conn, $i);
             $handler->handle_message($rawmessage);
             imap_delete($this->conn, $i);
         }
         imap_expunge($this->conn);
         common_log(LOG_INFO, "Finished processing messages");
     }
     return $count;
 }
Esempio n. 14
0
 /**
  * prüft, ob die Connection noch aktiv ist, Exception falls keine Connection definiert ist,
  * oder die Connection geschlossen wurde
  * wenn reconnect = true, dann wird bei einer geschlossenen Connection die Connection neu aufgebaut
  * @param boolean $reconnect
  * @return boolean
  */
 public function imapPing($reconnect = false)
 {
     if ($this->imap === null) {
         throw new IMAPException(__METHOD__ . ' not connected');
     }
     $ret = imap_ping($this->imap);
     if ($ret === false) {
         if ($reconnect === true) {
             $this->imap = $this->imapOpen($this->server . $this->mbox, $this->config->username, $this->config->password, OP_HALFOPEN);
             $ret = imap_ping($this->imap);
             if ($ret === false) {
                 throw new IMAPException(__METHOD__ . ' reconnect failed');
             }
             $this->reopenedConnection = true;
         } else {
             throw new IMAPException(__METHOD__ . ' not connected');
         }
     }
     return true;
 }
Esempio n. 15
0
 public function ping()
 {
     if ($this->closed) {
         return true;
     }
     imap_ping($this->resource);
 }
Esempio n. 16
0
 /**
  * Checks to see if the connection is alive. If not, reconnects to server.
  *
  * @return (empty)
  */
 function tickle($inbox)
 {
     if (!imap_ping($inbox)) {
         $this->reconnect;
     }
 }
Esempio n. 17
0
 /**
  * Public method to ping the server in order to keep the connection alive
  * If the server has disconnected, it will reconnect, else return the connection true
  *
  * @access public
  * @param void
  * @return unknown
  */
 public function pingServer()
 {
     if (!imap_ping($this->conn)) {
         return $this->connect();
     } else {
         return TRUE;
     }
 }
Esempio n. 18
0
if (!is_object($boxinfo) || !isset($boxinfo->Nmsgs)) {
    die("COULD NOT GET MAILBOX INFO\r\n");
}
if ($boxinfo->Driver != 'imap') {
    die("THIS SCRIPT HAS ONLY BEEN TESTED WITH IMAP MAILBOXES\r\n");
}
if ($boxinfo->Nmsgs < 1) {
    die("NO NEW MESSAGES\r\n");
}
echo "Fetching {$boxinfo->Mailbox}\r\n";
echo "{$boxinfo->Nmsgs} messages, {$boxinfo->Recent} recent\r\n";
// Helps clean up the mailbox, especially if a desktop client is interracting with it also
imap_expunge($mbox);
foreach ((array) imap_sort($mbox, SORTARRIVAL, 1) as $message_id) {
    // Detect a disconnect...
    if (!imap_ping($mbox)) {
        die("REMOTE IMAP SERVER HAS GONE AWAY\r\n");
    }
    // Fetch this message, fix the line endings, this makes a 1:1 copy of the message in ram
    // that, in my tests, matches the filesystem copy of the message on the imap server
    // ( tested with debian / postfix / dovecot )
    $r = processmail(str_replace("\r\n", "\n", imap_fetchheader($mbox, $message_id, FT_INTERNAL) . imap_body($mbox, $message_id)));
    // stop when we reach the first duplicate
    if (!$r) {
        break;
    }
    echo '.';
    imap_setflag_full($mbox, $message_id, '\\SEEN');
    continue;
    #imap_delete( $mbox, $message_id );
}
Esempio n. 19
0
 /**
  * This function creates or reopens an imapStream when called.
  *
  */
 protected function setImapStream()
 {
     if (is_resource($this->imapStream) && imap_ping($this->imapStream)) {
         if (!imap_reopen($this->imapStream, $this->getServerString(), $this->options, 1)) {
             throw new \RuntimeException(imap_last_error());
         }
     } else {
         $imapStream = @imap_open($this->getServerString(), $this->username, $this->password, $this->options, 1, $this->params);
         if ($imapStream === false) {
             throw new \RuntimeException(imap_last_error());
         }
         $this->imapStream = $imapStream;
     }
 }
Esempio n. 20
0
 /**
  * Reconnect IMAP connection if needed
  *
  * @access private
  */
 private function imap_reconnect()
 {
     if ($this->mbox) {
         imap_ping($this->mbox);
     } else {
         $this->mbox = @imap_open($this->server, $this->username, $this->password, OP_HALFOPEN);
         $this->mboxFolder = "";
     }
 }
 function noop_ping_test($stream)
 {
     return imap_ping($stream);
 }
Esempio n. 22
0
 /**
 	Just pings the connection
 */
 function ping()
 {
     // $this->_open();
     return imap_ping($this->_c);
 }
Esempio n. 23
0
File: Imap.php Progetto: drvup/Imap
 /**
  * Checks to see if the connection to the imap server is still alive. 
  */
 private function isConnectionAlive()
 {
     $conn = imap_ping($this->mailbox);
     if ($conn) {
         return true;
     } else {
         return false;
     }
 }
Esempio n. 24
0
 function ping()
 {
     return $this->mbox && imap_ping($this->mbox);
 }
Esempio n. 25
0
 public function isOpen()
 {
     return $this->_open === true && is_resource($this->_imapStream) && imap_ping($this->_imapStream);
 }
Esempio n. 26
0
 /**
  * Connects to mailserver.  If an existing IMAP resource is available, it
  * will attempt to reuse the connection, updating the mailbox path.
  *
  * @param bool test Flag to test connection
  * @param bool force Force reconnect
  * @return string "true" on success, "false" or $errorMessage on failure
  */
 function connectMailserver($test = false, $force = false)
 {
     global $mod_strings;
     if (!function_exists("imap_open")) {
         $GLOBALS['log']->debug('------------------------- IMAP libraries NOT available!!!! die()ing thread.----');
         return $mod_strings['LBL_WARN_NO_IMAP'];
     }
     imap_errors();
     // clearing error stack
     error_reporting(0);
     // turn off notices from IMAP
     // tls::ca::ssl::protocol::novalidate-cert::notls
     $useSsl = $_REQUEST['ssl'] == 'true' ? true : false;
     if ($test) {
         imap_timeout(1, 15);
         // 60 secs is the default
         imap_timeout(2, 15);
         imap_timeout(3, 15);
         $opts = $this->findOptimumSettings($useSsl);
         if (isset($opts['good']) && empty($opts['good'])) {
             return array_pop($opts['err']);
         } else {
             $service = $opts['service'];
             $service = str_replace('foo', '', $service);
             // foo there to support no-item explodes
         }
     } else {
         $service = $this->getServiceString();
     }
     $connectString = $this->getConnectString($service, $this->mailbox);
     /*
      * Try to recycle the current connection to reduce response times
      */
     if (is_resource($this->conn)) {
         if ($force) {
             // force disconnect
             imap_close($this->conn);
         }
         if (imap_ping($this->conn)) {
             // we have a live connection
             imap_reopen($this->conn, $connectString, CL_EXPUNGE);
         }
     }
     // final test
     if (!is_resource($this->conn) && !$test) {
         $this->conn = imap_open($connectString, $this->email_user, $this->email_password, CL_EXPUNGE);
     }
     if ($test) {
         if ($opts == false && !is_resource($this->conn)) {
             $this->conn = imap_open($connectString, $this->email_user, $this->email_password, CL_EXPUNGE);
         }
         $errors = '';
         $alerts = '';
         $successful = false;
         if (($errors = imap_last_error()) || ($alerts = imap_alerts())) {
             if ($errors == 'Mailbox is empty') {
                 // false positive
                 $successful = true;
             } else {
                 $msg .= $errors;
                 $msg .= '<p>' . $alerts . '<p>';
                 $msg .= '<p>' . $mod_strings['ERR_TEST_MAILBOX'];
             }
         } else {
             $successful = true;
         }
         if ($successful) {
             if ($this->protocol == 'imap') {
                 $msg .= $mod_strings['LBL_TEST_SUCCESSFUL'];
                 /*
                 $testConnectString = '{'.$this->server_url.':'.$this->port.'/service='.$this->protocol.$service.'}';
                 if (!is_resource($this->conn)) {
                 	$this->conn = imap_open($connectString, $this->email_user, $this->email_password, CL_EXPUNGE);
                 }
                 $list = imap_getmailboxes($this->conn, $testConnectString, "*");
                 if(isset($_REQUEST['personal']) && $_REQUEST['personal'] == 'true') {
                 	$msg .= $mod_strings['LBL_TEST_SUCCESSFUL'];
                 } elseif (is_array($list)) {
                 	sort($list);
                 	_ppd($boxes);
                 
                 	$msg .= '<b>'.$mod_strings['LBL_FOUND_MAILBOXES'].'</b><p>';
                 	foreach ($list as $key => $val) {
                 		$mb = imap_utf7_decode(str_replace($testConnectString,'',$val->name));
                 		$msg .= '<a onClick=\'setMailbox(\"'.$mb.'\"); window.close();\'>';
                 		$msg .= $mb;
                 		$msg .= '</a><br>';
                 	}
                 } else {
                 	$msg .= $errors;
                 	$msg .= '<p>'.$mod_strings['ERR_MAILBOX_FAIL'].imap_last_error().'</p>';
                 	$msg .= '<p>'.$mod_strings['ERR_TEST_MAILBOX'].'</p>';
                 }
                 */
             } else {
                 $msg .= $mod_strings['LBL_POP3_SUCCESS'];
             }
         }
         imap_errors();
         // collapse error stack
         imap_close($this->conn);
         return $msg;
     } elseif (!is_resource($this->conn)) {
         return "false";
     } else {
         return "true";
     }
 }
Esempio n. 27
0
 /**
  * @return bool
  */
 public function isAlive()
 {
     return (bool) @imap_ping($this->imap);
 }