diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-01-24 16:36:29 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-01-24 16:52:07 +0300 |
commit | 7942f00f94e236e9bbcf4ce01fa19e46c6de1d80 (patch) | |
tree | e4f53ca6c90a4db3c2df75ddf4fbd9a7c862c36e | |
parent | 9f254d8a7fd5f64b1ca1169915ba7c5212dafd79 (diff) |
Show embedded messages as attachments
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r-- | lib/Attachment.php | 2 | ||||
-rwxr-xr-x | lib/Controller/MessagesController.php | 17 | ||||
-rw-r--r-- | lib/Model/IMAPMessage.php | 16 | ||||
-rw-r--r-- | src/components/Composer.vue | 3 | ||||
-rw-r--r-- | src/components/MessageAttachment.vue | 17 | ||||
-rw-r--r-- | src/components/MessageAttachments.vue | 1 | ||||
-rw-r--r-- | tests/Unit/Controller/MessagesControllerTest.php | 2 |
7 files changed, 44 insertions, 14 deletions
diff --git a/lib/Attachment.php b/lib/Attachment.php index d80a46f3e..616a78f3f 100644 --- a/lib/Attachment.php +++ b/lib/Attachment.php @@ -114,7 +114,7 @@ class Attachment { } /** - * @return string + * @return string|null */ public function getName() { return $this->mimePart->getName(); diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php index 22b5d7b03..804022b96 100755 --- a/lib/Controller/MessagesController.php +++ b/lib/Controller/MessagesController.php @@ -292,8 +292,21 @@ class MessagesController extends Controller { $attachment = $mailBox->getAttachment($messageId, $attachmentId); + // Body party and embedded messages do not have a name + if ($attachment->getName() === null) { + return new AttachmentDownloadResponse( + $attachment->getContents(), + $this->l10n->t('Embedded message %s', [ + $attachmentId, + ]) . '.eml', + $attachment->getType() + ); + } return new AttachmentDownloadResponse( - $attachment->getContents(), $attachment->getName(), $attachment->getType()); + $attachment->getContents(), + $attachment->getName(), + $attachment->getType() + ); } /** @@ -452,7 +465,7 @@ class MessagesController extends Controller { * @return boolean */ private function attachmentIsCalendarEvent(array $attachment): bool { - return in_array($attachment['mime'], ['text/calendar', 'application/ics'], true); + return in_array($attachment['mime'], ['text/calendar', 'application/ics'], true); } } diff --git a/lib/Model/IMAPMessage.php b/lib/Model/IMAPMessage.php index 30301ebee..714342d6a 100644 --- a/lib/Model/IMAPMessage.php +++ b/lib/Model/IMAPMessage.php @@ -263,21 +263,20 @@ class IMAPMessage implements IMessage, JsonSerializable { */ private function hasAttachments($part) { foreach ($part->getParts() as $p) { - /** - * @var Horde_Mime_Part $p - */ + /** @var Horde_Mime_Part $p */ $filename = $p->getName(); - if (!is_null($p->getContentId())) { + if ($p->getContentId() !== null) { continue; } - if (isset($filename)) { + // TODO: show embedded messages and don't treat them as attachments + if ($p->getType() === 'message/rfc822' || isset($filename)) { // do not show technical attachments if (in_array($filename, $this->attachmentsToIgnore)) { continue; - } else { - return true; } + + return true; } if ($this->hasAttachments($p)) { return true; @@ -336,7 +335,8 @@ class IMAPMessage implements IMessage, JsonSerializable { // Any part with a filename is an attachment, // so an attached text file (type 0) is not mistaken as the message. $filename = $p->getName(); - if (isset($filename)) { + // TODO: show embedded messages and don't treat them as attachments + if ($p->getType() === 'message/rfc822' || isset($filename)) { if (in_array($filename, $this->attachmentsToIgnore)) { return; } diff --git a/src/components/Composer.vue b/src/components/Composer.vue index eb01617bd..d6af9ff4a 100644 --- a/src/components/Composer.vue +++ b/src/components/Composer.vue @@ -14,6 +14,7 @@ :hide-selected="true" :custom-label="formatAliases" :placeholder="t('mail', 'Select account')" + :clear-on-select="false" @keyup="onInputChanged" /> </div> @@ -31,6 +32,7 @@ track-by="email" :multiple="true" :placeholder="t('mail', 'Contact or email address …')" + :clear-on-select="false" :show-no-options="false" @keyup="onInputChanged" @tag="onNewToAddr" @@ -53,6 +55,7 @@ track-by="email" :multiple="true" :placeholder="t('mail', '')" + :clear-on-select="false" :show-no-options="false" @keyup="onInputChanged" @tag="onNewCcAddr" diff --git a/src/components/MessageAttachment.vue b/src/components/MessageAttachment.vue index d720429a9..6b8a8719e 100644 --- a/src/components/MessageAttachment.vue +++ b/src/components/MessageAttachment.vue @@ -24,7 +24,7 @@ <img v-if="isImage" class="mail-attached-image" :src="url" /> <img class="attachment-icon" :src="mimeUrl" /> <span class="attachment-name" :title="label" - >{{ fileName }} + >{{ name }} <span class="attachment-size">({{ humanReadable(size) }})</span> </span> <button @@ -78,7 +78,7 @@ export default { }, fileName: { type: String, - required: true, + required: false, }, url: { type: String, @@ -88,6 +88,10 @@ export default { type: Number, required: true, }, + mime: { + type: String, + required: true, + }, mimeUrl: { type: String, required: true, @@ -110,7 +114,16 @@ export default { } }, computed: { + name() { + if (this.mime === 'message/rfc822') { + return t('mail', 'Embedded message') + } + return this.fileName + }, label() { + if (this.mime === 'message/rfc822') { + return t('mail', 'Embedded message') + ' (' + formatFileSize(this.size) + ')' + } return this.fileName + ' (' + formatFileSize(this.size) + ')' }, calendarMenuEntries() { diff --git a/src/components/MessageAttachments.vue b/src/components/MessageAttachments.vue index ae0abb87d..589184813 100644 --- a/src/components/MessageAttachments.vue +++ b/src/components/MessageAttachments.vue @@ -31,6 +31,7 @@ :url="attachment.downloadUrl" :is-image="attachment.isImage" :is-calendar-event="attachment.isCalendarEvent" + :mime="attachment.mime" :mime-url="attachment.mimeUrl" /> </div> diff --git a/tests/Unit/Controller/MessagesControllerTest.php b/tests/Unit/Controller/MessagesControllerTest.php index fee9d4c36..1178a03c4 100644 --- a/tests/Unit/Controller/MessagesControllerTest.php +++ b/tests/Unit/Controller/MessagesControllerTest.php @@ -235,7 +235,7 @@ class MessagesControllerTest extends TestCase { $this->attachment->expects($this->once()) ->method('getContents') ->will($this->returnValue($contents)); - $this->attachment->expects($this->once()) + $this->attachment->expects($this->any()) ->method('getName') ->will($this->returnValue($name)); $this->attachment->expects($this->once()) |