Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14710200
D9342.id22273.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D9342.id22273.diff
View Options
diff --git a/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php b/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
--- a/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
+++ b/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
@@ -234,6 +234,15 @@
'[Differential]')
->setDescription(pht('Subject prefix for Differential mail.')),
$this->newOption(
+ 'metamta.differential.subject-template',
+ 'string',
+ 'D${id}: ${title}')
+ ->setSummary(pht('Subject template for Differential mail.'))
+ ->setDescription(pht('Available keys: id, title, repository, branch'))
+ ->addExample(
+ '[${repository}/${branch}] D${id}: ${title}',
+ pht('Use repository and branch')),
+ $this->newOption(
'metamta.differential.attach-patches',
'bool',
false)
diff --git a/src/applications/differential/editor/DifferentialTransactionEditor.php b/src/applications/differential/editor/DifferentialTransactionEditor.php
--- a/src/applications/differential/editor/DifferentialTransactionEditor.php
+++ b/src/applications/differential/editor/DifferentialTransactionEditor.php
@@ -1081,6 +1081,11 @@
return PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix');
}
+ private function getMailSubjectTemplate() {
+ return PhabricatorEnv::getEnvConfig(
+ 'metamta.differential.subject-template');
+ }
+
protected function getMailThreadID(PhabricatorLiskDAO $object) {
// This is nonstandard, but retains threading with older messages.
$phid = $object->getPHID();
@@ -1097,8 +1102,18 @@
$title = $object->getTitle();
$original_title = $object->getOriginalTitle();
+ $branch = nonempty($object->getActiveDiff()->getBranch(), '-');
+ $repository = $object->getRepository() ?
+ $object->getRepository()->getName() : '-';
+
+ $subject = $this->mergeVariables($this->getMailSubjectTemplate(),
+ array(
+ 'id' => $id,
+ 'branch' => $branch,
+ 'repository' => $repository,
+ 'title' => $title
+ ));
- $subject = "D{$id}: {$title}";
$thread_topic = "D{$id}: {$original_title}";
return id(new PhabricatorMetaMTAMail())
@@ -1106,6 +1121,42 @@
->addHeader('Thread-Topic', $thread_topic);
}
+ /**
+ * Convert a user-provided string with variables in it, like:
+ *
+ * ${project}/${branch}
+ *
+ * ...into a string with variables merged into it safely:
+ *
+ * myproject/mybranch
+ *
+ * Maybe move to libphutil?
+ * @param string User-provided pattern string containing `${variables}`.
+ * @param dict List of available replacement variables.
+ * @return string String with variables replaced safely into it.
+ *
+ */
+ protected function mergeVariables($pattern, array $variables) {
+ $regexp = '/\\$\\{(?P<name>[a-z\\.]+)\\}/';
+
+ $matches = null;
+ preg_match_all($regexp, $pattern, $matches);
+
+ $argv = array();
+ foreach ($matches['name'] as $name) {
+ if (!array_key_exists($name, $variables)) {
+ throw new Exception(pht("No such variable '%s'!", $name));
+ }
+ $argv[] = $variables[$name];
+ }
+
+ $pattern = str_replace('%', '%%', $pattern);
+ $pattern = preg_replace($regexp, '%s', $pattern);
+
+ return vsprintf($pattern, $argv);
+ }
+
+
protected function buildMailBody(
PhabricatorLiskDAO $object,
array $xactions) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 18, 1:28 PM (8 h, 13 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7002697
Default Alt Text
D9342.id22273.diff (3 KB)
Attached To
Mode
D9342: Make Differential email subject more configurable.
Attached
Detach File
Event Timeline
Log In to Comment