コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->_account = Felamimail_Controller_Account::getInstance()->search()->getFirstRecord();
     $this->_controller = Felamimail_Controller_Message::getInstance();
     $this->_imap = Felamimail_Backend_ImapFactory::factory($this->_account);
     $this->_folder = $this->getFolder($this->_testFolderName);
     $this->_imap->selectFolder($this->_testFolderName);
     $this->_cache = Felamimail_Controller_Cache_Message::getInstance();
     $this->_createdMessages = new Tinebase_Record_RecordSet('Felamimail_Model_Message');
 }
コード例 #3
0
ファイル: iMIP.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * 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);
 }
コード例 #4
0
 /**
  * (non-PHPdoc)
  * @see Syncroton_Data_IDataEmail::replyEmail()
  */
 public function replyEmail($source, $inputStream, $saveInSent, $replaceMime)
 {
     $account = $this->_getAccount();
     if (!$account) {
         if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " no email account configured");
         }
         throw new Syncroton_Exception('no email account configured');
     }
     if (empty(Tinebase_Core::getUser()->accountEmailAddress)) {
         throw new Syncroton_Exception('no email address set for current user');
     }
     if (!is_resource($inputStream)) {
         $stream = fopen("php://temp", 'r+');
         fwrite($stream, $inputStream);
         $inputStream = $stream;
         rewind($inputStream);
     }
     if ($this->_debugEmail == true) {
         $debugStream = fopen("php://temp", 'r+');
         stream_copy_to_stream($inputStream, $debugStream);
         rewind($debugStream);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " email to send:" . stream_get_contents($debugStream));
         }
         //replace original stream wirh debug stream, as php://input can't be rewinded
         $inputStream = $debugStream;
         rewind($inputStream);
     }
     $incomingMessage = new Zend_Mail_Message(array('file' => $inputStream));
     $messageId = is_array($source) ? $source['itemId'] : $source;
     $fmailMessage = Felamimail_Controller_Message::getInstance()->get($messageId);
     $fmailMessage->flags = Zend_Mail_Storage::FLAG_ANSWERED;
     if ($replaceMime === false) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " attach source: " . $messageId . " saveInSent: " . $saveInSent);
         }
         $replyBody = Felamimail_Controller_Message::getInstance()->getMessageBody($fmailMessage, null, 'text/plain');
     } else {
         $replyBody = null;
     }
     $mail = Tinebase_Mail::createFromZMM($incomingMessage, $replyBody);
     Felamimail_Controller_Message_Send::getInstance()->sendZendMail($account, $mail, (bool) $saveInSent, $fmailMessage);
 }
コード例 #5
0
ファイル: Http.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * 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;
 }
コード例 #6
0
 /**
  * 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);
     }
 }
コード例 #7
0
ファイル: Message.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * 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;
 }
コード例 #8
0
 /**
  * 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);
 }
 /**
  * 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;
 }
コード例 #10
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');
 }
コード例 #11
0
ファイル: Message.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * 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;
             }
         }
     }
 }
コード例 #12
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);
 }
コード例 #13
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());
 }
コード例 #14
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));
 }
 /**
  * _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);
 }
コード例 #16
0
 /**
  * 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);
     }
 }
コード例 #17
0
 /**
  * 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;
 }
コード例 #18
0
 /**
  * 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);
 }
コード例 #19
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']));
 }
コード例 #20
0
 /**
  * send reading confirmation
  * 
  * @param string $messageId
  * @return array
  */
 public function sendReadingConfirmation($messageId)
 {
     Felamimail_Controller_Message::getInstance()->sendReadingConfirmation($messageId);
     return array('status' => 'success');
 }
コード例 #21
0
ファイル: Json.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * 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);
 }
コード例 #22
0
 /**
  * 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));
 }
コード例 #23
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;
 }
コード例 #24
0
 /**
  * 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);
 }
コード例 #25
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']));
 }
コード例 #26
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', '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;
                 }
             }
         }
     }
 }
コード例 #27
0
ファイル: Send.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * 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);
 }