@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make "new task" and "new conpherence" not-so-awful

Summary: Ref T1205. Moves the handling logic for these email types to reply handlers.

Test Plan: Used test form to send conpherence and maniphest mail.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1205

Differential Revision: https://secure.phabricator.com/D5945

+90 -66
+37 -9
src/applications/conpherence/mail/ConpherenceCreateThreadMailReceiver.php
··· 9 9 } 10 10 11 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) { 12 28 $usernames = array(); 13 29 foreach ($mail->getToAddresses() as $to_address) { 14 30 $address = self::stripMailboxPrefix($to_address); 15 31 $usernames[] = id(new PhutilEmailAddress($address))->getLocalPart(); 16 32 } 17 33 18 - $usernames = array_unique($usernames); 34 + return array_unique($usernames); 35 + } 19 36 37 + private function loadMailUsers(PhabricatorMetaMTAReceivedMail $mail) { 38 + $usernames = $this->getMailUsernames($mail); 20 39 if (!$usernames) { 21 - return false; 40 + return array(); 22 41 } 23 42 24 - $users = id(new PhabricatorUser())->loadAllWhere( 43 + return id(new PhabricatorUser())->loadAllWhere( 25 44 'username in (%Ls)', 26 45 $usernames); 46 + } 27 47 28 - if (count($users) != count($usernames)) { 29 - // At least some of the addresses are not users, so don't accept this as 30 - // a new Conpherence thread. 31 - return false; 32 - } 48 + public 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(new ConpherenceThread()) 57 + ->setMailAddedParticipantPHIDs($phids) 58 + ->setActor($sender) 59 + ->setExcludeMailRecipientPHIDs($mail->loadExcludeMailRecipientPHIDs()) 60 + ->processEmail($mail); 33 61 34 - return true; 62 + $mail->setRelatedPHID($conpherence->getPHID()); 35 63 } 36 64 37 65 }
+22
src/applications/maniphest/mail/ManiphestCreateMailReceiver.php
··· 56 56 } 57 57 } 58 58 59 + public function processReceivedMail( 60 + PhabricatorMetaMTAReceivedMail $mail, 61 + PhabricatorUser $sender) { 62 + 63 + $task = new ManiphestTask(); 64 + 65 + $task->setAuthorPHID($sender->getPHID()); 66 + $task->setOriginalEmailSource($mail->getHeader('From')); 67 + $task->setPriority(ManiphestTaskPriority::PRIORITY_TRIAGE); 68 + 69 + $editor = new ManiphestTransactionEditor(); 70 + $editor->setActor($sender); 71 + $handler = $editor->buildReplyHandler($task); 72 + 73 + $handler->setActor($sender); 74 + $handler->setExcludeMailRecipientPHIDs( 75 + $mail->loadExcludeMailRecipientPHIDs()); 76 + $handler->processEmail($mail); 77 + 78 + $mail->setRelatedPHID($task->getPHID()); 79 + } 80 + 59 81 }
+12 -1
src/applications/metamta/receiver/PhabricatorMailReceiver.php
··· 2 2 3 3 abstract class PhabricatorMailReceiver { 4 4 5 - 6 5 abstract public function isEnabled(); 7 6 abstract public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail); 7 + 8 + public function processReceivedMail( 9 + PhabricatorMetaMTAReceivedMail $mail, 10 + PhabricatorUser $sender) { 11 + return; 12 + } 13 + 14 + final public function receiveMail( 15 + PhabricatorMetaMTAReceivedMail $mail, 16 + PhabricatorUser $sender) { 17 + $this->processReceivedMail($mail, $sender); 18 + } 8 19 9 20 public function validateSender( 10 21 PhabricatorMetaMTAReceivedMail $mail,
+19 -56
src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php
··· 61 61 return $this->getRawEmailAddresses(idx($this->headers, 'to')); 62 62 } 63 63 64 - private function loadExcludeMailRecipientPHIDs() { 64 + public function loadExcludeMailRecipientPHIDs() { 65 65 $addresses = array_merge( 66 66 $this->getToAddresses(), 67 67 $this->getCCAddresses()); ··· 115 115 $receiver_name = null; 116 116 $user_id = null; 117 117 $hash = null; 118 - $user_phids = array(); 119 118 $user_names = array(); 120 119 foreach ($this->getToAddresses() as $address) { 121 120 if ($address == $create_task) { ··· 150 149 } 151 150 } 152 151 153 - // since we haven't found a phabricator address, maybe this is 154 - // someone trying to create a conpherence? 155 - if (!$phabricator_address && $user_names) { 156 - $users = id(new PhabricatorUser()) 157 - ->loadAllWhere('userName IN (%Ls)', $user_names); 158 - $user_phids = mpull($users, 'getPHID'); 159 - } 160 - 161 152 return array( 162 153 $phabricator_address, 163 154 $receiver_name, 164 155 $user_id, 165 156 $hash, 166 - $user_phids 167 157 ); 168 158 } 169 159 ··· 178 168 $sender = $receiver->loadSender($this); 179 169 $receiver->validateSender($this, $sender); 180 170 171 + $this->setAuthorPHID($sender->getPHID()); 172 + 173 + // TODO: Once everything can receive mail, nuke this. 174 + $can_receive = false; 175 + if ($receiver instanceof ManiphestCreateMailReceiver) { 176 + $can_receive = true; 177 + } 178 + if ($receiver instanceof ConpherenceCreateThreadMailReceiver) { 179 + $can_receive = true; 180 + } 181 + 182 + if ($can_receive) { 183 + $receiver->receiveMail($this, $sender); 184 + return $this->setMessage('OK')->save(); 185 + } 186 + 181 187 } catch (PhabricatorMetaMTAReceivedMailProcessingException $ex) { 182 188 $this 183 189 ->setStatus($ex->getStatusCode()) ··· 189 195 list($to, 190 196 $receiver_name, 191 197 $user_id, 192 - $hash, 193 - $user_phids) = $this->getPhabricatorToInformation(); 194 - if (!$to && !$user_phids) { 198 + $hash) = $this->getPhabricatorToInformation(); 199 + if (!$to) { 195 200 $raw_to = idx($this->headers, 'to'); 196 201 return $this->setMessage("Unrecognized 'to' format: {$raw_to}")->save(); 197 202 } 198 203 199 204 $from = idx($this->headers, 'from'); 200 205 201 - // TODO: Move this into `ManiphestCreateMailReceiver`. 202 - if ($receiver instanceof ManiphestCreateMailReceiver) { 203 - $receiver = new ManiphestTask(); 204 - 205 - $user = $sender; 206 - 207 - $receiver->setAuthorPHID($user->getPHID()); 208 - $receiver->setOriginalEmailSource($from); 209 - $receiver->setPriority(ManiphestTaskPriority::PRIORITY_TRIAGE); 210 - 211 - $editor = new ManiphestTransactionEditor(); 212 - $editor->setActor($user); 213 - $handler = $editor->buildReplyHandler($receiver); 214 - 215 - $handler->setActor($user); 216 - $handler->setExcludeMailRecipientPHIDs( 217 - $this->loadExcludeMailRecipientPHIDs()); 218 - $handler->processEmail($this); 219 - 220 - $this->setRelatedPHID($receiver->getPHID()); 221 - $this->setMessage('OK'); 222 - 223 - return $this->save(); 224 - } 225 - 226 - // means we're creating a conpherence...! 227 - if ($user_phids) { 228 - $user = $sender; 229 - 230 - $conpherence = id(new ConpherenceReplyHandler()) 231 - ->setMailReceiver(new ConpherenceThread()) 232 - ->setMailAddedParticipantPHIDs($user_phids) 233 - ->setActor($user) 234 - ->setExcludeMailRecipientPHIDs($this->loadExcludeMailRecipientPHIDs()) 235 - ->processEmail($this); 236 - 237 - $this->setRelatedPHID($conpherence->getPHID()); 238 - $this->setMessage('OK'); 239 - return $this->save(); 240 - } 241 - 242 206 $user = $sender; 243 - $this->setAuthorPHID($user->getPHID()); 244 207 245 208 $receiver = self::loadReceiverObject($receiver_name); 246 209 if (!$receiver) {