From 802dcd4cfb17fadb0dbefb5aefa7e736bd687a49 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 8 Nov 2011 14:14:00 -0800 Subject: [PATCH] Add attchment support to SendGridAdapter Summary: - Add attachment support for SendGrid. - Add attachment support to the MetaMTA test console. Test Plan: - Sent myself a file with Amazon SES via test console. - Sent myself a file with SendGrid via test console. Reviewers: mareksapota, jungejason, nh, tuomaspelkonen, aran Reviewed By: jungejason CC: aran, jungejason Differential Revision: 1089 --- ...catorMailImplementationSendGridAdapter.php | 11 +++++++--- .../send/PhabricatorMetaMTASendController.php | 21 +++++++++++++++++++ .../metamta/controller/send/__init__.php | 3 +++ 3 files changed, 32 insertions(+), 3 deletions(-) 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');