diff --git a/src/applications/metamta/adapter/sendgrid/PhabricatorMailImplementationSendGridAdapter.php b/src/applications/metamta/adapter/sendgrid/PhabricatorMailImplementationSendGridAdapter.php index 72dc3286e2..4a0c3640bf 100644 --- a/src/applications/metamta/adapter/sendgrid/PhabricatorMailImplementationSendGridAdapter.php +++ b/src/applications/metamta/adapter/sendgrid/PhabricatorMailImplementationSendGridAdapter.php @@ -56,9 +56,10 @@ class PhabricatorMailImplementationSendGridAdapter } public function addAttachment($data, $filename, $mimetype) { - throw new Exception( - 'SendGrid adapter does not currently support attachments.' - ); + if (empty($this->params['files'])) { + $this->params['files'] = array(); + } + $this->params['files'][$filename] = $data; } public function addHeader($header_name, $header_value) { @@ -122,6 +123,10 @@ class PhabricatorMailImplementationSendGridAdapter $params['replyto'] = $replyto[0]['email']; } + foreach (idx($this->params, 'files', array()) as $name => $data) { + $params['files['.$name.']'] = $data; + } + $headers = idx($this->params, 'headers', array()); // See SendGrid Support Ticket #29390; there's no explicit REST API support diff --git a/src/applications/metamta/controller/send/PhabricatorMetaMTASendController.php b/src/applications/metamta/controller/send/PhabricatorMetaMTASendController.php index 0f865d7928..1a6d482e21 100644 --- a/src/applications/metamta/controller/send/PhabricatorMetaMTASendController.php +++ b/src/applications/metamta/controller/send/PhabricatorMetaMTASendController.php @@ -23,12 +23,24 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController { $request = $this->getRequest(); if ($request->isFormPost()) { + $mail = new PhabricatorMetaMTAMail(); $mail->addTos($request->getArr('to')); $mail->addCCs($request->getArr('cc')); $mail->setSubject($request->getStr('subject')); $mail->setBody($request->getStr('body')); + $files = $request->getArr('files'); + if ($files) { + foreach ($files as $phid) { + $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid); + $mail->addAttachment( + $file->loadFileData(), + $file->getName(), + $file->getMimeType()); + } + } + $mail->setFrom($request->getUser()->getPHID()); $mail->setSimulatedFailureCount($request->getInt('failures')); $mail->setIsHTML($request->getInt('html')); @@ -75,6 +87,8 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController { 'configure a real adapter.

'); } + $panel_id = celerity_generate_unique_node_id(); + $form = new AphrontFormView(); $form->setUser($request->getUser()); $form->setAction('/mail/send/'); @@ -102,6 +116,12 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController { id(new AphrontFormTextAreaControl()) ->setLabel('Body') ->setName('body')) + ->appendChild( + id(new AphrontFormDragAndDropUploadControl()) + ->setLabel('Attach Files') + ->setName('files') + ->setDragAndDropTarget($panel_id) + ->setActivatedClass('aphront-panel-view-drag-and-drop')) ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Simulate Failures') @@ -129,6 +149,7 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController { $panel = new AphrontPanelView(); $panel->setHeader('Send Email'); $panel->appendChild($form); + $panel->setID($panel_id); $panel->setWidth(AphrontPanelView::WIDTH_WIDE); return $this->buildStandardPageResponse( diff --git a/src/applications/metamta/controller/send/__init__.php b/src/applications/metamta/controller/send/__init__.php index d71faf02c8..26f519b740 100644 --- a/src/applications/metamta/controller/send/__init__.php +++ b/src/applications/metamta/controller/send/__init__.php @@ -7,11 +7,14 @@ phutil_require_module('phabricator', 'aphront/response/redirect'); +phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'applications/metamta/controller/base'); phutil_require_module('phabricator', 'applications/metamta/storage/mail'); +phutil_require_module('phabricator', 'infrastructure/celerity/api'); phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phabricator', 'view/form/base'); phutil_require_module('phabricator', 'view/form/control/checkbox'); +phutil_require_module('phabricator', 'view/form/control/draganddropupload'); phutil_require_module('phabricator', 'view/form/control/static'); phutil_require_module('phabricator', 'view/form/control/submit'); phutil_require_module('phabricator', 'view/form/control/text');