Skip to content
Snippets Groups Projects
Unverified Commit 9862e237 authored by Christoph Wurst's avatar Christoph Wurst Committed by GitHub
Browse files

Merge pull request #3637 from nextcloud/fix/3297/set-mime-type-to-attachments

Gets mime type of uploaded attachments
parents 306367f9 356602c3
No related branches found
Tags v1.5.0-beta3
No related merge requests found
......@@ -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;
......
......@@ -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;
......
<?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;
}
}
......@@ -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;
}
}
......@@ -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 {
......
......@@ -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';
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment