Remove messageid parameter to append()
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 23 Apr 2010 05:38:31 +0000 (23:38 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 23 Apr 2010 05:40:02 +0000 (23:40 -0600)
framework/Imap_Client/lib/Horde/Imap/Client/Base.php
imp/lib/Compose.php
imp/lib/Message.php

index c8b7a60..5530648 100644 (file)
@@ -1169,15 +1169,6 @@ abstract class Horde_Imap_Client_Base
      *                  appended message.
      *                  DEFAULT: internaldate will be the same date as when
      *                  the message was appended.
-     * 'messageid' - (string) For servers/drivers that support the UIDPLUS
-     *               IMAP extension, the UID of the appended message(s) can be
-     *               determined automatically. If this extension is not
-     *               available, the message-id of each message is needed to
-     *               determine the UID. If UIDPLUS is not available, and this
-     *               option is not defined, append() will return true only.
-     *               DEFAULT: If UIDPLUS is supported, or this string is
-     *               provided, appended ID is returned. Else, append() will
-     *               return true.
      * </pre>
      * @param array $options  Additonal options:
      * <pre>
@@ -1185,9 +1176,7 @@ abstract class Horde_Imap_Client_Base
      *             DEFAULT: No.
      * </pre>
      *
-     * @return mixed  An array of the UIDs of the appended messages (if server
-     *                supports UIDPLUS extension or 'messageid' is defined)
-     *                or true.
+     * @return array  The UIDs of the appended messages.
      * @throws Horde_Imap_Client_Exception
      */
     public function append($mailbox, $data, $options = array())
@@ -1201,22 +1190,34 @@ abstract class Horde_Imap_Client_Base
             return $ret;
         }
 
-        $msgid = false;
         $uids = array();
 
         while (list(,$val) = each($data)) {
-            if (empty($val['messageid'])) {
-                $uids[] = null;
-            } else {
-                $msgid = true;
+            if (is_string($data['data'])) {
+                $text = $data;
+            } elseif (is_resource($data['data'])) {
+                $text = '';
+                rewind($data['data']);
+                while ($in = fread($data['data'], 1024)) {
+                    $text .= $in;
+                    if (preg_match("/\n\r*\n\r*/", $text)) {
+                        break;
+                    }
+                }
+            }
+
+            $headers = Horde_Mime_Headers::parseHeaders($text);
+            $msgid = $headers->getValue('message-id');
+
+            if ($msgid) {
                 $search_query = new Horde_Imap_Client_Search_Query();
-                $search_query->headerText('Message-ID', $val['messageid']);
+                $search_query->headerText('Message-ID', $msgid);
                 $uidsearch = $this->search($mailbox, $search_query);
                 $uids[] = reset($uidsearch['match']);
             }
         }
 
-        return $msgid ? $uids : true;
+        return $uids;
     }
 
     /**
index c9c7686..a926d81 100644 (file)
@@ -299,15 +299,12 @@ class IMP_Compose
          * set the $MDNSent keyword. However, IMP doesn't write MDN headers
          * until send time so no need to set the flag here. */
 
-        /* Get the message ID. */
-        $headers = Horde_Mime_Headers::parseHeaders($data);
-
         $drafts_mbox = IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true);
         $old_uid = $this->getMetadata('draft_uid');
 
         /* Add the message to the mailbox. */
         try {
-            $ids = $GLOBALS['imp_imap']->ob()->append($drafts_mbox, array(array('data' => $data, 'flags' => $append_flags, 'messageid' => $headers->getValue('message-id'))));
+            $ids = $GLOBALS['imp_imap']->ob()->append($drafts_mbox, array(array('data' => $data, 'flags' => $append_flags)));
 
             if ($old_uid) {
                 $GLOBALS['injector']->getInstance('IMP_Message')->delete(array($old_uid), array('nuke' => true));
index 777ea39..eb748dd 100644 (file)
@@ -514,7 +514,6 @@ class IMP_Message
         try {
             $res = $GLOBALS['imp_imap']->ob()->fetch($mbox, array(
                 Horde_Imap_Client::FETCH_HEADERTEXT => array(array('peek' => true)),
-                Horde_Imap_Client::FETCH_ENVELOPE => true,
                 Horde_Imap_Client::FETCH_FLAGS => true
             ), array('ids' => array($index)));
             $res = reset($res);
@@ -526,7 +525,7 @@ class IMP_Message
                 unset($res['flags'][$pos]);
             }
 
-            $uid = $GLOBALS['imp_imap']->ob()->append($mbox, array(array('data' => $message->toString(array('headers' => $res['headertext'][0], 'stream' => true)), 'flags' => $res['flags'], 'messageid' => $res['envelope']['message-id'])));
+            $uid = $GLOBALS['imp_imap']->ob()->append($mbox, array(array('data' => $message->toString(array('headers' => $res['headertext'][0], 'stream' => true)), 'flags' => $res['flags'])));
         } catch (Horde_Imap_Client_Exception $e) {
             throw new Horde_Exception(_("An error occured while attempting to strip the attachment."));
         }