Allow noncritical blocks in email bodies to be disabled via config

Summary:
See T931. LLVM users would also prefer simpler mail, and have similarly harsh opinions about the current state of affairs.

Allow installs to disable the hint blocks if they don't want them.

Test Plan: Sent myself mail with these settings on/off, got mail with/without the blocks.

Reviewers: btrahan, vrana

Reviewed By: vrana

CC: aran

Maniphest Tasks: T931

Differential Revision: https://secure.phabricator.com/D2968
This commit is contained in:
epriestley
2012-07-16 19:02:06 -07:00
parent 378feb3ffb
commit 02f40fd7ef
5 changed files with 99 additions and 32 deletions

View File

@@ -486,12 +486,9 @@ final class PhabricatorAuditCommentEditor {
$verb = PhabricatorAuditActionConstants::getActionPastTenseVerb(
$comment->getAction());
$body = array();
$body[] = "{$name} {$verb} commit {$cname}.";
if ($comment->getContent()) {
$body[] = $comment->getContent();
}
$body = new PhabricatorMetaMTAMailBody();
$body->addRawSection("{$name} {$verb} commit {$cname}.");
$body->addRawSection($comment->getContent());
if ($inline_comments) {
$block = array();
@@ -518,18 +515,16 @@ final class PhabricatorAuditCommentEditor {
$content = $inline->getContent();
$block[] = "{$path}:{$range} {$content}";
}
$body[] = "INLINE COMMENTS\n ".implode("\n ", $block);
$body->addTextSection(pht('INLINE COMMENTS'), implode("\n", $block));
}
$body[] = "COMMIT\n ".PhabricatorEnv::getProductionURI($handle->getURI());
$body->addTextSection(
pht('COMMIT'),
PhabricatorEnv::getProductionURI($handle->getURI()));
$body->addReplySection($reply_handler->getReplyHandlerInstructions());
$reply_instructions = $reply_handler->getReplyHandlerInstructions();
if ($reply_instructions) {
$body[] = "REPLY HANDLER ACTIONS\n ".$reply_instructions;
}
return implode("\n\n", $body)."\n";
return $body->render();
}
}

View File

@@ -78,12 +78,16 @@ abstract class PhabricatorMailReplyHandler {
assert_instances_of($cc_handles, 'PhabricatorObjectHandle');
$body = '';
if ($to_handles) {
$body .= "To: ".implode(', ', mpull($to_handles, 'getName'))."\n";
}
if ($cc_handles) {
$body .= "Cc: ".implode(', ', mpull($cc_handles, 'getName'))."\n";
if (PhabricatorEnv::getEnvConfig('metamta.recipients.show-hints')) {
if ($to_handles) {
$body .= "To: ".implode(', ', mpull($to_handles, 'getName'))."\n";
}
if ($cc_handles) {
$body .= "Cc: ".implode(', ', mpull($cc_handles, 'getName'))."\n";
}
}
return $body;
}

View File

@@ -72,12 +72,17 @@ final class PhabricatorMetaMTAMailBody {
* @task compose
*/
public function addHeraldSection($rules_uri, $xscript_uri) {
if (!PhabricatorEnv::getEnvConfig('metamta.herald.show-hints')) {
return $this;
}
$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;
}
@@ -90,9 +95,15 @@ final class PhabricatorMetaMTAMailBody {
* @task compose
*/
public function addReplySection($instructions) {
if (strlen($instructions)) {
$this->addTextSection(pht('REPLY HANDLER ACTIONS'), $instructions);
if (!PhabricatorEnv::getEnvConfig('metamta.reply.show-hints')) {
return $this;
}
if (!strlen($instructions)) {
return $this;
}
$this->addTextSection(pht('REPLY HANDLER ACTIONS'), $instructions);
return $this;
}

View File

@@ -21,17 +21,8 @@
*/
final class PhabricatorMetaMTAMailBodyTestCase extends PhabricatorTestCase {
public function testBodyRender() {
$env = PhabricatorEnv::beginScopedEnv();
$env->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 = <<<EOTEXT
salmon
@@ -50,6 +41,58 @@ REPLY HANDLER ACTIONS
EOTEXT;
$this->assertEmail($expect, true, true);
}
public function testBodyRenderNoHerald() {
$expect = <<<EOTEXT
salmon
HEADER
bass
trout
REPLY HANDLER ACTIONS
pike
EOTEXT;
$this->assertEmail($expect, false, true);
}
public function testBodyRenderNoReply() {
$expect = <<<EOTEXT
salmon
HEADER
bass
trout
MANAGE HERALD RULES
http://test.com/rules/
WHY DID I GET THIS EMAIL?
http://test.com/xscript/
EOTEXT;
$this->assertEmail($expect, true, false);
}
private function assertEmail($expect, $herald_hints, $reply_hints) {
$env = PhabricatorEnv::beginScopedEnv();
$env->overrideEnvConfig('phabricator.base-uri', 'http://test.com/');
$env->overrideEnvConfig('metamta.herald.show-hints', $herald_hints);
$env->overrideEnvConfig('metamta.reply.show-hints', $reply_hints);
$body = new PhabricatorMetaMTAMailBody();
$body->addRawSection("salmon");
$body->addTextSection("HEADER", "bass\ntrout\n");
$body->addHeraldSection("/rules/", "/xscript/");
$body->addReplySection("pike");
$this->assertEqual($expect, $body->render());
}