diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2017-08-28 19:06:07 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2017-08-28 19:06:07 +0300 |
commit | e49d735b00675c12afaff771dea98eeb84328e4a (patch) | |
tree | add9c7a92afcd63a14b1334511009c552f893de3 /lib/Account.php | |
parent | f8ed3e36aabc1842f440fa7c1eadd123cf47d7c0 (diff) |
Fix encoding of drafts messages
Apparently the horde libs do not produce a valid MIME unless you
actually use the 'send' method. Since they fortunatelly have a
null transport with an empty impl, we can use this to have the same
encoding magic going on as we do have in place for actually sending
messages via SMTP. Now drafts stored to IMAP are encoded correctly.
Fixes https://github.com/nextcloud/mail/issues/9
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Account.php')
-rw-r--r-- | lib/Account.php | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/Account.php b/lib/Account.php index 0d0896b5b..f3c0b9812 100644 --- a/lib/Account.php +++ b/lib/Account.php @@ -34,7 +34,6 @@ namespace OCA\Mail; use Horde_Imap_Client; -use Horde_Imap_Client_Exception; use Horde_Imap_Client_Ids; use Horde_Imap_Client_Mailbox; use Horde_Imap_Client_Socket; @@ -42,6 +41,7 @@ use Horde_Mail_Rfc822_Address; use Horde_Mail_Rfc822_List; use Horde_Mail_Transport; use Horde_Mail_Transport_Mail; +use Horde_Mail_Transport_Null; use Horde_Mail_Transport_Smtphorde; use Horde_Mime_Headers_Date; use Horde_Mime_Mail; @@ -217,8 +217,7 @@ class Account implements IAccount { // Save the message in the sent folder $sentFolder = $this->getSentFolder(); - /** @var resource $raw */ - $raw = stream_get_contents($mail->getRaw()); + $raw = $mail->getRaw(false); $sentFolder->saveMessage($raw, [ Horde_Imap_Client::FLAG_SEEN ]); @@ -251,17 +250,15 @@ class Account implements IAccount { $mail = new Horde_Mime_Mail(); $mail->addHeaders($headers); - $body = new Horde_Mime_Part(); - $body->setType('text/plain'); - $body->setContents($message->getContent()); - $mail->setBasePart($body); + $mail->setBody($message->getContent()); - // create transport and save message + // "Send" the message + $transport = new Horde_Mail_Transport_Null(); + $mail->send($transport, false, false); // save the message in the drafts folder $draftsFolder = $this->getDraftsFolder(); - /** @var resource $raw */ - $raw = $mail->getRaw(); - $newUid = $draftsFolder->saveDraft(stream_get_contents($raw)); + $raw = $mail->getRaw(false); + $newUid = $draftsFolder->saveDraft($raw); // delete old version if one exists if (!is_null($previousUID)) { |