3 final class PhabricatorMetaMTASendGridReceiveController
4 extends PhabricatorMetaMTAController
{
6 public function shouldRequireLogin() {
10 public function handleRequest(AphrontRequest
$request) {
11 // SendGrid doesn't sign payloads so we can't be sure that SendGrid
12 // actually sent this request, but require a configured SendGrid mailer
13 // before we activate this endpoint.
14 $mailers = PhabricatorMetaMTAMail
::newMailers(
18 PhabricatorMailSendGridAdapter
::ADAPTERTYPE
,
22 return new Aphront404Response();
25 // No CSRF for SendGrid.
26 $unguarded = AphrontWriteGuard
::beginScopedUnguardedWrites();
27 $user = $request->getUser();
29 $raw_headers = $request->getStr('headers');
30 $raw_headers = explode("\n", rtrim($raw_headers));
32 foreach (array_filter($raw_headers) as $header) {
33 list($name, $value) = explode(':', $header, 2);
34 $raw_dict[$name] = ltrim($value);
38 'to' => $request->getStr('to'),
39 'from' => $request->getStr('from'),
40 'subject' => $request->getStr('subject'),
43 $received = new PhabricatorMetaMTAReceivedMail();
44 $received->setHeaders($headers);
45 $received->setBodies(array(
46 'text' => $request->getStr('text'),
47 'html' => $request->getStr('from'),
50 $file_phids = array();
51 foreach ($_FILES as $file_raw) {
53 $file = PhabricatorFile
::newFromPHPUpload(
56 'viewPolicy' => PhabricatorPolicies
::POLICY_NOONE
,
58 $file_phids[] = $file->getPHID();
59 } catch (Exception
$ex) {
63 $received->setAttachments($file_phids);
66 $received->processReceivedMail();
68 $response = new AphrontWebpageResponse();
69 $response->setContent(pht('Got it! Thanks, SendGrid!')."\n");