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
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2020-09-24 19:24:51 +0300
committerGitHub <noreply@github.com>2020-09-24 19:24:51 +0300
commit9862e2375b73fb88b44f898d90c4fa89aac4ed4f (patch)
treed3a694c4fd9a91ca75aaf1cd95438754699f578e
parent306367f91a4ae1f26ef307116f32a0880caa40c7 (diff)
parent356602c357c307609e7cecd540fbb9e5c9c85ce1 (diff)
Merge pull request #3637 from nextcloud/fix/3297/set-mime-type-to-attachmentsv1.5.0-beta3
Gets mime type of uploaded attachments
-rw-r--r--lib/Controller/LocalAttachmentsController.php2
-rw-r--r--lib/Db/LocalAttachment.php5
-rw-r--r--lib/Migration/Version1060Date20200921141700.php32
-rw-r--r--lib/Model/Message.php2
-rw-r--r--lib/Service/Attachment/AttachmentService.php1
-rw-r--r--lib/Service/Attachment/UploadedFile.php7
6 files changed, 47 insertions, 2 deletions
diff --git a/lib/Controller/LocalAttachmentsController.php b/lib/Controller/LocalAttachmentsController.php
index bcf6af69e..e58f56ce6 100644
--- a/lib/Controller/LocalAttachmentsController.php
+++ b/lib/Controller/LocalAttachmentsController.php
@@ -47,7 +47,7 @@ class LocalAttachmentsController extends Controller {
* @param string $UserId
*/
public function __construct(string $appName, IRequest $request,
- IAttachmentService $attachmentService, $UserId) {
+ IAttachmentService $attachmentService, $UserId) {
parent::__construct($appName, $request);
$this->attachmentService = $attachmentService;
$this->userId = $UserId;
diff --git a/lib/Db/LocalAttachment.php b/lib/Db/LocalAttachment.php
index f6dd8c50e..1052aee82 100644
--- a/lib/Db/LocalAttachment.php
+++ b/lib/Db/LocalAttachment.php
@@ -30,6 +30,8 @@ use OCP\AppFramework\Db\Entity;
* @method void setUserId(string $userId)
* @method string getFileName()
* @method void setFileName(string $fileName)
+ * @method string getMimeType()
+ * @method void setMimeType(string $mimeType)
* @method int getCreatedAt()
* @method void setCreatedAt(int $createdAt)
*/
@@ -41,6 +43,9 @@ class LocalAttachment extends Entity implements JsonSerializable {
/** @var string */
protected $fileName;
+ /** @var string */
+ protected $mimeType;
+
/** @var mixed */
protected $createdAt;
diff --git a/lib/Migration/Version1060Date20200921141700.php b/lib/Migration/Version1060Date20200921141700.php
new file mode 100644
index 000000000..8abfc8aa3
--- /dev/null
+++ b/lib/Migration/Version1060Date20200921141700.php
@@ -0,0 +1,32 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OCA\Mail\Migration;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+class Version1060Date20200921141700 extends SimpleMigrationStep {
+
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ * @return ISchemaWrapper
+ */
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ $accountsTable = $schema->getTable('mail_attachments');
+ $accountsTable->addColumn('mime_type', 'string', [
+ 'notnull' => false,
+ 'length' => 255, // RFC 4288 defines max size
+ ]);
+
+ return $schema;
+ }
+}
diff --git a/lib/Model/Message.php b/lib/Model/Message.php
index 55ebcf743..1fedcde8b 100644
--- a/lib/Model/Message.php
+++ b/lib/Model/Message.php
@@ -249,7 +249,7 @@ class Message implements IMessage {
$part->setDisposition('attachment');
$part->setName($attachment->getFileName());
$part->setContents($file->getContent());
- $part->setType($file->getMimeType());
+ $part->setType($attachment->getMimeType());
$this->localAttachments[] = $part;
}
}
diff --git a/lib/Service/Attachment/AttachmentService.php b/lib/Service/Attachment/AttachmentService.php
index 431873884..b74caf167 100644
--- a/lib/Service/Attachment/AttachmentService.php
+++ b/lib/Service/Attachment/AttachmentService.php
@@ -55,6 +55,7 @@ class AttachmentService implements IAttachmentService {
$attachment = new LocalAttachment();
$attachment->setUserId($userId);
$attachment->setFileName($file->getFileName());
+ $attachment->setMimeType($file->getMimeType());
$persisted = $this->mapper->insert($attachment);
try {
diff --git a/lib/Service/Attachment/UploadedFile.php b/lib/Service/Attachment/UploadedFile.php
index e99fb5f20..565b58f60 100644
--- a/lib/Service/Attachment/UploadedFile.php
+++ b/lib/Service/Attachment/UploadedFile.php
@@ -49,4 +49,11 @@ class UploadedFile {
public function getTempPath() {
return isset($this->fileData['tmp_name']) ? $this->fileData['tmp_name'] : null;
}
+
+ /**
+ * @return string
+ */
+ public function getMimeType() {
+ return isset($this->fileData['type']) ? $this->fileData['type'] : 'application/octet-stream';
+ }
}