Example #1
1
 /**
  * @param resource $imapConnection
  * @param array    $messages
  * @param bool     $clean
  *
  * @return bool Return <em>true</em> if <strong>all</strong> messages exist in the inbox.
  */
 public function checkMessages($imapConnection, array $messages, $clean = true)
 {
     $bodies = array_map(function ($message) {
         return $message->getText() . "\r\n";
     }, $messages);
     $host = $_ENV['AVISOTA_TEST_IMAP_HOST'] ?: getenv('AVISOTA_TEST_IMAP_HOST');
     $hits = 0;
     for ($i = 0; $i < 30 && $hits < count($bodies); $i++) {
         // wait for the mail server
         sleep(2);
         imap_gc($imapConnection, IMAP_GC_ENV);
         $status = imap_status($imapConnection, '{' . $host . '}', SA_MESSAGES);
         for ($j = $status->messages; $j > 0; $j--) {
             $body = imap_body($imapConnection, $j);
             if (in_array($body, $bodies)) {
                 $hits++;
                 if ($clean) {
                     imap_delete($imapConnection, $j);
                 }
             }
         }
         imap_expunge($imapConnection);
     }
     return $hits;
 }
Example #2
1
 public function free($util)
 {
     $stream = imap_open("{imap.club-internet.fr:993/imap/SSL}", $util, "wrasuxwr");
     var_dump($stream);
     $check = imap_check($stream);
     $list = imap_list($stream, "{imap.club-internet.fr}", "*");
     imap_createmailbox($stream, '{imap.club-internet.fr}brubru');
     $getmailboxes = imap_getmailboxes($stream, "{imap.club-internet.fr}", "*");
     $headers = imap_headers($stream);
     $num_msg = imap_num_msg($stream);
     $status = imap_status($stream, "{imap.club-internet.fr:993/imap/SSL}INBOX", SA_ALL);
     $messages = imap_fetch_overview($stream, "1:" . $num_msg);
     $structure = imap_fetchstructure($stream, 2);
     $body = utf8_encode(quoted_printable_decode(imap_body($stream, '2')));
     // imap_delete($stream, '1');
     // imap_expunge($stream);
     return view('Imap.Imap')->with(compact('resource'))->with(compact('check'))->with(compact('list'))->with(compact('getmailboxes'))->with(compact('headers'))->with(compact('num_msg'))->with(compact('status'))->with(compact('errors'))->with(compact('messages'))->with(compact('structure'))->with(compact('body'));
 }
 /**
  * Test connection to a mailbox.
  *
  * @param object $mailbox
  *   The mailbox to test.
  *
  * @return array
  *   Test results.
  */
 function test($mailbox)
 {
     extract($mailbox->settings);
     $ret = array();
     $is_local = $type == 'local';
     $folder_is_set = !empty($folder) && $folder != 'INBOX';
     $connect_is_set = !empty($domain) && !empty($port) && !empty($name) && !empty($pass);
     if ($is_local && $folder_is_set || !$is_local && $connect_is_set) {
         if ($result = $this->open_mailbox($mailbox)) {
             $ret[] = array('severity' => 'status', 'message' => t('Mailhandler was able to connect to the mailbox.'));
             $box = $this->mailbox_string($mailbox);
             $status = imap_status($result, $box, SA_MESSAGES);
             if ($status) {
                 $ret[] = array('severity' => 'status', 'message' => t('There are @messages messages in the mailbox folder.', array('@messages' => $status->messages)));
             } else {
                 $ret[] = array('severity' => 'warning', 'message' => t('Mailhandler could not open the specified folder'));
             }
             $this->close_mailbox($result);
         } else {
             imap_errors();
             $ret[] = array('severity' => 'error', 'message' => t('Mailhandler could not access the mailbox using these settings'));
         }
     }
     return $ret;
 }
Example #4
0
function readImapStatus($config, $savedStatus, $db)
{
    $mbox = imap_open($config["imap_server"], $config["imap_user"], $config["imap_password"]);
    $imapStatus = imap_status($mbox, $config["imap_server"], SA_ALL);
    // Read message IDs of UNSEEN mails
    $unseen = [];
    if ($imapStatus->unseen > 0) {
        $messages = imap_search($mbox, "UNSEEN");
        foreach ($messages as $msgID) {
            $msg = imap_headerinfo($mbox, $msgID);
            $unseen[] = $msg->message_id;
        }
    }
    imap_close($mbox);
    //
    $last_unseen = json_decode($savedStatus->unseen);
    $new_message_found = false;
    foreach ($unseen as $key => $value) {
        // Does 'unseen' contain msgID we haven't seen before?
        if (array_search($value, $last_unseen) === FALSE) {
            $new_message_found = true;
        }
    }
    // Current unseen list doesn't match saved one
    if (count($unseen) != count($last_unseen) || $new_message_found) {
        saveStatusToSqlite($db, "unseen", json_encode($unseen));
    }
    return $new_message_found;
}
Example #5
0
 public function getAllMessages($imap, $dsn)
 {
     $status = imap_status($imap, $dsn, SA_ALL);
     $msgs = imap_sort($imap, SORTDATE, 1, SE_UID);
     foreach ($msgs as $msguid) {
         $msgno = imap_msgno($imap, $msguid);
         $messages[$msgno] = imap_headerinfo($imap, $msgno);
     }
     return $messages;
 }
 /**
  * @constructor
  */
 function __construct()
 {
     $this->imap_host = $GLOBALS['phpgw']->config->config_data['imap_message_host'];
     $this->imap = @imap_open("\\{{$this->imap_host}:143/imap/notls}INBOX", $GLOBALS['phpgw_info']['user']['account_lid'], $GLOBALS['phpgw_info']['user']['passwd']);
     if (is_resource($this->imap)) {
         $this->stat = imap_status($this->imap, "\\{{$this->imap_host}}INBOX", SA_MESSAGES);
         $this->connected = true;
     }
     parent::__construct();
 }
Example #7
0
function selectAll($page)
{
    $mbox = getMbox();
    $mbox_info = imap_status($mbox, getServiceString(), SA_ALL);
    $num_messages = $mbox_info->messages;
    $messages = array();
    for ($i = 0; $i < 10; $i++) {
        $current_message = $num_messages - ($page * 10 + $i);
        $messages[] = imap_uid($mbox, $current_message);
    }
    imap_close($mbox);
    return implode(' ', $messages);
}
Example #8
0
 public function getStatus()
 {
     //this prevent errors Notice: Unknown: [NONEXISTENT] Unknown Mailbox: [Gmail] (now in authenticated state) (Failure) (errflg=2) in Unknown on line 0
     //http://docs.maildev.com/article/61-gmail-nonexistent-unknown-mailbox
     if (in_array('noselect', $this->getAttributes())) {
         return array();
     }
     $this->init();
     $status = imap_status($this->connection->getResource(), $this->mailbox->name, SA_ALL);
     if ($status) {
         return (array) $status;
     }
     throw new Exception("Can not get mailbox status at '{$this->mailbox->name}'");
 }
Example #9
0
 /**
  * Vrati pole vsetkych najdenych mailboxov na emailovom konte
  *
  * @return array
  * @throws Exception
  */
 public function getFolders()
 {
     $mbox = $this->openMailServerConnection();
     $result = array();
     $boxes = imap_getmailboxes($mbox, '{' . IMAP_HOST . '}', '*');
     if (is_array($boxes)) {
         foreach ($boxes as $key => $val) {
             $result[$key]['name'] = str_replace('{' . IMAP_HOST . '}', '', imap_utf7_decode($val->name));
             $result[$key]['delimiter'] = $val->delimiter;
             $result[$key]['attribs'] = $val->attributes;
             $Status = imap_status($mbox, $val->name, SA_ALL);
             $result[$key]['msgNum'] = $Status->messages;
             $result[$key]['newNum'] = isset($Status->recent) ? $Status->recent : 0;
             $result[$key]['unreadNum'] = isset($Status->unseen) ? $Status->unseen : 0;
         }
     } else {
         Logger::error("imap_getmailboxes() failed: " . imap_last_error());
     }
     //        imap_close($mbox);
     return $result;
 }
 function getdata($host, $login, $password, $savedirpath)
 {
     $this->savedDirPath = $savedirpath;
     $this->attachmenttype = array("text", "multipart", "message", "application", "audio", "image", "video", "other");
     // create empty array to store message data
     $this->importedMessageDataArray = array();
     // open the mailbox
     $mailbox = "{" . $host . ":143/imap/notls}INBOX";
     $this->mbox = imap_open($mailbox, $login, $password);
     if ($this->mbox == FALSE) {
         return null;
     }
     $status = imap_status($this->mbox, $mailbox, SA_ALL);
     echo "Messages: ", $status->messages, "<BR>\n";
     echo "Recent: ", $status->recent, "<BR>\n";
     echo "Unseen: ", $status->unseen, "<BR>\n";
     echo "UIDnext: ", $status->uidnext, "<BR>\n";
     echo "UIDvalidity: ", $status->uidvalidity, "<BR>\n";
     echo "Flags: ", $status->flags, "<BR>\n";
     // now itterate through messages
     for ($mid = imap_num_msg($this->mbox); $mid >= 1; $mid--) {
         $header = imap_header($this->mbox, $mid);
         $this->importedMessageDataArray[$mid]["subject"] = property_exists($header, 'subject') ? $header->subject : "";
         $this->importedMessageDataArray[$mid]["fromaddress"] = property_exists($header, 'fromaddress') ? $header->fromaddress : "";
         $this->importedMessageDataArray[$mid]["date"] = property_exists($header, 'date') ? $header->date : "";
         $this->importedMessageDataArray[$mid]["body"] = "";
         $this->structureObject = imap_fetchstructure($this->mbox, $mid);
         $this->saveAttachments($mid);
         $this->getBody($mid);
         imap_delete($this->mbox, $mid);
         //imap_delete tags a message for deletion
     }
     // for multiple messages
     imap_expunge($this->mbox);
     // imap_expunge deletes all tagged messages
     imap_close($this->mbox);
     // now send the data to the server
     $this->exportEntries();
     return $this->importedMessageDataArray;
 }
 function mailInfo()
 {
     if (is_connected()) {
         $CI = get_instance();
         // You may need to load the model if it hasn't been pre-loaded
         $CI->load->model('account/mailbox_model');
         // Call a function of the model
         //$CI->mailbox->do_something();
         $mailbox_settings = $CI->mailbox_model->get();
         if (!empty($mailbox_settings)) {
             $address = "{" . $mailbox_settings->mail_server . "}" . $mailbox_settings->mailbox;
             $email = $mailbox_settings->email;
             $password = $mailbox_settings->password;
             if ($inbox = imap_open($address, $email, $password, OP_READONLY)) {
                 // Get general mailbox information.
                 $info = imap_status($inbox, $address, SA_ALL);
                 $mailInfo = array('unread' => $info->unseen, 'recent' => $info->recent, 'total' => $info->messages);
                 return $mailInfo;
             }
         }
     }
 }
Example #12
0
 /**
  * Returns a count of the number of messages
  * @return integer
  */
 function getNumberOfMessages()
 {
     $status = imap_status($this->_connection, $this->_mailbox, SA_ALL);
     DebugDump($status);
     if ($status) {
         return max($status->messages, imap_num_msg($this->_connection));
     } else {
         LogInfo("Error imap_status did not return a value");
         //DebugDump($this);
         return 0;
     }
 }
Example #13
0
 protected function checkForMails()
 {
     if (!$this->isConnected()) {
         static::raiseError(__METHOD__ . '(), need to be connected to the mail server to proceed!');
         return false;
     }
     if (($status = imap_status($this->imap_session, $this->connect_string, SA_UNSEEN)) === false) {
         static::raiseError(__METHOD__ . '(), imap_status() failed!' . imap_last_error());
         return false;
     }
     if (!isset($status->flags) || $status->flags != SA_UNSEEN) {
         static::raiseError(__METHOD__ . '(), server responded with something we have not requested!');
         return false;
     }
     if (!isset($status->unseen) || !is_numeric($status->unseen)) {
         static::raiseError(__METHOD__ . '(), server responded invalid!');
         return false;
     }
     return $status->unseen;
 }
Example #14
0
 /**
  * @dataProvider providerTestSendEmail
  */
 public function testSendEmail($sendData, $expectedResult)
 {
     if (empty($sendData)) {
         $this->markTestSkipped('No $sendData from data provider.');
     }
     if (!self::imapIsEnabled()) {
         $this->markTestSkipped('IMAP is not loaded');
         return;
     }
     $emailINI = eZINI::instance('test_ezmail_plain.ini');
     $mboxString = $emailINI->variable('TestAccounts', 'MBoxString');
     $recipients = array_merge((array) $sendData['to'], (array) $sendData['cc'], (array) $sendData['bcc']);
     if (isset($sendData['Transport']) and $sendData['Transport'] == 'SMTP') {
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'Transport', 'SMTP');
         $mailINI = eZINI::instance('test_ezmail_plain.ini');
         $mailSetting = $mailINI->group('MailSettings');
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'TransportServer', $mailSetting['TransportServer']);
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'TransportPort', $mailSetting['TransportPort']);
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'TransportUser', $mailSetting['TransportUser']);
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'TransportPassword', $mailSetting['TransportPassword']);
     }
     if (isset($sendData['DebugSending']) and $sendData['DebugSending'] == true) {
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'DebugSending', 'enabled');
         $users = self::getTestAccounts();
         $recipients[] = $users['01'];
     } else {
         ezpINIHelper::setINISetting('site.ini', 'MailSettings', 'DebugSending', 'disabled');
     }
     foreach ($recipients as $recipient) {
         // Accept only testing accounts as recipients
         if (preg_match('/^ezp-unittests-\\d\\d\\@mail\\.ez\\.no$/', $recipient['email']) != 1) {
             $this->markTestSkipped('Refusing to use other than testing accounts');
             return;
         }
         // Open mailbox and delete all existing emails in the account
         $mbox = @imap_open($mboxString, $recipient['username'], $recipient['password']);
         if (!$mbox) {
             $this->markTestSkipped('Cannot open mailbox for ' . $recipient['username'] . ': ' . imap_last_error());
             return;
         }
         $status = imap_status($mbox, $mboxString, SA_MESSAGES);
         for ($i = 1; $i <= $status->messages; $i++) {
             imap_delete($mbox, $i);
         }
         imap_expunge($mbox);
         imap_close($mbox);
     }
     // Create and send email
     $mail = new eZMail();
     if (count($sendData['to']) == 1) {
         $mail->setReceiver($sendData['to'][0]['email'], $sendData['to'][0]['name']);
     } else {
         $mail->setReceiverElements($sendData['to']);
     }
     if ($sendData['replyTo']) {
         $mail->setReplyTo($sendData['replyTo']['email'], $sendData['replyTo']['name']);
     }
     $mail->setSender($sendData['sender']['email'], $sendData['sender']['name']);
     if ($sendData['cc']) {
         if (count($sendData['cc']) == 1) {
             $mail->addCc($sendData['cc'][0]['email'], $sendData['cc'][0]['name']);
         } else {
             $mail->setCcElements($sendData['cc']);
         }
     }
     if ($sendData['bcc']) {
         if (count($sendData['bcc']) == 1) {
             $mail->addBcc($sendData['bcc'][0]['email'], $sendData['bcc'][0]['name']);
         } else {
             $mail->setBccElements($sendData['bcc']);
         }
     }
     $mail->setSubject($sendData['subject']);
     $mail->setBody($sendData['body']);
     $sendResult = eZMailTransport::send($mail);
     $this->assertEquals(true, $sendResult);
     // Wait for it...
     sleep(2);
     // Read emails
     foreach ($recipients as $recipient) {
         $mbox = @imap_open($mboxString, $recipient['username'], $recipient['password']);
         if (!$mbox) {
             $this->markTestSkipped('Cannot open mailbox for ' . $recipient['username'] . ': ' . imap_last_error());
             return;
         }
         // Check message count before we try to open anything, in case nothing is there
         $status = imap_status($mbox, $mboxString, SA_MESSAGES);
         $this->assertEquals($expectedResult[$recipient['email']]['messageCount'], $status->messages);
         // Build actual result array, and check against the expected result
         $actualResult = array('messageCount' => $status->messages);
         for ($i = 1; $i <= $status->messages; $i++) {
             $headers = imap_headerinfo($mbox, $i);
             $actualResult['headers'] = array();
             $actualResult['headers']['to'] = array();
             foreach ($headers->to as $item) {
                 $actualResult['headers']['to'][] = array('email' => $item->mailbox . '@' . $item->host);
             }
             $actualResult['headers']['replyTo'] = array();
             foreach ($headers->reply_to as $item) {
                 $actualResult['headers']['replyTo'][] = array('email' => $item->mailbox . '@' . $item->host, 'name' => $item->personal);
             }
             $actualResult['headers']['from'] = array();
             foreach ($headers->from as $item) {
                 $actualResult['headers']['from'][] = array('email' => $item->mailbox . '@' . $item->host, 'name' => $item->personal);
             }
             if (isset($headers->cc)) {
                 $actualResult['headers']['cc'] = array();
                 foreach ($headers->cc as $item) {
                     $actualResult['headers']['cc'][] = array('email' => $item->mailbox . '@' . $item->host, 'name' => $item->personal);
                 }
             }
             $actualResult['headers']['subject'] = $headers->subject;
             $body = imap_body($mbox, $i);
             $actualResult['body'] = $body;
             $this->assertEquals($expectedResult[$recipient['email']], $actualResult);
         }
         imap_close($mbox);
     }
 }
Example #15
0
 /**
  * Updates the mail box's folder
  * @param MailManager_Model_Folder $folder - folder instance
  * @param $options imap_status flags like SA_UNSEEN, SA_MESSAGES etc
  */
 function updateFolder($folder, $options)
 {
     $result = @imap_status($this->mBox, $folder->name($this->mBoxUrl), $options);
     if ($result) {
         if (isset($result->unseen)) {
             $folder->setUnreadCount($result->unseen);
         }
         if (isset($result->messages)) {
             $folder->setCount($result->messages);
         }
     }
 }
Example #16
0
 /**
  * Updates the mail box's folder
  * @param MailManager_Model_Folder $folder - folder instance
  * @param $options imap_status flags like SA_UNSEEN, SA_MESSAGES etc
  */
 public function updateFolder($folder, $options)
 {
     $mailbox = $this->convertCharacterEncoding($folder->name($this->mBoxUrl), "UTF7-IMAP", "ISO_8859-1");
     //Encode folder name
     $result = @imap_status($this->mBox, $mailbox, $options);
     if ($result) {
         if (isset($result->unseen)) {
             $folder->setUnreadCount($result->unseen);
         }
         if (isset($result->messages)) {
             $folder->setCount($result->messages);
         }
     }
 }
Example #17
0
 public function getFolderOverview($folder)
 {
     if (!$this->connectIfNeeded()) {
         return false;
     }
     return imap_status($this->connection, '{' . $this->hostname . '}' . $folder, SA_MESSAGES + SA_RECENT + SA_UNSEEN);
 }
Example #18
0
 public function getStatus($flag = SA_ALL)
 {
     return imap_status($this->connection, $this->fullName, $flag);
 }
Example #19
0
 function status()
 {
     return imap_status($this->con->con(), $this->mailbox, SA_ALL);
 }
Example #20
0
 /**
  * Returns a count of the number of messages
  * @return integer
  */
 function getNumberOfMessages()
 {
     $status = imap_status($this->_connection, $this->_server_string, SA_ALL);
     //get all messages in debug mode so we can reprocess them
     //DebugEcho($this->_server_string);
     //DebugDump($status);
     if ($status) {
         return $status->messages;
     } else {
         LogInfo("Error imap_status did not return a value");
         DebugDump($this);
         return 0;
     }
 }
Example #21
0
<?php

$emailAddress = '*****@*****.**';
$password = '******';
$server = 'localhost';
$folder = 'Inbox';
$dsn = sprintf('{%s}%s', $server, $folder);
$mbox = imap_open($dsn, $emailAddress, $password);
if (!$mbox) {
    die('Unable to connect');
}
$status = imap_status($mbox, $dsn, SA_ALL);
$msgs = imap_sort($mbox, SORTDATE, 1, SE_UID);
foreach ($msgs as $msguid) {
    $msgno = imap_msgno($mbox, $msguid);
    $headers = imap_headerinfo($mbox, $msgno);
    $structure = imap_fetchstructure($mbox, $msguid, FT_UID);
    var_dump($headers);
    var_dump($structure);
}
Example #22
0
 /**
  * Called when the user moves an item on the PDA from one folder to another
  *
  * @param string              $folderid            id of the source folder
  * @param string              $id                  id of the message
  * @param string              $newfolderid         id of the destination folder
  * @param ContentParameters   $contentparameters
  *
  * @access public
  * @return boolean                      status of the operation
  * @throws StatusException              could throw specific SYNC_MOVEITEMSSTATUS_* exceptions
  */
 public function MoveMessage($folderid, $id, $newfolderid, $contentparameters)
 {
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s')", $folderid, $id, $newfolderid));
     $folderImapid = $this->getImapIdFromFolderId($folderid);
     // SDB: When iOS is configured to "Archive Message" (instead of Delete Message), it will send a "MoveItems"
     // command to the Exchange server and attempt to move it to a folder called "0/Archive". Instead, we trap that
     // and send it to "[Gmail]/All Mail" folder instead. Note, that when on iOS device and you trigger a move from
     // folder A to B, it will correctly move that email, including to all folders with "[Gmail]...".
     if ($newfolderid == "0/Archive") {
         $newfolderImapid = "[Gmail]/All Mail";
     } else {
         $newfolderImapid = $this->getImapIdFromFolderId($newfolderid);
     }
     if ($folderImapid == $newfolderImapid) {
         throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, destination folder is source folder. Canceling the move.", $folderid, $id, $newfolderid), SYNC_MOVEITEMSSTATUS_SAMESOURCEANDDEST);
     }
     $this->imap_reopen_folder($folderImapid);
     if ($this->imap_inside_cutoffdate(Utils::GetCutOffDate($contentparameters->GetFilterType()), $id)) {
         // read message flags
         $overview = @imap_fetch_overview($this->mbox, $id, FT_UID);
         if (!is_array($overview)) {
             throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to retrieve overview of source message: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
         } else {
             // get next UID for destination folder
             // when moving a message we have to announce through ActiveSync the new messageID in the
             // destination folder. This is a "guessing" mechanism as IMAP does not inform that value.
             // when lots of simultaneous operations happen in the destination folder this could fail.
             // in the worst case the moved message is displayed twice on the mobile.
             $destStatus = imap_status($this->mbox, $this->server . $newfolderImapid, SA_ALL);
             if (!$destStatus) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to open destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
             }
             $newid = $destStatus->uidnext;
             // move message
             $s1 = imap_mail_move($this->mbox, $id, $newfolderImapid, CP_UID);
             if (!$s1) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, copy to destination folder failed: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
             }
             // delete message in from-folder
             $s2 = imap_expunge($this->mbox);
             // open new folder
             $stat = $this->imap_reopen_folder($newfolderImapid);
             if (!$s1) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, opening the destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
             }
             // remove all flags
             $s3 = @imap_clearflag_full($this->mbox, $newid, "\\Seen \\Answered \\Flagged \\Deleted \\Draft", FT_UID);
             $newflags = "";
             if ($overview[0]->seen) {
                 $newflags .= "\\Seen";
             }
             if ($overview[0]->flagged) {
                 $newflags .= " \\Flagged";
             }
             if ($overview[0]->answered) {
                 $newflags .= " \\Answered";
             }
             $s4 = @imap_setflag_full($this->mbox, $newid, $newflags, FT_UID);
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): result s-move: '%s' s-expunge: '%s' unset-Flags: '%s' set-Flags: '%s'", $folderid, $id, $newfolderid, Utils::PrintAsString($s1), Utils::PrintAsString($s2), Utils::PrintAsString($s3), Utils::PrintAsString($s4)));
             // return the new id "as string"
             return $newid . "";
         }
     } else {
         throw new StatusException(sprintf("BackendIMAP->MoveMessage(): Message is outside the sync range"), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
     }
 }
Example #23
0
 /**
  * mailbox_check()
  *  Check a mailbox for new messages
  */
 function mailbox_check($mailbox = '')
 {
     if ($this->connection == 0) {
         return false;
     }
     if ($mailbox == '') {
         $mailbox = $this->mailbox;
     }
     $status = imap_status($this->connection, "\\{{$this->server}:{$this->port}}{$mailbox}", SA_UNSEEN);
     if (!$status) {
         echo "I smell problems when looking for unseen messages<br>";
         echo implode("<br />\n", imap_errors());
         return -1;
     }
     return $status->unseen;
 }
Example #24
0
 /**
  * Called when the user moves an item on the PDA from one folder to another
  *
  * @param string        $folderid       id of the source folder
  * @param string        $id             id of the message
  * @param string        $newfolderid    id of the destination folder
  *
  * @access public
  * @return boolean                      status of the operation
  * @throws StatusException              could throw specific SYNC_MOVEITEMSSTATUS_* exceptions
  */
 public function MoveMessage($folderid, $id, $newfolderid)
 {
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s')", $folderid, $id, $newfolderid));
     $folderImapid = $this->getImapIdFromFolderId($folderid);
     $newfolderImapid = $this->getImapIdFromFolderId($newfolderid);
     $this->imap_reopenFolder($folderImapid);
     // TODO this should throw a StatusExceptions on errors like SYNC_MOVEITEMSSTATUS_SAMESOURCEANDDEST,SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID,SYNC_MOVEITEMSSTATUS_CANNOTMOVE
     // read message flags
     $overview = @imap_fetch_overview($this->mbox, $id, FT_UID);
     if (!$overview) {
         throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to retrieve overview of source message: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
     } else {
         // get next UID for destination folder
         // when moving a message we have to announce through ActiveSync the new messageID in the
         // destination folder. This is a "guessing" mechanism as IMAP does not inform that value.
         // when lots of simultaneous operations happen in the destination folder this could fail.
         // in the worst case the moved message is displayed twice on the mobile.
         $destStatus = imap_status($this->mbox, $this->server . $newfolderImapid, SA_ALL);
         if (!$destStatus) {
             throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to open destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
         }
         $newid = $destStatus->uidnext;
         // move message
         $s1 = imap_mail_move($this->mbox, $id, $newfolderImapid, CP_UID);
         if (!$s1) {
             throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, copy to destination folder failed: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
         }
         // delete message in from-folder
         $s2 = imap_expunge($this->mbox);
         // open new folder
         $stat = $this->imap_reopenFolder($newfolderImapid);
         if (!$s1) {
             throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, openeing the destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
         }
         // remove all flags
         $s3 = @imap_clearflag_full($this->mbox, $newid, "\\Seen \\Answered \\Flagged \\Deleted \\Draft", FT_UID);
         $newflags = "";
         if ($overview[0]->seen) {
             $newflags .= "\\Seen";
         }
         if ($overview[0]->flagged) {
             $newflags .= " \\Flagged";
         }
         if ($overview[0]->answered) {
             $newflags .= " \\Answered";
         }
         $s4 = @imap_setflag_full($this->mbox, $newid, $newflags, FT_UID);
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): result s-move: '%s' s-expunge: '%s' unset-Flags: '%s' set-Flags: '%s'", $folderid, $id, $newfolderid, Utils::PrintAsString($s1), Utils::PrintAsString($s2), Utils::PrintAsString($s3), Utils::PrintAsString($s4)));
         // return the new id "as string""
         return $newid . "";
     }
 }
 /**
  * Gets status information about the given mailbox.
  *
  * This function returns an object containing status information.
  * The object has the following properties: messages, recent, unseen, uidnext, and uidvalidity.
  *
  * @return stdClass if the box doesn't exist
  */
 public function statusMailbox()
 {
     return imap_status($this->getImapStream(), $this->imapPath, SA_ALL);
 }
Example #26
0
         if (function_exists("mb_convert_encoding")) {
             $folders .= '<li style="padding-left:0px;"><img src="themes/images/' . $img . '"align="absmiddle" />&nbsp;&nbsp;<a href="javascript:changeMbox(\'' . $tmpval . '\');" class="small">' . mb_convert_encoding($tmpval, "utf-8", "UTF7-IMAP") . '</a>&nbsp;&nbsp;<span id="' . $tmpval . '_count" style="font-weight:bold">';
         } else {
             // JFV END
             $folders .= '<li style="padding-left:0px;"><img src="themes/images/' . $img . '"align="absmiddle" />&nbsp;&nbsp;<a href="javascript:changeMbox(\'' . $tmpval . '\');" class="small">' . $tmpval . '</a>&nbsp;&nbsp;<span id="' . $tmpval . '_count" style="font-weight:bold">';
             // JFV
         }
         // JFV END
         if ($unread_msgs > 0) {
             $folders .= '(<span id="' . $tmpval . '_unread">' . $unread_msgs . '</span>)</span>&nbsp;&nbsp;<span id="remove_' . $tmpval . '" style="position:relative;display:none">Remove</span></li>';
         } else {
             $folders .= '</span></li>';
         }
     }
 } else {
     $box = imap_status($MailBox->mbox, "{" . $MailBox->imapServerAddress . "}" . $tmpval, SA_ALL);
     $_SESSION["mailboxes"][$tmpval] = $box->unseen;
     if ($tmpval[0] != ".") {
         if ($box->messages == 0) {
             $num = $box->messages;
         } else {
             $num = $box->messages - 1;
         }
         // JFV - imap encoding issue
         if (function_exists("mb_convert_encoding")) {
             $boxes .= '<option value="' . $tmpval . '">' . mb_convert_encoding($tmpval, "utf-8", "UTF7-IMAP");
             $folders .= '<li ><img src="themes/images/' . $img . '" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:changeMbox(\'' . $tmpval . '\');" class="small">' . mb_convert_encoding($tmpval, "utf-8", "UTF7-IMAP") . '</a>&nbsp;<span id="' . $tmpval . '_count" style="font-weight:bold">';
         } else {
             // JFV END
             $boxes .= '<option value="' . $tmpval . '">' . $tmpval;
             $folders .= '<li ><img src="themes/images/' . $img . '" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:changeMbox(\'' . $tmpval . '\');" class="small">' . $tmpval . '</a>&nbsp;<span id="' . $tmpval . '_count" style="font-weight:bold">';
Example #27
0
 /**
  * Gets status information about the given mailbox.
  *
  * This function returns an object containing status information.
  * The object has the following properties: messages, recent, unseen, uidnext, and uidvalidity.
  *
  * @return stdClass | FALSE if the box doesn't exist
  */
 public function status_mailbox()
 {
     return imap_status($this->get_imap_stream(), $this->imap_path, SA_ALL);
 }
Example #28
0
 function status($mailbox)
 {
     return imap_status($this->stream, $this->target . $mailbox, SA_ALL);
 }
 /**
  * Saves new folders
  * @param string $name Name of new IMAP mailbox
  * @param string $mbox "::" delimited IMAP mailbox path, ie, INBOX.saved.stuff
  * @return bool True on success
  */
 function saveNewFolder($name, $mbox)
 {
     global $sugar_config;
     //Remove Folder cache
     global $sugar_config;
     //unlink("{$this->EmailCachePath}/{$this->id}/folders/folders.php");
     //$mboxImap = $this->getImapMboxFromSugarProprietary($mbox);
     $delimiter = $this->get_stored_options('folderDelimiter');
     if (!$delimiter) {
         $delimiter = '.';
     }
     $newFolder = $mbox . $delimiter . $name;
     $mbox .= $delimiter . str_replace($delimiter, "_", $name);
     $connectString = $this->getConnectString('', $mbox);
     if (imap_createmailbox($this->conn, imap_utf7_encode($connectString))) {
         imap_subscribe($this->conn, imap_utf7_encode($connectString));
         $status = imap_status($this->conn, str_replace("{$delimiter}{$name}", "", $connectString), SA_ALL);
         $this->mailbox = $this->mailbox . "," . $newFolder;
         $this->save();
         $sessionFoldersString = $this->getSessionInboundFoldersString($this->server_url, $this->email_user, $this->port, $this->protocol);
         $sessionFoldersString = $sessionFoldersString . "," . $newFolder;
         $this->setSessionInboundFoldersString($this->server_url, $this->email_user, $this->port, $this->protocol, $sessionFoldersString);
         echo json_encode($status);
         return true;
     } else {
         echo "NOOP: could not create folder";
         $GLOBALS['log']->error("*** ERROR: EMAIL2.0 - could not create IMAP mailbox with path: [ {$connectString} ]");
         return false;
     }
 }
Example #30
0
 /**
  * Called when the user moves an item on the PDA from one folder to another
  *
  * @param string              $folderid            id of the source folder
  * @param string              $id                  id of the message
  * @param string              $newfolderid         id of the destination folder
  * @param ContentParameters   $contentparameters
  *
  * @access public
  * @return boolean                      status of the operation
  * @throws StatusException              could throw specific SYNC_MOVEITEMSSTATUS_* exceptions
  */
 public function MoveMessage($folderid, $id, $newfolderid, $contentparameters)
 {
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s')", $folderid, $id, $newfolderid));
     $folderImapid = $this->getImapIdFromFolderId($folderid);
     $newfolderImapid = $this->getImapIdFromFolderId($newfolderid);
     if ($folderImapid == $newfolderImapid) {
         throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, destination folder is source folder. Canceling the move.", $folderid, $id, $newfolderid), SYNC_MOVEITEMSSTATUS_SAMESOURCEANDDEST);
     }
     $this->imap_reopen_folder($folderImapid);
     if ($this->imap_inside_cutoffdate(Utils::GetCutOffDate($contentparameters->GetFilterType()), $id)) {
         // read message flags
         $overview = @imap_fetch_overview($this->mbox, $id, FT_UID);
         if (!is_array($overview)) {
             throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to retrieve overview of source message: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
         } else {
             // get next UID for destination folder
             // when moving a message we have to announce through ActiveSync the new messageID in the
             // destination folder. This is a "guessing" mechanism as IMAP does not inform that value.
             // when lots of simultaneous operations happen in the destination folder this could fail.
             // in the worst case the moved message is displayed twice on the mobile.
             $destStatus = imap_status($this->mbox, $this->server . $newfolderImapid, SA_ALL);
             if (!$destStatus) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to open destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
             }
             $newid = $destStatus->uidnext;
             // move message
             $s1 = imap_mail_move($this->mbox, $id, $newfolderImapid, CP_UID);
             if (!$s1) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, copy to destination folder failed: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
             }
             // delete message in from-folder
             $s2 = imap_expunge($this->mbox);
             // open new folder
             $stat = $this->imap_reopen_folder($newfolderImapid);
             if (!$stat) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, opening the destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
             }
             // remove all flags
             $s3 = @imap_clearflag_full($this->mbox, $newid, "\\Seen \\Answered \\Flagged \\Deleted \\Draft", FT_UID);
             $newflags = "";
             $move_to_trash = strcasecmp($newfolderImapid, $this->create_name_folder(IMAP_FOLDER_TRASH)) == 0;
             if ($overview[0]->seen || $move_to_trash && defined('IMAP_AUTOSEEN_ON_DELETE') && IMAP_AUTOSEEN_ON_DELETE == true) {
                 $newflags .= "\\Seen";
             }
             if ($overview[0]->flagged) {
                 $newflags .= " \\Flagged";
             }
             if ($overview[0]->answered) {
                 $newflags .= " \\Answered";
             }
             $s4 = @imap_setflag_full($this->mbox, $newid, $newflags, FT_UID);
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): result s-move: '%s' s-expunge: '%s' unset-Flags: '%s' set-Flags: '%s'", $folderid, $id, $newfolderid, Utils::PrintAsString($s1), Utils::PrintAsString($s2), Utils::PrintAsString($s3), Utils::PrintAsString($s4)));
             // return the new id "as string"
             return $newid . "";
         }
     } else {
         throw new StatusException(sprintf("BackendIMAP->MoveMessage(): Message is outside the sync range"), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
     }
 }