Author: Michael Slusarz (slusarz@horde.org)
Inheritance: extends Horde_Imap_Client_Data_Format
示例#1
0
 /**
  * Prepares append message data for insertion into the IMAP command
  * string.
  *
  * @param mixed $data      Either a resource or a string.
  * @param integer &$asize  Total append size.
  *
  * @return Horde_Imap_Client_Data_Format_String  The data object.
  */
 protected function _appendData($data, &$asize)
 {
     if (is_resource($data)) {
         rewind($data);
     }
     $ob = new Horde_Imap_Client_Data_Format_String($data, array('eol' => true, 'skipscan' => true));
     // APPEND data MUST be sent in a literal (RFC 3501 [6.3.11]).
     $ob->forceLiteral();
     $asize += $ob->length();
     return $ob;
 }
示例#2
0
文件: Nstring.php 项目: horde/horde
 /**
  */
 public function getStream()
 {
     return is_null($this->_data) ? new Horde_Stream_Temp() : parent::getStream();
 }
示例#3
0
 /**
  */
 protected function _append(Horde_Imap_Client_Mailbox $mailbox, $data, $options)
 {
     // Check for MULTIAPPEND extension (RFC 3502)
     if (count($data) > 1 && !$this->queryCapability('MULTIAPPEND')) {
         $result = $this->getIdsOb();
         foreach (array_keys($data) as $key) {
             $res = $this->_append($mailbox, array($data[$key]), $options);
             if ($res === true || $result === true) {
                 $result = true;
             } else {
                 $result->add($res);
             }
         }
         return $result;
     }
     // If the mailbox is currently selected read-only, we need to close
     // because some IMAP implementations won't allow an append.
     $this->close();
     // Check for CATENATE extension (RFC 4469)
     $catenate = $this->queryCapability('CATENATE');
     $t =& $this->_temp;
     $t['appendsize'] = 0;
     $t['appenduid'] = $this->getIdsOb();
     $t['trycreate'] = null;
     $t['uidplusmbox'] = $mailbox;
     $cmd = $this->_clientCommand(array('APPEND', new Horde_Imap_Client_Data_Format_Mailbox($mailbox)));
     foreach (array_keys($data) as $key) {
         if (!empty($data[$key]['flags'])) {
             $tmp = new Horde_Imap_Client_Data_Format_List();
             foreach ($data[$key]['flags'] as $val) {
                 /* Ignore recent flag. RFC 3501 [9]: flag definition */
                 if (strcasecmp($val, Horde_Imap_Client::FLAG_RECENT) !== 0) {
                     $tmp->add($val);
                 }
             }
             $cmd->add($tmp);
         }
         if (!empty($data[$key]['internaldate'])) {
             $cmd->add(new Horde_Imap_Client_Data_Format_DateTime($data[$key]['internaldate']));
         }
         if (is_array($data[$key]['data'])) {
             if ($catenate) {
                 $cmd->add('CATENATE');
                 $tmp = new Horde_Imap_Client_Data_Format_List();
             } else {
                 $data_stream = new Horde_Stream_Temp();
             }
             reset($data[$key]['data']);
             while (list(, $v) = each($data[$key]['data'])) {
                 switch ($v['t']) {
                     case 'text':
                         $text_data = $this->_appendData($v['v']);
                         if ($catenate) {
                             $text_str = new Horde_Imap_Client_Data_Format_String($text_data);
                             $text_str->forceLiteral();
                             $tmp->add(array('TEXT', $text_str));
                         } else {
                             $data_stream->add($text_data);
                         }
                         break;
                     case 'url':
                         if ($catenate) {
                             $tmp->add(array('URL', new Horde_Imap_Client_Data_Format_Astring($v['v'])));
                         } else {
                             $data_stream->add($this->_convertCatenateUrl($v['v']));
                         }
                         break;
                 }
             }
             if ($catenate) {
                 $cmd->add($tmp);
             } else {
                 rewind($data_stream->stream);
                 $text_data = new Horde_Imap_Client_Data_Format_String($data_stream);
                 $text_data->forceLiteral();
                 $cmd->add($text_data);
             }
         } else {
             $cmd->add(new Horde_Imap_Client_Data_Format_String($this->_appendData($data[$key]['data'])));
         }
     }
     try {
         $this->_sendLine($cmd, array('noliteralplus' => $this->_temp['appendsize'] > 524288));
     } catch (Horde_Imap_Client_Exception $e) {
         switch ($e->getCode()) {
             case $e::CATENATE_BADURL:
             case $e::CATENATE_TOOBIG:
                 /* Cyrus 2.4 (at least as of .14) has a broken CATENATE (see
                  * Bug #11111). Regardless, if CATENATE is broken, we can try
                  * to fallback to APPEND. */
                 $cap = $this->capability();
                 unset($cap['CATENATE']);
                 $this->_setInit('capability', $cap);
                 return $this->_append($mailbox, $data, $options);
         }
         if (!empty($options['create']) && $this->_temp['trycreate']) {
             $this->createMailbox($mailbox);
             unset($options['create']);
             return $this->_append($mailbox, $data, $options);
         }
         throw $e;
     }
     /* If we reach this point and have data in $_temp['appenduid'],
      * UIDPLUS (RFC 4315) has done the dirty work for us. */
     return count($t['appenduid']) ? $t['appenduid'] : true;
 }
示例#4
0
 /**
  */
 public function quoted()
 {
     return is_null($this->_data) ? false : parent::quoted();
 }