mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00: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) {
|
public function addAttachment($data, $filename, $mimetype) {
|
||||||
throw new Exception(
|
if (empty($this->params['files'])) {
|
||||||
'SendGrid adapter does not currently support attachments.'
|
$this->params['files'] = array();
|
||||||
);
|
}
|
||||||
|
$this->params['files'][$filename] = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addHeader($header_name, $header_value) {
|
public function addHeader($header_name, $header_value) {
|
||||||
|
@ -122,6 +123,10 @@ class PhabricatorMailImplementationSendGridAdapter
|
||||||
$params['replyto'] = $replyto[0]['email'];
|
$params['replyto'] = $replyto[0]['email'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (idx($this->params, 'files', array()) as $name => $data) {
|
||||||
|
$params['files['.$name.']'] = $data;
|
||||||
|
}
|
||||||
|
|
||||||
$headers = idx($this->params, 'headers', array());
|
$headers = idx($this->params, 'headers', array());
|
||||||
|
|
||||||
// See SendGrid Support Ticket #29390; there's no explicit REST API support
|
// See SendGrid Support Ticket #29390; there's no explicit REST API support
|
||||||
|
|
|
@ -23,12 +23,24 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
|
|
||||||
$mail = new PhabricatorMetaMTAMail();
|
$mail = new PhabricatorMetaMTAMail();
|
||||||
$mail->addTos($request->getArr('to'));
|
$mail->addTos($request->getArr('to'));
|
||||||
$mail->addCCs($request->getArr('cc'));
|
$mail->addCCs($request->getArr('cc'));
|
||||||
$mail->setSubject($request->getStr('subject'));
|
$mail->setSubject($request->getStr('subject'));
|
||||||
$mail->setBody($request->getStr('body'));
|
$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->setFrom($request->getUser()->getPHID());
|
||||||
$mail->setSimulatedFailureCount($request->getInt('failures'));
|
$mail->setSimulatedFailureCount($request->getInt('failures'));
|
||||||
$mail->setIsHTML($request->getInt('html'));
|
$mail->setIsHTML($request->getInt('html'));
|
||||||
|
@ -75,6 +87,8 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController {
|
||||||
'configure a real adapter.</p>');
|
'configure a real adapter.</p>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$panel_id = celerity_generate_unique_node_id();
|
||||||
|
|
||||||
$form = new AphrontFormView();
|
$form = new AphrontFormView();
|
||||||
$form->setUser($request->getUser());
|
$form->setUser($request->getUser());
|
||||||
$form->setAction('/mail/send/');
|
$form->setAction('/mail/send/');
|
||||||
|
@ -102,6 +116,12 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController {
|
||||||
id(new AphrontFormTextAreaControl())
|
id(new AphrontFormTextAreaControl())
|
||||||
->setLabel('Body')
|
->setLabel('Body')
|
||||||
->setName('body'))
|
->setName('body'))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormDragAndDropUploadControl())
|
||||||
|
->setLabel('Attach Files')
|
||||||
|
->setName('files')
|
||||||
|
->setDragAndDropTarget($panel_id)
|
||||||
|
->setActivatedClass('aphront-panel-view-drag-and-drop'))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormTextControl())
|
id(new AphrontFormTextControl())
|
||||||
->setLabel('Simulate Failures')
|
->setLabel('Simulate Failures')
|
||||||
|
@ -129,6 +149,7 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController {
|
||||||
$panel = new AphrontPanelView();
|
$panel = new AphrontPanelView();
|
||||||
$panel->setHeader('Send Email');
|
$panel->setHeader('Send Email');
|
||||||
$panel->appendChild($form);
|
$panel->appendChild($form);
|
||||||
|
$panel->setID($panel_id);
|
||||||
$panel->setWidth(AphrontPanelView::WIDTH_WIDE);
|
$panel->setWidth(AphrontPanelView::WIDTH_WIDE);
|
||||||
|
|
||||||
return $this->buildStandardPageResponse(
|
return $this->buildStandardPageResponse(
|
||||||
|
|
|
@ -7,11 +7,14 @@
|
||||||
|
|
||||||
|
|
||||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
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/controller/base');
|
||||||
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
|
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', 'infrastructure/env');
|
||||||
phutil_require_module('phabricator', 'view/form/base');
|
phutil_require_module('phabricator', 'view/form/base');
|
||||||
phutil_require_module('phabricator', 'view/form/control/checkbox');
|
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/static');
|
||||||
phutil_require_module('phabricator', 'view/form/control/submit');
|
phutil_require_module('phabricator', 'view/form/control/submit');
|
||||||
phutil_require_module('phabricator', 'view/form/control/text');
|
phutil_require_module('phabricator', 'view/form/control/text');
|
||||||
|
|
Loading…
Reference in a new issue