0012392: allow to forward mail nodes with attachments
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 1 Dec 2016 14:43:49 +0000 (15:43 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 1 Dec 2016 17:01:16 +0000 (18:01 +0100)
* and fixes reply/forward message quoting

https://forge.tine20.org/view.php?id=12392

Change-Id: I79e9d07ccdc48f61157ccf264871e9473a5cae48
Reviewed-on: http://gerrit.tine20.com/customers/3911
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Felamimail/Controller/Message/Send.php
tine20/MailFiler/js/NodeGridPanel.js

index 9edaaf8..6d09d0c 100644 (file)
@@ -625,6 +625,11 @@ class Felamimail_Controller_Message_Send extends Felamimail_Controller_Message
             ) {
                 $part = $this->_getRfc822Attachment($attachment, $_message);
 
+            } else if (isset($attachment['type'])
+                && $attachment['type'] == 'filenode'
+            ) {
+                $part = $this->_getFileNodeAttachment($attachment);
+
             } else if ($attachment instanceof Tinebase_Model_TempFile || isset($attachment['tempFile'])) {
                 $part = $this->_getTempFileAttachment($attachment);
 
@@ -677,6 +682,55 @@ class Felamimail_Controller_Message_Send extends Felamimail_Controller_Message
     }
 
     /**
+     * get attachment defined by a file node (mailfiler or filemanager)
+     *
+     * @param $attachment
+     * @return null|Zend_Mime_Part
+     * @throws Tinebase_Exception_NotFound
+     *
+     * TODO support Filemanager files
+     * TODO allow to omit $messageuid, $partId
+     */
+    protected function _getFileNodeAttachment(&$attachment)
+    {
+        list($appname, $path, $messageuid, $partId) = explode('|', $attachment['id']);
+
+        $nodeController = Tinebase_Core::getApplicationInstance($appname . '_Model_Node');
+
+        // remove filename from path
+        // TODO remove DRY with \MailFiler_Frontend_Http::downloadAttachment
+        $pathParts = explode('/', $path);
+        array_pop($pathParts);
+        $path = implode('/', $pathParts);
+
+        $filter = array(
+            array(
+                'field'    => 'path',
+                'operator' => 'equals',
+                'value'    => $path
+            ),
+            array(
+                'field'    => 'messageuid',
+                'operator' => 'equals',
+                'value'    => $messageuid
+            ));
+        $node = $nodeController->search(new MailFiler_Model_NodeFilter($filter))->getFirstRecord();
+        if ($node) {
+            $mailpart = $nodeController->getPartFromNode($node, $partId);
+            // TODO use streams
+            $content = $content = Felamimail_Message::getDecodedContent($mailpart);
+            $part = new Zend_Mime_Part($content);
+            $part->encoding = Zend_Mime::ENCODING_BASE64;
+        } else {
+            if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__
+                . ' Could not find file node attachment');
+            $part = null;
+        }
+
+        return $part;
+    }
+
+    /**
      * get attachment defined by temp file
      *
      * @param $attachment
index 1405977..e8d6be7 100644 (file)
@@ -560,22 +560,53 @@ Tine.MailFiler.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
 
     onMessageReplyTo: function(toAll) {
         var sm = this.getGrid().getSelectionModel(),
-            msg = sm.getSelected().get('message');
+            node = sm.getSelected();
+            msg = node.get('message'),
+            msgBody = msg.body;
 
-        // TODO pass all relevant params (body, subject, ...) to prevent mail loading in Felamimail
+        msgBody = '<br/>'
+            + '<blockquote class="felamimail-body-blockquote">' + msgBody + '</blockquote><br/>';
+
+        var date = msg.sent
+            ? msg.sent
+            : (msg.received) ? msg.received : new Date();
+
+        var quote = String.format(this.app.i18n._('On {0}, {1} wrote'),
+                Tine.Tinebase.common.dateTimeRenderer(date),
+                Ext.util.Format.htmlEncode(msg.from_name)
+            ) + ':';
+
+        // pass all relevant params (body, subject, ...) to prevent mail loading in Felamimail
         var win = Tine.Felamimail.MessageEditDialog.openWindow({
+            //record: msg,
             replyTo : Ext.encode(msg),
-            replyToAll: toAll
+            replyToAll: toAll,
+            msgBody: quote + msgBody
         });
     },
 
     onMessageForward: function() {
         var sm = this.getGrid().getSelectionModel(),
-            msg = sm.getSelected().get('message');
+            node = sm.getSelected();
+            msg = node.get('message'),
+            msgBody = msg.body,
+            quote = String.format('{0}-----' + this.app.i18n._('Original message') + '-----{1}',
+                '<br /><b>',
+                '</b><br />'),
+            attachments = msg.attachments;
+
+        Ext.each(attachments, function(attachment) {
+            // set name and MailFiler path for fetching attachment from filesystem when sending
+            attachment.name = attachment.filename;
+            attachment.type = 'filenode';
+            attachment.id = 'MailFiler'  + '|' + node.get('path') + '|' + msg.messageuid  + '|' + attachment.partId
+        }, this);
 
-        // TODO pass all relevant params (body, subject, ...) to prevent mail loading in Felamimail
+        // pass all relevant params (body, subject, ...) to prevent mail loading in Felamimail
         var win = Tine.Felamimail.MessageEditDialog.openWindow({
-            forwardMsgs : Ext.encode([msg])
+            forwardMsgs : Ext.encode([msg]),
+            attachments: attachments,
+            msgBody: quote + msgBody
         });
     },