예제 #1
0
/* SOAP_Server_Email */
require_once 'SOAP/Server/Email.php';
/* Include a class to access POP3. */
require_once 'Net/POP3.php';
/* Create the SOAP Server object. */
$server = new SOAP_Server_Email();
/* Tell the server to translate to classes we provide if possible. */
$server->_auto_translation = true;
require_once './example_server.php';
$soapclass = new SOAP_Example_Server();
$server->addObjectMap($soapclass, 'urn:SOAP_Example_Server');
/* Connect to a POP3 server and read the messages. */
$pop3 = new Net_POP3();
if ($pop3->connect('localhost', 110)) {
    if ($pop3->login('username', 'password')) {
        $listing = $pop3->getListing();
        /* Now loop through each message, and call the SOAP server with that
         * message. */
        foreach ($listing as $msg) {
            $email = $pop3->getMsg($msg['msg_id']);
            /* This is where we actually handle the SOAP response.  The
             * SOAP_Server_Email class we are using will send the SOAP
             * response to the sender via email. */
            if ($email) {
                $server->client($email);
                $pop3->deleteMsg($msg['msg_id']);
            }
        }
    }
    $pop3->disconnect();
}
 function deleteMailsFromServer(MailAccount $account)
 {
     $count = 0;
     if ($account->getDelFromServer() > 0) {
         $max_date = DateTimeValueLib::now();
         $max_date->add('d', -1 * $account->getDelFromServer());
         if ($account->getIsImap()) {
             if ($account->getIncomingSsl()) {
                 $imap = new Net_IMAP($ret, "ssl://" . $account->getServer(), $account->getIncomingSslPort());
             } else {
                 $imap = new Net_IMAP($ret, "tcp://" . $account->getServer());
             }
             if (PEAR::isError($ret)) {
                 Logger::log($ret->getMessage());
                 throw new Exception($ret->getMessage());
             }
             $ret = $imap->login($account->getEmail(), self::ENCRYPT_DECRYPT($account->getPassword()));
             $result = array();
             if ($ret === true) {
                 $mailboxes = MailAccountImapFolders::getMailAccountImapFolders($account->getId());
                 if (is_array($mailboxes)) {
                     foreach ($mailboxes as $box) {
                         if ($box->getCheckFolder()) {
                             $numMessages = $imap->getNumberOfMessages(utf8_decode($box->getFolderName()));
                             for ($i = 1; $i <= $numMessages; $i++) {
                                 $summary = $imap->getSummary($i);
                                 if (is_array($summary)) {
                                     $m_date = DateTimeValueLib::makeFromString($summary[0]['INTERNALDATE']);
                                     if ($m_date instanceof DateTimeValue && $max_date->getTimestamp() > $m_date->getTimestamp()) {
                                         if (MailContents::mailRecordExists($account->getId(), $summary[0]['UID'], $box->getFolderName(), null)) {
                                             $imap->deleteMessages($i);
                                             $count++;
                                         }
                                     } else {
                                         break;
                                     }
                                 }
                             }
                             $imap->expunge();
                         }
                     }
                 }
             }
         } else {
             //require_once "Net/POP3.php";
             $pop3 = new Net_POP3();
             // Connect to mail server
             if ($account->getIncomingSsl()) {
                 $pop3->connect("ssl://" . $account->getServer(), $account->getIncomingSslPort());
             } else {
                 $pop3->connect($account->getServer());
             }
             if (PEAR::isError($ret = $pop3->login($account->getEmail(), self::ENCRYPT_DECRYPT($account->getPassword()), 'USER'))) {
                 throw new Exception($ret->getMessage());
             }
             $emails = $pop3->getListing();
             foreach ($emails as $email) {
                 if (MailContents::mailRecordExists($account->getId(), $email['uidl'], null, null)) {
                     $headers = $pop3->getParsedHeaders($email['msg_id']);
                     $date = DateTimeValueLib::makeFromString(array_var($headers, 'Date'));
                     if ($date instanceof DateTimeValue && $max_date->getTimestamp() > $date->getTimestamp()) {
                         $pop3->deleteMsg($email['msg_id']);
                         $count++;
                     }
                 }
             }
             $pop3->disconnect();
         }
     }
     return $count;
 }
예제 #3
0
 function execute()
 {
     global $PIVOTX;
     if (!$this->active) {
         return;
     }
     $messages[] = "Checking email..";
     // Create the class and fetch the list of available emails..
     if ($this->cfg['use_imap']) {
         $mail = new Mail();
         $protocol = strtolower(substr($this->cfg['imap_protocol'], 0, 4));
         if (str_replace($protocol, '', $this->cfg['imap_protocol']) == 's') {
             $secure = true;
         } else {
             $secure = false;
         }
         $server = array('type' => $protocol, 'server' => $this->cfg['server'], 'secure' => $secure, 'mailbox' => $this->cfg['imap_mailbox'], 'username' => $this->cfg['username'], 'password' => $this->cfg['password']);
         if (!$mail->connect($server)) {
             debug("Moblog: No connection (using IMAP extension).");
             exit(1);
         } else {
             $messages[] = "Moblog: OK connection (using IMAP extension).\n";
         }
         $mail->parse_messages();
         if (is_array($mail->messages)) {
             $listing = $mail->messages;
         } else {
             $listing = array();
         }
     } else {
         $pop3 = new Net_POP3();
         $ret = $pop3->connect($this->cfg['server'], $this->cfg['pop_port']);
         if (!$ret) {
             debug("Moblog: No connection.");
             exit(1);
         } elseif (PEAR::isError($ret = $pop3->login($this->cfg['username'], $this->cfg['password'], 'USER'))) {
             debug("Moblog: error logging in: " . $ret->getMessage());
             exit(1);
         } else {
             $messages[] = "Moblog: OK connection.\n";
         }
         $listing = $pop3->getListing();
     }
     $messages[] = count($listing) . " email found on the server.";
     $regen = false;
     // Then we iterate through the list..
     foreach ($listing as $list_item) {
         if ($this->cfg['use_imap']) {
             $msg_id = $list_item['message_id'];
             $email = $list_item['rawdata'];
         } else {
             $msg_id = $list_item['msg_id'];
             $email = $pop3->getMsg($msg_id);
         }
         $messages[] = "fetched mail {$msg_id}";
         if (!$this->cfg['leave_on_server']) {
             if ($this->cfg['use_imap']) {
                 $mail->delete($list_item['msgno']);
             } else {
                 $pop3->deleteMsg($msg_id);
             }
             $messages[] = "Message was deleted from the server..";
         } else {
             $messages[] = "Message was left on the server (if supported)..";
         }
         // Perhaps save a local copy..
         if ($this->cfg['save_mail']) {
             $maildir = $PIVOTX['paths']['db_path'] . 'mail/';
             if (!file_exists($maildir)) {
                 makeDir($maildir);
             }
             $msg_id = str_replace(array('<', '>'), '', $msg_id);
             $filename = $maildir . date("Ymd-His") . "-" . $msg_id . ".eml";
             if ($fp = fopen($filename, "w")) {
                 fwrite($fp, $email);
                 $messages[] = "Local copy saved as: {$filename}";
                 fclose($fp);
             } else {
                 $messages[] = "Alas! Woe is me! I couldn't save a local copy.";
             }
         }
         $this->entry = array();
         // Parse and post the email..
         $this->parse_email($email);
         $messages[] = $this->compose_entry();
         $regen = true;
     }
     if ($this->cfg['use_imap']) {
         $mail->close();
     } else {
         $pop3->disconnect();
     }
     if ($regen) {
         // Clear cache?
         // $messages[] = "Cleared cache after adding new moblog entry";
     }
     $messages[] = "Done!";
     return $messages;
 }