示例#1
0
 /**
  * the singleton pattern
  *
  * @return Felamimail_Controller_Message
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = Felamimail_Controller_Cache_Message::getInstance();
     }
     return self::$_instance;
 }
    /**
     * @see: 0010150: Jump Labels get converted
     * 
     * https://forge.tine20.org/mantisbt/view.php?id=10150
     */
    public function testHtmlJumpLabels()
    {
        $cachedMessage = $this->messageTestHelper('html_jump_labels.eml');
        $message = $this->_controller->getCompleteMessage($cachedMessage);
        $this->assertContains('<a href="#felamimail_inline_test" target="_blank">test</a>
<p>Hello,</p>
<p id="felamimail_inline_test">Text Content</p>', $message->body);
    }
 /**
  * this function generates the response for the client
  * 
  * @return void
  */
 public function getResponse()
 {
     $rfc822 = Felamimail_Controller_Message::getInstance()->getMessagePart($this->_itemId);
     $rfc822->type = Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822;
     $rfc822->filename = 'forwarded email.eml';
     $rfc822->encoding = Zend_Mime::ENCODING_7BIT;
     $mail = Tinebase_Mail::createFromZMM($this->_incomingMessage);
     $mail->addAttachment($rfc822);
     Felamimail_Controller_Message_Send::getInstance()->sendZendMail($this->_account, $mail, $this->_saveInSent);
 }
示例#4
0
 /**
  * append message (from given filename) to cache
  *
  * @param string $_filename
  * @param string $_folder
  * @param array $_replacements
  */
 protected function _appendMessage($_filename, $_folder, $_replacements = array())
 {
     $filename = dirname(dirname(__FILE__)) . '/files/' . $_filename;
     if (!empty($_replacements)) {
         $message = file_get_contents($filename);
         $message = preg_replace('/' . preg_quote($_replacements[0]) . '/m', $_replacements[1], $message);
     } else {
         $message = fopen($filename, 'r');
     }
     $this->_controller->appendMessage($_folder, $message);
 }
示例#5
0
 /**
  * update existing entry
  *
  * @param  string  $_folderId
  * @param  string  $_serverId
  * @param SimpleXMLElement $_data
  * @return Tinebase_Record_Abstract
  */
 public function updateEntry($_folderId, $_serverId, SimpleXMLElement $_entry)
 {
     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " CollectionId: {$_folderId} Id: {$_serverId}");
     $xmlData = $_entry->children('uri:Email');
     if (isset($xmlData->Read)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " CollectionId: {$_folderId} Id: {$_serverId} set read flag: {$xmlData->Read}");
         }
         if ((int) $xmlData->Read === 1) {
             Felamimail_Controller_Message_Flags::getInstance()->addFlags($_serverId, Zend_Mail_Storage::FLAG_SEEN);
         } else {
             Felamimail_Controller_Message_Flags::getInstance()->clearFlags($_serverId, Zend_Mail_Storage::FLAG_SEEN);
         }
         $message = $this->_contentController->get($_serverId);
         $message->timestamp = $this->_syncTimeStamp;
         $this->_contentController->update($message);
     }
     return;
 }
 /**
  * (non-PHPdoc)
  * @see ActiveSync_Frontend_Abstract::updateEntry()
  */
 public function updateEntry($folderId, $serverId, Syncroton_Model_IEntry $entry)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " CollectionId: {$folderId} Id: {$serverId}");
     }
     try {
         $message = $this->_contentController->get($serverId);
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $tenf);
         }
         throw new Syncroton_Exception_NotFound($tenf->getMessage());
     }
     if (isset($entry->read)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " CollectionId: {$folderId} Id: {$serverId} set read flag: {$entry->read}");
         }
         if ($entry->read == 1) {
             Felamimail_Controller_Message_Flags::getInstance()->addFlags($serverId, Zend_Mail_Storage::FLAG_SEEN);
         } else {
             Felamimail_Controller_Message_Flags::getInstance()->clearFlags($serverId, Zend_Mail_Storage::FLAG_SEEN);
         }
     }
     if (isset($entry->flag)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " CollectionId: {$folderId} Id: {$serverId} set flagged flag: {$entry->flag->status}");
         }
         if ($entry->flag->status == Syncroton_Model_EmailFlag::STATUS_ACTIVE) {
             Felamimail_Controller_Message_Flags::getInstance()->addFlags($serverId, Zend_Mail_Storage::FLAG_FLAGGED);
         } else {
             Felamimail_Controller_Message_Flags::getInstance()->clearFlags($serverId, Zend_Mail_Storage::FLAG_FLAGGED);
         }
     }
     $message->timestamp = $this->_syncTimeStamp;
     $this->_contentController->update($message);
     return;
 }
 /**
  * save message in tinebase cache
  * - only cache message headers if received during the last day
  * 
  * @param Felamimail_Model_Message $_message
  * @param Felamimail_Model_Folder $_folder
  * @param array $_messageData
  * 
  * @todo do we need the headers in the Tinebase cache?
  */
 protected function _saveMessageInTinebaseCache(Felamimail_Model_Message $_message, Felamimail_Model_Folder $_folder, $_messageData)
 {
     if (!$_message->received->isLater(Tinebase_DateTime::now()->subDay(3))) {
         return;
     }
     $memory = function_exists('memory_get_peak_usage') ? memory_get_peak_usage(true) : memory_get_usage(true);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' caching message ' . $_message->getId() . ' / memory usage: ' . $memory / 1024 / 1024 . ' MBytes');
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_message->toArray(), TRUE));
     }
     $cacheId = 'getMessageHeaders' . $_message->getId();
     Tinebase_Core::getCache()->save($_messageData['header'], $cacheId, array('getMessageHeaders'));
     // prefetch body to cache
     if (Felamimail_Config::getInstance()->get(Felamimail_Config::CACHE_EMAIL_BODY, TRUE) && $_message->size < $this->_maxMessageSizeToCacheBody) {
         $account = Felamimail_Controller_Account::getInstance()->get($_folder->account_id);
         $mimeType = $account->display_format == Felamimail_Model_Account::DISPLAY_HTML || $account->display_format == Felamimail_Model_Account::DISPLAY_CONTENT_TYPE ? Zend_Mime::TYPE_HTML : Zend_Mime::TYPE_TEXT;
         Felamimail_Controller_Message::getInstance()->getMessageBody($_message, null, $mimeType, $account);
     }
 }
 /**
  * move messages to another email account
  * 
  * @param Tinebase_Record_RecordSet $_messages
  * @param Felamimail_Model_Folder $_targetFolder
  */
 protected function _moveMessagesToAnotherAccount(Tinebase_Record_RecordSet $_messages, Felamimail_Model_Folder $_targetFolder)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Move ' . count($_messages) . ' message(s) to ' . $_targetFolder->globalname . ' in account ' . $_targetFolder->account_id);
     }
     foreach ($_messages as $message) {
         $part = Felamimail_Controller_Message::getInstance()->getMessagePart($message);
         $this->appendMessage($_targetFolder, $part->getRawStream(), $message->flags);
     }
 }
示例#9
0
 /**
  * manual process iMIP component and optionally set status
  * 
  * @param  Calendar_Model_iMIP   $_iMIP
  * @param  string                $_status
  */
 public function process($_iMIP, $_status = NULL)
 {
     // client spoofing protection
     $iMIP = Felamimail_Controller_Message::getInstance()->getiMIP($_iMIP->getId());
     return $this->_process($_iMIP, $_status);
 }
示例#10
0
 /**
  * test sync of existing imap folder
  */
 public function testPingForEmails()
 {
     $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP);
     if (!$imapConfig || !isset($imapConfig->useSystemAccount) || $imapConfig->useSystemAccount != TRUE) {
         $this->markTestSkipped('IMAP backend not configured');
     }
     $emailController = new ActiveSync_Controller_Email($this->_device, new Tinebase_DateTime(null, null, 'de_DE'));
     $folders = $emailController->getAllFolders();
     $this->assertGreaterThan(0, count($folders));
     foreach ($folders as $folder) {
         if (strtoupper($folder['displayName']) == 'INBOX') {
             break;
         }
     }
     $emailController->updateCache($folder['folderId']);
     // first do a foldersync
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <FolderSync xmlns="uri:FolderHierarchy"><SyncKey>0</SyncKey></FolderSync>');
     $folderSync = new Syncope_Command_FolderSync($doc, $this->_device, $this->_device->policykey);
     $folderSync->handle();
     $syncDoc = $folderSync->getResponse();
     #$syncDoc->formatOutput = true; echo $syncDoc->saveXML();
     // request initial synckey
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <Sync xmlns="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase"><Collections><Collection><Class>Email</Class><SyncKey>0</SyncKey><CollectionId>' . $folder['folderId'] . '</CollectionId><DeletesAsMoves/><GetChanges/><WindowSize>100</WindowSize><Options><FilterType>4</FilterType><AirSyncBase:BodyPreference><AirSyncBase:Type>1</AirSyncBase:Type><AirSyncBase:TruncationSize>5120</AirSyncBase:TruncationSize></AirSyncBase:BodyPreference><Conflict>1</Conflict></Options></Collection></Collections></Sync>');
     $sync = new Syncope_Command_Sync($doc, $this->_device, $this->_device->policykey);
     $sync->handle();
     $syncDoc = $sync->getResponse();
     #$syncDoc->formatOutput = true; echo $syncDoc->saveXML();
     // now do the first sync
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <Sync xmlns="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase"><Collections><Collection><Class>Email</Class><SyncKey>1</SyncKey><CollectionId>' . $folder['folderId'] . '</CollectionId><DeletesAsMoves/><GetChanges/><WindowSize>100</WindowSize><Options><FilterType>4</FilterType><AirSyncBase:BodyPreference><AirSyncBase:Type>1</AirSyncBase:Type><AirSyncBase:TruncationSize>5120</AirSyncBase:TruncationSize></AirSyncBase:BodyPreference><Conflict>1</Conflict></Options></Collection></Collections></Sync>');
     $sync = new Syncope_Command_Sync($doc, $this->_device, $this->_device->policykey);
     $sync->handle();
     $syncDoc = $sync->getResponse();
     #$syncDoc->formatOutput = true; echo $syncDoc->saveXML();
     // and now we can start the ping request
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <Ping xmlns="uri:Ping"><HeartBeatInterval>10</HeartBeatInterval><Folders><Folder><Id>' . $folder['folderId'] . '</Id><Class>Email</Class></Folder></Folders></Ping>');
     // add test email message to folder
     $emailTest = new Felamimail_Controller_MessageTest();
     $emailTest->setUp();
     $inbox = $emailTest->getFolder('INBOX');
     $email = file_get_contents(dirname(__FILE__) . '/../../Felamimail/files/text_plain.eml');
     Felamimail_Controller_Message::getInstance()->appendMessage($inbox, $email);
     $ping = new Syncope_Command_Ping($doc, $this->_device, null);
     $ping->handle();
     $responseDoc = $ping->getResponse();
     $responseDoc->formatOutput = true;
     //echo $responseDoc->saveXML();
     $xpath = new DomXPath($responseDoc);
     $xpath->registerNamespace('Ping', 'uri:Ping');
     $nodes = $xpath->query('//Ping:Ping/Ping:Status');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertEquals(Syncope_Command_Ping::STATUS_CHANGES_FOUND, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
     $nodes = $xpath->query('//Ping:Ping/Ping:Folders/Ping:Folder');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertEquals($folder['folderId'], $nodes->item(0)->nodeValue, $responseDoc->saveXML());
     $message = $emailTest->searchAndCacheMessage('text/plain', $inbox);
     Felamimail_Controller_Message_Flags::getInstance()->addFlags(array($message), array(Zend_Mail_Storage::FLAG_DELETED));
 }
示例#11
0
 /**
  * download message part
  * 
  * @param string $_messageId
  * @param string $_partId
  */
 protected function _downloadMessagePart($_messageId, $_partId = NULL)
 {
     $oldMaxExcecutionTime = Tinebase_Core::setExecutionLifeTime(0);
     try {
         if (count($_messageId) == 1) {
             $part = Felamimail_Controller_Message::getInstance()->getMessagePart($_messageId[0], $_partId);
             if ($part instanceof Zend_Mime_Part) {
                 $filename = !empty($part->filename) ? $part->filename : $_messageId[0] . '.eml';
                 $contentType = $_partId === NULL ? Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 : $part->type;
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . ' filename: ' . $filename . ' content type' . $contentType);
                 }
                 // cache for 3600 seconds
                 $maxAge = 3600;
                 header('Cache-Control: private, max-age=' . $maxAge);
                 header("Expires: " . gmdate('D, d M Y H:i:s', Tinebase_DateTime::now()->addSecond($maxAge)->getTimestamp()) . " GMT");
                 // overwrite Pragma header from session
                 header("Pragma: cache");
                 header('Content-Disposition: attachment; filename="' . $filename . '"');
                 header("Content-Type: " . $contentType);
                 $stream = $_partId === NULL ? $part->getRawStream() : $part->getDecodedStream();
                 fpassthru($stream);
                 fclose($stream);
             }
         } else {
             $ZIPfile = new ZipArchive();
             $tmpFile = tempnam(Tinebase_Core::getTempDir(), 'tine20_');
             if ($ZIPfile->open($tmpFile) === TRUE) {
                 foreach ($_messageId as $messageID) {
                     $part = Felamimail_Controller_Message::getInstance()->getRawMessage($messageID);
                     $filename = $messageID . '.eml';
                     $ZIPfile->addFromString($filename, $part);
                 }
                 $ZIPfile->close();
             }
             $maxAge = 3600;
             header('Cache-Control: private, max-age=' . $maxAge);
             header("Expires: " . gmdate('D, d M Y H:i:s', Tinebase_DateTime::now()->addSecond($maxAge)->getTimestamp()) . " GMT");
             // overwrite Pragma header from session
             header("Pragma: cache");
             header('Content-Disposition: attachment; filename="menssagem.zip"');
             header("Content-Type: application/zip");
             $stream = fopen($tmpFile, 'r');
             fpassthru($stream);
             fclose($stream);
             unlink($tmpFile);
         }
     } catch (Exception $e) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Failed to get message part: ' . $e->getMessage());
     }
     Tinebase_Core::setExecutionLifeTime($oldMaxExcecutionTime);
     exit;
 }
 /**
  * set In-Reply-To and References headers
  * 
  * @param Felamimail_Model_Message $message
  * 
  * @see http://www.faqs.org/rfcs/rfc2822.html / Section 3.6.4.
  */
 protected function _addReplyHeaders(Felamimail_Model_Message $message)
 {
     $originalHeaders = Felamimail_Controller_Message::getInstance()->getMessageHeaders($message->original_id);
     if (!isset($originalHeaders['message-id'])) {
         // no message-id -> skip this
         return;
     }
     $messageHeaders = is_array($message->headers) ? $message->headers : array();
     $messageHeaders['In-Reply-To'] = $originalHeaders['message-id'];
     $references = '';
     if (isset($originalHeaders['references'])) {
         $references = $originalHeaders['references'] . ' ';
     } else {
         if (isset($originalHeaders['in-reply-to'])) {
             $references = $originalHeaders['in-reply-to'] . ' ';
         }
     }
     $references .= $originalHeaders['message-id'];
     $messageHeaders['References'] = $references;
     $message->headers = $messageHeaders;
 }
示例#13
0
 /**
  * forward message test
  */
 public function testForwardMessageWithAttachment()
 {
     $testFolder = $this->_getFolder($this->_testFolderName);
     $message = fopen(dirname(__FILE__) . '/files/multipart_related.eml', 'r');
     Felamimail_Controller_Message::getInstance()->appendMessage($testFolder, $message);
     $subject = 'Tine 2.0 bei Metaways - Verbessurngsvorschlag';
     $message = $this->_searchForMessageBySubject($subject, $this->_testFolderName);
     $fwdSubject = 'Fwd: ' . $subject;
     $forwardMessageData = array('account_id' => $this->_account->getId(), 'subject' => $fwdSubject, 'to' => array('unittest@' . $this->_mailDomain), 'body' => "aaaaaä <br>", 'headers' => array('X-Tine20TestMessage' => 'jsontest'), 'original_id' => $message['id'], 'attachments' => array(new Tinebase_Model_TempFile(array('type' => Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822, 'name' => $subject), TRUE)), 'flags' => Zend_Mail_Storage::FLAG_PASSED);
     $this->_foldersToClear[] = 'INBOX';
     $this->_json->saveMessage($forwardMessageData);
     $forwardMessage = $this->_searchForMessageBySubject($fwdSubject);
     $this->assertEquals(Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822, $forwardMessage['structure']['parts'][2]['contentType']);
     // check forwarded/passed flag
     $message = $this->_json->getMessage($message['id']);
     $this->assertTrue(in_array(Zend_Mail_Storage::FLAG_PASSED, $message['flags']));
 }
示例#14
0
 /**
  * import messages to folder from file(eml), or/and from a zip file.
  *
  * @param string $accountId
  * @param string $globalName
  * @param array $file
  * @return array
  */
 public function importMessagefromfile($accountId, $folderId, $file)
 {
     $zip = zip_open($file);
     if (gettype($zip) === 'resource') {
         // is a zip file ...
         while ($zip_entry = zip_read($zip)) {
             $filename = zip_entry_name($zip_entry);
             if (substr($filename, strlen($filename) - 4) == '.eml') {
                 if (zip_entry_open($zip, $zip_entry, "r")) {
                     $email = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                     $result = Felamimail_Controller_Message::getInstance()->appendMessage($folderId, $email);
                     zip_entry_close($zip_entry);
                 }
             }
         }
         zip_close($zip);
     } else {
         // Error!!! Not zip file. But may be a eml file. Then try ...
         $msg = file_get_contents($file);
         $result = Felamimail_Controller_Message::getInstance()->appendMessage($folderId, $msg);
     }
     return array('status' => 'success');
 }
示例#15
0
 /**
  * get message data
  *
  * @param  string $id
  * @return array
  */
 public function getMessage($id)
 {
     // close session to allow other requests
     Zend_Session::writeClose(true);
     if (strpos($id, '_') !== false) {
         list($messageId, $partId) = explode('_', $id);
     } else {
         $messageId = $id;
         $partId = null;
     }
     $message = Felamimail_Controller_Message::getInstance()->getCompleteMessage($messageId, $partId, false);
     $message->id = $id;
     return $this->_recordToJson($message);
 }
示例#16
0
 /**
  * this function generates the response for the client
  * 
  * @return void
  */
 public function getResponse()
 {
     $replyBody = Felamimail_Controller_Message::getInstance()->getMessageBody($this->_itemId, null, 'text/plain');
     $mail = Tinebase_Mail::createFromZMM($this->_incomingMessage, $replyBody);
     Felamimail_Controller_Message_Send::getInstance()->sendZendMail($this->_account, $mail, $this->_saveInSent);
 }
示例#17
0
 /**
  * parse headers and set 'date', 'from', 'to', 'cc', 'bcc', 'subject', 'sender' fields
  * 
  * @param array $_headers
  * @return void
  */
 public function parseHeaders(array $_headers)
 {
     // remove duplicate headers (which can't be set twice in real life)
     foreach (array('date', 'from', 'to', 'cc', 'bcc', 'subject', 'sender') as $field) {
         if (isset($_headers[$field]) && is_array($_headers[$field])) {
             $_headers[$field] = $_headers[$field][0];
         }
     }
     $this->importance = isset($_headers['importance']) && $_headers['importance'] === 'high' ? true : false;
     $this->subject = isset($_headers['subject']) ? Felamimail_Message::convertText($_headers['subject']) : null;
     if (array_key_exists('date', $_headers)) {
         $this->sent = Felamimail_Message::convertDate($_headers['date']);
     } elseif (array_key_exists('resent-date', $_headers)) {
         $this->sent = Felamimail_Message::convertDate($_headers['resent-date']);
     }
     $punycodeConverter = Felamimail_Controller_Message::getInstance()->getPunycodeConverter();
     foreach (array('to', 'cc', 'bcc', 'from', 'sender') as $field) {
         if (isset($_headers[$field])) {
             $value = Felamimail_Message::convertAddresses($_headers[$field], $punycodeConverter);
             switch ($field) {
                 case 'from':
                     $this->from_email = isset($value[0]) && array_key_exists('email', $value[0]) ? $value[0]['email'] : '';
                     $this->from_name = isset($value[0]) && array_key_exists('name', $value[0]) && !empty($value[0]['name']) ? $value[0]['name'] : $this->from_email;
                     break;
                 case 'sender':
                     $this->sender = isset($value[0]) && array_key_exists('email', $value[0]) ? '<' . $value[0]['email'] . '>' : '';
                     if (isset($value[0]) && array_key_exists('name', $value[0]) && !empty($value[0]['name'])) {
                         $this->sender = '"' . $value[0]['name'] . '" ' . $this->sender;
                     }
                     break;
                 default:
                     $this->{$field} = $value;
             }
         }
     }
 }
示例#18
0
 /**
  * test flag update
  */
 public function testUpdateFlags()
 {
     $message = $this->_emailTestClass->messageTestHelper('multipart_mixed.eml', 'multipart/mixed');
     // appended messages already have the SEEN flag
     $this->assertTrue(in_array(Zend_Mail_Storage::FLAG_SEEN, $message->flags), 'SEEN flag not found: ' . print_r($message->flags, TRUE));
     // add another flag
     Felamimail_Controller_Message_Flags::getInstance()->addFlags($message, Zend_Mail_Storage::FLAG_ANSWERED);
     while (!isset($updatedFolder) || $updatedFolder->cache_status === Felamimail_Model_Folder::CACHE_STATUS_INCOMPLETE) {
         $updatedFolder = $this->_controller->updateCache($this->_folder, 30, 1);
     }
     // clear/add flag on imap
     $this->_imap->clearFlags($message->messageuid, array(Zend_Mail_Storage::FLAG_SEEN));
     $flagsToAdd = array(Zend_Mail_Storage::FLAG_FLAGGED, Zend_Mail_Storage::FLAG_DRAFT, Zend_Mail_Storage::FLAG_PASSED);
     try {
         $this->_imap->addFlags($message->messageuid, $flagsToAdd);
     } catch (Zend_Mail_Storage_Exception $zmse) {
         // some imap servers (dbmail, ...) do not support PASSED flag
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $zmse->getMessage());
         }
         $this->_imap->addFlags($message->messageuid, array(Zend_Mail_Storage::FLAG_FLAGGED, Zend_Mail_Storage::FLAG_DRAFT));
     }
     $this->_controller->updateFlags($updatedFolder);
     $cachedMessage = Felamimail_Controller_Message::getInstance()->get($message->getId());
     $this->assertTrue(!in_array(Zend_Mail_Storage::FLAG_SEEN, $cachedMessage->flags), 'SEEN flag found: ' . print_r($cachedMessage->flags, TRUE));
     $expectedFlags = array(Zend_Mail_Storage::FLAG_FLAGGED, Zend_Mail_Storage::FLAG_DRAFT, Zend_Mail_Storage::FLAG_ANSWERED);
     $this->assertEquals(3, count($cachedMessage->flags), 'found too many flags: ' . print_r($cachedMessage->flags, TRUE));
     foreach ($expectedFlags as $expectedFlag) {
         $this->assertTrue(in_array($expectedFlag, $cachedMessage->flags), $expectedFlag . ' flag not found: ' . print_r($cachedMessage->flags, TRUE));
     }
     $this->_controller->updateFlags($updatedFolder);
     $cachedMessageAgain = Felamimail_Controller_Message::getInstance()->get($message->getId());
     // cached message should not have been updated again
     $this->assertEquals($cachedMessage->timestamp->__toString(), $cachedMessageAgain->timestamp->__toString());
 }
 /**
  * testExternalPublishProcess
  * - uses felamimail to cache external publish message
  * 
  * NOTE: meetup sends REQUEST w.o. attendee. We might think of autoconvert this to PUBLISH
  */
 public function testExternalPublishProcess()
 {
     $this->_checkIMAPConfig();
     // handle message with fmail (add to cache)
     $message = $this->_emailTestClass->messageTestHelper('meetup.eml');
     $complete = Felamimail_Controller_Message::getInstance()->getCompleteMessage($message);
     $iMIP = $complete->preparedParts->getFirstRecord()->preparedData;
     $this->setExpectedException('Calendar_Exception_iMIP', 'iMIP preconditions failed: ATTENDEE');
     $result = $this->_iMIPFrontend->process($iMIP);
 }
示例#20
0
 /**
  * create new message for the cache
  * 
  * @param array $_message
  * @param Felamimail_Model_Folder $_folder
  * @return Felamimail_Model_Message
  */
 protected function _createModelMessage(array $_message, Felamimail_Model_Folder $_folder = NULL)
 {
     // Optimization!!!
     if ($_folder == NULL) {
         if (isset($_message['folder_id'])) {
             $_folder = array_key_exists($_message['folder_id'], $this->_folderMap) ? $this->_folderMap[$_message['folder_id']] : ($this->_folderMap[$_message['folder_id']] = Felamimail_Controller_Folder::getInstance()->get($_message['folder_id']));
         } else {
             return NULL;
         }
     }
     $message = new Felamimail_Model_Message(array('id' => self::createMessageId($_folder->account_id, $_folder->getId(), $_message['uid']), 'account_id' => $_folder->account_id, 'messageuid' => $_message['uid'], 'folder_id' => $_folder->getId(), 'timestamp' => Tinebase_DateTime::now(), 'received' => Felamimail_Message::convertDate($_message['received']), 'size' => $_message['size'], 'flags' => $_message['flags']), true);
     $message->parseStructure($_message['structure']);
     $message->parseHeaders($_message['header']);
     $message->fixToListModel();
     $message->parseBodyParts();
     $message->parseSmime($_message['structure']);
     $attachments = Felamimail_Controller_Message::getInstance()->getAttachments($message);
     $message->has_attachment = count($attachments) > 0 ? true : false;
     return $message;
 }
 /**
  * get test alarm emails
  * 
  * @param boolean $deleteThem
  * @return Tinebase_Record_RecordSet
  */
 protected function _getAlarmMails($deleteThem = FALSE)
 {
     // search and assert alarm mail
     $folder = $this->_emailTestClass->getFolder('INBOX');
     $folder = Felamimail_Controller_Cache_Message::getInstance()->updateCache($folder, 10, 1);
     $i = 0;
     while ($folder->cache_status != Felamimail_Model_Folder::CACHE_STATUS_COMPLETE && $i < 10) {
         $folder = Felamimail_Controller_Cache_Message::getInstance()->updateCache($folder, 10);
         $i++;
     }
     $account = Felamimail_Controller_Account::getInstance()->search()->getFirstRecord();
     $filter = new Felamimail_Model_MessageFilter(array(array('field' => 'folder_id', 'operator' => 'equals', 'value' => $folder->getId()), array('field' => 'account_id', 'operator' => 'equals', 'value' => $account->getId()), array('field' => 'subject', 'operator' => 'startswith', 'value' => 'Alarm for event "Wakeup" at')));
     $result = Felamimail_Controller_Message::getInstance()->search($filter);
     if ($deleteThem) {
         Felamimail_Controller_Message_Move::getInstance()->moveMessages($filter, Felamimail_Model_Folder::FOLDER_TRASH);
     }
     return $result;
 }
 /**
  * delete folder in cache
  * 
  * @param string|Felamimail_Model_Account $_account
  * @param Felamimail_Model_Folder $_folder
  */
 protected function _deleteFolderInCache($_accountId, $_folder)
 {
     if ($_folder === NULL) {
         return;
     }
     Felamimail_Controller_Message::getInstance()->deleteByFolder($_folder);
     $this->_backend->delete($_folder->getId());
     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Deleted folder ' . $_folder->globalname);
     $this->_updateHasChildren($_accountId, $_folder->parent);
 }
 /**
  * send reading confirmation
  * 
  * @param string $messageId
  * @return array
  */
 public function sendReadingConfirmation($messageId)
 {
     Felamimail_Controller_Message::getInstance()->sendReadingConfirmation($messageId);
     return array('status' => 'success');
 }
 /**
  * _sendMailTestHelper
  * 
  * @param string $xml
  * @param string $messageId
  * @param string $stringToCheck
  * @param string $command
  * @param string $device
  */
 protected function _sendMailTestHelper($xml, $messageId, $stringToCheck, $command = "Syncroton_Command_SmartReply", $device = Syncroton_Model_Device::TYPE_ANDROID_40)
 {
     $doc = new DOMDocument();
     $doc->loadXML($xml);
     $device = $this->_getDevice($device);
     $sync = new $command($doc, $device, $device->policykey);
     $sync->handle();
     $sync->getResponse();
     $inbox = $this->_emailTestClass->getFolder('INBOX');
     $message = $this->_emailTestClass->searchAndCacheMessage($messageId, $inbox, TRUE, 'Message-ID');
     $this->_createdMessages->addRecord($message);
     $completeMessage = Felamimail_Controller_Message::getInstance()->getCompleteMessage($message);
     $this->assertContains($stringToCheck, $completeMessage->body);
 }
 /**
  * testMessageWithInvalidICS
  *
  * @see 0008786: broken ics causes js error when showing details
  */
 public function testMessageWithInvalidICS()
 {
     $inbox = $this->_getFolder('INBOX');
     $mailAsString = file_get_contents(dirname(__FILE__) . '/../files/invalidimip.eml');
     Felamimail_Controller_Message::getInstance()->appendMessage($inbox, $mailAsString);
     $this->_foldersToClear = array('INBOX');
     $message = $this->_searchForMessageBySubject('test invalid imip');
     $fullMessage = $this->_json->getMessage($message['id']);
     $this->assertTrue(empty($fullMessage->preparedParts));
 }
示例#26
0
 /**
  * get messages befora a date 
  * 
  * @param  mixed  $_folderId
  * @param  string $_date
  * @return array
  */
 public function SelectBeforeDate($_folderId, $_date)
 {
     $folderId = $_folderId instanceof Felamimail_Model_Folder ? $_folderId->getId() : $_folderId;
     $imapbbackend = Felamimail_Controller_Message::getInstance()->_getBackendAndSelectFolder($folderId);
     $filter = new Felamimail_Model_MessageFilter(array(array('field' => 'folder_id', 'operator' => 'equals', 'value' => $folderId), array('field' => 'received', 'operator' => 'before', 'value' => $_date)));
     $result = $this->_backend->searchMessageUids($filter);
     if (count($result) === 0) {
         return null;
     }
     $temp_result = array();
     foreach ($result as $key => $value) {
         $imapbbackend->addFlags($value, array('\\Deleted'));
         $temp_result[] = $key;
     }
     $result = $this->_deleteMessagesByIdAndUpdateCounters($temp_result, $_folderId);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Got Messages before date: ' . print_r($temp_result, TRUE));
     }
     return $result;
 }
 /**
  * get resource, delivers the image (audio, video) data
  * 
  * @param string $cid
  * @param string $messageId
  * 
  * @todo add param string $folderId
  * @todo support audio/video 
  */
 public function getResource($cid, $messageId)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Requesting resource <' . $cid . '> for message ' . $messageId);
     }
     $resPart = Felamimail_Controller_Message::getInstance()->getResourcePartStructure($cid, $messageId);
     $this->_outputMessagePart($messageId, $resPart['partId'], 'inline', TRUE);
 }
示例#28
0
 /**
  * test (plain text) mail sending via ActiveSync_Command_SendMail
  */
 public function testSendMail()
 {
     $email = file_get_contents(dirname(__FILE__) . '/../../Felamimail/files/text_plain.eml');
     $email = str_replace('gentoo-dev@lists.gentoo.org, webmaster@changchung.org', $this->_emailTestClass->getEmailAddress(), $email);
     $stream = fopen('data://text/plain;base64,' . base64_encode($email), 'r');
     $sendMail = new Syncope_Command_SendMail($stream);
     $sendMail->handle();
     $sendMail->getResponse();
     // check if mail is in INBOX of test account
     $inbox = $this->_emailTestClass->getFolder('INBOX');
     $testHeaderValue = 'text/plain';
     $message = $this->_emailTestClass->searchAndCacheMessage($testHeaderValue, $inbox);
     $this->_createdMessages->addRecord($message);
     $this->assertEquals("Re: [gentoo-dev] `paludis --info' is not like `emerge --info'", $message->subject);
     // check duplicate headers
     $completeMessage = Felamimail_Controller_Message::getInstance()->getCompleteMessage($message);
     $this->assertEquals(1, count($completeMessage->headers['mime-version']));
     $this->assertEquals(1, count($completeMessage->headers['content-type']));
 }
 /**
  * parse headers and set 'date', 'from', 'to', 'cc', 'bcc', 'subject', 'sender' fields
  * 
  * @param array $_headers
  * @return void
  */
 public function parseHeaders(array $_headers)
 {
     // remove duplicate headers (which can't be set twice in real life)
     foreach (array('date', 'from', 'subject', 'sender') as $field) {
         if (isset($_headers[$field]) && is_array($_headers[$field])) {
             $_headers[$field] = $_headers[$field][0];
         }
     }
     // @see 0008644: error when sending mail with note (wrong charset)
     $this->subject = isset($_headers['subject']) ? Tinebase_Core::filterInputForDatabase(Felamimail_Message::convertText($_headers['subject'])) : null;
     if (isset($_headers['date']) || array_key_exists('date', $_headers)) {
         $this->sent = Felamimail_Message::convertDate($_headers['date']);
     } elseif (isset($_headers['resent-date']) || array_key_exists('resent-date', $_headers)) {
         $this->sent = Felamimail_Message::convertDate($_headers['resent-date']);
     }
     $punycodeConverter = Felamimail_Controller_Message::getInstance()->getPunycodeConverter();
     foreach (array('to', 'cc', 'bcc', 'from', 'sender') as $field) {
         if (isset($_headers[$field])) {
             if (is_array($_headers[$field])) {
                 $value = array();
                 foreach ($_headers[$field] as $headerValue) {
                     $value = array_merge($value, Felamimail_Message::convertAddresses($headerValue, $punycodeConverter));
                 }
                 $this->{$field} = $value;
             } else {
                 $value = Felamimail_Message::convertAddresses($_headers[$field], $punycodeConverter);
                 switch ($field) {
                     case 'from':
                         $this->from_email = isset($value[0]) && (isset($value[0]['email']) || array_key_exists('email', $value[0])) ? $value[0]['email'] : '';
                         $this->from_name = isset($value[0]) && (isset($value[0]['name']) || array_key_exists('name', $value[0])) && !empty($value[0]['name']) ? $value[0]['name'] : $this->from_email;
                         break;
                     case 'sender':
                         $this->sender = isset($value[0]) && (isset($value[0]['email']) || array_key_exists('email', $value[0])) ? '<' . $value[0]['email'] . '>' : '';
                         if (isset($value[0]) && (isset($value[0]['name']) || array_key_exists('name', $value[0])) && !empty($value[0]['name'])) {
                             $this->sender = '"' . $value[0]['name'] . '" ' . $this->sender;
                         }
                         break;
                     default:
                         $this->{$field} = $value;
                 }
             }
         }
     }
 }
示例#30
0
 /**
  * set In-Reply-To and References headers
  * 
  * @param Zend_Mail $mail
  * @param Felamimail_Model_Message $message
  * 
  * @see http://www.faqs.org/rfcs/rfc2822.html / Section 3.6.4.
  */
 protected function _addReplyHeaders(Zend_Mail $mail, Felamimail_Model_Message $message)
 {
     $originalHeaders = Felamimail_Controller_Message::getInstance()->getMessageHeaders($message->original_id);
     if (!isset($originalHeaders['message-id'])) {
         // no message-id -> skip this
         return;
     }
     $mail->addHeader('In-Reply-To', $originalHeaders['message-id']);
     $references = '';
     if (isset($originalHeaders['references'])) {
         $references = $originalHeaders['references'] . ' ';
     } else {
         if (isset($originalHeaders['in-reply-to'])) {
             $references = $originalHeaders['in-reply-to'] . ' ';
         }
     }
     $references .= $originalHeaders['message-id'];
     while (strlen($references) > 998) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Very long references header, need to cut some chars off.');
         }
         $pos = strpos($references, ' ');
         $references = substr($references, $pos !== FALSE ? $pos : 80);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $references);
     }
     $mail->addHeader('References', $references);
 }