Add strip attachments support to DIMP.
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 10 May 2010 18:33:27 +0000 (12:33 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 10 May 2010 20:28:52 +0000 (14:28 -0600)
imp/docs/CHANGES
imp/js/DimpBase.js
imp/js/fullmessage-dimp.js
imp/lib/Ajax/Application.php
imp/lib/Contents.php
imp/lib/Message.php
imp/lib/Views/ShowMessage.php
imp/message-dimp.php
imp/templates/dimp/chunks/message.php

index 904f9e0..d93f690 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Add strip attachments support in DIMP.
 [mms] Add PGP & S/MIME compose support to DIMP.
 [mms] Check for incorrect identity on compose if a single recipient address
       is tied to a different identity than the sending identity.
index fc6c30d..4fac0dd 100644 (file)
@@ -9,8 +9,8 @@
 
 var DimpBase = {
     // Vars used and defaulting to null/false:
-    //   cfolderaction, folder, folderswitch, pollPE, pp, resize, rownum,
-    //   search, splitbar, template, uid, viewport
+    //   cfolderaction, folder, folderswitch, pollPE, pp, preview_replace,
+    //   resize, rownum, search, splitbar, template, uid, viewport
     // msglist_template_horiz and msglist_template_vert set via
     //   js/mailbox-dimp.js
     cacheids: {},
@@ -629,7 +629,9 @@ var DimpBase = {
 
             this.toggleButtons();
             if (e.memo.opts.right || !count) {
-                this.clearPreviewPane();
+                if (!this.preview_replace) {
+                    this.clearPreviewPane();
+                }
             } else if ((count == 1) && DIMP.conf.preview_pref) {
                 this.loadPreview(sel.get('dataob').first());
             }
@@ -1220,6 +1222,25 @@ var DimpBase = {
         location.hash = encodeURIComponent('msg:' + row.view + ':' + row.imapuid);
     },
 
+    _stripAttachmentCallback: function(r)
+    {
+        // Let the normal viewport refresh code and preview display code
+        // handle replacing the current preview. Set preview_replace to
+        // prevent a refresh flicker, since viewport refreshing would normally
+        // cause the preview pane to be cleared.
+        if (DimpCore.inAjaxCallback) {
+            this.preview_replace = true;
+            this.uid = r.response.newuid;
+            this._stripAttachmentCallback.bind(this, r).defer();
+            return;
+        }
+
+        this.preview_replace = false;
+
+        // Remove old cache value.
+        this._expirePPCache([ this._getPPId(r.olduid, r.oldmbox) ]);
+    },
+
     // opts = mailbox, uid
     updateMsgLog: function(log, opts)
     {
@@ -2090,6 +2111,11 @@ var DimpBase = {
                     DimpCore.popupWindow(DimpCore.addURLParam(DIMP.conf.URI_VIEW, { uid: this.pp.imapuid, mailbox: this.pp.view, actionID: 'print_attach', id: elt.readAttribute('mimeid') }, true), this.pp.imapuid + '|' + this.pp.view + '|print', IMP.printWindow);
                     e.stop();
                     return;
+                } else if (elt.hasClassName('stripAtc')) {
+                    this.loadingImg('msg', true);
+                    DimpCore.doAction('stripAttachment', this.viewport.addRequestParams({ id: elt.readAttribute('mimeid') }), { uids: this.viewport.createSelection('dataob', this.pp), callback: this._stripAttachmentCallback.bind(this) });
+                    e.stop();
+                    return;
                 }
             }
 
index 24e8785..f5c722e 100644 (file)
@@ -155,6 +155,15 @@ var DimpFullmessage = {
                     DimpCore.popupWindow(DimpCore.addURLParam(DIMP.conf.URI_VIEW, { uid: this.uid, mailbox: this.mailbox, actionID: 'print_attach', id: elt.readAttribute('mimeid') }, true), this.uid + '|' + this.mailbox + '|print', IMP.printWindow);
                     e.stop();
                     return;
+                } else if (elt.hasClassName('stripAtc')) {
+                    DimpCore.reloadMessage({
+                        actionID: 'strip_attachment',
+                        mailbox: this.mailbox,
+                        id: elt.readAttribute('mimeid'),
+                        uid: this.uid
+                    });
+                    e.stop();
+                    return;
                 }
                 break;
             }
@@ -222,6 +231,10 @@ var DimpFullmessage = {
             DimpCore.updateMsgLog(this.log);
         }
 
+        if (this.strip && DIMP.baseWindow && DIMP.baseWindow.DimpBase) {
+            DIMP.baseWindow.DimpBase.poll();
+        }
+
         $('dimpLoading').hide();
         $('pageContainer').show();
 
index a3356a8..ae4457a 100644 (file)
@@ -1237,7 +1237,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      *
      * Variables used:
      * <pre>
-     * 'uid' - (string) Indices of the messages to isend MDN for (IMAP sequence
+     * 'uid' - (string) Indices of the messages to send MDN for (IMAP sequence
      *         string).
      * 'view' - (string) The current full mailbox.
      * </pre>
@@ -1265,6 +1265,59 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
     }
 
     /**
+     * AJAX action: strip attachment.
+     *
+     * See the list of variables needed for _changed() and
+     * _checkUidvalidity().  Additional variables used:
+     * <pre>
+     * 'uid' - (string) Index of the messages to preview (IMAP sequence
+     *         string) - must be single index.
+     * </pre>
+     *
+     * @return mixed  False on failure, the return from showPreview() on
+     *                success along with these properties:
+     * <pre>
+     * 'newuid' - (integer) UID of new message.
+     * 'oldmbox' - (string) Mailbox of old message.
+     * 'olduid' - (integer) UID of old message.
+     * 'ViewPort' - (object) See _viewPortData().
+     * </pre>
+     */
+    public function stripAttachment()
+    {
+        $indices = new IMP_Indices($this->_vars->uid);
+        if ($indices->count() != 1) {
+            return false;
+        }
+
+        $change = $this->_changed(false);
+        if (is_null($change)) {
+            return false;
+        }
+
+        try {
+            $new_indices = $GLOBALS['injector']->getInstance('IMP_Message')->stripPart($indices, $this->_vars->id);
+        } catch (IMP_Exception $e) {
+            $GLOBALS['notification']->push($e);
+            return false;
+        }
+
+        $GLOBALS['notification']->push(_("Attachment successfully stripped."), 'horde.success');
+
+        $this->_vars->uid = strval($new_indices);
+
+        $result = $this->showPreview();
+        $new_indices_list = $new_indices->getSingle();
+        $result->newuid = intval($new_indices_list[1]);
+        $old_indices_list = $indices->getSingle();
+        $result->oldmbox = $old_indices_list[0];
+        $result->olduid = intval($old_indices_list[1]);
+        $result->ViewPort = $this->_viewPortData(true);
+
+        return $result;
+    }
+
+    /**
      * AJAX action: Add an attachment to a compose message.
      *
      * Variables used:
@@ -1732,7 +1785,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      * Generate the information necessary for a ViewPort request from/to the
      * browser.
      *
-     * @param boolean $change        True if cache information has changed.
+     * @param boolean $change  True if cache information has changed.
      *
      * @return array  See IMP_Views_ListMessages::listMessages().
      */
index d0ea2a4..2d5e07f 100644 (file)
@@ -27,6 +27,7 @@ class IMP_Contents
     const SUMMARY_PRINT = 1024;
     const SUMMARY_PRINT_STUB = 2048;
     const SUMMARY_STRIP_LINK = 4096;
+    const SUMMARY_STRIP_STUB = 8192;
 
     /* Rendering mask entries. */
     const RENDER_FULL = 1;
@@ -574,6 +575,7 @@ class IMP_Contents
      *   Output: parts = 'print'
      *
      * IMP_Contents::SUMMARY_STRIP_LINK
+     * IMP_Contents::SUMMARY_STRIP_STUB
      *   Output: parts = 'strip'
      * </pre>
      *
@@ -679,12 +681,17 @@ class IMP_Contents
 
         /* Strip Attachment? Allow stripping of base parts other than the
          * base multipart and the base text (body) part. */
-        if (($mask & self::SUMMARY_STRIP_LINK) &&
+        if ((($mask & self::SUMMARY_STRIP_LINK) ||
+             ($mask & self::SUMMARY_STRIP_STUB)) &&
             ($id != 0) &&
             (intval($id) != 1) &&
             (strpos($id, '.') === false)) {
-            $url = Horde::selfUrl(true)->remove(array('actionID', 'imapid', 'uid'))->add(array('actionID' => 'strip_attachment', 'imapid' => $id, 'uid' => $this->_uid, 'message_token' => Horde::getRequestToken('imp.impcontents')));
-            $part['strip'] = Horde::link($url, _("Strip Attachment"), 'deleteImg', null, "return window.confirm('" . addslashes(_("Are you sure you wish to PERMANENTLY delete this attachment?")) . "');") . '</a>';
+            if ($mask & self::SUMMARY_STRIP_LINK) {
+                $url = Horde::selfUrl(true)->remove(array('actionID', 'imapid', 'uid'))->add(array('actionID' => 'strip_attachment', 'imapid' => $id, 'uid' => $this->_uid, 'message_token' => Horde::getRequestToken('imp.impcontents')));
+                $part['strip'] = Horde::link($url, _("Strip Attachment"), 'deleteImg', null, "return window.confirm('" . addslashes(_("Are you sure you wish to PERMANENTLY delete this attachment?")) . "');") . '</a>';
+            } else {
+                $part['strip'] = Horde::link('#', _("Strip Attachment"), 'deleteImg stripAtc', null, null, null, null, array('mimeid' => $id)) . '</a>';
+            }
         }
 
         return $part;
index 8f21414..ab5c16b 100644 (file)
@@ -444,6 +444,7 @@ class IMP_Message
      * @param string $partid        The MIME ID of the part to strip. All
      *                              parts are stripped if null.
      *
+     * @return IMP_Indices  Returns the new indices object.
      * @throws IMP_Exception
      */
     public function stripPart($indices, $partid = null)
@@ -558,6 +559,8 @@ class IMP_Message
         /* We need to replace the old index in the query string with the
          * new index. */
         $_SERVER['QUERY_STRING'] = str_replace($uid, $new_uid, $_SERVER['QUERY_STRING']);
+
+        return new IMP_Indices($mbox, $new_uid);
     }
 
     /**
index f379ce4..04a5a4c 100644 (file)
@@ -116,6 +116,12 @@ class IMP_Views_ShowMessage
             return $result;
         }
 
+        if (!isset($fetch_ret[$uid]['headertext'])) {
+            $result['error'] = $error_msg;
+            $result['errortype'] = 'horde.error';
+            return $result;
+        }
+
         /* Parse MIME info and create the body of the message. */
         try {
             $imp_contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb(new IMP_Indices($mailbox, $uid));
@@ -250,10 +256,12 @@ class IMP_Views_ShowMessage
             IMP_Contents::SUMMARY_DESCRIP_LINK |
             IMP_Contents::SUMMARY_DOWNLOAD |
             IMP_Contents::SUMMARY_DOWNLOAD_ZIP |
-            IMP_Contents::SUMMARY_PRINT_STUB;
+            IMP_Contents::SUMMARY_PRINT_STUB |
+            IMP_Contents::SUMMARY_STRIP_STUB;
 
         $part_info = $part_info_display = array('icon', 'description', 'size', 'download', 'download_zip');
         $part_info_display[] = 'print';
+        $part_info_display[] = 'strip';
 
         /* Do MDN processing now. */
         if ($imp_ui->MDNCheck($mailbox, $uid, $mime_headers)) {
index a6815d3..e90888f 100644 (file)
 require_once dirname(__FILE__) . '/lib/Application.php';
 Horde_Registry::appInit('imp', array('impmode' => 'dimp'));
 
-$folder = Horde_Util::getFormData('folder');
-$uid = Horde_Util::getFormData('uid');
-if (!$uid || !$folder) {
+$vars = Horde_Variables::getDefaultVariables();
+
+if (!$vars->uid || !$vars->folder) {
     exit;
 }
 
 $imp_ui = new IMP_Ui_Message();
-$readonly = $injector->getInstance('IMP_Imap')->getOb()->isReadOnly($folder);
+$js_onload = $js_out = array();
+$readonly = $injector->getInstance('IMP_Imap')->getOb()->isReadOnly($vars->folder);
+
+switch ($vars->actionID) {
+case 'strip_attachment':
+    try {
+        $indices = $injector->getInstance('IMP_Message')->stripPart(new IMP_Indices($vars->folder, $vars->uid), $vars->id);
+        $js_out[] = 'DimpFullmessage.strip = 1';
+        list(,$vars->uid) = $indices->getSingle();
+        $notification->push(_("Attachment successfully stripped."), 'horde.success');
+    } catch (IMP_Exception $e) {
+        $notification->push($e);
+    }
+    break;
+}
 
 $args = array(
     'headers' => array_diff(array_keys($imp_ui->basicHeaders()), array('subject')),
-    'mailbox' => $folder,
+    'mailbox' => $vars->folder,
     'preview' => false,
-    'uid' => $uid
+    'uid' => $vars->uid
 );
 
 $show_msg = new IMP_Views_ShowMessage();
@@ -47,7 +61,6 @@ $scripts = array(
     array('md5.js', 'horde')
 );
 
-$js_onload = $js_out = array();
 foreach (array('from', 'to', 'cc', 'bcc', 'replyTo', 'log', 'uid', 'mailbox') as $val) {
     if (!empty($show_msg_result[$val])) {
         $js_out[] = 'DimpFullmessage.' . $val . ' = ' . Horde_Serialize::serialize($show_msg_result[$val], Horde_Serialize::JSON);
@@ -59,11 +72,11 @@ $disable_compose = !IMP::canCompose();
 
 if (!$disable_compose) {
     $compose_args = array(
-        'folder' => $folder,
+        'folder' => $vars->folder,
         'messageCache' => '',
         'popup' => false,
         'qreply' => true,
-        'uid' => $uid,
+        'uid' => $vars->uid,
     );
     $compose_result = IMP_Views_Compose::showCompose($compose_args);
 
index 03065e6..06637fe 100644 (file)
    <div class="headercloseimg closeImg" id="windowclose" title="X"></div>
    <div><?php echo IMP_Dimp::actionButton(array('class' => 'hasmenu', 'icon' => 'Reply', 'id' => 'reply_link', 'title' => _("Reply"))) ?></div>
    <div><?php echo IMP_Dimp::actionButton(array('class' => 'hasmenu', 'icon' => 'Forward', 'id' => 'forward_link', 'title' => _("Forward"))) ?></div>
-<?php if (!empty($conf['spam']['reporting']) && (!$conf['spam']['spamfolder'] || ($folder != IMP::folderPref($prefs->getValue('spam_folder'), true)))): ?>
+<?php if (!empty($conf['spam']['reporting']) && (!$conf['spam']['spamfolder'] || ($vars->folder != IMP::folderPref($prefs->getValue('spam_folder'), true)))): ?>
    <div><?php echo IMP_Dimp::actionButton(array('icon' => 'Spam', 'id' => 'button_spam', 'title' => _("Spam"))) ?></div>
 <?php endif; ?>
-<?php if (!empty($conf['notspam']['reporting']) && (!$conf['notspam']['spamfolder'] || ($folder == IMP::folderPref($prefs->getValue('spam_folder'), true)))): ?>
+<?php if (!empty($conf['notspam']['reporting']) && (!$conf['notspam']['spamfolder'] || ($vars->folder == IMP::folderPref($prefs->getValue('spam_folder'), true)))): ?>
    <div><?php echo IMP_Dimp::actionButton(array('icon' => 'Ham', 'id' => 'button_ham', 'title' => _("Innocent"))) ?></div>
 <?php endif; ?>
 <?php if (!$readonly): ?>