Page MenuHomePhabricator

D18986.diff
No OneTemporary

D18986.diff

diff --git a/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php b/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php
--- a/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php
+++ b/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php
@@ -151,6 +151,12 @@
$properties->addTextContent($body);
+ $file_phids = $mail->getAttachmentFilePHIDs();
+ if ($file_phids) {
+ $properties->addProperty(
+ pht('Attached Files'),
+ $viewer->loadHandles($file_phids)->renderList());
+ }
return $properties;
}
diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAAttachment.php b/src/applications/metamta/storage/PhabricatorMetaMTAAttachment.php
--- a/src/applications/metamta/storage/PhabricatorMetaMTAAttachment.php
+++ b/src/applications/metamta/storage/PhabricatorMetaMTAAttachment.php
@@ -1,9 +1,12 @@
<?php
final class PhabricatorMetaMTAAttachment extends Phobject {
- protected $data;
- protected $filename;
- protected $mimetype;
+
+ private $data;
+ private $filename;
+ private $mimetype;
+ private $file;
+ private $filePHID;
public function __construct($data, $filename, $mimetype) {
$this->setData($data);
@@ -39,18 +42,49 @@
}
public function toDictionary() {
+ if (!$this->file) {
+ $iterator = new ArrayIterator(array($this->getData()));
+
+ $source = id(new PhabricatorIteratorFileUploadSource())
+ ->setName($this->getFilename())
+ ->setViewPolicy(PhabricatorPolicies::POLICY_NOONE)
+ ->setMIMEType($this->getMimeType())
+ ->setIterator($iterator);
+
+ $this->file = $source->uploadFile();
+ }
+
return array(
'filename' => $this->getFilename(),
'mimetype' => $this->getMimeType(),
- 'data' => $this->getData(),
+ 'filePHID' => $this->file->getPHID(),
);
}
public static function newFromDictionary(array $dict) {
- return new PhabricatorMetaMTAAttachment(
+ $file = null;
+
+ $file_phid = idx($dict, 'filePHID');
+ if ($file_phid) {
+ $file = id(new PhabricatorFileQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->withPHIDs(array($file_phid))
+ ->executeOne();
+ if ($file) {
+ $dict['data'] = $file->loadFileData();
+ }
+ }
+
+ $attachment = new self(
idx($dict, 'data'),
idx($dict, 'filename'),
idx($dict, 'mimetype'));
+
+ if ($file) {
+ $attachment->file = $file;
+ }
+
+ return $attachment;
}
}
diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php
--- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php
+++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php
@@ -197,6 +197,35 @@
return $result;
}
+ public function getAttachmentFilePHIDs() {
+ $file_phids = array();
+
+ $dictionaries = $this->getParam('attachments');
+ if ($dictionaries) {
+ foreach ($dictionaries as $dictionary) {
+ $file_phid = idx($dictionary, 'filePHID');
+ if ($file_phid) {
+ $file_phids[] = $file_phid;
+ }
+ }
+ }
+
+ return $file_phids;
+ }
+
+ public function loadAttachedFiles(PhabricatorUser $viewer) {
+ $file_phids = $this->getAttachmentFilePHIDs();
+
+ if (!$file_phids) {
+ return array();
+ }
+
+ return id(new PhabricatorFileQuery())
+ ->setViewer($viewer)
+ ->withPHIDs($file_phids)
+ ->execute();
+ }
+
public function setAttachments(array $attachments) {
assert_instances_of($attachments, 'PhabricatorMetaMTAAttachment');
$this->setParam('attachments', mpull($attachments, 'toDictionary'));
@@ -526,6 +555,12 @@
mpull($cc_actors, 'getEmailAddress'));
break;
case 'attachments':
+ $attached_viewer = PhabricatorUser::getOmnipotentUser();
+ $files = $this->loadAttachedFiles($attached_viewer);
+ foreach ($files as $file) {
+ $file->attachToObject($this->getPHID());
+ }
+
// If the mail content must be encrypted, don't add attachments.
if ($must_encrypt) {
break;
@@ -1299,6 +1334,12 @@
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
+
+ $files = $this->loadAttachedFiles($engine->getViewer());
+ foreach ($files as $file) {
+ $engine->destroyObject($file);
+ }
+
$this->delete();
}

File Metadata

Mime Type
text/plain
Expires
Sun, Jan 12, 4:28 AM (20 h, 34 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6986295
Default Alt Text
D18986.diff (4 KB)

Event Timeline