Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/Model
diff options
context:
space:
mode:
authorCyrille Bollu <cyrpub@bollu.be>2020-10-27 12:03:14 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-12-16 17:05:45 +0300
commit67d75c3173ba2c76b9fd100d769e8cf6d93c3321 (patch)
tree290d80f5dcd62af755a8444737efa8a39e966c4e /lib/Model
parent64ca3bd53e1f78e9c6bddf8e7dbe2fcb0b027a20 (diff)
Add original attachments when forwarding a mail
Signed-off-by: Cyrille Bollu <cyrpub@bollu.be> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Model')
-rw-r--r--lib/Model/IMAPMessage.php13
-rw-r--r--lib/Model/IMessage.php7
-rw-r--r--lib/Model/Message.php36
3 files changed, 37 insertions, 19 deletions
diff --git a/lib/Model/IMAPMessage.php b/lib/Model/IMAPMessage.php
index 7069ff825..96689f0cc 100644
--- a/lib/Model/IMAPMessage.php
+++ b/lib/Model/IMAPMessage.php
@@ -589,17 +589,20 @@ class IMAPMessage implements IMessage, JsonSerializable {
}
/**
- * @return array
+ * @return Horde_Mime_Part[]
*/
- public function getCloudAttachments(): array {
+ public function getAttachments(): array {
throw new Exception('not implemented');
}
/**
- * @return Horde_Mime_Part[]
+ * @param string $name
+ * @param string $content
+ *
+ * @return void
*/
- public function getLocalAttachments(): array {
- throw new Exception('not implemented');
+ public function addForwardedAttachment(string $name, string $content): void {
+ throw new Exception('IMAP message is immutable');
}
/**
diff --git a/lib/Model/IMessage.php b/lib/Model/IMessage.php
index dbdc2426b..09adcb05f 100644
--- a/lib/Model/IMessage.php
+++ b/lib/Model/IMessage.php
@@ -123,12 +123,13 @@ interface IMessage {
/**
* @return Horde_Mime_Part[]
*/
- public function getCloudAttachments(): array;
+ public function getAttachments(): array;
/**
- * @return Horde_Mime_Part[]
+ * @param string $name
+ * @param string $content
*/
- public function getLocalAttachments(): array;
+ public function addForwardedAttachment(string $name, string $content): void;
/**
* @param File $fileName
diff --git a/lib/Model/Message.php b/lib/Model/Message.php
index 9c7cc420a..90aced254 100644
--- a/lib/Model/Message.php
+++ b/lib/Model/Message.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace OCA\Mail\Model;
+use finfo;
use Horde_Mime_Part;
use OCA\Mail\AddressList;
use OCA\Mail\Db\LocalAttachment;
@@ -57,10 +58,7 @@ class Message implements IMessage {
private $content = '';
/** @var Horde_Mime_Part[] */
- private $cloudAttachments = [];
-
- /** @var Horde_Mime_Part[] */
- private $localAttachments = [];
+ private $attachments = [];
public function __construct() {
$this->from = new AddressList();
@@ -211,15 +209,31 @@ class Message implements IMessage {
/**
* @return Horde_Mime_Part[]
*/
- public function getCloudAttachments(): array {
- return $this->cloudAttachments;
+ public function getAttachments(): array {
+ return $this->attachments;
}
/**
- * @return Horde_Mime_Part[]
+ * Adds a file that's coming from another email's attachment (typical
+ * use case is forwarding a message)
*/
- public function getLocalAttachments(): array {
- return $this->localAttachments;
+ public function addForwardedAttachment(string $name, string $content): void {
+ $mime = 'application/octet-stream';
+ if (extension_loaded('fileinfo')) {
+ $finfo = new finfo(FILEINFO_MIME_TYPE);
+ $detectedMime = $finfo->buffer($content);
+ if ($detectedMime !== false) {
+ $mime = $detectedMime;
+ }
+ }
+
+ $part = new Horde_Mime_Part();
+ $part->setCharset('us-ascii');
+ $part->setDisposition('attachment');
+ $part->setName($name);
+ $part->setContents($content);
+ $part->setType($mime);
+ $this->attachments[] = $part;
}
/**
@@ -234,7 +248,7 @@ class Message implements IMessage {
$part->setName($file->getName());
$part->setContents($file->getContent());
$part->setType($file->getMimeType());
- $this->cloudAttachments[] = $part;
+ $this->attachments[] = $part;
}
/**
@@ -250,6 +264,6 @@ class Message implements IMessage {
$part->setName($attachment->getFileName());
$part->setContents($file->getContent());
$part->setType($attachment->getMimeType());
- $this->localAttachments[] = $part;
+ $this->attachments[] = $part;
}
}