Exemple #1
0
 public function testLateFetch()
 {
     $mail = new Storage\Mbox(array('filename' => __DIR__ . '/../_files/test.mbox/INBOX'));
     $message = new Message(array('handler' => $mail, 'id' => 5));
     $this->assertEquals($message->countParts(), 2);
     $this->assertEquals($message->countParts(), 2);
     $message = new Message(array('handler' => $mail, 'id' => 5));
     $this->assertEquals($message->subject, 'multipart');
     $message = new Message(array('handler' => $mail, 'id' => 5));
     $this->assertTrue(strpos($message->getContent(), 'multipart message') === 0);
 }
Exemple #2
0
 /**
  * @param Message $message
  *
  * @return array|null
  */
 public function getAttachments(Message $message)
 {
     $attachments = null;
     // Only multi-part will have attachments
     if ($message->isMultipart()) {
         if ($message->countParts() > 1) {
             $partCount = $message->countParts();
             for ($i = 0; $i < $partCount; $i++) {
                 $part = $message->getPart($i + 1);
                 // Check for headers, to avoid exceptions
                 if ($part->getHeaders() !== null) {
                     // Getting disposition
                     $disposition = null;
                     try {
                         $disposition = $part->getHeaderField('Content-Disposition');
                     } catch (\Exception $e) {
                         // Zend throws an Exception, if headerField does not exist
                     }
                     if ($disposition == 'attachment') {
                         $content = quoted_printable_decode($part->getContent());
                         // Encoding?
                         try {
                             $transferEncoding = $part->getHeaderField('Content-Transfer-Encoding');
                             if ($transferEncoding == 'base64') {
                                 $content = base64_decode($content);
                             }
                         } catch (\Exception $e) {
                             // Zend throws an Exception, if headerField does not exist
                         }
                         $attachments[] = array('mime' => $part->getHeaderField('Content-Type'), 'filename' => $part->getHeaderField('Content-Disposition', 'filename'), 'content' => $content);
                     }
                 }
             }
         }
     }
     return $attachments;
 }