0013264: Wrong name in "from:" in sent mail
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 26 Jun 2017 07:28:54 +0000 (09:28 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 26 Jun 2017 11:42:53 +0000 (13:42 +0200)
* allow to set from_name from client
* fixes fetching of from_name on server
* adds a json frontend test

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

Change-Id: Ia776f538498f61b12b98034681d9c480cc9a6259
Reviewed-on: http://gerrit.tine20.com/customers/4945
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Felamimail/Frontend/JsonTest.php
tine20/Felamimail/Controller/Message/Send.php
tine20/Felamimail/js/MessageEditDialog.js

index 46bb781..52d6e73 100644 (file)
@@ -565,6 +565,21 @@ class Felamimail_Frontend_JsonTest extends TestCase
     }
 
     /**
+     * test send message
+     *
+     * @see 0013264: Wrong name in "from:" in sent mail
+     */
+    public function testSendMessageWithFromName()
+    {
+        // send email
+        $messageToSend = $this->_getMessageData();
+        $messageToSend['from_name'] = 'My Special Name';
+        $message = $this->_sendMessage('INBOX', array(), '', 'test', $messageToSend);
+
+        self::assertEquals($messageToSend['from_name'], $message['from_name'], print_r($message, true));
+    }
+
+    /**
      * test mail sanitize
      */
     public function testSanitizeMail()
@@ -1191,7 +1206,7 @@ class Felamimail_Frontend_JsonTest extends TestCase
         $this->_json->saveMessage($messageData);
         $message = $this->_searchForMessageBySubject(Tinebase_Core::filterInputForDatabase($subject));
     }
-    
+
     /**
      * testMessageWithInvalidICS
      *
@@ -1533,7 +1548,7 @@ IbVx8ZTO7dJRKrg72aFmWTf0uNla7vicAhpiLWobyNYcZbIjrAGDfg==
     public function testGetVacationTemplates()
     {
         $this->markTestSkipped('0010194: fix felamimail webdav tests');
-        
+
         $this->_addVacationTemplateFile();
         $result = $this->_json->getVacationMessageTemplates();
         
@@ -1569,7 +1584,7 @@ IbVx8ZTO7dJRKrg72aFmWTf0uNla7vicAhpiLWobyNYcZbIjrAGDfg==
     public function testGetVacationMessage()
     {
         $this->markTestSkipped('0010194: fix felamimail webdav tests');
-        
+
         $result = $this->_getVacationMessageWithTemplate();
         $sclever = Tinebase_User::getInstance()->getFullUserByLoginName('sclever');
         $pwulf = Tinebase_User::getInstance()->getFullUserByLoginName('pwulf');
@@ -1612,7 +1627,7 @@ IbVx8ZTO7dJRKrg72aFmWTf0uNla7vicAhpiLWobyNYcZbIjrAGDfg==
     public function testGetVacationWithSignature()
     {
         $this->markTestSkipped('0010194: fix felamimail webdav tests');
-        
+
         $this->_sieveVacationTemplateFile = 'vacation_template_sig.tpl';
         
         // set signature with <br> + linebreaks
@@ -1756,10 +1771,15 @@ IbVx8ZTO7dJRKrg72aFmWTf0uNla7vicAhpiLWobyNYcZbIjrAGDfg==
      * @param array $addtionalHeaders
      * @return array
      */
-    protected function _sendMessage($folderName = 'INBOX', $addtionalHeaders = array())
+    protected function _sendMessage(
+        $folderName = 'INBOX',
+        $additionalHeaders = array(),
+        $_emailFrom = '',
+        $_subject = 'test',
+        $_messageToSend = null)
     {
-        $messageToSend = $this->_getMessageData();
-        $messageToSend['headers'] = array_merge($messageToSend['headers'], $addtionalHeaders);
+        $messageToSend = $_messageToSend ? $_messageToSend : $this->_getMessageData($_emailFrom, $_subject);
+        $messageToSend['headers'] = array_merge($messageToSend['headers'], $additionalHeaders);
         $this->_json->saveMessage($messageToSend);
         $this->_foldersToClear = array('INBOX', $this->_account->sent_folder);
 
index 4fa99be..2d9c391 100644 (file)
@@ -424,7 +424,7 @@ class Felamimail_Controller_Message_Send extends Felamimail_Controller_Message
     {
         $_mail->clearFrom();
         
-        $from = $this->_getSenderName($_account);
+        $from = $this->_getSenderName($_message, $_account);
         
         $email = ($_message !== NULL && ! empty($_message->from_email)) ? $_message->from_email : $_account->email;
         
@@ -433,11 +433,20 @@ class Felamimail_Controller_Message_Send extends Felamimail_Controller_Message
         $_mail->setFrom($email, $from);
     }
 
-    protected function _getSenderName($account)
+    /**
+     * @param $_message
+     * @param $_account
+     * @return string
+     */
+    protected function _getSenderName($_message, $_account)
     {
-        return (isset($_account->from) && ! empty($_account->from))
-            ? $_account->from
-            : Tinebase_Core::getUser()->accountFullName;
+        $messageFrom = ($_message && ! empty($_message->from_name)) ? $_message->from_name : null;
+
+        return $messageFrom
+            ? $messageFrom
+            : (isset($_account->from) && ! empty($_account->from)
+                ? $_account->from
+                : Tinebase_Core::getUser()->accountFullName);
     }
     
     /**
@@ -525,7 +534,7 @@ class Felamimail_Controller_Message_Send extends Felamimail_Controller_Message
 
         // add reply-to
         if (! empty($_account->reply_to)) {
-            $_mail->setReplyTo($_account->reply_to, $this->_getSenderName($_account));
+            $_mail->setReplyTo($_account->reply_to, $this->_getSenderName($_message, $_account));
         }
         
         // set message-id (we could use Zend_Mail::createMessageId() here)
index f89785d..e8ab97d 100644 (file)
@@ -1002,6 +1002,7 @@ Tine.Felamimail.MessageEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
             emailFrom = account.get('email');
             
         this.record.set('from_email', emailFrom);
+        this.record.set('from_name', account.get('from'));
         
         Tine.Felamimail.MessageEditDialog.superclass.onRecordUpdate.call(this);