Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2890334
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
12 KB
Referenced Files
None
Subscribers
None
View Options
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
@@ -1,169 +1,174 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Mail adapter that uses SendGrid's web API to deliver email.
*/
class PhabricatorMailImplementationSendGridAdapter
extends PhabricatorMailImplementationAdapter {
private $params = array();
public function setFrom($email, $name = '') {
$this->params['from'] = $email;
$this->params['from-name'] = $name;
return $this;
}
public function addReplyTo($email, $name = '') {
if (empty($this->params['reply-to'])) {
$this->params['reply-to'] = array();
}
$this->params['reply-to'][] = array(
'email' => $email,
'name' => $name,
);
return $this;
}
public function addTos(array $emails) {
foreach ($emails as $email) {
$this->params['tos'][] = $email;
}
return $this;
}
public function addCCs(array $emails) {
foreach ($emails as $email) {
$this->params['ccs'][] = $email;
}
return $this;
}
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) {
$this->params['headers'][] = array($header_name, $header_value);
return $this;
}
public function setBody($body) {
$this->params['body'] = $body;
return $this;
}
public function setSubject($subject) {
$this->params['subject'] = $subject;
return $this;
}
public function setIsHTML($is_html) {
$this->params['is-html'] = $is_html;
return $this;
}
public function supportsMessageIDHeader() {
return false;
}
public function send() {
$user = PhabricatorEnv::getEnvConfig('sendgrid.api-user');
$key = PhabricatorEnv::getEnvConfig('sendgrid.api-key');
if (!$user || !$key) {
throw new Exception(
"Configure 'sendgrid.api-user' and 'sendgrid.api-key' to use ".
"SendGrid for mail delivery.");
}
$params = array();
$ii = 0;
foreach (idx($this->params, 'tos', array()) as $to) {
$params['to['.($ii++).']'] = $to;
}
$params['subject'] = idx($this->params, 'subject');
if (idx($this->params, 'is-html')) {
$params['html'] = idx($this->params, 'body');
} else {
$params['text'] = idx($this->params, 'body');
}
$params['from'] = idx($this->params, 'from');
if (idx($this->params, 'from-name')) {
$params['fromname'] = $this->params['from-name'];
}
if (idx($this->params, 'reply-to')) {
$replyto = $this->params['reply-to'];
// Pick off the email part, no support for the name part in this API.
$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
// for CC right now but it works if you add a generic "Cc" header.
//
// SendGrid said this is supported:
// "You can use CC as you are trying to do there [by adding a generic
// header]. It is supported despite our limited documentation to this
// effect, I am glad you were able to figure it out regardless. ..."
if (idx($this->params, 'ccs')) {
$headers[] = array('Cc', implode(', ', $this->params['ccs']));
}
if ($headers) {
// Convert to dictionary.
$headers = ipull($headers, 1, 0);
$headers = json_encode($headers);
$params['headers'] = $headers;
}
$params['api_user'] = $user;
$params['api_key'] = $key;
$future = new HTTPSFuture(
'https://sendgrid.com/api/mail.send.json',
$params);
$future->setMethod('POST');
list($body) = $future->resolvex();
$response = json_decode($body, true);
if (!is_array($response)) {
throw new Exception("Failed to JSON decode response: {$body}");
}
if ($response['message'] !== 'success') {
$errors = implode(";", $response['errors']);
throw new Exception("Request failed with errors: {$errors}.");
}
return true;
}
}
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
@@ -1,144 +1,165 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController {
public function processRequest() {
$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'));
$mail->setIsBulk($request->getInt('bulk'));
$mail->save();
if ($request->getInt('immediately')) {
$mail->sendNow();
}
return id(new AphrontRedirectResponse())
->setURI('/mail/view/'.$mail->getID().'/');
}
$failure_caption =
"Enter a number to simulate that many consecutive send failures before ".
"really attempting to deliver via the underlying MTA.";
$doclink_href = PhabricatorEnv::getDoclink(
'article/Configuring_Outbound_Email.html');
$doclink = phutil_render_tag(
'a',
array(
'href' => $doclink_href,
'target' => '_blank',
),
'Configuring Outbound Email');
$instructions =
'<p class="aphront-form-instructions">This form will send a normal '.
'email using the settings you have configured for Phabricator. For more '.
'information, see '.$doclink.'.</p>';
$adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
$warning = null;
if ($adapter == 'PhabricatorMailImplementationTestAdapter') {
$warning = new AphrontErrorView();
$warning->setTitle('Email is Disabled');
$warning->setSeverity(AphrontErrorView::SEVERITY_WARNING);
$warning->appendChild(
'<p>This installation of Phabricator is currently set to use '.
'<tt>PhabricatorMailImplementationTestAdapter</tt> to deliver '.
'outbound email. This completely disables outbound email! All '.
'outbound email will be thrown in a deep, dark hole until you '.
'configure a real adapter.</p>');
}
+ $panel_id = celerity_generate_unique_node_id();
+
$form = new AphrontFormView();
$form->setUser($request->getUser());
$form->setAction('/mail/send/');
$form
->appendChild($instructions)
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Configured Adapter')
->setValue($adapter))
->appendChild(
id(new AphrontFormTokenizerControl())
->setLabel('To')
->setName('to')
->setDatasource('/typeahead/common/mailable/'))
->appendChild(
id(new AphrontFormTokenizerControl())
->setLabel('CC')
->setName('cc')
->setDatasource('/typeahead/common/mailable/'))
->appendChild(
id(new AphrontFormTextControl())
->setLabel('Subject')
->setName('subject'))
->appendChild(
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')
->setName('failures')
->setCaption($failure_caption))
->appendChild(
id(new AphrontFormCheckboxControl())
->setLabel('HTML')
->addCheckbox('html', '1', 'Send as HTML email.'))
->appendChild(
id(new AphrontFormCheckboxControl())
->setLabel('Bulk')
->addCheckbox('bulk', '1', 'Send with bulk email headers.'))
->appendChild(
id(new AphrontFormCheckboxControl())
->setLabel('Send Now')
->addCheckbox(
'immediately',
'1',
'Send immediately, not via MetaMTA background script.'))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Send Mail'));
$panel = new AphrontPanelView();
$panel->setHeader('Send Email');
$panel->appendChild($form);
+ $panel->setID($panel_id);
$panel->setWidth(AphrontPanelView::WIDTH_WIDE);
return $this->buildStandardPageResponse(
array(
$warning,
$panel,
),
array(
'title' => 'Send Mail',
));
}
}
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
@@ -1,27 +1,30 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
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');
phutil_require_module('phabricator', 'view/form/control/textarea');
phutil_require_module('phabricator', 'view/form/control/tokenizer');
phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorMetaMTASendController.php');
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 13:24 (3 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1125036
Default Alt Text
(12 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment