Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/receiver/PhabricatorMailReceiver.php
| Show All 19 Lines | final protected function canAcceptApplicationMail( | ||||
| PhabricatorApplication $app, | PhabricatorApplication $app, | ||||
| PhabricatorMetaMTAReceivedMail $mail) { | PhabricatorMetaMTAReceivedMail $mail) { | ||||
| $application_emails = id(new PhabricatorMetaMTAApplicationEmailQuery()) | $application_emails = id(new PhabricatorMetaMTAApplicationEmailQuery()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
| ->withApplicationPHIDs(array($app->getPHID())) | ->withApplicationPHIDs(array($app->getPHID())) | ||||
| ->execute(); | ->execute(); | ||||
| foreach ($mail->getToAddresses() as $to_address) { | foreach ($mail->newTargetAddresses() as $address) { | ||||
| foreach ($application_emails as $application_email) { | foreach ($application_emails as $application_email) { | ||||
| $create_address = $application_email->getAddress(); | $create_address = $application_email->newAddress(); | ||||
| if ($this->matchAddresses($create_address, $to_address)) { | if (PhabricatorMailUtil::matchAddresses($create_address, $address)) { | ||||
| $this->setApplicationEmail($application_email); | $this->setApplicationEmail($application_email); | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | public function loadSender(PhabricatorMetaMTAReceivedMail $mail) { | ||||
| $reasons = implode("\n\n", $reasons); | $reasons = implode("\n\n", $reasons); | ||||
| throw new PhabricatorMetaMTAReceivedMailProcessingException( | throw new PhabricatorMetaMTAReceivedMailProcessingException( | ||||
| MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER, | MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER, | ||||
| $reasons); | $reasons); | ||||
| } | } | ||||
| /** | /** | ||||
| * Determine if two inbound email addresses are effectively identical. This | |||||
| * method strips and normalizes addresses so that equivalent variations are | |||||
| * correctly detected as identical. For example, these addresses are all | |||||
| * considered to match one another: | |||||
| * | |||||
| * "Abraham Lincoln" <alincoln@example.com> | |||||
| * alincoln@example.com | |||||
| * <ALincoln@example.com> | |||||
| * "Abraham" <phabricator+ALINCOLN@EXAMPLE.COM> # With configured prefix. | |||||
| * | |||||
| * @param string Email address. | |||||
| * @param string Another email address. | |||||
| * @return bool True if addresses match. | |||||
| */ | |||||
| public static function matchAddresses($u, $v) { | |||||
| $u = self::getRawAddress($u); | |||||
| $v = self::getRawAddress($v); | |||||
| $u = self::stripMailboxPrefix($u); | |||||
| $v = self::stripMailboxPrefix($v); | |||||
| return ($u === $v); | |||||
| } | |||||
| /** | |||||
| * Strip a global mailbox prefix from an address if it is present. Phabricator | |||||
| * can be configured to prepend a prefix to all reply addresses, which can | |||||
| * make forwarding rules easier to write. A prefix looks like: | |||||
| * | |||||
| * example@phabricator.example.com # No Prefix | |||||
| * phabricator+example@phabricator.example.com # Prefix "phabricator" | |||||
| * | |||||
| * @param string Email address, possibly with a mailbox prefix. | |||||
| * @return string Email address with any prefix stripped. | |||||
| */ | |||||
| public static function stripMailboxPrefix($address) { | |||||
| $address = id(new PhutilEmailAddress($address))->getAddress(); | |||||
| $prefix_key = 'metamta.single-reply-handler-prefix'; | |||||
| $prefix = PhabricatorEnv::getEnvConfig($prefix_key); | |||||
| $len = strlen($prefix); | |||||
| if ($len) { | |||||
| $prefix = $prefix.'+'; | |||||
| $len = $len + 1; | |||||
| } | |||||
| if ($len) { | |||||
| if (!strncasecmp($address, $prefix, $len)) { | |||||
| $address = substr($address, strlen($prefix)); | |||||
| } | |||||
| } | |||||
| return $address; | |||||
| } | |||||
| /** | |||||
| * Reduce an email address to its canonical form. For example, an address | * Reduce an email address to its canonical form. For example, an address | ||||
| * like: | * like: | ||||
| * | * | ||||
| * "Abraham Lincoln" < ALincoln@example.com > | * "Abraham Lincoln" < ALincoln@example.com > | ||||
| * | * | ||||
| * ...will be reduced to: | * ...will be reduced to: | ||||
| * | * | ||||
| * alincoln@example.com | * alincoln@example.com | ||||
| Show All 10 Lines | |||||