[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/conpherence/mail/ -> ConpherenceCreateThreadMailReceiver.php (source)

   1  <?php
   2  
   3  final class ConpherenceCreateThreadMailReceiver
   4    extends PhabricatorMailReceiver {
   5  
   6    public function isEnabled() {
   7      $app_class = 'PhabricatorConpherenceApplication';
   8      return PhabricatorApplication::isClassInstalled($app_class);
   9    }
  10  
  11    public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
  12      $usernames = $this->getMailUsernames($mail);
  13      if (!$usernames) {
  14        return false;
  15      }
  16  
  17      $users = $this->loadMailUsers($mail);
  18      if (count($users) != count($usernames)) {
  19        // At least some of the addresses are not users, so don't accept this as
  20        // a new Conpherence thread.
  21        return false;
  22      }
  23  
  24      return true;
  25    }
  26  
  27    private function getMailUsernames(PhabricatorMetaMTAReceivedMail $mail) {
  28      $usernames = array();
  29      foreach ($mail->getToAddresses() as $to_address) {
  30        $address = self::stripMailboxPrefix($to_address);
  31        $usernames[] = id(new PhutilEmailAddress($address))->getLocalPart();
  32      }
  33  
  34      return array_unique($usernames);
  35    }
  36  
  37    private function loadMailUsers(PhabricatorMetaMTAReceivedMail $mail) {
  38      $usernames = $this->getMailUsernames($mail);
  39      if (!$usernames) {
  40        return array();
  41      }
  42  
  43      return id(new PhabricatorUser())->loadAllWhere(
  44        'username in (%Ls)',
  45        $usernames);
  46    }
  47  
  48    protected function processReceivedMail(
  49      PhabricatorMetaMTAReceivedMail $mail,
  50      PhabricatorUser $sender) {
  51  
  52      $users = $this->loadMailUsers($mail);
  53      $phids = mpull($users, 'getPHID');
  54  
  55      $conpherence = id(new ConpherenceReplyHandler())
  56        ->setMailReceiver(ConpherenceThread::initializeNewThread($sender))
  57        ->setMailAddedParticipantPHIDs($phids)
  58        ->setActor($sender)
  59        ->setExcludeMailRecipientPHIDs($mail->loadExcludeMailRecipientPHIDs())
  60        ->processEmail($mail);
  61  
  62      if ($conpherence) {
  63        $mail->setRelatedPHID($conpherence->getPHID());
  64      }
  65    }
  66  
  67  }


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