diff --git a/src/applications/differential/DifferentialReplyHandler.php b/src/applications/differential/DifferentialReplyHandler.php index 49e03155a1..50b2c4099d 100644 --- a/src/applications/differential/DifferentialReplyHandler.php +++ b/src/applications/differential/DifferentialReplyHandler.php @@ -107,10 +107,10 @@ class DifferentialReplyHandler extends PhabricatorMailReplyHandler { protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) { $this->receivedMail = $mail; - $this->handleAction($mail->getCleanTextBody()); + $this->handleAction($mail->getCleanTextBody(), $mail->getAttachments()); } - public function handleAction($body) { + public function handleAction($body, array $attachments) { // all commands start with a bang and separated from the body by a newline // to make sure that actual feedback text couldn't trigger an action. // unrecognized commands will be parsed as part of the comment. @@ -135,6 +135,8 @@ class DifferentialReplyHandler extends PhabricatorMailReplyHandler { return null; } + $body = $this->enhanceBodyWithAttachments($body, $attachments); + try { $editor = new DifferentialCommentEditor( $this->getMailReceiver(), diff --git a/src/applications/maniphest/ManiphestReplyHandler.php b/src/applications/maniphest/ManiphestReplyHandler.php index 423f36e1b4..5eb9ab23f7 100644 --- a/src/applications/maniphest/ManiphestReplyHandler.php +++ b/src/applications/maniphest/ManiphestReplyHandler.php @@ -63,9 +63,9 @@ final class ManiphestReplyHandler extends PhabricatorMailReplyHandler { $body = $mail->getCleanTextBody(); $body = trim($body); + $body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments()); $xactions = array(); - $content_source = PhabricatorContentSource::newForSource( PhabricatorContentSource::SOURCE_EMAIL, array( @@ -76,6 +76,7 @@ final class ManiphestReplyHandler extends PhabricatorMailReplyHandler { $template->setContentSource($content_source); $template->setAuthorPHID($user->getPHID()); + if ($is_new_task) { // If this is a new task, create a "User created this task." transaction // and then set the title and description. @@ -134,21 +135,14 @@ final class ManiphestReplyHandler extends PhabricatorMailReplyHandler { $xactions[] = $xaction; } - // TODO: We should look at CCs on the mail and add them as CCs. - - $files = $mail->getAttachments(); - if ($files) { - $file_xaction = clone $template; - $file_xaction->setTransactionType(ManiphestTransactionType::TYPE_ATTACH); - - $phid_type = PhabricatorPHIDConstants::PHID_TYPE_FILE; - $new = $task->getAttached(); - foreach ($files as $file_phid) { - $new[$phid_type][$file_phid] = array(); - } - - $file_xaction->setNewValue($new); - $xactions[] = $file_xaction; + $ccs = $mail->loadCCPHIDs(); + if ($ccs) { + $old_ccs = $task->getCCPHIDs(); + $new_ccs = array_unique(array_merge($old_ccs, $ccs)); + $cc_xaction = clone $template; + $cc_xaction->setTransactionType(ManiphestTransactionType::TYPE_CCS); + $cc_xaction->setNewValue($new_ccs); + $xactions[] = $cc_xaction; } $event = new PhabricatorEvent( diff --git a/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php b/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php index 02429d9d36..7ea011f1a9 100644 --- a/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php +++ b/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php @@ -72,8 +72,10 @@ abstract class PhabricatorMailReplyHandler { } private function sanityCheckEmail(PhabricatorMetaMTAReceivedMail $mail) { - $body = $mail->getCleanTextBody(); - if (empty($body)) { + $body = $mail->getCleanTextBody(); + $attachments = $mail->getAttachments(); + + if (empty($body) && empty($attachments)) { return 'Empty email body. Email should begin with an !action and / or '. 'text to comment. Inline replies and signatures are ignored.'; } @@ -305,4 +307,26 @@ EOBODY; return $this->getSingleReplyHandlerPrefix($address); } + final protected function enhanceBodyWithAttachments($body, + array $attachments) { + if (!$attachments) { + return $body; + } + + $files = id(new PhabricatorFile()) + ->loadAllWhere('phid in (%Ls)', $attachments); + + // if we have some text then double return before adding our file list + if ($body) { + $body .= "\n\n"; + } + + foreach ($files as $file) { + $file_str = sprintf('- {F%d, layout=link}', $file->getID()); + $body .= $file_str."\n"; + } + + return rtrim($body); + } + } diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php index 2ddd902644..fcd6f60bde 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php @@ -68,6 +68,14 @@ final class PhabricatorMetaMTAReceivedMail extends PhabricatorMetaMTADAO { $this->getCCAddresses() ); + return $this->loadPHIDsFromAddresses($addresses); + } + + final public function loadCCPHIDs() { + return $this->loadPHIDsFromAddresses($this->getCCAddresses()); + } + + private function loadPHIDsFromAddresses(array $addresses) { $users = id(new PhabricatorUserEmail()) ->loadAllWhere('address IN (%Ls)', $addresses); $user_phids = mpull($users, 'getUserPHID');