diff --git a/.divinerconfig b/.divinerconfig index ef6c805d91..8757fdb13b 100644 --- a/.divinerconfig +++ b/.divinerconfig @@ -23,7 +23,8 @@ "search" : "Search", "daemon" : "Daemons, Tasks and Workers", "irc" : "IRC", - "markup" : "Remarkup Extensions" + "markup" : "Remarkup Extensions", + "metamta" : "MetaMTA (Mail)" }, "engines" : [ ["DivinerArticleEngine", {}], diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e398a3c9c5..5f5de293ac 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -751,6 +751,8 @@ phutil_register_library_map(array( 'PhabricatorMetaMTAEmailBodyParserTestCase' => 'applications/metamta/__tests__/PhabricatorMetaMTAEmailBodyParserTestCase.php', 'PhabricatorMetaMTAListController' => 'applications/metamta/controller/PhabricatorMetaMTAListController.php', 'PhabricatorMetaMTAMail' => 'applications/metamta/storage/PhabricatorMetaMTAMail.php', + 'PhabricatorMetaMTAMailBody' => 'applications/metamta/view/PhabricatorMetaMTAMailBody.php', + 'PhabricatorMetaMTAMailBodyTestCase' => 'applications/metamta/view/__tests__/PhabricatorMetaMTAMailBodyTestCase.php', 'PhabricatorMetaMTAMailTestCase' => 'applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php', 'PhabricatorMetaMTAMailingList' => 'applications/metamta/storage/PhabricatorMetaMTAMailingList.php', 'PhabricatorMetaMTAMailingListEditController' => 'applications/metamta/controller/PhabricatorMetaMTAMailingListEditController.php', @@ -1763,6 +1765,7 @@ phutil_register_library_map(array( 'PhabricatorMetaMTAEmailBodyParserTestCase' => 'PhabricatorTestCase', 'PhabricatorMetaMTAListController' => 'PhabricatorMetaMTAController', 'PhabricatorMetaMTAMail' => 'PhabricatorMetaMTADAO', + 'PhabricatorMetaMTAMailBodyTestCase' => 'PhabricatorTestCase', 'PhabricatorMetaMTAMailTestCase' => 'PhabricatorTestCase', 'PhabricatorMetaMTAMailingList' => 'PhabricatorMetaMTADAO', 'PhabricatorMetaMTAMailingListEditController' => 'PhabricatorMetaMTAController', diff --git a/src/applications/differential/editor/DifferentialRevisionEditor.php b/src/applications/differential/editor/DifferentialRevisionEditor.php index eab033a6c4..62c1c3b64e 100644 --- a/src/applications/differential/editor/DifferentialRevisionEditor.php +++ b/src/applications/differential/editor/DifferentialRevisionEditor.php @@ -251,8 +251,7 @@ final class DifferentialRevisionEditor { $adapter->setForbiddenCCs($revision->getUnsubscribedPHIDs()); $xscript = HeraldEngine::loadAndApplyRules($adapter); - $xscript_uri = PhabricatorEnv::getProductionURI( - '/herald/transcript/'.$xscript->getID().'/'); + $xscript_uri = '/herald/transcript/'.$xscript->getID().'/'; $xscript_phid = $xscript->getPHID(); $xscript_header = $xscript->getXHeraldRulesHeader(); diff --git a/src/applications/differential/mail/DifferentialMail.php b/src/applications/differential/mail/DifferentialMail.php index 1820ec1a89..f232186222 100644 --- a/src/applications/differential/mail/DifferentialMail.php +++ b/src/applications/differential/mail/DifferentialMail.php @@ -260,34 +260,21 @@ abstract class DifferentialMail { } protected function buildBody() { + $main_body = $this->renderBody(); - $body = $this->renderBody(); + $body = new PhabricatorMetaMTAMailBody(); + $body->addRawSection($main_body); $reply_handler = $this->getReplyHandler(); - $reply_instructions = $reply_handler->getReplyHandlerInstructions(); - if ($reply_instructions) { - $body .= - "\nREPLY HANDLER ACTIONS\n". - " {$reply_instructions}\n"; - } + $body->addReplySection($reply_handler->getReplyHandlerInstructions()); if ($this->getHeraldTranscriptURI() && $this->isFirstMailToRecipients()) { - $manage_uri = PhabricatorEnv::getProductionURI( - '/herald/view/differential/'); - + $manage_uri = '/herald/view/differential/'; $xscript_uri = $this->getHeraldTranscriptURI(); - $body .= <<addHeraldSection($manage_uri, $xscript_uri); } - return $body; + return $body->render(); } /** diff --git a/src/applications/maniphest/editor/ManiphestTransactionEditor.php b/src/applications/maniphest/editor/ManiphestTransactionEditor.php index 55a7f714c6..8ced7f62c3 100644 --- a/src/applications/maniphest/editor/ManiphestTransactionEditor.php +++ b/src/applications/maniphest/editor/ManiphestTransactionEditor.php @@ -245,7 +245,7 @@ final class ManiphestTransactionEditor { $view->setTransactionGroup($transactions); $view->setHandles($handles); $view->setAuxiliaryFields($this->auxiliaryFields); - list($action, $body) = $view->renderForEmail($with_date = false); + list($action, $main_body) = $view->renderForEmail($with_date = false); $is_create = $this->isCreate($transactions); @@ -253,25 +253,13 @@ final class ManiphestTransactionEditor { $reply_handler = $this->buildReplyHandler($task); + $body = new PhabricatorMetaMTAMailBody(); + $body->addRawSection($main_body); if ($is_create) { - $body .= - "\n\n". - "TASK DESCRIPTION\n". - " ".$task->getDescription(); - } - - $body .= - "\n\n". - "TASK DETAIL\n". - " ".$task_uri."\n"; - - $reply_instructions = $reply_handler->getReplyHandlerInstructions(); - if ($reply_instructions) { - $body .= - "\n". - "REPLY HANDLER ACTIONS\n". - " ".$reply_instructions."\n"; + $body->addTextSection(pht('TASK DESCRIPTION'), $task->getDescription()); } + $body->addTextSection(pht('TASK DETAIL'), $task_uri); + $body->addReplySection($reply_handler->getReplyHandlerInstructions()); $thread_id = 'maniphest-task-'.$task->getPHID(); $task_id = $task->getID(); @@ -290,7 +278,7 @@ final class ManiphestTransactionEditor { ->setRelatedPHID($task->getPHID()) ->setIsBulk(true) ->setMailTags($mailtags) - ->setBody($body); + ->setBody($body->render()); $mails = $reply_handler->multiplexMail( $template, diff --git a/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php b/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php new file mode 100644 index 0000000000..3bf292670f --- /dev/null +++ b/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php @@ -0,0 +1,125 @@ +sections[] = rtrim($text); + } + return $this; + } + + + /** + * Add a block of text with a section header. This is rendered like this: + * + * HEADER + * Text is indented. + * + * @param string Header text. + * @param string Section text. + * @return this + * @task compose + */ + public function addTextSection($header, $text) { + $this->sections[] = $header."\n".$this->indent($text); + return $this; + } + + + /** + * Add a Herald section with a rule management URI and a transcript URI. + * + * @param string URI to rule management. + * @param string URI to rule transcripts. + * @return this + * @task compose + */ + public function addHeraldSection($rules_uri, $xscript_uri) { + $this->addTextSection( + pht('MANAGE HERALD RULES'), + PhabricatorEnv::getProductionURI($rules_uri)); + $this->addTextSection( + pht('WHY DID I GET THIS EMAIL?'), + PhabricatorEnv::getProductionURI($xscript_uri)); + return $this; + } + + + /** + * Add a section with reply handler instructions. + * + * @param string Reply handler instructions. + * @return this + * @task compose + */ + public function addReplySection($instructions) { + if (strlen($instructions)) { + $this->addTextSection(pht('REPLY HANDLER ACTIONS'), $instructions); + } + return $this; + } + + +/* -( Rendering )---------------------------------------------------------- */ + + + /** + * Render the email body. + * + * @return string Rendered body. + * @task render + */ + public function render() { + return implode("\n\n", $this->sections)."\n"; + } + + + /** + * Indent a block of text for rendering under a section heading. + * + * @param string Text to indent. + * @return string Indented text. + * @task render + */ + private function indent($text) { + return rtrim(" ".str_replace("\n", "\n ", $text)); + } + +} diff --git a/src/applications/metamta/view/__tests__/PhabricatorMetaMTAMailBodyTestCase.php b/src/applications/metamta/view/__tests__/PhabricatorMetaMTAMailBodyTestCase.php new file mode 100644 index 0000000000..abbb2dbe93 --- /dev/null +++ b/src/applications/metamta/view/__tests__/PhabricatorMetaMTAMailBodyTestCase.php @@ -0,0 +1,57 @@ +overrideEnvConfig('phabricator.base-uri', 'http://test.com/'); + + $body = new PhabricatorMetaMTAMailBody(); + $body->addRawSection("salmon"); + $body->addTextSection("HEADER", "bass\ntrout\n"); + $body->addHeraldSection("/rules/", "/xscript/"); + $body->addReplySection("pike"); + + $expect = <<assertEqual($expect, $body->render()); + } + + +} diff --git a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php index c58032c3f2..b73bab67e8 100644 --- a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php +++ b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php @@ -111,49 +111,29 @@ final class PhabricatorRepositoryCommitHeraldWorker $files = $adapter->loadAffectedPaths(); sort($files); - $files = implode("\n ", $files); + $files = implode("\n", $files); $xscript_id = $xscript->getID(); - $manage_uri = PhabricatorEnv::getProductionURI('/herald/view/commits/'); - $why_uri = PhabricatorEnv::getProductionURI( - '/herald/transcript/'.$xscript_id.'/'); + $manage_uri = '/herald/view/commits/'; + $why_uri = '/herald/transcript/'.$xscript_id.'/'; $reply_handler = PhabricatorAuditCommentEditor::newReplyHandlerForCommit( $commit); - $reply_instructions = $reply_handler->getReplyHandlerInstructions(); - if ($reply_instructions) { - $reply_instructions = - "\n". - "REPLY HANDLER ACTIONS\n". - " ".$reply_instructions."\n"; - } - $template = new PhabricatorMetaMTAMail(); $inline_patch_text = $this->buildPatch($template, $repository, $commit); - $body = <<addRawSection($description); + $body->addTextSection(pht('DETAILS'), $commit_uri); + $body->addTextSection(pht('DIFFERENTIAL REVISION'), $differential); + $body->addTextSection(pht('AFFECTED FILES'), $files); + $body->addReplySection($reply_handler->getReplyHandlerInstructions()); + $body->addHeraldSection($manage_uri, $why_uri); + $body->addRawSection($inline_patch_text); + $body = $body->render(); $prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix'); @@ -369,7 +349,7 @@ EOBODY; } if ($result) { - $result = "\nPATCH\n\n{$result}\n"; + $result = "PATCH\n\n{$result}\n"; } return $result;