IMP_Compose:: improvements.
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 26 Jun 2009 07:53:00 +0000 (01:53 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 26 Jun 2009 08:05:43 +0000 (02:05 -0600)
No need to carry around state/information about reply, forward, and
drafts.  Store this information inside the cached IMP_Compose object and
internally retrieve it from this object when needed.
Proactively remove unused IMP_Compose objects from the session when
finished using them.

imp/ajax.php
imp/compose-dimp.php
imp/compose-mimp.php
imp/compose.php
imp/js/src/compose-dimp.js
imp/lib/Compose.php
imp/lib/Views/Compose.php
imp/templates/chunks/compose.php
imp/templates/compose/compose-mimp.inc

index 4d2cd50..dfaed6e 100644 (file)
@@ -532,14 +532,15 @@ case 'GetReplyData':
     $result->identity = $reply_msg['identity'];
     break;
 
+case 'CancelCompose':
 case 'DeleteDraft':
-    $index = Horde_Util::getPost('index');
-    if (empty($indices)) {
-        break;
+    $imp_compose = IMP_Compose::singleton(Horde_Util::getPost('imp_compose'));
+    $imp_compose->destroy();
+    if ($action == 'DeleteDraft') {
+        $imp_message = &IMP_Message::singleton();
+        $idx_array = array($imp_compose->getMetadata('draft_index') . IMP::IDX_SEP . IMP::folderPref($prefs->getValue('drafts_folder'), true));
+        $imp_message->delete($idx_array, array('nuke' => true));
     }
-    $imp_message = &IMP_Message::singleton();
-    $idx_array = array($index . IMP::IDX_SEP . IMP::folderPref($prefs->getValue('drafts_folder'), true));
-    $imp_message->delete($idx_array, array('nuke' => true));
     break;
 
 case 'DeleteAttach':
index 4b0d279..6bd8d46 100644 (file)
@@ -33,7 +33,7 @@ $compose_disable = !empty($conf['hooks']['disable_compose']) &&
 
 /* The headers of the message. */
 $header = array();
-foreach (array('to', 'cc', 'bcc', 'subject', 'in_reply_to', 'references') as $v) {
+foreach (array('to', 'cc', 'bcc', 'subject') as $v) {
     $header[$v] = rawurldecode(Horde_Util::getFormData($v, ''));
 }
 
@@ -101,13 +101,9 @@ if (count($_POST)) {
             $result->success = 1;
 
             /* Delete existing draft. */
-            _removeAutoSaveDraft(Horde_Util::getFormData('draft_index'));
+            _removeAutoSaveDraft($imp_compose->getMetadata('draft_index'));
 
-            if ($action == 'auto_save_draft') {
-                /* Just update the last draft index so subsequent
-                 * drafts are properly replaced. */
-                $result->draft_index = (int)$imp_compose->saveDraftIndex();
-            } else {
+            if ($action != 'auto_save_draft') {
                 $notification->push($res);
             }
         } catch (IMP_Compose_Exception $e) {
@@ -140,11 +136,10 @@ if (count($_POST)) {
         $message = Horde_Util::getFormData('message');
         $html = Horde_Util::getFormData('html');
 
-        $result->index = intval(Horde_Util::getFormData('index'));
+        $result->index = $imp_compose->getMetadata('index');
 
-        $reply_folder = Horde_Util::getFormData('folder');
-        if ($reply_type = Horde_Util::getFormData('reply_type')) {
-            $result->reply_folder = Horde_Util::getFormData('folder');
+        if ($reply_type = $imp_compose->getMetadata('reply_type')) {
+            $result->reply_folder = $imp_compose->getMetadata('mailbox');
             $result->reply_type = $reply_type;
         }
 
@@ -155,8 +150,6 @@ if (count($_POST)) {
 
         $options = array(
             'readreceipt' => Horde_Util::getFormData('request_read_receipt'),
-            'reply_index' => $result->index . IMP::IDX_SEP . $reply_folder,
-            'reply_type' => $reply_type,
             'save_attachments' => Horde_Util::getFormData('save_attachments_select'),
             'save_sent' => (($prefs->isLocked('save_sent_mail'))
                             ? $identity->getValue('save_sent_mail')
@@ -175,7 +168,7 @@ if (count($_POST)) {
         /* Remove any auto-saved drafts. */
         if ($prefs->getValue('auto_save_drafts') ||
             $prefs->getValue('auto_delete_drafts')) {
-            _removeAutoSaveDraft(Horde_Util::getFormData('draft_index'));
+            _removeAutoSaveDraft($imp_compose->getMetadata('draft_index'));
             $result->draft_delete = 1;
         }
 
@@ -187,10 +180,12 @@ if (count($_POST)) {
         }
 
         /* Update maillog information. */
-        if (!empty($header['in_reply_to']) &&
-            !empty($GLOBALS['conf']['maillog']['use_maillog']) &&
-            ($tmp = DIMP::getMsgLogInfo($header['in_reply_to']))) {
-            $result->log = $tmp;
+        if (!empty($GLOBALS['conf']['maillog']['use_maillog'])) {
+            $in_reply_to = $imp_compose->getMetadata('in_reply_to');
+            if (!empty($in_reply_to) &&
+                ($tmp = DIMP::getMsgLogInfo($in_reply_to))) {
+                $result->log = $tmp;
+            }
         }
 
         $res = DIMP::getFolderResponse($imptree);
@@ -306,19 +301,18 @@ if ($get_sig && !empty($sig)) {
         : $msg . "\n" . $sig;
 }
 
-$args = array(
-    'folder' => $folder,
-    'index' => $index,
-    'composeCache' => $imp_compose->getCacheId(),
-    'qreply' => false,
-);
-
 $t = new IMP_Template(IMP_TEMPLATES . '/imp/');
 $t->setOption('gettext', true);
 $t->set('title', $title);
 $t->set('closelink', IMP::img('close.png', 'X', array('id' => 'compose_close'), $registry->getImageDir('horde')));
 
-$compose_result = IMP_Views_Compose::showCompose($args);
+$compose_result = IMP_Views_Compose::showCompose(array(
+    'folder' => $folder,
+    'index' => $index,
+    'composeCache' => $imp_compose->getCacheId(),
+    'qreply' => false,
+));
+
 $t->set('compose_html', $compose_result['html']);
 
 /* Javscript variables to be set immediately. */
index 92b5f25..6b0d6ca 100644 (file)
@@ -31,10 +31,7 @@ require_once 'Horde/Identity.php';
 
 /* The message text and headers. */
 $msg = '';
-$header = array(
-    'in_reply_to' => Horde_Util::getFormData('in_reply_to'),
-    'references' => Horde_Util::getFormData('references')
-);
+$header = array();
 
 /* Set the current identity. */
 $identity = &Identity::singleton(array('imp', 'imp'));
@@ -161,7 +158,10 @@ case _("Send"):
     $f_cc = $f_bcc = null;
     $header = array();
 
-    if ($ctype = Horde_Util::getFormData('ctype')) {
+    $index = $imp_compose->getMetadata('index');
+    $thismailbox = $imp_compose->getMetadata('mailbox');
+
+    if ($ctype = $imp_compose->getMetadata('reply_type')) {
         if (!($imp_contents = &_getIMPContents($index, $thismailbox))) {
             break;
         }
@@ -208,13 +208,13 @@ case _("Send"):
     $options = array(
         'save_sent' => $save_sent_mail,
         'sent_folder' => $sent_mail_folder,
-        'reply_type' => $ctype,
-        'reply_index' => empty($index) ? null : $index . IMP::IDX_SEP . $thismailbox,
         'readreceipt' => Horde_Util::getFormData('request_read_receipt')
     );
 
     try {
         if ($imp_compose->buildAndSendMessage($message, $header, NLS::getEmailCharset(), false, $options)) {
+            $imp_compose->destroy();
+
             if (Horde_Util::getFormData('resume_draft') &&
                 $prefs->getValue('auto_delete_drafts')) {
                 $imp_message = &IMP_Message::singleton();
index d1a1589..142d6af 100644 (file)
@@ -61,15 +61,10 @@ $session_control = 'netscape';
 require_once dirname(__FILE__) . '/lib/base.php';
 require_once 'Horde/Identity.php';
 
-/* The message text. */
+/* The message headers and text. */
+$header = array();
 $msg = '';
 
-/* The headers of the message. */
-$header = array(
-    'in_reply_to' => Horde_Util::getFormData('in_reply_to'),
-    'references' => Horde_Util::getFormData('references')
-);
-
 $get_sig = true;
 $pgp_passphrase_dialog = $pgp_symmetric_passphrase_dialog = $showmenu = $smime_passphrase_dialog = false;
 $cursor_pos = $oldrtemode = $rtemode = $siglocation = null;
@@ -120,7 +115,6 @@ if ($actionID) {
 $save_sent_mail = Horde_Util::getFormData('save_sent_mail');
 $sent_mail_folder = $identity->getValue('sent_mail_folder');
 $index = Horde_Util::getFormData('index');
-$reply_index = Horde_Util::getFormData('reply_index');
 $thismailbox = Horde_Util::getFormData('thismailbox');
 
 /* Check for duplicate submits. */
@@ -338,7 +332,6 @@ case 'reply_list':
     $title .= ' ' . $header['subject'];
 
     $encoding = empty($charset) ? $reply_msg['encoding'] : $charset;
-    $reply_index = $index;
     break;
 
 case 'forward':
@@ -368,6 +361,7 @@ case 'redirect_send':
 
     try {
         $imp_ui->redirectMessage($f_to, $imp_compose, $imp_contents, $encoding);
+        $imp_compose->destroy();
         if ($isPopup) {
             if ($prefs->getValue('compose_confirm')) {
                 $notification->push(_("Message redirected successfully."), 'horde.success');
@@ -422,8 +416,6 @@ case 'send_message':
         'save_sent' => $save_sent_mail,
         'sent_folder' => $sent_mail_folder,
         'save_attachments' => Horde_Util::getFormData('save_attachments_select'),
-        'reply_type' => Horde_Util::getFormData('reply_type'),
-        'reply_index' => (empty($reply_index) ? null : $reply_index . IMP::IDX_SEP . $thismailbox),
         'encrypt' => $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : Horde_Util::getFormData('encrypt_options'),
         'priority' => Horde_Util::getFormData('x_priority'),
         'readreceipt' => Horde_Util::getFormData('request_read_receipt')
@@ -431,6 +423,7 @@ case 'send_message':
 
     try {
         $sent = $imp_compose->buildAndSendMessage($message, $header, $charset, $rtemode, $options);
+        $imp_compose->destroy();
     } catch (IMP_Compose_Exception $e) {
         $get_sig = false;
         $code = $e->getCode();
@@ -502,6 +495,7 @@ case 'save_draft':
     /* Save the draft. */
     try {
         $result = $imp_compose->saveDraft($header, $message, NLS::getCharset(), $rtemode);
+        $imp_compose->destroy();
 
         /* Closing draft if requested by preferences. */
         if ($isPopup) {
@@ -538,6 +532,7 @@ case 'fwd_digest':
 
 case 'cancel_compose':
     $imp_compose->deleteAllAttachments();
+    $imp_compose->destroy();
     if ($isPopup) {
         Horde_Util::closeWindowJS();
     } else {
@@ -874,20 +869,6 @@ if ($redirect) {
 
     $template_output = $t->fetch(IMP_TEMPLATES . '/compose/redirect.html');
 } else {
-    if (!($reply_type = Horde_Util::getFormData('reply_type'))) {
-        switch ($actionID) {
-        case 'reply':
-        case 'reply_all':
-        case 'reply_list':
-            $reply_type = 'reply';
-            break;
-
-        case 'forward':
-            $reply_type = 'forward';
-            break;
-        }
-    }
-
     /* Prepare the compose template. */
     $tabindex = 0;
 
@@ -901,11 +882,9 @@ if ($redirect) {
         'compose_formToken' => Horde_Token::generateId('compose'),
         'composeCache' => $composeCacheID,
         'mailbox' => htmlspecialchars($imp_mbox['mailbox']),
-        'thismailbox' => $thismailbox,
         'attachmentAction' => '',
         'oldrtemode' => $rtemode,
-        'rtemode' => $rtemode,
-        'index' => $index
+        'rtemode' => $rtemode
     );
 
     if ($_SESSION['imp']['file_upload']) {
@@ -914,14 +893,6 @@ if ($redirect) {
     foreach (array('page', 'start', 'popup') as $val) {
         $hidden[$val] = htmlspecialchars(Horde_Util::getFormData($val));
     }
-    if ($reply_type) {
-        $hidden['reply_type'] = $reply_type;
-        $hidden['reply_index'] = $reply_index;
-        $hidden['in_reply_to'] = htmlspecialchars($header['in_reply_to']);
-        if ($reply_type == 'reply') {
-            $hidden['references'] = htmlspecialchars($header['references']);
-        }
-    }
     if (!empty($resume_draft)) {
         $hidden['resume_draft'] = 1;
     }
index 17ce0fd..1a3bb1a 100644 (file)
@@ -18,9 +18,7 @@ var DimpCompose = {
     confirmCancel: function()
     {
         if (window.confirm(DIMP.text_compose.cancel)) {
-            if (DIMP.conf_compose.auto_save_interval_val) {
-                DimpCore.doAction('DeleteDraft', { index: $F('index') });
-            }
+            DimpCore.doAction(DIMP.conf_compose.auto_save_interval_val ? 'DeleteDraft' : 'CancelCompose', { imp_compose: $F('composeCache') });
             return this.closeCompose();
         }
     },
@@ -45,7 +43,7 @@ var DimpCompose = {
             this.removeAttach(al);
         }
 
-        $('draft_index', 'composeCache').invoke('setValue', '');
+        $('composeCache').setValue('');
         $('qreply', 'sendcc', 'sendbcc').invoke('hide');
         [ $('msgData'), $('togglecc').up(), $('togglebcc').up() ].invoke('show');
         if (this.editor_on) {
@@ -219,7 +217,6 @@ var DimpCompose = {
             switch (d.action) {
             case 'auto_save_draft':
                 this.button_pressed = false;
-                $('draft_index').setValue(d.draft_index);
                 break;
 
             case 'save_draft':
@@ -242,6 +239,7 @@ var DimpCompose = {
                         DIMP.baseWindow.DimpBase.flag(d.reply_type == 'reply' ? '\\answered' : '$forwarded', true, { index: d.index, mailbox: d.reply_folder, noserver: true });
                     }
 
+                    // @TODO: Needed?
                     if (d.folder) {
                         DIMP.baseWindow.DimpBase.createFolder(d.folder);
                     }
@@ -489,9 +487,6 @@ var DimpCompose = {
             this.toggleCC('bcc');
         }
         $('subject').setValue(header.subject);
-        $('in_reply_to').setValue(header.in_reply_to);
-        $('references').setValue(header.references);
-        $('reply_type').setValue(header.replytype);
 
         Field.focus(focus || 'to');
         this.resizeMsgArea();
index a68974d..bbe6bad 100644 (file)
@@ -23,6 +23,13 @@ class IMP_Compose
     const VFS_DRAFTS_PATH = '.horde/imp/drafts';
 
     /**
+     * Singleton instances.
+     *
+     * @var array
+     */
+    static protected $_instances = array();
+
+    /**
      * The cached attachment data.
      *
      * @var array
@@ -30,6 +37,13 @@ class IMP_Compose
     protected $_cache = array();
 
     /**
+     * Various metadata for this message.
+     *
+     * @var array
+     */
+    protected $_metadata = array();
+
+    /**
      * The aggregate size of all attachments (in bytes).
      *
      * @var integer
@@ -59,13 +73,6 @@ class IMP_Compose
     protected $_linkAttach = false;
 
     /**
-     * The UID of the last draft saved via saveDraft().
-     *
-     * @var integer
-     */
-    protected $_draftIdx;
-
-    /**
      * The cache ID used to store object in session.
      *
      * @var string
@@ -73,7 +80,7 @@ class IMP_Compose
     protected $_cacheid;
 
     /**
-     * Has the attachment list been modified.
+     * Mark as modified for purposes of storing in the session.
      *
      * @var boolean
      */
@@ -91,22 +98,17 @@ class IMP_Compose
      */
     static public function singleton($cacheid = null)
     {
-        static $instance = array();
-
-        if (!is_null($cacheid) && !isset($instance[$cacheid])) {
-            $cacheSess = Horde_SessionObjects::singleton();
-            $instance[$cacheid] = $cacheSess->query($cacheid);
-            if (!empty($instance[$cacheid])) {
-                $cacheSess->setPruneFlag($cacheid, true);
-            }
+        if (!is_null($cacheid) && !isset(self::$_instances[$cacheid])) {
+            $obs = Horde_SessionObjects::singleton();
+            self::$_instances[$cacheid] = $obs->query($cacheid);
         }
 
-        if (is_null($cacheid) || empty($instance[$cacheid])) {
+        if (is_null($cacheid) || empty(self::$_instances[$cacheid])) {
             $cacheid = is_null($cacheid) ? uniqid(mt_rand()) : $cacheid;
-            $instance[$cacheid] = new IMP_Compose($cacheid);
+            self::$_instances[$cacheid] = new IMP_Compose($cacheid);
         }
 
-        return $instance[$cacheid];
+        return self::$_instances[$cacheid];
     }
 
     /**
@@ -127,12 +129,35 @@ class IMP_Compose
     {
         if ($this->_modified) {
             $this->_modified = false;
-            $cacheSess = Horde_SessionObjects::singleton();
-            $cacheSess->overwrite($this->_cacheid, $this, false);
+            $obs = Horde_SessionObjects::singleton();
+            $obs->overwrite($this->_cacheid, $this, false);
         }
     }
 
     /**
+     * Destroys an IMP_Compose instance.
+     */
+    public function destroy()
+    {
+        $obs = Horde_SessionObjects::singleton();
+        $obs->prune($this->_cacheid);
+    }
+
+    /**
+     * Gets metadata about the current object.
+     *
+     * @param string $name  The metadata name.
+     *
+     * @return mixed  The metadata value or null if it doesn't exist.
+     */
+    public function getMetadata($name)
+    {
+        return isset($this->_metadata[$name])
+            ? $this->_metadata[$name]
+            : null;
+    }
+
+    /**
      * Saves a message to the draft folder.
      *
      * @param array $header    List of message headers.
@@ -223,7 +248,6 @@ class IMP_Compose
     protected function _saveDraftServer($data, $drafts_mbox)
     {
         $imp_folder = IMP_Folder::singleton();
-        $this->_draftIdx = null;
 
         /* Check for access to drafts folder. */
         if (!$imp_folder->exists($drafts_mbox) &&
@@ -246,24 +270,15 @@ class IMP_Compose
         /* 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'))));
-            $this->_draftIdx = reset($ids);
+            $this->_metadata['draft_index'] = reset($ids);
             return sprintf(_("The draft has been saved to the \"%s\" folder."), IMP::displayFolder($drafts_mbox));
         } catch (Horde_Imap_Client_Exception $e) {
+            unset($this->_metadata['draft_index']);
             return _("The draft was not successfully saved.");
         }
     }
 
     /**
-     * Returns the UID of the last message saved via saveDraft().
-     *
-     * @return integer  An IMAP UID.
-     */
-    public function saveDraftIndex()
-    {
-        return $this->_draftIdx;
-    }
-
-    /**
      * Resumes a previously saved draft message.
      *
      * @param string $index  The IMAP message mailbox/index. The index should
@@ -321,7 +336,7 @@ class IMP_Compose
             'subject' => $headers->getValue('subject')
         );
 
-        list($this->_draftIdx,) = explode(IMP::IDX_SEP, $index);
+        list($this->_metadata['draft_index'],) = explode(IMP::IDX_SEP, $index);
 
         return array(
             'header' => $header,
@@ -331,7 +346,6 @@ class IMP_Compose
         );
     }
 
-
     /**
      * Builds and sends a MIME message.
      *
@@ -344,10 +358,6 @@ class IMP_Compose
      * 'save_sent' = (bool) Save sent mail?
      * 'sent_folder' = (string) The sent-mail folder (UTF7-IMAP).
      * 'save_attachments' = (bool) Save attachments with the message?
-     * 'reply_type' = (string) What kind of reply this is (reply or forward).
-     * 'reply_index' = (string) The IMAP message mailbox/index of the message
-     *                 we are replying to. The index should be in
-     *                 IMP::parseIndicesList() format #1.
      * 'encrypt' => (integer) A flag whether to encrypt or sign the message.
      *              One of IMP::PGP_ENCRYPT, IMP::PGP_SIGNENC,
      *              IMP::SMIME_ENCRYPT, or IMP::SMIME_SIGNENC.
@@ -463,12 +473,13 @@ class IMP_Compose
         $headers->addHeader('Subject', Horde_String::convertCharset($header['subject'], $browser_charset, $charset));
 
         /* Add necessary headers for replies. */
-        if (!empty($opts['reply_type']) && ($opts['reply_type'] == 'reply')) {
-            if (!empty($header['references'])) {
-                $headers->addHeader('References', implode(' ', preg_split('|\s+|', trim($header['references']))));
+        if (!empty($this->_metadata['reply_type']) &&
+            ($this->_metadata['reply_type'] == 'reply')) {
+            if (!empty($this->_metadata['references'])) {
+                $headers->addHeader('References', implode(' ', preg_split('|\s+|', trim($this->_metadata['references']))));
             }
-            if (!empty($header['in_reply_to'])) {
-                $headers->addHeader('In-Reply-To', $header['in_reply_to']);
+            if (!empty($this->_metadata['in_reply_to'])) {
+                $headers->addHeader('In-Reply-To', $this->_metadata['in_reply_to']);
             }
         }
 
@@ -501,7 +512,7 @@ class IMP_Compose
                 /* Unsuccessful send. */
                 Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
                 if (isset($sentmail)) {
-                    $sentmail->log(empty($opts['reply_type']) ? 'new' : $opts['reply_type'], $headers->getValue('message-id'), $val['recipients'], false);
+                    $sentmail->log(empty($this->_metadata['reply_type']) ? 'new' : $this->_metadata['reply_type'], $headers->getValue('message-id'), $val['recipients'], false);
                 }
 
                 throw new IMP_Compose_Exception(sprintf(_("There was an error sending your message: %s"), $e->getMessage()));
@@ -509,37 +520,35 @@ class IMP_Compose
 
             /* Store history information. */
             if (isset($sentmail)) {
-                $sentmail->log(empty($opts['reply_type']) ? 'new' : $opts['reply_type'], $headers->getValue('message-id'), $val['recipients'], true);
+                $sentmail->log(empty($this->_metadata['reply_type']) ? 'new' : $this->_metadata['reply_type'], $headers->getValue('message-id'), $val['recipients'], true);
             }
         }
 
         $sent_saved = true;
 
-        if (!empty($opts['reply_type'])) {
+        if (!empty($this->_metadata['reply_type'])) {
             /* Log the reply. */
-            if (!empty($header['in_reply_to']) &&
+            if (!empty($this->_metadata['in_reply_to']) &&
                 !empty($conf['maillog']['use_maillog'])) {
-                IMP_Maillog::log($opts['reply_type'], $header['in_reply_to'], $recipients);
+                IMP_Maillog::log($this->_metadata['reply_type'], $this->_metadata['in_reply_to'], $recipients);
             }
 
-            if (!empty($opts['reply_index'])) {
-                $imp_message = IMP_Message::singleton();
+            $imp_message = IMP_Message::singleton();
+            $reply_index = array($this->_metadata['index'] . IMP::IDX_SEP . $this->_metadata['mailbox']);
 
-                switch ($opts['reply_type']) {
-                case 'reply':
-                    /* Make sure to set the IMAP reply flag and unset any
-                     * 'flagged' flag. */
-                    $imp_message->flag(array('\\answered'), array($opts['reply_index']));
-                    $imp_message->flag(array('\\flagged'), array($opts['reply_index']), false);
-                    break;
+            switch ($this->_metadata['reply_type']) {
+            case 'reply':
+                /* Make sure to set the IMAP reply flag and unset any
+                 * 'flagged' flag. */
+                $imp_message->flag(array('\\answered'), $reply_index);
+                $imp_message->flag(array('\\flagged'), $reply_index, false);
+                break;
 
-                case 'forward':
-                    /* Set the '$Forwarded' flag, if possible, in the mailbox.
-                     * This flag is a pseudo-standard flag. See, e.g.:
-                     * http://tools.ietf.org/html/draft-melnikov-imap-keywords-03 */
-                    $imp_message->flag(array('$Forwarded'), array($opts['reply_index']));
-                    break;
-                }
+            case 'forward':
+                /* Set the '$Forwarded' flag, if possible, in the mailbox.
+                 * See RFC 4550 [2.8] */
+                $imp_message->flag(array('$Forwarded'), $reply_index);
+                break;
             }
         }
 
@@ -1170,22 +1179,27 @@ class IMP_Compose
             'to' => '',
             'cc' => '',
             'bcc' => '',
-            'subject' => '',
-            'in_reply_to' => '',
-            'references' => ''
+            'subject' => ''
         );
 
         $h = $contents->getHeaderOb();
         $match_identity = $this->_getMatchingIdentity($h);
 
-        /* Set the message_id and references headers. */
+        $this->_metadata['index'] = $contents->getIndex();
+        $this->_metadata['mailbox'] = $contents->getMailbox();
+        $this->_metadata['reply_type'] = 'reply';
+        $this->_modified = true;
+
+        /* Set the message-id related headers. */
         if (($msg_id = $h->getValue('message-id'))) {
-            $header['in_reply_to'] = chop($msg_id);
-            if (($header['references'] = $h->getValue('references'))) {
-                $header['references'] .= ' ' . $header['in_reply_to'];
+            $this->_metadata['in_reply_to'] = chop($msg_id);
+
+            if (($refs = $h->getValue('references'))) {
+                $refs .= ' ' . $this->_metadata['in_reply_to'];
             } else {
-                $header['references'] = $header['in_reply_to'];
+                $refs = $this->_metadata['in_reply_to'];
             }
+            $this->_metadata['references'] = $refs;
         }
 
         $subject = $h->getValue('subject');
@@ -1349,18 +1363,21 @@ class IMP_Compose
             'to' => '',
             'cc' => '',
             'bcc' => '',
-            'subject' => '',
-            'in_reply_to' => '',
-            'references' => ''
+            'subject' => ''
         );
 
         $h = $contents->getHeaderOb();
         $format = 'text';
         $msg = '';
 
-        /* We need the Message-Id so we can log this event. */
-        $message_id = $h->getValue('message-id');
-        $header['in_reply_to'] = chop($message_id);
+        $this->_metadata['index'] = $contents->getIndex();
+        $this->_metadata['mailbox'] = $contents->getMailbox();
+
+        /* We need the Message-Id so we can log this event. This header is not
+         * added to the outgoing messages. */
+        $this->_metadata['in_reply_to'] = trim($h->getValue('message-id'));
+        $this->_metadata['reply_type'] = 'forward';
+        $this->_modified = true;
 
         $header['subject'] = $h->getValue('subject');
         if (!empty($header['subject'])) {
index a08dd43..a029c86 100644 (file)
@@ -66,10 +66,9 @@ class IMP_Views_Compose
             );
         }
 
-        $draft_index = $composeCache = null;
+        $composeCache = null;
         if (!empty($args['composeCache'])) {
             $imp_compose = &IMP_Compose::singleton($args['composeCache']);
-            $draft_index = intval($imp_compose->saveDraftIndex());
             $composeCache = $args['composeCache'];
 
             if ($imp_compose->numberOfAttachments()) {
index a6f7740..a825f53 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 /**
- * compose.php - Used by DIMP_Views_Compose:: to render the compose screen.
+ * compose.php - Used by IMP_Views_Compose:: to render the compose screen.
  *
  * Variables passed in from calling code:
- *   $args('folder', 'index'), $compose_html, $draft_index, $from, $id,
- *   $identity, $composeCache, $rte, $selected_identity, $sent_mail_folder
+ *   $compose_html, $from, $id, $identity, $composeCache, $rte,
+ *   $selected_identity, $sent_mail_folder
  *
  * Copyright 2005-2009 The Horde Project (http://www.horde.org/)
  *
@@ -39,12 +39,6 @@ function _createDAcompose($text, $image, $id)
 <input type="hidden" id="action" name="action" />
 <input type="hidden" id="last_identity" name="last_identity" value="<?php echo (int)$selected_identity ?>" />
 <input type="hidden" id="html" name="html" value="<?php echo intval($rte && $compose_html) ?>" />
-<input type="hidden" id="in_reply_to" name="in_reply_to" />
-<input type="hidden" id="references" name="references" />
-<input type="hidden" id="folder" name="folder" value="<?php echo $args['folder'] ?>" />
-<input type="hidden" id="index" name="index" value="<?php echo $args['index'] ?>" />
-<input type="hidden" id="draft_index" name="draft_index" value="<?php echo $draft_index ?>" />
-<input type="hidden" id="reply_type" name="reply_type" />
 <input type="hidden" id="composeCache" name="composeCache" value="<?php echo $composeCache ?>" />
 
 <div class="dimpActions dimpActionsCompose">
index 22d288d..33b3d57 100644 (file)
@@ -10,33 +10,8 @@ $f = &$c->add(new Horde_Mobile_form('compose-mimp.php'));
 
 // Hidden Variables.
 $f->add(new Horde_Mobile_hidden('composeCache', $cacheID));
-$f->add(new Horde_Mobile_hidden('thismailbox', Horde_Util::getFormData('thismailbox')));
-$f->add(new Horde_Mobile_hidden('index', Horde_Util::getFormData('index')));
 $f->add(new Horde_Mobile_hidden('resume_draft', Horde_Util::getFormData('resume_draft', $resume_draft)));
 
-if (Horde_Util::getFormData('ctype')) {
-    $f->add(new Horde_Mobile_hidden('ctype', Horde_Util::getFormData('ctype')));
-} else {
-    switch ($actionID) {
-    case 'r':
-    case 'ra':
-    case 'rl':
-        $f->add(new Horde_Mobile_hidden('ctype', 'reply'));
-        break;
-
-    case 'f':
-        $f->add(new Horde_Mobile_hidden('ctype', 'forward'));
-        break;
-    }
-}
-
-if ((Horde_Util::getFormData('is_reply') == 1) ||
-    (strpos($actionID, 'reply') === 0)) {
-    $f->add(new Horde_Mobile_hidden('is_reply', 1));
-    $f->add(new Horde_Mobile_hidden('in_reply_to', $header['in_reply_to']));
-    $f->add(new Horde_Mobile_hidden('references', $header['references']));
-}
-
 if (!$prefs->isLocked('default_identity')) {
     $ib = &$f->add(new Horde_Mobile_block(new Horde_Mobile_text(_("Identity"))));
     $ident_sel = &$ib->add(new Horde_Mobile_select('identity'));