Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php
Show First 20 Lines • Show All 257 Lines • ▼ Show 20 Lines | try { | ||||
// NOTE: Currently, we'll always drop this mail (since it's headed to | // NOTE: Currently, we'll always drop this mail (since it's headed to | ||||
// an unverified recipient). See T12237. These details are still | // an unverified recipient). See T12237. These details are still | ||||
// useful because they'll appear in the mail logs and Mail web UI. | // useful because they'll appear in the mail logs and Mail web UI. | ||||
throw new PhabricatorMetaMTAReceivedMailProcessingException( | throw new PhabricatorMetaMTAReceivedMailProcessingException( | ||||
MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER, | MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER, | ||||
pht( | pht( | ||||
'This email was sent from an email address ("%s") that is not '. | 'This email was sent from an email address ("%s") that is not '. | ||||
'associated with a Phabricator account. To interact with '. | 'associated with a registered user account. To interact via '. | ||||
'Phabricator via email, add this address to your account.', | 'email, add this address to your account.', | ||||
(string)$this->newFromAddress())); | (string)$this->newFromAddress())); | ||||
} else { | } else { | ||||
throw new PhabricatorMetaMTAReceivedMailProcessingException( | throw new PhabricatorMetaMTAReceivedMailProcessingException( | ||||
MetaMTAReceivedMailStatus::STATUS_NO_RECEIVERS, | MetaMTAReceivedMailStatus::STATUS_NO_RECEIVERS, | ||||
pht( | pht( | ||||
'Phabricator can not process this mail because no application '. | 'This mail can not be processed because no application '. | ||||
'knows how to handle it. Check that the address you sent it to '. | 'knows how to handle it. Check that the address you sent it to '. | ||||
'is correct.'. | 'is correct.')); | ||||
"\n\n". | |||||
'(No concrete, enabled subclass of PhabricatorMailReceiver can '. | |||||
'accept this mail.)')); | |||||
} | } | ||||
} | } | ||||
} catch (PhabricatorMetaMTAReceivedMailProcessingException $ex) { | } catch (PhabricatorMetaMTAReceivedMailProcessingException $ex) { | ||||
switch ($ex->getStatusCode()) { | switch ($ex->getStatusCode()) { | ||||
case MetaMTAReceivedMailStatus::STATUS_DUPLICATE: | case MetaMTAReceivedMailStatus::STATUS_DUPLICATE: | ||||
case MetaMTAReceivedMailStatus::STATUS_FROM_PHABRICATOR: | case MetaMTAReceivedMailStatus::STATUS_FROM_PHABRICATOR: | ||||
// Don't send an error email back in these cases, since they're | // Don't send an error email back in these cases, since they're | ||||
// very unlikely to be the sender's fault. | // very unlikely to be the sender's fault. | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | private function getRawEmailAddress($address) { | ||||
if ($ok) { | if ($ok) { | ||||
$address = $matches[1]; | $address = $matches[1]; | ||||
} | } | ||||
return $address; | return $address; | ||||
} | } | ||||
private function getRawEmailAddresses($addresses) { | private function getRawEmailAddresses($addresses) { | ||||
$raw_addresses = array(); | $raw_addresses = array(); | ||||
if (phutil_nonempty_string($addresses)) { | |||||
foreach (explode(',', $addresses) as $address) { | foreach (explode(',', $addresses) as $address) { | ||||
$raw_addresses[] = $this->getRawEmailAddress($address); | $raw_addresses[] = $this->getRawEmailAddress($address); | ||||
} | } | ||||
} | |||||
return array_filter($raw_addresses); | return array_filter($raw_addresses); | ||||
} | } | ||||
/** | /** | ||||
* If Phabricator sent the mail, always drop it immediately. This prevents | * If Phabricator sent the mail, always drop it immediately. This prevents | ||||
* loops where, e.g., the public bug address is also a user email address | * loops where, e.g., the public bug address is also a user email address | ||||
* and creating a bug sends them an email, which loops. | * and creating a bug sends them an email, which loops. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | private function dropEmptyMail() { | ||||
} else { | } else { | ||||
$status_code = MetaMTAReceivedMailStatus::STATUS_EMPTY_IGNORED; | $status_code = MetaMTAReceivedMailStatus::STATUS_EMPTY_IGNORED; | ||||
} | } | ||||
throw new PhabricatorMetaMTAReceivedMailProcessingException( | throw new PhabricatorMetaMTAReceivedMailProcessingException( | ||||
$status_code, | $status_code, | ||||
pht( | pht( | ||||
'Your message does not contain any body text or attachments, so '. | 'Your message does not contain any body text or attachments, so '. | ||||
'Phabricator can not do anything useful with it. Make sure comment '. | 'this server can not do anything useful with it. Make sure comment '. | ||||
'text appears at the top of your message: quoted replies, inline '. | 'text appears at the top of your message: quoted replies, inline '. | ||||
'text, and signatures are discarded and ignored.')); | 'text, and signatures are discarded and ignored.')); | ||||
} | } | ||||
private function sendExceptionMail( | private function sendExceptionMail( | ||||
Exception $ex, | Exception $ex, | ||||
PhabricatorUser $viewer = null) { | PhabricatorUser $viewer = null) { | ||||
Show All 31 Lines | foreach ($this->headers as $key => $values) { | ||||
} | } | ||||
foreach ($values as $value) { | foreach ($values as $value) { | ||||
$headers[] = pht('%s: %s', $key, $value); | $headers[] = pht('%s: %s', $key, $value); | ||||
} | } | ||||
} | } | ||||
$headers = implode("\n", $headers); | $headers = implode("\n", $headers); | ||||
$body = pht(<<<EOBODY | $body = pht(<<<EOBODY | ||||
Your email to Phabricator was not processed, because an error occurred while | Your email to %s was not processed, because an error occurred while | ||||
trying to handle it: | trying to handle it: | ||||
%s | %s | ||||
-- Original Message Body ----------------------------------------------------- | -- Original Message Body ----------------------------------------------------- | ||||
%s | %s | ||||
-- Original Message Headers -------------------------------------------------- | -- Original Message Headers -------------------------------------------------- | ||||
%s | %s | ||||
EOBODY | EOBODY | ||||
, | , | ||||
PlatformSymbols::getPlatformServerName(), | |||||
wordwrap($description, 78), | wordwrap($description, 78), | ||||
$this->getRawTextBody(), | $this->getRawTextBody(), | ||||
$headers); | $headers); | ||||
$mail = id(new PhabricatorMetaMTAMail()) | $mail = id(new PhabricatorMetaMTAMail()) | ||||
->setIsErrorEmail(true) | ->setIsErrorEmail(true) | ||||
->setSubject($title) | ->setSubject($title) | ||||
->addTos(array($viewer->getPHID())) | ->addTos(array($viewer->getPHID())) | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | private function loadSender() { | ||||
return null; | return null; | ||||
} | } | ||||
private function validateSender(PhabricatorUser $sender) { | private function validateSender(PhabricatorUser $sender) { | ||||
$failure_reason = null; | $failure_reason = null; | ||||
if ($sender->getIsDisabled()) { | if ($sender->getIsDisabled()) { | ||||
$failure_reason = pht( | $failure_reason = pht( | ||||
'Your account ("%s") is disabled, so you can not interact with '. | 'Your account ("%s") is disabled, so you can not interact with '. | ||||
'Phabricator over email.', | 'over email.', | ||||
$sender->getUsername()); | $sender->getUsername()); | ||||
} else if ($sender->getIsStandardUser()) { | } else if ($sender->getIsStandardUser()) { | ||||
if (!$sender->getIsApproved()) { | if (!$sender->getIsApproved()) { | ||||
$failure_reason = pht( | $failure_reason = pht( | ||||
'Your account ("%s") has not been approved yet. You can not '. | 'Your account ("%s") has not been approved yet. You can not '. | ||||
'interact with Phabricator over email until your account is '. | 'interact over email until your account is approved.', | ||||
'approved.', | |||||
$sender->getUsername()); | $sender->getUsername()); | ||||
} else if (PhabricatorUserEmail::isEmailVerificationRequired() && | } else if (PhabricatorUserEmail::isEmailVerificationRequired() && | ||||
!$sender->getIsEmailVerified()) { | !$sender->getIsEmailVerified()) { | ||||
$failure_reason = pht( | $failure_reason = pht( | ||||
'You have not verified the email address for your account ("%s"). '. | 'You have not verified the email address for your account ("%s"). '. | ||||
'You must verify your email address before you can interact '. | 'You must verify your email address before you can interact over '. | ||||
'with Phabricator over email.', | 'email.', | ||||
$sender->getUsername()); | $sender->getUsername()); | ||||
} | } | ||||
} | } | ||||
if ($failure_reason) { | if ($failure_reason) { | ||||
throw new PhabricatorMetaMTAReceivedMailProcessingException( | throw new PhabricatorMetaMTAReceivedMailProcessingException( | ||||
MetaMTAReceivedMailStatus::STATUS_DISABLED_SENDER, | MetaMTAReceivedMailStatus::STATUS_DISABLED_SENDER, | ||||
$failure_reason); | $failure_reason); | ||||
} | } | ||||
} | } | ||||
} | } |