[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/maniphest/mail/ -> ManiphestCreateMailReceiver.php (source)

   1  <?php
   2  
   3  final class ManiphestCreateMailReceiver extends PhabricatorMailReceiver {
   4  
   5    public function isEnabled() {
   6      $app_class = 'PhabricatorManiphestApplication';
   7      return PhabricatorApplication::isClassInstalled($app_class);
   8    }
   9  
  10    public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
  11      $config_key = 'metamta.maniphest.public-create-email';
  12      $create_address = PhabricatorEnv::getEnvConfig($config_key);
  13  
  14      foreach ($mail->getToAddresses() as $to_address) {
  15        if ($this->matchAddresses($create_address, $to_address)) {
  16          return true;
  17        }
  18      }
  19  
  20      return false;
  21    }
  22  
  23    public function loadSender(PhabricatorMetaMTAReceivedMail $mail) {
  24      try {
  25        // Try to load the sender normally.
  26        return parent::loadSender($mail);
  27      } catch (PhabricatorMetaMTAReceivedMailProcessingException $ex) {
  28  
  29        // If we failed to load the sender normally, use this special legacy
  30        // black magic.
  31  
  32        // TODO: Deprecate and remove this.
  33  
  34        $default_author_key = 'metamta.maniphest.default-public-author';
  35        $default_author = PhabricatorEnv::getEnvConfig($default_author_key);
  36  
  37        if (!strlen($default_author)) {
  38          throw $ex;
  39        }
  40  
  41        $user = id(new PhabricatorUser())->loadOneWhere(
  42          'username = %s',
  43          $default_author);
  44  
  45        if ($user) {
  46          return $user;
  47        }
  48  
  49        throw new PhabricatorMetaMTAReceivedMailProcessingException(
  50          MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER,
  51          pht(
  52            "Phabricator is misconfigured, the configuration key ".
  53            "'metamta.maniphest.default-public-author' is set to user ".
  54            "'%s' but that user does not exist.",
  55            $default_author));
  56      }
  57    }
  58  
  59    protected function processReceivedMail(
  60      PhabricatorMetaMTAReceivedMail $mail,
  61      PhabricatorUser $sender) {
  62  
  63      $task = ManiphestTask::initializeNewTask($sender);
  64      $task->setOriginalEmailSource($mail->getHeader('From'));
  65  
  66      $handler = PhabricatorEnv::newObjectFromConfig(
  67        'metamta.maniphest.reply-handler');
  68      $handler->setMailReceiver($task);
  69  
  70      $handler->setActor($sender);
  71      $handler->setExcludeMailRecipientPHIDs(
  72        $mail->loadExcludeMailRecipientPHIDs());
  73      $handler->processEmail($mail);
  74  
  75      $mail->setRelatedPHID($task->getPHID());
  76    }
  77  
  78  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1