mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-28 20:18:13 +01:00
Summary: Depends on D19955. Ref T920. Ref T5969. Update Postmark to accept new Message objects. Also: - Update the inbound whitelist. - Add a little support for `media` configuration. - Add a service call timeout (see T5969). - Drop the needless word "Implementation" from the Adapter class tree. I could call these "Mailers" instead of "Adapters", but then we get "PhabricatorMailMailer" which feels questionable. Test Plan: Used `bin/mail send-test` to send mail via Postmark with various options (mulitple recipients, text vs html, attachments). Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T5969, T920 Differential Revision: https://secure.phabricator.com/D19956
105 lines
2.8 KiB
PHP
105 lines
2.8 KiB
PHP
<?php
|
|
|
|
final class PhabricatorMetaMTAPostmarkReceiveController
|
|
extends PhabricatorMetaMTAController {
|
|
|
|
public function shouldRequireLogin() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @phutil-external-symbol class PhabricatorStartup
|
|
*/
|
|
public function handleRequest(AphrontRequest $request) {
|
|
// Don't process requests if we don't have a configured Postmark adapter.
|
|
$mailers = PhabricatorMetaMTAMail::newMailers(
|
|
array(
|
|
'inbound' => true,
|
|
'types' => array(
|
|
PhabricatorMailPostmarkAdapter::ADAPTERTYPE,
|
|
),
|
|
));
|
|
if (!$mailers) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$remote_address = $request->getRemoteAddress();
|
|
$any_remote_match = false;
|
|
foreach ($mailers as $mailer) {
|
|
$inbound_addresses = $mailer->getOption('inbound-addresses');
|
|
$cidr_list = PhutilCIDRList::newList($inbound_addresses);
|
|
if ($cidr_list->containsAddress($remote_address)) {
|
|
$any_remote_match = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$any_remote_match) {
|
|
return new Aphront400Response();
|
|
}
|
|
|
|
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
|
$raw_input = PhabricatorStartup::getRawInput();
|
|
|
|
try {
|
|
$data = phutil_json_decode($raw_input);
|
|
} catch (Exception $ex) {
|
|
return new Aphront400Response();
|
|
}
|
|
|
|
$raw_headers = array();
|
|
$header_items = idx($data, 'Headers', array());
|
|
foreach ($header_items as $header_item) {
|
|
$name = idx($header_item, 'Name');
|
|
$value = idx($header_item, 'Value');
|
|
$raw_headers[$name] = $value;
|
|
}
|
|
|
|
$headers = array(
|
|
'to' => idx($data, 'To'),
|
|
'from' => idx($data, 'From'),
|
|
'cc' => idx($data, 'Cc'),
|
|
'subject' => idx($data, 'Subject'),
|
|
) + $raw_headers;
|
|
|
|
|
|
$received = id(new PhabricatorMetaMTAReceivedMail())
|
|
->setHeaders($headers)
|
|
->setBodies(
|
|
array(
|
|
'text' => idx($data, 'TextBody'),
|
|
'html' => idx($data, 'HtmlBody'),
|
|
));
|
|
|
|
$file_phids = array();
|
|
$attachments = idx($data, 'Attachments', array());
|
|
foreach ($attachments as $attachment) {
|
|
$file_data = idx($attachment, 'Content');
|
|
$file_data = base64_decode($file_data);
|
|
|
|
try {
|
|
$file = PhabricatorFile::newFromFileData(
|
|
$file_data,
|
|
array(
|
|
'name' => idx($attachment, 'Name'),
|
|
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
|
|
));
|
|
$file_phids[] = $file->getPHID();
|
|
} catch (Exception $ex) {
|
|
phlog($ex);
|
|
}
|
|
}
|
|
$received->setAttachments($file_phids);
|
|
|
|
try {
|
|
$received->save();
|
|
$received->processReceivedMail();
|
|
} catch (Exception $ex) {
|
|
phlog($ex);
|
|
}
|
|
|
|
return id(new AphrontWebpageResponse())
|
|
->setContent(pht("Got it! Thanks, Postmark!\n"));
|
|
}
|
|
|
|
}
|