From 7e7c28dd6bf2f2078b9e2efa66041a0c22babc8a Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 27 Oct 2009 18:47:10 -0600 Subject: [PATCH] Request #8663: Save message index information in reply/forward drafts --- imp/docs/CHANGES | 2 ++ imp/lib/Compose.php | 46 +++++++++++++++++++++++++++++++++++++++++++++- imp/lib/Imap.php | 3 +++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index c0018eee8..7c0b8031d 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -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. diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index a64d6d8c5..f86fada9b 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -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; diff --git a/imp/lib/Imap.php b/imp/lib/Imap.php index adda112c2..07664ba1b 100644 --- a/imp/lib/Imap.php +++ b/imp/lib/Imap.php @@ -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]; } /** -- 2.11.0