mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 21:10:56 +01:00
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
This commit is contained in:
parent
88dc9c471d
commit
802dcd4cfb
3 changed files with 32 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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.</p>');
|
||||
}
|
||||
|
||||
$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(
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue