@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

vrana 27938287 e1f2f7f2

+59 -63
+3 -4
src/applications/audit/editor/PhabricatorAuditCommentEditor.php
··· 394 394 $reply_handler = self::newReplyHandlerForCommit($commit); 395 395 396 396 $prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix'); 397 - $subject = "{$prefix} {$name}: {$summary}"; 398 - $vary_subject = "{$prefix} [{$verb}] {$name}: {$summary}"; 399 397 400 398 $threading = self::getMailThreading($commit->getPHID()); 401 399 list($thread_id, $thread_topic) = $threading; ··· 434 432 $is_new = false; 435 433 436 434 $template = id(new PhabricatorMetaMTAMail()) 437 - ->setSubject($subject) 438 - ->setVarySubject($subject) 435 + ->setSubject("{$name}: {$summary}") 436 + ->setSubjectPrefix($prefix) 437 + ->setVarySubjectPrefix("[{$verb}]") 439 438 ->setFrom($comment->getActorPHID()) 440 439 ->setThreadID($thread_id, $is_new) 441 440 ->addHeader('Thread-Topic', $thread_topic)
+2 -2
src/applications/differential/mail/DifferentialCCWelcomeMail.php
··· 18 18 19 19 final class DifferentialCCWelcomeMail extends DifferentialReviewRequestMail { 20 20 21 - protected function renderVarySubject() { 22 - return '[Added to CC] '.$this->renderSubject(); 21 + protected function renderVaryPrefix() { 22 + return '[Added to CC]'; 23 23 } 24 24 25 25 protected function renderBody() {
+2 -2
src/applications/differential/mail/DifferentialCommentMail.php
··· 75 75 return $tags; 76 76 } 77 77 78 - protected function renderVarySubject() { 78 + protected function renderVaryPrefix() { 79 79 $verb = ucwords($this->getVerb()); 80 - return "[{$verb}] ".$this->renderSubject(); 80 + return "[{$verb}]"; 81 81 } 82 82 83 83 protected function getVerb() {
+2 -2
src/applications/differential/mail/DifferentialDiffContentMail.php
··· 25 25 $this->content = $content; 26 26 } 27 27 28 - protected function renderVarySubject() { 29 - return '[Content] '.$this->renderSubject(); 28 + protected function renderVaryPrefix() { 29 + return '[Content]'; 30 30 } 31 31 32 32 protected function renderBody() {
+3 -3
src/applications/differential/mail/DifferentialExceptionMail.php
··· 33 33 } 34 34 35 35 protected function renderSubject() { 36 - return "Exception: unable to process your mail request."; 36 + return "Exception: unable to process your mail request"; 37 37 } 38 38 39 - protected function renderVarySubject() { 40 - return $this->renderSubject(); 39 + protected function renderVaryPrefix() { 40 + return ''; 41 41 } 42 42 43 43 protected function buildBody() {
+4 -13
src/applications/differential/mail/DifferentialMail.php
··· 41 41 return "D{$id}: {$title}"; 42 42 } 43 43 44 - abstract protected function renderVarySubject(); 44 + abstract protected function renderVaryPrefix(); 45 45 abstract protected function renderBody(); 46 46 47 47 public function setActorHandle($actor_handle) { ··· 78 78 } 79 79 80 80 $cc_phids = $this->getCCPHIDs(); 81 - $subject = $this->buildSubject(); 82 - $vary_subject = $this->buildVarySubject(); 83 81 $body = $this->buildBody(); 84 82 $attachments = $this->buildAttachments(); 85 83 ··· 92 90 } 93 91 94 92 $template 95 - ->setSubject($subject) 96 - ->setVarySubject($vary_subject) 93 + ->setSubject($this->renderSubject()) 94 + ->setSubjectPrefix($this->getSubjectPrefix()) 95 + ->setVarySubjectPrefix($this->renderVaryPrefix()) 97 96 ->setBody($body) 98 97 ->setIsHTML($this->shouldMarkMailAsHTML()) 99 98 ->setParentMessageID($this->parentMessageID) ··· 200 199 201 200 protected function getSubjectPrefix() { 202 201 return PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix'); 203 - } 204 - 205 - protected function buildSubject() { 206 - return trim($this->getSubjectPrefix().' '.$this->renderSubject()); 207 - } 208 - 209 - protected function buildVarySubject() { 210 - return trim($this->getSubjectPrefix().' '.$this->renderVarySubject()); 211 202 } 212 203 213 204 protected function shouldMarkMailAsHTML() {
+2 -2
src/applications/differential/mail/DifferentialNewDiffMail.php
··· 18 18 19 19 final class DifferentialNewDiffMail extends DifferentialReviewRequestMail { 20 20 21 - protected function renderVarySubject() { 21 + protected function renderVaryPrefix() { 22 22 $revision = $this->getRevision(); 23 23 $line_count = $revision->getLineCount(); 24 24 $lines = ($line_count == 1 ? "1 line" : "{$line_count} lines"); ··· 29 29 $verb = 'Updated'; 30 30 } 31 31 32 - return "[{$verb}, {$lines}] ".$this->renderSubject(); 32 + return "[{$verb}, {$lines}]"; 33 33 } 34 34 35 35 protected function renderBody() {
+3 -5
src/applications/maniphest/editor/ManiphestTransactionEditor.php
··· 269 269 $thread_id = 'maniphest-task-'.$task->getPHID(); 270 270 $task_id = $task->getID(); 271 271 $title = $task->getTitle(); 272 - $prefix = $this->getSubjectPrefix(); 273 - $subject = trim("{$prefix} T{$task_id}: {$title}"); 274 - $vary_subject = trim("{$prefix} [{$action}] T{$task_id}: {$title}"); 275 272 276 273 $mailtags = $this->getMailTags($transactions); 277 274 278 275 $template = id(new PhabricatorMetaMTAMail()) 279 - ->setSubject($subject) 280 - ->setVarySubject($vary_subject) 276 + ->setSubject("T{$task_id}: {$title}") 277 + ->setSubjectPrefix($this->getSubjectPrefix()) 278 + ->setVarySubjectPrefix("[{$action}]") 281 279 ->setFrom($transaction->getAuthorPHID()) 282 280 ->setParentMessageID($this->parentMessageID) 283 281 ->addHeader('Thread-Topic', 'Maniphest Task '.$task->getID())
+32 -20
src/applications/metamta/storage/PhabricatorMetaMTAMail.php
··· 154 154 return $this; 155 155 } 156 156 157 - public function setVarySubject($subject) { 158 - $this->setParam('vary-subject', $subject); 157 + public function setSubjectPrefix($prefix) { 158 + $this->setParam('subject-prefix', $prefix); 159 + return $this; 160 + } 161 + 162 + public function setVarySubjectPrefix($prefix) { 163 + $this->setParam('vary-subject-prefix', $prefix); 159 164 return $this; 160 165 } 161 166 ··· 416 421 } 417 422 } 418 423 419 - $alt_subject = idx($params, 'vary-subject'); 420 - if ($alt_subject) { 421 - $use_subject = PhabricatorEnv::getEnvConfig( 422 - 'metamta.vary-subjects'); 423 - 424 - if ($prefs) { 425 - $use_subject = $prefs->getPreference( 426 - PhabricatorUserPreferences::PREFERENCE_VARY_SUBJECT, 427 - $use_subject); 428 - } 429 - 430 - if ($use_subject) { 431 - $value = $alt_subject; 432 - } 433 - } 424 + $subject = array(); 434 425 435 426 if ($is_threaded) { 436 427 $add_re = PhabricatorEnv::getEnvConfig('metamta.re-prefix'); ··· 442 433 } 443 434 444 435 if ($add_re) { 445 - $value = 'Re: '.$value; 436 + $subject[] = 'Re:'; 446 437 } 447 438 } 448 439 449 - $mailer->setSubject($value); 440 + $subject[] = trim(idx($params, 'subject-prefix')); 441 + 442 + $vary_prefix = idx($params, 'vary-subject-prefix'); 443 + if ($vary_prefix != '') { 444 + $use_subject = PhabricatorEnv::getEnvConfig( 445 + 'metamta.vary-subjects'); 446 + 447 + if ($prefs) { 448 + $use_subject = $prefs->getPreference( 449 + PhabricatorUserPreferences::PREFERENCE_VARY_SUBJECT, 450 + $use_subject); 451 + } 452 + 453 + if ($use_subject) { 454 + $subject[] = $vary_prefix; 455 + } 456 + } 457 + 458 + $subject[] = $value; 459 + 460 + $mailer->setSubject(implode(' ', array_filter($subject))); 450 461 break; 451 462 case 'is-html': 452 463 if ($value) { ··· 491 502 case 'mailtags': 492 503 // Handled below. 493 504 break; 494 - case 'vary-subject': 505 + case 'subject-prefix': 506 + case 'vary-subject-prefix': 495 507 // Handled above. 496 508 break; 497 509 default:
+3 -5
src/applications/owners/mail/PackageMail.php
··· 181 181 $package = $this->getPackage(); 182 182 $prefix = PhabricatorEnv::getEnvConfig('metamta.package.subject-prefix'); 183 183 $verb = $this->getVerb(); 184 - $package_title = $this->renderPackageTitle(); 185 - $subject = trim("{$prefix} {$package_title}"); 186 - $vary_subject = trim("{$prefix} [{$verb}] {$package_title}"); 187 184 $threading = $this->getMailThreading(); 188 185 list($thread_id, $thread_topic) = $threading; 189 186 190 187 $template = id(new PhabricatorMetaMTAMail()) 191 - ->setSubject($subject) 192 - ->setVarySubject($vary_subject) 188 + ->setSubject($this->renderPackageTitle()) 189 + ->setSubjectPrefix($prefix) 190 + ->setVarySubjectPrefix("[{$verb}]") 193 191 ->setFrom($package->getActorPHID()) 194 192 ->setThreadID($thread_id, $this->isNewThread()) 195 193 ->addHeader('Thread-Topic', $thread_topic)
+3 -5
src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
··· 152 152 153 153 $prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix'); 154 154 155 - $subject = trim("{$prefix} {$commit_name}: {$name}"); 156 - $vary_subject = trim("{$prefix} [Commit] {$commit_name}: {$name}"); 157 - 158 155 $threading = PhabricatorAuditCommentEditor::getMailThreading( 159 156 $commit->getPHID()); 160 157 list($thread_id, $thread_topic) = $threading; 161 158 162 159 $template = new PhabricatorMetaMTAMail(); 163 160 $template->setRelatedPHID($commit->getPHID()); 164 - $template->setSubject($subject); 165 - $template->setVarySubject($subject); 161 + $template->setSubject("{$commit_name}: {$name}"); 162 + $template->setSubjectPrefix($prefix); 163 + $template->setVarySubjectPrefix("[Commit]"); 166 164 $template->setBody($body); 167 165 $template->setThreadID($thread_id, $is_new = true); 168 166 $template->addHeader('Thread-Topic', $thread_topic);