1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Refactor setting e-mail subjects

Summary:
It seems that Outlook and Mail.app mostly ignores the threading headers and thread primarily by subject.
They are also very picky about the Re: part in the header.
I guess that's because users of these clients often hit Reply when they want to create a new message to the sender of an e-mail.

We need both of these applications to work with the same setting because we don't use multiplexing to prevent sending multiple e-mails to people in lists.
I also believe that the default behavior should just work in most setups.

I've tried several different combinations of putting "Re:" and none of them seems to always work in both clients.

This diff at least adds more abstraction to the code which should prevent copy/paste errors (two fixed by this diff!).

Test Plan: Sent several e-mails with varying subject, verified that they look as before in Outlook and Mail.app.

Reviewers: epriestley, nh

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D2709
This commit is contained in:
vrana 2012-06-11 12:21:37 -07:00
parent e1f2f7f2d9
commit 2793828795
11 changed files with 59 additions and 63 deletions

View file

@ -394,8 +394,6 @@ final class PhabricatorAuditCommentEditor {
$reply_handler = self::newReplyHandlerForCommit($commit); $reply_handler = self::newReplyHandlerForCommit($commit);
$prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix'); $prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix');
$subject = "{$prefix} {$name}: {$summary}";
$vary_subject = "{$prefix} [{$verb}] {$name}: {$summary}";
$threading = self::getMailThreading($commit->getPHID()); $threading = self::getMailThreading($commit->getPHID());
list($thread_id, $thread_topic) = $threading; list($thread_id, $thread_topic) = $threading;
@ -434,8 +432,9 @@ final class PhabricatorAuditCommentEditor {
$is_new = false; $is_new = false;
$template = id(new PhabricatorMetaMTAMail()) $template = id(new PhabricatorMetaMTAMail())
->setSubject($subject) ->setSubject("{$name}: {$summary}")
->setVarySubject($subject) ->setSubjectPrefix($prefix)
->setVarySubjectPrefix("[{$verb}]")
->setFrom($comment->getActorPHID()) ->setFrom($comment->getActorPHID())
->setThreadID($thread_id, $is_new) ->setThreadID($thread_id, $is_new)
->addHeader('Thread-Topic', $thread_topic) ->addHeader('Thread-Topic', $thread_topic)

View file

@ -18,8 +18,8 @@
final class DifferentialCCWelcomeMail extends DifferentialReviewRequestMail { final class DifferentialCCWelcomeMail extends DifferentialReviewRequestMail {
protected function renderVarySubject() { protected function renderVaryPrefix() {
return '[Added to CC] '.$this->renderSubject(); return '[Added to CC]';
} }
protected function renderBody() { protected function renderBody() {

View file

@ -75,9 +75,9 @@ final class DifferentialCommentMail extends DifferentialMail {
return $tags; return $tags;
} }
protected function renderVarySubject() { protected function renderVaryPrefix() {
$verb = ucwords($this->getVerb()); $verb = ucwords($this->getVerb());
return "[{$verb}] ".$this->renderSubject(); return "[{$verb}]";
} }
protected function getVerb() { protected function getVerb() {

View file

@ -25,8 +25,8 @@ final class DifferentialDiffContentMail extends DifferentialMail {
$this->content = $content; $this->content = $content;
} }
protected function renderVarySubject() { protected function renderVaryPrefix() {
return '[Content] '.$this->renderSubject(); return '[Content]';
} }
protected function renderBody() { protected function renderBody() {

View file

@ -33,11 +33,11 @@ final class DifferentialExceptionMail extends DifferentialMail {
} }
protected function renderSubject() { protected function renderSubject() {
return "Exception: unable to process your mail request."; return "Exception: unable to process your mail request";
} }
protected function renderVarySubject() { protected function renderVaryPrefix() {
return $this->renderSubject(); return '';
} }
protected function buildBody() { protected function buildBody() {

View file

@ -41,7 +41,7 @@ abstract class DifferentialMail {
return "D{$id}: {$title}"; return "D{$id}: {$title}";
} }
abstract protected function renderVarySubject(); abstract protected function renderVaryPrefix();
abstract protected function renderBody(); abstract protected function renderBody();
public function setActorHandle($actor_handle) { public function setActorHandle($actor_handle) {
@ -78,8 +78,6 @@ abstract class DifferentialMail {
} }
$cc_phids = $this->getCCPHIDs(); $cc_phids = $this->getCCPHIDs();
$subject = $this->buildSubject();
$vary_subject = $this->buildVarySubject();
$body = $this->buildBody(); $body = $this->buildBody();
$attachments = $this->buildAttachments(); $attachments = $this->buildAttachments();
@ -92,8 +90,9 @@ abstract class DifferentialMail {
} }
$template $template
->setSubject($subject) ->setSubject($this->renderSubject())
->setVarySubject($vary_subject) ->setSubjectPrefix($this->getSubjectPrefix())
->setVarySubjectPrefix($this->renderVaryPrefix())
->setBody($body) ->setBody($body)
->setIsHTML($this->shouldMarkMailAsHTML()) ->setIsHTML($this->shouldMarkMailAsHTML())
->setParentMessageID($this->parentMessageID) ->setParentMessageID($this->parentMessageID)
@ -202,14 +201,6 @@ abstract class DifferentialMail {
return PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix'); 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() { protected function shouldMarkMailAsHTML() {
return false; return false;
} }

View file

@ -18,7 +18,7 @@
final class DifferentialNewDiffMail extends DifferentialReviewRequestMail { final class DifferentialNewDiffMail extends DifferentialReviewRequestMail {
protected function renderVarySubject() { protected function renderVaryPrefix() {
$revision = $this->getRevision(); $revision = $this->getRevision();
$line_count = $revision->getLineCount(); $line_count = $revision->getLineCount();
$lines = ($line_count == 1 ? "1 line" : "{$line_count} lines"); $lines = ($line_count == 1 ? "1 line" : "{$line_count} lines");
@ -29,7 +29,7 @@ final class DifferentialNewDiffMail extends DifferentialReviewRequestMail {
$verb = 'Updated'; $verb = 'Updated';
} }
return "[{$verb}, {$lines}] ".$this->renderSubject(); return "[{$verb}, {$lines}]";
} }
protected function renderBody() { protected function renderBody() {

View file

@ -269,15 +269,13 @@ final class ManiphestTransactionEditor {
$thread_id = 'maniphest-task-'.$task->getPHID(); $thread_id = 'maniphest-task-'.$task->getPHID();
$task_id = $task->getID(); $task_id = $task->getID();
$title = $task->getTitle(); $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); $mailtags = $this->getMailTags($transactions);
$template = id(new PhabricatorMetaMTAMail()) $template = id(new PhabricatorMetaMTAMail())
->setSubject($subject) ->setSubject("T{$task_id}: {$title}")
->setVarySubject($vary_subject) ->setSubjectPrefix($this->getSubjectPrefix())
->setVarySubjectPrefix("[{$action}]")
->setFrom($transaction->getAuthorPHID()) ->setFrom($transaction->getAuthorPHID())
->setParentMessageID($this->parentMessageID) ->setParentMessageID($this->parentMessageID)
->addHeader('Thread-Topic', 'Maniphest Task '.$task->getID()) ->addHeader('Thread-Topic', 'Maniphest Task '.$task->getID())

View file

@ -154,8 +154,13 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
return $this; return $this;
} }
public function setVarySubject($subject) { public function setSubjectPrefix($prefix) {
$this->setParam('vary-subject', $subject); $this->setParam('subject-prefix', $prefix);
return $this;
}
public function setVarySubjectPrefix($prefix) {
$this->setParam('vary-subject-prefix', $prefix);
return $this; return $this;
} }
@ -416,21 +421,7 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
} }
} }
$alt_subject = idx($params, 'vary-subject'); $subject = array();
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;
}
}
if ($is_threaded) { if ($is_threaded) {
$add_re = PhabricatorEnv::getEnvConfig('metamta.re-prefix'); $add_re = PhabricatorEnv::getEnvConfig('metamta.re-prefix');
@ -442,11 +433,31 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
} }
if ($add_re) { 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; break;
case 'is-html': case 'is-html':
if ($value) { if ($value) {
@ -491,7 +502,8 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
case 'mailtags': case 'mailtags':
// Handled below. // Handled below.
break; break;
case 'vary-subject': case 'subject-prefix':
case 'vary-subject-prefix':
// Handled above. // Handled above.
break; break;
default: default:

View file

@ -181,15 +181,13 @@ abstract class PackageMail {
$package = $this->getPackage(); $package = $this->getPackage();
$prefix = PhabricatorEnv::getEnvConfig('metamta.package.subject-prefix'); $prefix = PhabricatorEnv::getEnvConfig('metamta.package.subject-prefix');
$verb = $this->getVerb(); $verb = $this->getVerb();
$package_title = $this->renderPackageTitle();
$subject = trim("{$prefix} {$package_title}");
$vary_subject = trim("{$prefix} [{$verb}] {$package_title}");
$threading = $this->getMailThreading(); $threading = $this->getMailThreading();
list($thread_id, $thread_topic) = $threading; list($thread_id, $thread_topic) = $threading;
$template = id(new PhabricatorMetaMTAMail()) $template = id(new PhabricatorMetaMTAMail())
->setSubject($subject) ->setSubject($this->renderPackageTitle())
->setVarySubject($vary_subject) ->setSubjectPrefix($prefix)
->setVarySubjectPrefix("[{$verb}]")
->setFrom($package->getActorPHID()) ->setFrom($package->getActorPHID())
->setThreadID($thread_id, $this->isNewThread()) ->setThreadID($thread_id, $this->isNewThread())
->addHeader('Thread-Topic', $thread_topic) ->addHeader('Thread-Topic', $thread_topic)

View file

@ -152,17 +152,15 @@ EOBODY;
$prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix'); $prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix');
$subject = trim("{$prefix} {$commit_name}: {$name}");
$vary_subject = trim("{$prefix} [Commit] {$commit_name}: {$name}");
$threading = PhabricatorAuditCommentEditor::getMailThreading( $threading = PhabricatorAuditCommentEditor::getMailThreading(
$commit->getPHID()); $commit->getPHID());
list($thread_id, $thread_topic) = $threading; list($thread_id, $thread_topic) = $threading;
$template = new PhabricatorMetaMTAMail(); $template = new PhabricatorMetaMTAMail();
$template->setRelatedPHID($commit->getPHID()); $template->setRelatedPHID($commit->getPHID());
$template->setSubject($subject); $template->setSubject("{$commit_name}: {$name}");
$template->setVarySubject($subject); $template->setSubjectPrefix($prefix);
$template->setVarySubjectPrefix("[Commit]");
$template->setBody($body); $template->setBody($body);
$template->setThreadID($thread_id, $is_new = true); $template->setThreadID($thread_id, $is_new = true);
$template->addHeader('Thread-Topic', $thread_topic); $template->addHeader('Thread-Topic', $thread_topic);