示例#1
0
 /**
  * Access headers collection
  *
  * Lazy-loads if not already attached.
  *
  * @return Headers
  */
 public function getHeaders()
 {
     if (null === $this->headers) {
         if ($this->mail) {
             $part = $this->mail->getRawHeader($this->messageNum);
             $this->headers = Headers::fromString($part);
         } else {
             $this->headers = new Headers();
         }
     }
     return $this->headers;
 }
示例#2
0
文件: Part.php 项目: bradley-holt/zf2
 /**
  * Get all headers
  *
  * The returned headers are as saved internally. All names are lowercased. The value is a string or an array
  * if a header with the same name occurs more than once.
  *
  * @return array headers as array(name => value)
  */
 public function getHeaders()
 {
     if ($this->_headers === null) {
         if (!$this->_mail) {
             $this->_headers = array();
         } else {
             $part = $this->_mail->getRawHeader($this->_messageNum);
             $body = null;
             // "Declare" variable since it's passed by reference
             Mime\Decode::splitMessage($part, $this->_headers, $body);
         }
     }
     return $this->_headers;
 }
 /**
  * @param array $exceptProtocolUids
  *
  * @return array
  * @throws \Exception
  */
 public function fetchAll($exceptProtocolUids = [])
 {
     $this->findRootFolder();
     $exceptProtocolUids = $this->prepareExceptUids($exceptProtocolUids);
     $uids = $this->transport->getUniqueId();
     prn('root folder', $this->rootFolder->getGlobalName());
     prn('uids before', count($uids));
     $uids = array_diff($uids, $exceptProtocolUids);
     $this->lastSyncSuccessful = true;
     $settingID = $this->setting['id'];
     //        $uids = ['3AB4A466-FC5E-11E3-89A8-00215AD99F24'];
     $resUids = [];
     $count = 0;
     prn('total count', count($uids));
     foreach ($uids as $uid) {
         //            prn( 'outside' );
         $storeMail = $this->storage->find(['protocol_ids.' . $settingID => $this->getFullUid($uid)])->current();
         $rawMail = null;
         if (!isset($storeMail) || !$storeMail->is_converted) {
             prn('new mail');
             $storeMail = $this->getModelServiceVerify()->get($this->storeModel);
             //                prn( 'inside', $storeMail );
             $storeMail->protocol_ids = [$settingID => $this->getFullUid($uid)];
             //                prn( $storeMail );
             try {
                 $rawMail = $this->transport->getMessage($this->transport->getNumberByUniqueId($uid));
             } catch (\Exception $ex) {
                 $storeMail->error = ['sync_error' => $ex->getMessage()];
                 $this->lastSyncSuccessful = false;
             }
             $sameMail = $this->storage->find(['message_id' => $rawMail->message_id])->current();
             if (isset($sameMail)) {
                 $storeMail = $sameMail;
                 $protocolIds = $storeMail->protocol_ids;
                 $protocolIds[$settingID] = $this->getFullUid($uid);
                 $storeMail->protocol_ids = $protocolIds;
             }
         }
         if (!$storeMail->is_converted && isset($rawMail)) {
             $convertedMail = [];
             $content = $rawMail->getContent();
             $headers = $rawMail->getHeaders()->toString();
             if (mb_check_encoding($content, 'UTF-8')) {
                 $storeMail->raw_content = $content;
             }
             if (mb_check_encoding($headers, 'UTF-8')) {
                 $storeMail->raw_headers = $headers;
             }
             try {
                 $convertedMail = $this->convertor->convertMailToInternalFormat($rawMail);
                 prn(count($convertedMail['text']));
                 $convertedMail['link'] = [];
                 $storeMail->is_converted = false;
             } catch (\Exception $ex) {
                 $error = $storeMail->error;
                 $error['convert_error'] = $ex->getMessage();
                 $storeMail->error = $error;
             }
             $storeMail->converted_mail = $convertedMail;
             $storeMail->message_id = $rawMail->message_id;
             $size = $this->checkVariableSize($storeMail);
             if ($size > 16777216) {
                 $storeMail->raw_content = 'too big, size = ' . $size . ' bytes';
             }
             prn('size', $size);
             //                prn($storeMail);
         } else {
             $convertedMail = $storeMail->converted_mail;
             $convertedMail['link'] = [];
             $storeMail->converted_mail = $convertedMail;
         }
         $storeMail->raw_content = iconv("utf-8", "utf-8//ignore", $storeMail->raw_content);
         $cm = $storeMail->converted_mail;
         $cm['text'] = iconv("utf-8", "utf-8//ignore", $cm['text']);
         $storeMail->converted_mail = $cm;
         prn(++$count, 'here', $storeMail->message_id);
         $this->storage->save($storeMail);
         $resUids[] = $this->getFullUid($uid);
     }
     return $resUids;
 }
示例#4
0
 /**
  * Special handling for hasTop and hasUniqueid. The headers of the first message is
  * retrieved if Top wasn't needed/tried yet.
  *
  * @see AbstractStorage::__get()
  * @param  string $var
  * @return string
  */
 public function __get($var)
 {
     $result = parent::__get($var);
     if ($result !== null) {
         return $result;
     }
     if (strtolower($var) == 'hastop') {
         if ($this->protocol->hasTop === null) {
             // need to make a real call, because not all server are honest in their capas
             try {
                 $this->protocol->top(1, 0, false);
             } catch (MailException\ExceptionInterface $e) {
                 // ignoring error
             }
         }
         $this->has['top'] = $this->protocol->hasTop;
         return $this->protocol->hasTop;
     }
     if (strtolower($var) == 'hasuniqueid') {
         $id = null;
         try {
             $id = $this->protocol->uniqueid(1);
         } catch (MailException\ExceptionInterface $e) {
             // ignoring error
         }
         $this->has['uniqueid'] = $id ? true : false;
         return $this->has['uniqueid'];
     }
     return $result;
 }