Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php final class PhabricatorMetaMTASendGridReceiveController extends PhabricatorMetaMT..

Decoded Output download

<?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(
          PhabricatorMailSendGridAdapter::ADAPTERTYPE,
        ),
      ));
    if (!$mailers) {
      return new Aphront404Response();
    }

    // No CSRF for SendGrid.
    $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
    $user = $request->getUser();

    $raw_headers = $request->getStr('headers');
    $raw_headers = explode("
", 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!')."
");
    return $response;
  }

}
 ?>

Did this file decode correctly?

Original Code

<?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(
          PhabricatorMailSendGridAdapter::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;
  }

}

Function Calls

None

Variables

None

Stats

MD5 668be12039d5024f89b1d4dcc1e46844
Eval Count 0
Decode Time 156 ms