2011-01-26 02:40:21 +01:00
|
|
|
<?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()) {
|
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'));
|
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())
|
|
|
|
->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.";
|
|
|
|
|
2011-06-13 05:16:34 +02:00
|
|
|
$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>');
|
|
|
|
}
|
2011-01-26 02:40:21 +01:00
|
|
|
|
2011-11-08 23:14:00 +01:00
|
|
|
$panel_id = celerity_generate_unique_node_id();
|
|
|
|
|
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->setAction('/mail/send/');
|
|
|
|
$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())
|
|
|
|
->setLabel('Configured Adapter')
|
|
|
|
->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'))
|
2011-11-08 23:14:00 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormDragAndDropUploadControl())
|
|
|
|
->setLabel('Attach Files')
|
|
|
|
->setName('files')
|
|
|
|
->setDragAndDropTarget($panel_id)
|
|
|
|
->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',
|
|
|
|
'Send immediately, not via MetaMTA background script.'))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue('Send Mail'));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Send Email');
|
|
|
|
$panel->appendChild($form);
|
2011-11-08 23:14:00 +01:00
|
|
|
$panel->setID($panel_id);
|
2011-01-26 02:40:21 +01:00
|
|
|
$panel->setWidth(AphrontPanelView::WIDTH_WIDE);
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
2011-06-13 05:16:34 +02:00
|
|
|
array(
|
|
|
|
$warning,
|
|
|
|
$panel,
|
|
|
|
),
|
2011-01-26 02:40:21 +01:00
|
|
|
array(
|
|
|
|
'title' => 'Send Mail',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|