示例#1
0
 public function testIconvHtmlMessage()
 {
     $conn = $this->getMockBuilder('Horde_Imap_Client_Socket')->disableOriginalConstructor()->setMethods(['fetch'])->getMock();
     $urlGenerator = $this->getMockBuilder('\\OCP\\IURLGenerator')->disableOriginalConstructor()->getMock();
     //linkToRoute 'mail.proxy.proxy'
     $urlGenerator->expects($this->any())->method('linkToRoute')->will($this->returnCallback(function ($url) {
         return "https://docs.example.com/server/go.php?to={$url}";
     }));
     $htmlService = new \OCA\Mail\Service\Html($urlGenerator);
     // mock first fetch
     $firstFetch = new Horde_Imap_Client_Data_Fetch();
     $firstPart = Horde_Mime_Part::parseMessage(file_get_contents(__DIR__ . '/../data/mail-message-123.txt'), ['level' => 1]);
     $firstFetch->setStructure($firstPart);
     $firstFetch->setBodyPart(1, $firstPart->getPart(1)->getContents());
     $firstFetch->setBodyPart(2, $firstPart->getPart(2)->getContents());
     $firstResult = new Horde_Imap_Client_Fetch_Results();
     $firstResult[123] = $firstFetch;
     $conn->expects($this->any())->method('fetch')->willReturn($firstResult);
     $message = new IMAPMessage($conn, 'INBOX', 123, null, true, $htmlService);
     $htmlBody = $message->getHtmlBody(0, 0, 123, function () {
         return null;
     });
     $this->assertTrue(strlen($htmlBody) > 1000);
     $plainTextBody = $message->getPlainBody();
     $this->assertTrue(strlen($plainTextBody) > 1000);
 }
示例#2
0
文件: mailbox.php 项目: Gomez/mail
 public function getMessages($from = 0, $count = 2, $filter = '')
 {
     if ($filter instanceof Horde_Imap_Client_Search_Query) {
         $query = $filter;
     } else {
         $query = new Horde_Imap_Client_Search_Query();
         if ($filter) {
             $query->text($filter, false);
         }
     }
     if ($this->getSpecialRole() !== 'trash') {
         $query->flag(Horde_Imap_Client::FLAG_DELETED, false);
     }
     $result = $this->conn->search($this->mailBox, $query, ['sort' => [Horde_Imap_Client::SORT_DATE]]);
     $ids = array_reverse($result['match']->ids);
     if ($from >= 0 && $count >= 0) {
         $ids = array_slice($ids, $from, $count);
     }
     $ids = new \Horde_Imap_Client_Ids($ids, false);
     $headers = [];
     $fetch_query = new \Horde_Imap_Client_Fetch_Query();
     $fetch_query->envelope();
     $fetch_query->flags();
     $fetch_query->size();
     $fetch_query->uid();
     $fetch_query->imapDate();
     $fetch_query->structure();
     $headers = array_merge($headers, ['importance', 'list-post', 'x-priority']);
     $headers[] = 'content-type';
     $fetch_query->headers('imp', $headers, ['cache' => true, 'peek' => true]);
     $options = ['ids' => $ids];
     // $list is an array of Horde_Imap_Client_Data_Fetch objects.
     $headers = $this->conn->fetch($this->mailBox, $fetch_query, $options);
     ob_start();
     // fix for Horde warnings
     $messages = [];
     foreach ($headers->ids() as $message_id) {
         $header = $headers[$message_id];
         $message = new IMAPMessage($this->conn, $this->mailBox, $message_id, $header);
         $messages[] = $message->getListArray();
     }
     ob_get_clean();
     // sort by time
     usort($messages, function ($a, $b) {
         return $a['dateInt'] < $b['dateInt'];
     });
     return $messages;
 }