2011-01-26 02:40:21 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorMetaMTASendController
|
|
|
|
extends PhabricatorMetaMTAController {
|
2011-01-26 02:40:21 +01:00
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
2011-11-08 23:14:00 +01:00
|
|
|
|
2011-01-26 02:40:21 +01:00
|
|
|
$mail = new PhabricatorMetaMTAMail();
|
|
|
|
$mail->addTos($request->getArr('to'));
|
|
|
|
$mail->addCCs($request->getArr('cc'));
|
|
|
|
$mail->setSubject($request->getStr('subject'));
|
|
|
|
$mail->setBody($request->getStr('body'));
|
|
|
|
|
2011-11-08 23:14:00 +01:00
|
|
|
$files = $request->getArr('files');
|
|
|
|
if ($files) {
|
|
|
|
foreach ($files as $phid) {
|
|
|
|
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid);
|
2011-11-09 00:15:44 +01:00
|
|
|
$mail->addAttachment(new PhabricatorMetaMTAAttachment(
|
2011-11-08 23:14:00 +01:00
|
|
|
$file->loadFileData(),
|
|
|
|
$file->getName(),
|
2011-11-09 00:15:44 +01:00
|
|
|
$file->getMimeType()
|
|
|
|
));
|
2011-11-08 23:14:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-27 01:02:12 +01:00
|
|
|
$mail->setFrom($request->getUser()->getPHID());
|
2011-01-26 02:40:21 +01:00
|
|
|
$mail->setSimulatedFailureCount($request->getInt('failures'));
|
|
|
|
$mail->setIsHTML($request->getInt('html'));
|
2011-10-23 21:07:37 +02:00
|
|
|
$mail->setIsBulk($request->getInt('bulk'));
|
Add email preferences to receive fewer less-important notifications
Summary:
A few similar requests have come in across several tools and use cases that I
think this does a reasonable job of resolving.
We currently send one email for each update an object receives, but these aren't
always appreciated:
- Asana does post-commit review via Differential, so the "committed" mails are
useless.
- Quora wants to make project category edits to bugs without spamming people
attached to them.
- Some users in general are very sensitive to email volumes, and this gives us
a good way to reduce the volumes without incurring the complexity of
delayed-send-batching.
The technical mechanism is basically:
- Mail may optionally have "mail tags", which indicate content in the mail
(e.g., "maniphest-priority, maniphest-cc, maniphest-comment" for a mail which
contains a priority change, a CC change, and a comment).
- If a mail has tags, remove any recipients who have opted out of all the
tags.
- Some tags can't be opted out of via the UI, so this ensures that important
email is still delivered (e.g., cc + assign + comment is always delivered
because you can't opt out of "assign" or "comment").
Test Plan:
- Disabled all mail tags in the web UI.
- Used test console to send myself mail with an opt-outable tag, it was
immediately dropped.
- Used test console to send myself mail with an opt-outable tag and a custom
tag, it was delivered.
- Made Differential updates affecting CCs with and without comments, got
appropriate delivery.
- Made Maniphest updates affecting project, priority and CCs with and without
comments, got appropriate delivery.
- Verified mail headers in all cases.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, epriestley, moskov
Maniphest Tasks: T616, T855
Differential Revision: https://secure.phabricator.com/D1635
2012-02-18 07:57:07 +01:00
|
|
|
$mail->setMailTags($request->getStrList('mailtags'));
|
2011-01-26 02:40:21 +01:00
|
|
|
$mail->save();
|
2011-05-01 07:51:25 +02:00
|
|
|
if ($request->getInt('immediately')) {
|
|
|
|
$mail->sendNow();
|
2011-01-26 02:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
2012-08-13 21:37:06 +02:00
|
|
|
->setURI($this->getApplicationURI('/view/'.$mail->getID().'/'));
|
2011-01-26 02:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$failure_caption =
|
|
|
|
"Enter a number to simulate that many consecutive send failures before ".
|
|
|
|
"really attempting to deliver via the underlying MTA.";
|
|
|
|
|
2011-06-13 05:16:34 +02:00
|
|
|
$doclink_href = PhabricatorEnv::getDoclink(
|
|
|
|
'article/Configuring_Outbound_Email.html');
|
|
|
|
|
2013-01-18 03:57:09 +01:00
|
|
|
$doclink = phutil_tag(
|
2011-06-13 05:16:34 +02:00
|
|
|
'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>');
|
|
|
|
}
|
2011-01-26 02:40:21 +01:00
|
|
|
|
2012-08-13 23:41:12 +02:00
|
|
|
$phdlink_href = PhabricatorEnv::getDoclink(
|
|
|
|
'article/Managing_Daemons_with_phd.html');
|
|
|
|
|
2013-01-18 03:57:09 +01:00
|
|
|
$phdlink = phutil_tag(
|
2012-08-13 23:41:12 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $phdlink_href,
|
|
|
|
'target' => '_blank',
|
|
|
|
),
|
|
|
|
'"phd start"');
|
|
|
|
|
2011-01-26 02:40:21 +01:00
|
|
|
$form = new AphrontFormView();
|
2011-01-31 03:52:29 +01:00
|
|
|
$form->setUser($request->getUser());
|
2011-01-26 02:40:21 +01:00
|
|
|
$form
|
2011-06-13 05:16:34 +02:00
|
|
|
->appendChild($instructions)
|
2011-01-26 02:40:21 +01:00
|
|
|
->appendChild(
|
2011-06-13 05:16:34 +02:00
|
|
|
id(new AphrontFormStaticControl())
|
2012-08-13 21:37:06 +02:00
|
|
|
->setLabel('Adapter')
|
2011-06-13 05:16:34 +02:00
|
|
|
->setValue($adapter))
|
2011-01-26 02:40:21 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setLabel('To')
|
|
|
|
->setName('to')
|
2011-01-26 19:40:38 +01:00
|
|
|
->setDatasource('/typeahead/common/mailable/'))
|
2011-01-26 02:40:21 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setLabel('CC')
|
|
|
|
->setName('cc')
|
2011-01-26 19:40:38 +01:00
|
|
|
->setDatasource('/typeahead/common/mailable/'))
|
2011-01-26 02:40:21 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel('Subject')
|
|
|
|
->setName('subject'))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextAreaControl())
|
|
|
|
->setLabel('Body')
|
|
|
|
->setName('body'))
|
Add email preferences to receive fewer less-important notifications
Summary:
A few similar requests have come in across several tools and use cases that I
think this does a reasonable job of resolving.
We currently send one email for each update an object receives, but these aren't
always appreciated:
- Asana does post-commit review via Differential, so the "committed" mails are
useless.
- Quora wants to make project category edits to bugs without spamming people
attached to them.
- Some users in general are very sensitive to email volumes, and this gives us
a good way to reduce the volumes without incurring the complexity of
delayed-send-batching.
The technical mechanism is basically:
- Mail may optionally have "mail tags", which indicate content in the mail
(e.g., "maniphest-priority, maniphest-cc, maniphest-comment" for a mail which
contains a priority change, a CC change, and a comment).
- If a mail has tags, remove any recipients who have opted out of all the
tags.
- Some tags can't be opted out of via the UI, so this ensures that important
email is still delivered (e.g., cc + assign + comment is always delivered
because you can't opt out of "assign" or "comment").
Test Plan:
- Disabled all mail tags in the web UI.
- Used test console to send myself mail with an opt-outable tag, it was
immediately dropped.
- Used test console to send myself mail with an opt-outable tag and a custom
tag, it was delivered.
- Made Differential updates affecting CCs with and without comments, got
appropriate delivery.
- Made Maniphest updates affecting project, priority and CCs with and without
comments, got appropriate delivery.
- Verified mail headers in all cases.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, epriestley, moskov
Maniphest Tasks: T616, T855
Differential Revision: https://secure.phabricator.com/D1635
2012-02-18 07:57:07 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel('Mail Tags')
|
|
|
|
->setName('mailtags')
|
|
|
|
->setCaption(
|
|
|
|
'Example: <tt>differential-cc, differential-comment</tt>'))
|
2011-11-08 23:14:00 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormDragAndDropUploadControl())
|
|
|
|
->setLabel('Attach Files')
|
|
|
|
->setName('files')
|
|
|
|
->setActivatedClass('aphront-panel-view-drag-and-drop'))
|
2011-01-26 02:40:21 +01:00
|
|
|
->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.'))
|
2011-10-23 21:07:37 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormCheckboxControl())
|
|
|
|
->setLabel('Bulk')
|
|
|
|
->addCheckbox('bulk', '1', 'Send with bulk email headers.'))
|
2011-01-26 02:40:21 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormCheckboxControl())
|
|
|
|
->setLabel('Send Now')
|
|
|
|
->addCheckbox(
|
|
|
|
'immediately',
|
|
|
|
'1',
|
2012-08-13 23:41:12 +02:00
|
|
|
'Send immediately. (Do not enqueue for daemons.)',
|
|
|
|
PhabricatorEnv::getEnvConfig('metamta.send-immediately'))
|
|
|
|
->setCaption('Daemons can be started with '.$phdlink.'.')
|
|
|
|
)
|
2011-01-26 02:40:21 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue('Send Mail'));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Send Email');
|
|
|
|
$panel->appendChild($form);
|
2012-08-13 21:37:06 +02:00
|
|
|
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
2011-01-26 02:40:21 +01:00
|
|
|
|
2012-08-13 21:37:06 +02:00
|
|
|
$nav = $this->buildSideNavView();
|
|
|
|
$nav->selectFilter('send');
|
|
|
|
$nav->appendChild(
|
2011-06-13 05:16:34 +02:00
|
|
|
array(
|
|
|
|
$warning,
|
|
|
|
$panel,
|
2012-08-13 21:37:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
$nav,
|
2011-01-26 02:40:21 +01:00
|
|
|
array(
|
2012-08-13 21:37:06 +02:00
|
|
|
'title' => 'Send Test',
|
2011-01-26 02:40:21 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|