private function getMailUsernames(PhabricatorMetaMTAReceivedMail $mail)
 {
     $usernames = array();
     foreach ($mail->getToAddresses() as $to_address) {
         $address = self::stripMailboxPrefix($to_address);
         $usernames[] = id(new PhutilEmailAddress($address))->getLocalPart();
     }
     return array_unique($usernames);
 }
 private function matchObjectAddressInMail(PhabricatorMetaMTAReceivedMail $mail)
 {
     foreach ($mail->getToAddresses() as $address) {
         $parts = $this->matchObjectAddress($address);
         if ($parts) {
             return $parts;
         }
     }
     return null;
 }
 public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail)
 {
     $config_key = 'metamta.maniphest.public-create-email';
     $create_address = PhabricatorEnv::getEnvConfig($config_key);
     foreach ($mail->getToAddresses() as $to_address) {
         if ($this->matchAddresses($create_address, $to_address)) {
             return true;
         }
     }
     return false;
 }
 protected final function canAcceptApplicationMail(PhabricatorApplication $app, PhabricatorMetaMTAReceivedMail $mail)
 {
     $application_emails = id(new PhabricatorMetaMTAApplicationEmailQuery())->setViewer($this->getViewer())->withApplicationPHIDs(array($app->getPHID()))->execute();
     foreach ($mail->getToAddresses() as $to_address) {
         foreach ($application_emails as $application_email) {
             $create_address = $application_email->getAddress();
             if ($this->matchAddresses($create_address, $to_address)) {
                 $this->setApplicationEmail($application_email);
                 return true;
             }
         }
     }
     return false;
 }
 private function dropEmptyMail(PhabricatorMetaMTAReceivedMail $mail)
 {
     $body = $mail->getCleanTextBody();
     $attachments = $mail->getAttachments();
     if (strlen($body) || $attachments) {
         return;
     }
     // Only send an error email if the user is talking to just Phabricator.
     // We can assume if there is only one "To" address it is a Phabricator
     // address since this code is running and everything.
     $is_direct_mail = count($mail->getToAddresses()) == 1 && count($mail->getCCAddresses()) == 0;
     if ($is_direct_mail) {
         $status_code = MetaMTAReceivedMailStatus::STATUS_EMPTY;
     } else {
         $status_code = MetaMTAReceivedMailStatus::STATUS_EMPTY_IGNORED;
     }
     throw new PhabricatorMetaMTAReceivedMailProcessingException($status_code, pht('Your message does not contain any body text or attachments, so ' . 'Phabricator can not do anything useful with it. Make sure comment ' . 'text appears at the top of your message: quoted replies, inline ' . 'text, and signatures are discarded and ignored.'));
 }
 /**
  * Only send an error email if the user is talking to just Phabricator. We
  * can assume if there is only one To address it is a Phabricator address
  * since this code is running and everything.
  */
 private function shouldSendErrorEmail(PhabricatorMetaMTAReceivedMail $mail)
 {
     return count($mail->getToAddresses() == 1) && count($mail->getCCAddresses() == 0);
 }