1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-09 06:11:01 +01:00

Fix some issues with Maniphest inbound email

Summary:
Fixes T3181.

  - Inbound `bugs@` mail is broken right now if it doesn't use the new external user stuff, because it calls `$user->getPhabricatorUser()` on an object which is already a `PhabricatorUser`. Instead, build the right `$user` object from the external user earlier on.
  - Maniphest mail is nuking or otherwise awkwardly altering CCs. Make this work properly.
  - Make sure "!unsubscribe" works correctly.

Test Plan: Sent `bugs@` mail. Sent CC mail. Sent "!unsubscribe" mail.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran, tido

Maniphest Tasks: T3181

Differential Revision: https://secure.phabricator.com/D5911
This commit is contained in:
epriestley 2013-05-13 08:10:02 -07:00
parent 9c87ba8b09
commit 9e6da42206
2 changed files with 23 additions and 17 deletions

View file

@ -60,7 +60,7 @@ final class ManiphestReplyHandler extends PhabricatorMailReplyHandler {
$template->setContentSource($content_source); $template->setContentSource($content_source);
$template->setAuthorPHID($user->getPHID()); $template->setAuthorPHID($user->getPHID());
$is_unsub = false;
if ($is_new_task) { if ($is_new_task) {
// If this is a new task, create a "User created this task." transaction // If this is a new task, create a "User created this task." transaction
// and then set the title and description. // and then set the title and description.
@ -100,6 +100,7 @@ final class ManiphestReplyHandler extends PhabricatorMailReplyHandler {
$new_value = $user->getPHID(); $new_value = $user->getPHID();
break; break;
case 'unsubscribe': case 'unsubscribe':
$is_unsub = true;
$ttype = ManiphestTransactionType::TYPE_CCS; $ttype = ManiphestTransactionType::TYPE_CCS;
$ccs = $task->getCCPHIDs(); $ccs = $task->getCCPHIDs();
foreach ($ccs as $k => $phid) { foreach ($ccs as $k => $phid) {
@ -119,11 +120,15 @@ final class ManiphestReplyHandler extends PhabricatorMailReplyHandler {
$xactions[] = $xaction; $xactions[] = $xaction;
} }
$task->setCCPHIDs(array($user->getPHID()));
$ccs = $mail->loadCCPHIDs(); $ccs = $mail->loadCCPHIDs();
if ($ccs) { $old_ccs = $task->getCCPHIDs();
$old_ccs = $task->getCCPHIDs(); $new_ccs = array_merge($old_ccs, $ccs);
$new_ccs = array_unique(array_merge($old_ccs, $ccs)); if (!$is_unsub) {
$new_ccs[] = $user->getPHID();
}
$new_ccs = array_unique($new_ccs);
if (array_diff($new_ccs, $old_ccs)) {
$cc_xaction = clone $template; $cc_xaction = clone $template;
$cc_xaction->setTransactionType(ManiphestTransactionType::TYPE_CCS); $cc_xaction->setTransactionType(ManiphestTransactionType::TYPE_CCS);
$cc_xaction->setNewValue($new_ccs); $cc_xaction->setNewValue($new_ccs);

View file

@ -217,19 +217,20 @@ final class PhabricatorMetaMTAReceivedMail extends PhabricatorMetaMTADAO {
if ($allow_email_users) { if ($allow_email_users) {
$email = new PhutilEmailAddress($from); $email = new PhutilEmailAddress($from);
$user = id(new PhabricatorExternalAccount())->loadOneWhere( $xuser = id(new PhabricatorExternalAccount())->loadOneWhere(
'accountType = %s AND accountDomain IS NULL and accountID = %s', 'accountType = %s AND accountDomain IS NULL and accountID = %s',
'email', $email->getAddress()); 'email',
$email->getAddress());
if (!$user) {
$user = new PhabricatorExternalAccount();
$user->setAccountID($email->getAddress());
$user->setAccountType('email');
$user->setDisplayName($email->getDisplayName());
$user->save();
if (!$xuser) {
$xuser = new PhabricatorExternalAccount();
$xuser->setAccountID($email->getAddress());
$xuser->setAccountType('email');
$xuser->setDisplayName($email->getDisplayName());
$xuser->save();
} }
$user = $xuser->getPhabricatorUser();
} else { } else {
$default_author = PhabricatorEnv::getEnvConfig( $default_author = PhabricatorEnv::getEnvConfig(
'metamta.maniphest.default-public-author'); 'metamta.maniphest.default-public-author');
@ -260,12 +261,12 @@ final class PhabricatorMetaMTAReceivedMail extends PhabricatorMetaMTADAO {
$receiver->setPriority(ManiphestTaskPriority::PRIORITY_TRIAGE); $receiver->setPriority(ManiphestTaskPriority::PRIORITY_TRIAGE);
$editor = new ManiphestTransactionEditor(); $editor = new ManiphestTransactionEditor();
$editor->setActor($user->getPhabricatorUser()); $editor->setActor($user);
$handler = $editor->buildReplyHandler($receiver); $handler = $editor->buildReplyHandler($receiver);
$handler->setActor($user->getPhabricatorUser()); $handler->setActor($user);
$handler->setExcludeMailRecipientPHIDs( $handler->setExcludeMailRecipientPHIDs(
$this->loadExcludeMailRecipientPHIDs()); $this->loadExcludeMailRecipientPHIDs());
$handler->processEmail($this); $handler->processEmail($this);
$this->setRelatedPHID($receiver->getPHID()); $this->setRelatedPHID($receiver->getPHID());