diff --git a/scripts/mail/mail_handler.php b/scripts/mail/mail_handler.php index 001a03491b..6136ef6859 100755 --- a/scripts/mail/mail_handler.php +++ b/scripts/mail/mail_handler.php @@ -1,58 +1,58 @@ #!/usr/bin/php 1) { $_SERVER['PHABRICATOR_ENV'] = $argv[1]; } $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; require_once $root.'/scripts/__init_env__.php'; require_once $root.'/externals/mimemailparser/MimeMailParser.class.php'; phutil_require_module( 'phabricator', 'applications/metamta/storage/receivedmail'); phutil_require_module( 'phabricator', 'applications/files/storage/file'); $parser = new MimeMailParser(); $parser->setText(file_get_contents('php://stdin')); $received = new PhabricatorMetaMTAReceivedMail(); $received->setHeaders($parser->getHeaders()); $received->setBodies(array( 'text' => $parser->getMessageBody('text'), 'html' => $parser->getMessageBody('html'), )); $attachments = array(); -foreach ($received->getAttachments() as $attachment) { +foreach ($parser->getAttachments() as $attachment) { $file = PhabricatorFile::newFromFileData( $attachment->getContent(), array( 'name' => $attachment->getFilename(), )); $attachments[] = $file->getPHID(); } $received->setAttachments($attachments); $received->save(); $received->processReceivedMail(); diff --git a/src/applications/maniphest/replyhandler/ManiphestReplyHandler.php b/src/applications/maniphest/replyhandler/ManiphestReplyHandler.php index d7d541c4f8..004b971c5a 100644 --- a/src/applications/maniphest/replyhandler/ManiphestReplyHandler.php +++ b/src/applications/maniphest/replyhandler/ManiphestReplyHandler.php @@ -1,101 +1,121 @@ getDefaultPrivateReplyHandlerEmailAddress($handle, 'T'); } public function getReplyHandlerDomain() { return PhabricatorEnv::getEnvConfig( 'metamta.maniphest.reply-handler-domain'); } public function getReplyHandlerInstructions() { if ($this->supportsReplies()) { return "Reply to comment or attach files, or !close, !claim, or ". "!unsubscribe."; } else { return null; } } public function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) { $task = $this->getMailReceiver(); $user = $this->getActor(); $body = $mail->getCleanTextBody(); $body = trim($body); $lines = explode("\n", trim($body)); $first_line = head($lines); $command = null; $matches = null; if (preg_match('/^!(\w+)/', $first_line, $matches)) { $lines = array_slice($lines, 1); $body = implode("\n", $lines); $body = trim($body); $command = $matches[1]; } + $xactions = array(); + + $files = $mail->getAttachments(); + if ($files) { + $file_xaction = new ManiphestTransaction(); + $file_xaction->setAuthorPHID($user->getPHID()); + $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; + } + $ttype = ManiphestTransactionType::TYPE_NONE; $new_value = null; switch ($command) { case 'close': $ttype = ManiphestTransactionType::TYPE_STATUS; $new_value = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED; break; case 'claim': $ttype = ManiphestTransactionType::TYPE_OWNER; $new_value = $user->getPHID(); break; case 'unsubscribe': $ttype = ManiphestTransactionType::TYPE_CCS; $ccs = $task->getCCPHIDs(); foreach ($ccs as $k => $phid) { if ($phid == $user->getPHID()) { unset($ccs[$k]); } } $new_value = array_values($ccs); break; } $xaction = new ManiphestTransaction(); $xaction->setAuthorPHID($user->getPHID()); $xaction->setTransactionType($ttype); $xaction->setNewValue($new_value); $xaction->setComments($body); + $xactions[] = $xaction; + $editor = new ManiphestTransactionEditor(); - $editor->applyTransactions($task, array($xaction)); + $editor->applyTransactions($task, $xactions); } } diff --git a/src/applications/maniphest/replyhandler/__init__.php b/src/applications/maniphest/replyhandler/__init__.php index 73f2b10c1e..376777c40f 100644 --- a/src/applications/maniphest/replyhandler/__init__.php +++ b/src/applications/maniphest/replyhandler/__init__.php @@ -1,19 +1,20 @@