diff --git a/src/applications/audit/editor/PhabricatorAuditCommentEditor.php b/src/applications/audit/editor/PhabricatorAuditCommentEditor.php index 1771507857..4b06aa03be 100644 --- a/src/applications/audit/editor/PhabricatorAuditCommentEditor.php +++ b/src/applications/audit/editor/PhabricatorAuditCommentEditor.php @@ -394,8 +394,6 @@ final class PhabricatorAuditCommentEditor { $reply_handler = self::newReplyHandlerForCommit($commit); $prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix'); - $subject = "{$prefix} {$name}: {$summary}"; - $vary_subject = "{$prefix} [{$verb}] {$name}: {$summary}"; $threading = self::getMailThreading($commit->getPHID()); list($thread_id, $thread_topic) = $threading; @@ -434,8 +432,9 @@ final class PhabricatorAuditCommentEditor { $is_new = false; $template = id(new PhabricatorMetaMTAMail()) - ->setSubject($subject) - ->setVarySubject($subject) + ->setSubject("{$name}: {$summary}") + ->setSubjectPrefix($prefix) + ->setVarySubjectPrefix("[{$verb}]") ->setFrom($comment->getActorPHID()) ->setThreadID($thread_id, $is_new) ->addHeader('Thread-Topic', $thread_topic) diff --git a/src/applications/differential/mail/DifferentialCCWelcomeMail.php b/src/applications/differential/mail/DifferentialCCWelcomeMail.php index 004822177a..33a58f0124 100644 --- a/src/applications/differential/mail/DifferentialCCWelcomeMail.php +++ b/src/applications/differential/mail/DifferentialCCWelcomeMail.php @@ -18,8 +18,8 @@ final class DifferentialCCWelcomeMail extends DifferentialReviewRequestMail { - protected function renderVarySubject() { - return '[Added to CC] '.$this->renderSubject(); + protected function renderVaryPrefix() { + return '[Added to CC]'; } protected function renderBody() { diff --git a/src/applications/differential/mail/DifferentialCommentMail.php b/src/applications/differential/mail/DifferentialCommentMail.php index d5821617d0..b8d32b93ab 100644 --- a/src/applications/differential/mail/DifferentialCommentMail.php +++ b/src/applications/differential/mail/DifferentialCommentMail.php @@ -75,9 +75,9 @@ final class DifferentialCommentMail extends DifferentialMail { return $tags; } - protected function renderVarySubject() { + protected function renderVaryPrefix() { $verb = ucwords($this->getVerb()); - return "[{$verb}] ".$this->renderSubject(); + return "[{$verb}]"; } protected function getVerb() { diff --git a/src/applications/differential/mail/DifferentialDiffContentMail.php b/src/applications/differential/mail/DifferentialDiffContentMail.php index 110c98117c..37b079c342 100644 --- a/src/applications/differential/mail/DifferentialDiffContentMail.php +++ b/src/applications/differential/mail/DifferentialDiffContentMail.php @@ -25,8 +25,8 @@ final class DifferentialDiffContentMail extends DifferentialMail { $this->content = $content; } - protected function renderVarySubject() { - return '[Content] '.$this->renderSubject(); + protected function renderVaryPrefix() { + return '[Content]'; } protected function renderBody() { diff --git a/src/applications/differential/mail/DifferentialExceptionMail.php b/src/applications/differential/mail/DifferentialExceptionMail.php index ef11cf9e6b..d168302054 100644 --- a/src/applications/differential/mail/DifferentialExceptionMail.php +++ b/src/applications/differential/mail/DifferentialExceptionMail.php @@ -33,11 +33,11 @@ final class DifferentialExceptionMail extends DifferentialMail { } protected function renderSubject() { - return "Exception: unable to process your mail request."; + return "Exception: unable to process your mail request"; } - protected function renderVarySubject() { - return $this->renderSubject(); + protected function renderVaryPrefix() { + return ''; } protected function buildBody() { diff --git a/src/applications/differential/mail/DifferentialMail.php b/src/applications/differential/mail/DifferentialMail.php index fae1cda58c..2f539caf50 100644 --- a/src/applications/differential/mail/DifferentialMail.php +++ b/src/applications/differential/mail/DifferentialMail.php @@ -41,7 +41,7 @@ abstract class DifferentialMail { return "D{$id}: {$title}"; } - abstract protected function renderVarySubject(); + abstract protected function renderVaryPrefix(); abstract protected function renderBody(); public function setActorHandle($actor_handle) { @@ -78,8 +78,6 @@ abstract class DifferentialMail { } $cc_phids = $this->getCCPHIDs(); - $subject = $this->buildSubject(); - $vary_subject = $this->buildVarySubject(); $body = $this->buildBody(); $attachments = $this->buildAttachments(); @@ -92,8 +90,9 @@ abstract class DifferentialMail { } $template - ->setSubject($subject) - ->setVarySubject($vary_subject) + ->setSubject($this->renderSubject()) + ->setSubjectPrefix($this->getSubjectPrefix()) + ->setVarySubjectPrefix($this->renderVaryPrefix()) ->setBody($body) ->setIsHTML($this->shouldMarkMailAsHTML()) ->setParentMessageID($this->parentMessageID) @@ -202,14 +201,6 @@ abstract class DifferentialMail { return PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix'); } - protected function buildSubject() { - return trim($this->getSubjectPrefix().' '.$this->renderSubject()); - } - - protected function buildVarySubject() { - return trim($this->getSubjectPrefix().' '.$this->renderVarySubject()); - } - protected function shouldMarkMailAsHTML() { return false; } diff --git a/src/applications/differential/mail/DifferentialNewDiffMail.php b/src/applications/differential/mail/DifferentialNewDiffMail.php index 06cd6e45b8..3b95f4ee13 100644 --- a/src/applications/differential/mail/DifferentialNewDiffMail.php +++ b/src/applications/differential/mail/DifferentialNewDiffMail.php @@ -18,7 +18,7 @@ final class DifferentialNewDiffMail extends DifferentialReviewRequestMail { - protected function renderVarySubject() { + protected function renderVaryPrefix() { $revision = $this->getRevision(); $line_count = $revision->getLineCount(); $lines = ($line_count == 1 ? "1 line" : "{$line_count} lines"); @@ -29,7 +29,7 @@ final class DifferentialNewDiffMail extends DifferentialReviewRequestMail { $verb = 'Updated'; } - return "[{$verb}, {$lines}] ".$this->renderSubject(); + return "[{$verb}, {$lines}]"; } protected function renderBody() { diff --git a/src/applications/maniphest/editor/ManiphestTransactionEditor.php b/src/applications/maniphest/editor/ManiphestTransactionEditor.php index d27ec0cd3c..4876fb5849 100644 --- a/src/applications/maniphest/editor/ManiphestTransactionEditor.php +++ b/src/applications/maniphest/editor/ManiphestTransactionEditor.php @@ -269,15 +269,13 @@ final class ManiphestTransactionEditor { $thread_id = 'maniphest-task-'.$task->getPHID(); $task_id = $task->getID(); $title = $task->getTitle(); - $prefix = $this->getSubjectPrefix(); - $subject = trim("{$prefix} T{$task_id}: {$title}"); - $vary_subject = trim("{$prefix} [{$action}] T{$task_id}: {$title}"); $mailtags = $this->getMailTags($transactions); $template = id(new PhabricatorMetaMTAMail()) - ->setSubject($subject) - ->setVarySubject($vary_subject) + ->setSubject("T{$task_id}: {$title}") + ->setSubjectPrefix($this->getSubjectPrefix()) + ->setVarySubjectPrefix("[{$action}]") ->setFrom($transaction->getAuthorPHID()) ->setParentMessageID($this->parentMessageID) ->addHeader('Thread-Topic', 'Maniphest Task '.$task->getID()) diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php index ae845745ac..f6ccdbe25d 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php @@ -154,8 +154,13 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { return $this; } - public function setVarySubject($subject) { - $this->setParam('vary-subject', $subject); + public function setSubjectPrefix($prefix) { + $this->setParam('subject-prefix', $prefix); + return $this; + } + + public function setVarySubjectPrefix($prefix) { + $this->setParam('vary-subject-prefix', $prefix); return $this; } @@ -416,21 +421,7 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { } } - $alt_subject = idx($params, 'vary-subject'); - if ($alt_subject) { - $use_subject = PhabricatorEnv::getEnvConfig( - 'metamta.vary-subjects'); - - if ($prefs) { - $use_subject = $prefs->getPreference( - PhabricatorUserPreferences::PREFERENCE_VARY_SUBJECT, - $use_subject); - } - - if ($use_subject) { - $value = $alt_subject; - } - } + $subject = array(); if ($is_threaded) { $add_re = PhabricatorEnv::getEnvConfig('metamta.re-prefix'); @@ -442,11 +433,31 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { } if ($add_re) { - $value = 'Re: '.$value; + $subject[] = 'Re:'; } } - $mailer->setSubject($value); + $subject[] = trim(idx($params, 'subject-prefix')); + + $vary_prefix = idx($params, 'vary-subject-prefix'); + if ($vary_prefix != '') { + $use_subject = PhabricatorEnv::getEnvConfig( + 'metamta.vary-subjects'); + + if ($prefs) { + $use_subject = $prefs->getPreference( + PhabricatorUserPreferences::PREFERENCE_VARY_SUBJECT, + $use_subject); + } + + if ($use_subject) { + $subject[] = $vary_prefix; + } + } + + $subject[] = $value; + + $mailer->setSubject(implode(' ', array_filter($subject))); break; case 'is-html': if ($value) { @@ -491,7 +502,8 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { case 'mailtags': // Handled below. break; - case 'vary-subject': + case 'subject-prefix': + case 'vary-subject-prefix': // Handled above. break; default: diff --git a/src/applications/owners/mail/PackageMail.php b/src/applications/owners/mail/PackageMail.php index 1ec79512d8..6be89d2df0 100644 --- a/src/applications/owners/mail/PackageMail.php +++ b/src/applications/owners/mail/PackageMail.php @@ -181,15 +181,13 @@ abstract class PackageMail { $package = $this->getPackage(); $prefix = PhabricatorEnv::getEnvConfig('metamta.package.subject-prefix'); $verb = $this->getVerb(); - $package_title = $this->renderPackageTitle(); - $subject = trim("{$prefix} {$package_title}"); - $vary_subject = trim("{$prefix} [{$verb}] {$package_title}"); $threading = $this->getMailThreading(); list($thread_id, $thread_topic) = $threading; $template = id(new PhabricatorMetaMTAMail()) - ->setSubject($subject) - ->setVarySubject($vary_subject) + ->setSubject($this->renderPackageTitle()) + ->setSubjectPrefix($prefix) + ->setVarySubjectPrefix("[{$verb}]") ->setFrom($package->getActorPHID()) ->setThreadID($thread_id, $this->isNewThread()) ->addHeader('Thread-Topic', $thread_topic) diff --git a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php index 203dee9e33..bcc0b658b7 100644 --- a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php +++ b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php @@ -152,17 +152,15 @@ EOBODY; $prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix'); - $subject = trim("{$prefix} {$commit_name}: {$name}"); - $vary_subject = trim("{$prefix} [Commit] {$commit_name}: {$name}"); - $threading = PhabricatorAuditCommentEditor::getMailThreading( $commit->getPHID()); list($thread_id, $thread_topic) = $threading; $template = new PhabricatorMetaMTAMail(); $template->setRelatedPHID($commit->getPHID()); - $template->setSubject($subject); - $template->setVarySubject($subject); + $template->setSubject("{$commit_name}: {$name}"); + $template->setSubjectPrefix($prefix); + $template->setVarySubjectPrefix("[Commit]"); $template->setBody($body); $template->setThreadID($thread_id, $is_new = true); $template->addHeader('Thread-Topic', $thread_topic);