@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.

robustify Differential and Maniphest mailhandlers wrt attachments

Summary:
a few things

- make the parent mailhandler class not send "blank body" error if you have attachments
- make both differential and maniphest append a list of attachments to the body if any exist
- BONUS - made the cc stuff work in Maniphest

Test Plan: I haven't actually tested this yet. :( i need to figure out how to send a mail with an attachment from the command-line and figured I'd serve this up first.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2012

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

+48 -20
+4 -2
src/applications/differential/DifferentialReplyHandler.php
··· 107 107 108 108 protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) { 109 109 $this->receivedMail = $mail; 110 - $this->handleAction($mail->getCleanTextBody()); 110 + $this->handleAction($mail->getCleanTextBody(), $mail->getAttachments()); 111 111 } 112 112 113 - public function handleAction($body) { 113 + public function handleAction($body, array $attachments) { 114 114 // all commands start with a bang and separated from the body by a newline 115 115 // to make sure that actual feedback text couldn't trigger an action. 116 116 // unrecognized commands will be parsed as part of the comment. ··· 134 134 // TODO: Send the user a confirmation email? 135 135 return null; 136 136 } 137 + 138 + $body = $this->enhanceBodyWithAttachments($body, $attachments); 137 139 138 140 try { 139 141 $editor = new DifferentialCommentEditor(
+10 -16
src/applications/maniphest/ManiphestReplyHandler.php
··· 63 63 64 64 $body = $mail->getCleanTextBody(); 65 65 $body = trim($body); 66 + $body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments()); 66 67 67 68 $xactions = array(); 68 - 69 69 $content_source = PhabricatorContentSource::newForSource( 70 70 PhabricatorContentSource::SOURCE_EMAIL, 71 71 array( ··· 75 75 $template = new ManiphestTransaction(); 76 76 $template->setContentSource($content_source); 77 77 $template->setAuthorPHID($user->getPHID()); 78 + 78 79 79 80 if ($is_new_task) { 80 81 // If this is a new task, create a "User created this task." transaction ··· 134 135 $xactions[] = $xaction; 135 136 } 136 137 137 - // TODO: We should look at CCs on the mail and add them as CCs. 138 - 139 - $files = $mail->getAttachments(); 140 - if ($files) { 141 - $file_xaction = clone $template; 142 - $file_xaction->setTransactionType(ManiphestTransactionType::TYPE_ATTACH); 143 - 144 - $phid_type = PhabricatorPHIDConstants::PHID_TYPE_FILE; 145 - $new = $task->getAttached(); 146 - foreach ($files as $file_phid) { 147 - $new[$phid_type][$file_phid] = array(); 148 - } 149 - 150 - $file_xaction->setNewValue($new); 151 - $xactions[] = $file_xaction; 138 + $ccs = $mail->loadCCPHIDs(); 139 + if ($ccs) { 140 + $old_ccs = $task->getCCPHIDs(); 141 + $new_ccs = array_unique(array_merge($old_ccs, $ccs)); 142 + $cc_xaction = clone $template; 143 + $cc_xaction->setTransactionType(ManiphestTransactionType::TYPE_CCS); 144 + $cc_xaction->setNewValue($new_ccs); 145 + $xactions[] = $cc_xaction; 152 146 } 153 147 154 148 $event = new PhabricatorEvent(
+26 -2
src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php
··· 72 72 } 73 73 74 74 private function sanityCheckEmail(PhabricatorMetaMTAReceivedMail $mail) { 75 - $body = $mail->getCleanTextBody(); 76 - if (empty($body)) { 75 + $body = $mail->getCleanTextBody(); 76 + $attachments = $mail->getAttachments(); 77 + 78 + if (empty($body) && empty($attachments)) { 77 79 return 'Empty email body. Email should begin with an !action and / or '. 78 80 'text to comment. Inline replies and signatures are ignored.'; 79 81 } ··· 303 305 304 306 $address = "{$prefix}{$receiver_id}+{$user_id}+{$hash}@{$domain}"; 305 307 return $this->getSingleReplyHandlerPrefix($address); 308 + } 309 + 310 + final protected function enhanceBodyWithAttachments($body, 311 + array $attachments) { 312 + if (!$attachments) { 313 + return $body; 314 + } 315 + 316 + $files = id(new PhabricatorFile()) 317 + ->loadAllWhere('phid in (%Ls)', $attachments); 318 + 319 + // if we have some text then double return before adding our file list 320 + if ($body) { 321 + $body .= "\n\n"; 322 + } 323 + 324 + foreach ($files as $file) { 325 + $file_str = sprintf('- {F%d, layout=link}', $file->getID()); 326 + $body .= $file_str."\n"; 327 + } 328 + 329 + return rtrim($body); 306 330 } 307 331 308 332 }
+8
src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php
··· 68 68 $this->getCCAddresses() 69 69 ); 70 70 71 + return $this->loadPHIDsFromAddresses($addresses); 72 + } 73 + 74 + final public function loadCCPHIDs() { 75 + return $this->loadPHIDsFromAddresses($this->getCCAddresses()); 76 + } 77 + 78 + private function loadPHIDsFromAddresses(array $addresses) { 71 79 $users = id(new PhabricatorUserEmail()) 72 80 ->loadAllWhere('address IN (%Ls)', $addresses); 73 81 $user_phids = mpull($users, 'getUserPHID');