From: Michael M Slusarz Date: Mon, 10 May 2010 18:33:27 +0000 (-0600) Subject: Add strip attachments support to DIMP. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=aa13f34bdde9e00ca3f9085dd30d49539f0c2e39;p=horde.git Add strip attachments support to DIMP. --- diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 904f9e0d8..d93f690b1 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -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. diff --git a/imp/js/DimpBase.js b/imp/js/DimpBase.js index fc6c30d00..4fac0ddea 100644 --- a/imp/js/DimpBase.js +++ b/imp/js/DimpBase.js @@ -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; } } diff --git a/imp/js/fullmessage-dimp.js b/imp/js/fullmessage-dimp.js index 24e878534..f5c722e9f 100644 --- a/imp/js/fullmessage-dimp.js +++ b/imp/js/fullmessage-dimp.js @@ -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(); diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index a3356a82e..ae4457afd 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -1237,7 +1237,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base * * Variables used: *
-     * '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.
      * 
@@ -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: + *
+     * 'uid' - (string) Index of the messages to preview (IMAP sequence
+     *         string) - must be single index.
+     * 
+ * + * @return mixed False on failure, the return from showPreview() on + * success along with these properties: + *
+     * 'newuid' - (integer) UID of new message.
+     * 'oldmbox' - (string) Mailbox of old message.
+     * 'olduid' - (integer) UID of old message.
+     * 'ViewPort' - (object) See _viewPortData().
+     * 
+ */ + 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(). */ diff --git a/imp/lib/Contents.php b/imp/lib/Contents.php index d0ea2a45b..2d5e07f67 100644 --- a/imp/lib/Contents.php +++ b/imp/lib/Contents.php @@ -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' * * @@ -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?")) . "');") . ''; + 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?")) . "');") . ''; + } else { + $part['strip'] = Horde::link('#', _("Strip Attachment"), 'deleteImg stripAtc', null, null, null, null, array('mimeid' => $id)) . ''; + } } return $part; diff --git a/imp/lib/Message.php b/imp/lib/Message.php index 8f21414c6..ab5c16b28 100644 --- a/imp/lib/Message.php +++ b/imp/lib/Message.php @@ -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); } /** diff --git a/imp/lib/Views/ShowMessage.php b/imp/lib/Views/ShowMessage.php index f379ce430..04a5a4c37 100644 --- a/imp/lib/Views/ShowMessage.php +++ b/imp/lib/Views/ShowMessage.php @@ -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)) { diff --git a/imp/message-dimp.php b/imp/message-dimp.php index a6815d31f..e90888fe9 100644 --- a/imp/message-dimp.php +++ b/imp/message-dimp.php @@ -13,20 +13,34 @@ 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); diff --git a/imp/templates/dimp/chunks/message.php b/imp/templates/dimp/chunks/message.php index 03065e69f..06637feeb 100644 --- a/imp/templates/dimp/chunks/message.php +++ b/imp/templates/dimp/chunks/message.php @@ -15,10 +15,10 @@
'hasmenu', 'icon' => 'Reply', 'id' => 'reply_link', 'title' => _("Reply"))) ?>
'hasmenu', 'icon' => 'Forward', 'id' => 'forward_link', 'title' => _("Forward"))) ?>
-getValue('spam_folder'), true)))): ?> +folder != IMP::folderPref($prefs->getValue('spam_folder'), true)))): ?>
'Spam', 'id' => 'button_spam', 'title' => _("Spam"))) ?>
-getValue('spam_folder'), true)))): ?> +folder == IMP::folderPref($prefs->getValue('spam_folder'), true)))): ?>
'Ham', 'id' => 'button_ham', 'title' => _("Innocent"))) ?>