mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-10 22:08:32 +01:00
Summary: See PHI785. Ref T13164. In this case, an install wants to receive mail via Mailgun, but not configure it (DKIM + SPF) for outbound mail. Allow individual mailers to be marked as not supporting inbound or outbound mail. Test Plan: - Added and ran unit tests. - Went through some mail pathways locally, but I don't have every inbound/outbound configured so this isn't totally conclusive. - Hit `bin/mail send-test` with a no-outbound mailer. - I'll hold this until after the release cut so it can soak on `secure` for a bit. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13164 Differential Revision: https://secure.phabricator.com/D19546
73 lines
2 KiB
PHP
73 lines
2 KiB
PHP
<?php
|
|
|
|
final class PhabricatorMetaMTASendGridReceiveController
|
|
extends PhabricatorMetaMTAController {
|
|
|
|
public function shouldRequireLogin() {
|
|
return false;
|
|
}
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
// SendGrid doesn't sign payloads so we can't be sure that SendGrid
|
|
// actually sent this request, but require a configured SendGrid mailer
|
|
// before we activate this endpoint.
|
|
$mailers = PhabricatorMetaMTAMail::newMailers(
|
|
array(
|
|
'inbound' => true,
|
|
'types' => array(
|
|
PhabricatorMailImplementationSendGridAdapter::ADAPTERTYPE,
|
|
),
|
|
));
|
|
if (!$mailers) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
// No CSRF for SendGrid.
|
|
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
|
$user = $request->getUser();
|
|
|
|
$raw_headers = $request->getStr('headers');
|
|
$raw_headers = explode("\n", rtrim($raw_headers));
|
|
$raw_dict = array();
|
|
foreach (array_filter($raw_headers) as $header) {
|
|
list($name, $value) = explode(':', $header, 2);
|
|
$raw_dict[$name] = ltrim($value);
|
|
}
|
|
|
|
$headers = array(
|
|
'to' => $request->getStr('to'),
|
|
'from' => $request->getStr('from'),
|
|
'subject' => $request->getStr('subject'),
|
|
) + $raw_dict;
|
|
|
|
$received = new PhabricatorMetaMTAReceivedMail();
|
|
$received->setHeaders($headers);
|
|
$received->setBodies(array(
|
|
'text' => $request->getStr('text'),
|
|
'html' => $request->getStr('from'),
|
|
));
|
|
|
|
$file_phids = array();
|
|
foreach ($_FILES as $file_raw) {
|
|
try {
|
|
$file = PhabricatorFile::newFromPHPUpload(
|
|
$file_raw,
|
|
array(
|
|
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
|
|
));
|
|
$file_phids[] = $file->getPHID();
|
|
} catch (Exception $ex) {
|
|
phlog($ex);
|
|
}
|
|
}
|
|
$received->setAttachments($file_phids);
|
|
$received->save();
|
|
|
|
$received->processReceivedMail();
|
|
|
|
$response = new AphrontWebpageResponse();
|
|
$response->setContent(pht('Got it! Thanks, SendGrid!')."\n");
|
|
return $response;
|
|
}
|
|
|
|
}
|