Request #8663: Save message index information in reply/forward drafts
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 28 Oct 2009 00:47:10 +0000 (18:47 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 28 Oct 2009 00:47:10 +0000 (18:47 -0600)
imp/docs/CHANGES
imp/lib/Compose.php
imp/lib/Imap.php

index c0018ee..7c0b803 100644 (file)
@@ -2,6 +2,8 @@
 v5.0-git
 --------
 
+[mms] For drafts, save the original message index for forwards/replies so when
+      eventually sent, log information can be updated (Request #8663).
 [mms] Upgrade RTE to CKEditor v3.
 [mms] Sort by display name for to/from fields if supported on IMAP server.
 [mms] Add ability to quickly filter by flags in DIMP.
index a64d6d8..f86fada 100644 (file)
@@ -238,7 +238,27 @@ class IMP_Compose
         /* Add necessary headers for replies. */
         $this->_addReferences($draft_headers);
 
-        return $base->toString(array('defserver' => $session ? $_SESSION['imp']['maildomain'] : null, 'headers' => $draft_headers));
+        /* Add information necessary to log replies/forwards when finally
+         * sent. */
+        if (!empty($this->_metadata['reply_type'])) {
+            try {
+                $imap_url = $GLOBALS['imp_imap']->ob()->utils->createUrl(array(
+                    'type' => $_SESSION['imp']['protocol'],
+                    'username' => $GLOBALS['imp_imap']->ob()->getParam('username'),
+                    'hostspec' => $GLOBALS['imp_imap']->ob()->getParam('hostspec'),
+                    'mailbox' => $this->_metadata['mailbox'],
+                    'uid' => $this->_metadata['index'],
+                    'uidvalidity' => $GLOBALS['imp_imap']->checkUidvalidity($this->_metadata['mailbox'])
+                ));
+
+                $draft_headers->addHeader($this->_metadata['reply_type'] == 'reply' ? 'X-IMP-Draft-Reply' : 'X-IMP-Draft-Forward', '<' . $imap_url . '>');
+            } catch (Horde_Exception $e) {}
+        }
+
+        return $base->toString(array(
+            'defserver' => $session ? $_SESSION['imp']['maildomain'] : null,
+            'headers' => $draft_headers
+        ));
     }
 
     /**
@@ -354,6 +374,30 @@ class IMP_Compose
             }
         }
 
+        if ($val = $headers->getValue('x-imp-draft-reply')) {
+            $reply_type = 'reply';
+        } elseif ($val = $headers->getValue('x-imp-draft-forward')) {
+            $reply_type = 'forward';
+        }
+
+        if ($val) {
+            $imap_url = $GLOBALS['imp_imap']->ob()->utils->parseUrl(rtrim(ltrim($val, '<'), '>'));
+
+            try {
+                if (($imap_url['type'] == $_SESSION['imp']['protocol']) &&
+                    ($imap_url['username'] == $GLOBALS['imp_imap']->ob()->getParam('username')) &&
+                    // Ignore hostspec and port, since these can change
+                    // even though the server is the same. UIDVALIDITY should
+                    // catch any true server/backend changes.
+                    ($GLOBALS['imp_imap']->checkUidvalidity($imap_url['mailbox']) == $imap_url['uidvalidity']) &&
+                    IMP_Contents::singleton($imap_url['uid'] . IMP::IDX_SEP . $imap_url['mailbox'])) {
+                    $this->_metadata['index'] = $imap_url['uid'];
+                    $this->_metadata['mailbox'] = $imap_url['mailbox'];
+                    $this->_metadata['reply_type'] = $reply_type;
+                }
+            } catch (Horde_Exception $e) {}
+        }
+
         list($this->_metadata['draft_index'],) = explode(IMP::IDX_SEP, $index);
         $this->_modified = true;
 
index adda112..07664ba 100644 (file)
@@ -280,6 +280,7 @@ class IMP_Imap
      *
      * @param string $mailbox  The mailbox to check. Must be an IMAP mailbox.
      *
+     * @return string  The mailbox UIDVALIDITY.
      * @throws Horde_Exception
      */
     public function checkUidvalidity($mailbox)
@@ -303,6 +304,8 @@ class IMP_Imap
         if ($this->_uidvalid[$mailbox]) {
             throw new Horde_Exception(_("Mailbox structure on server has changed."));
         }
+
+        return $_SESSION['imp']['cache']['uidvalid'][$mailbox];
     }
 
     /**