Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14321690
D9342.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
D9342.diff
View Options
diff --git a/src/applications/audit/editor/PhabricatorAuditEditor.php b/src/applications/audit/editor/PhabricatorAuditEditor.php
--- a/src/applications/audit/editor/PhabricatorAuditEditor.php
+++ b/src/applications/audit/editor/PhabricatorAuditEditor.php
@@ -366,7 +366,7 @@
return $reply_handler;
}
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
return PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix');
}
diff --git a/src/applications/conpherence/editor/ConpherenceEditor.php b/src/applications/conpherence/editor/ConpherenceEditor.php
--- a/src/applications/conpherence/editor/ConpherenceEditor.php
+++ b/src/applications/conpherence/editor/ConpherenceEditor.php
@@ -412,7 +412,7 @@
return $body;
}
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
return PhabricatorEnv::getEnvConfig('metamta.conpherence.subject-prefix');
}
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
@@ -244,7 +244,11 @@
'metamta.differential.subject-prefix',
'string',
'[Differential]')
- ->setDescription(pht('Subject prefix for Differential mail.')),
+ ->setSummary(pht('Subject prefix template for Differential mail.'))
+ ->setDescription(pht('Available keys: id, title, repository, branch'))
+ ->addExample(
+ '[${repository}/${branch}] [Differential]',
+ pht('Use repository and branch')),
$this->newOption(
'metamta.differential.attach-patches',
'bool',
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
@@ -1095,8 +1095,24 @@
return $action;
}
- protected function getMailSubjectPrefix() {
- return PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix');
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
+ $branch = nonempty($object->getActiveDiff()->getBranch(), '-');
+ $repo_name = null;
+
+ if ($object->getRepository()) {
+ $repo_name = $object->getRepository()->getName();
+ }
+
+ if ($repo_name === null) {
+ $repo_name = basename($object->getActiveDiff()->getSourcePath());
+ }
+
+ return $this->mergeVariables(
+ PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix'),
+ array(
+ 'branch' => $branch,
+ 'repository' => $repo_name,
+ ));
}
protected function getMailThreadID(PhabricatorLiskDAO $object) {
@@ -1124,6 +1140,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) {
diff --git a/src/applications/files/editor/PhabricatorFileEditor.php b/src/applications/files/editor/PhabricatorFileEditor.php
--- a/src/applications/files/editor/PhabricatorFileEditor.php
+++ b/src/applications/files/editor/PhabricatorFileEditor.php
@@ -54,7 +54,7 @@
return true;
}
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
return PhabricatorEnv::getEnvConfig('metamta.files.subject-prefix');
}
diff --git a/src/applications/legalpad/editor/LegalpadDocumentEditor.php b/src/applications/legalpad/editor/LegalpadDocumentEditor.php
--- a/src/applications/legalpad/editor/LegalpadDocumentEditor.php
+++ b/src/applications/legalpad/editor/LegalpadDocumentEditor.php
@@ -201,7 +201,7 @@
return $body;
}
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
return PhabricatorEnv::getEnvConfig('metamta.legalpad.subject-prefix');
}
diff --git a/src/applications/macro/editor/PhabricatorMacroEditor.php b/src/applications/macro/editor/PhabricatorMacroEditor.php
--- a/src/applications/macro/editor/PhabricatorMacroEditor.php
+++ b/src/applications/macro/editor/PhabricatorMacroEditor.php
@@ -160,7 +160,7 @@
return $body;
}
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
return PhabricatorEnv::getEnvConfig('metamta.macro.subject-prefix');
}
diff --git a/src/applications/maniphest/editor/ManiphestTransactionEditor.php b/src/applications/maniphest/editor/ManiphestTransactionEditor.php
--- a/src/applications/maniphest/editor/ManiphestTransactionEditor.php
+++ b/src/applications/maniphest/editor/ManiphestTransactionEditor.php
@@ -403,7 +403,7 @@
return $xactions;
}
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
return PhabricatorEnv::getEnvConfig('metamta.maniphest.subject-prefix');
}
diff --git a/src/applications/paste/editor/PhabricatorPasteEditor.php b/src/applications/paste/editor/PhabricatorPasteEditor.php
--- a/src/applications/paste/editor/PhabricatorPasteEditor.php
+++ b/src/applications/paste/editor/PhabricatorPasteEditor.php
@@ -136,7 +136,7 @@
return true;
}
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
return PhabricatorEnv::getEnvConfig('metamta.paste.subject-prefix');
}
diff --git a/src/applications/pholio/editor/PholioMockEditor.php b/src/applications/pholio/editor/PholioMockEditor.php
--- a/src/applications/pholio/editor/PholioMockEditor.php
+++ b/src/applications/pholio/editor/PholioMockEditor.php
@@ -416,7 +416,7 @@
return $body;
}
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
return PhabricatorEnv::getEnvConfig('metamta.pholio.subject-prefix');
}
diff --git a/src/applications/phriction/editor/PhrictionDocumentEditor.php b/src/applications/phriction/editor/PhrictionDocumentEditor.php
--- a/src/applications/phriction/editor/PhrictionDocumentEditor.php
+++ b/src/applications/phriction/editor/PhrictionDocumentEditor.php
@@ -350,7 +350,7 @@
$body = implode("\n\n", $body);
- $subject_prefix = $this->getMailSubjectPrefix();
+ $subject_prefix = $this->getMailSubjectPrefix(null);
$mail = new PhabricatorMetaMTAMail();
$mail->setSubject($name)
@@ -368,7 +368,7 @@
/* --( For less copy-pasting when switching to ApplicationTransactions )--- */
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
return PhabricatorEnv::getEnvConfig('metamta.phriction.subject-prefix');
}
diff --git a/src/applications/ponder/editor/PonderEditor.php b/src/applications/ponder/editor/PonderEditor.php
--- a/src/applications/ponder/editor/PonderEditor.php
+++ b/src/applications/ponder/editor/PonderEditor.php
@@ -31,7 +31,7 @@
);
}
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
return '[Ponder]';
}
diff --git a/src/applications/releeph/editor/ReleephRequestTransactionalEditor.php b/src/applications/releeph/editor/ReleephRequestTransactionalEditor.php
--- a/src/applications/releeph/editor/ReleephRequestTransactionalEditor.php
+++ b/src/applications/releeph/editor/ReleephRequestTransactionalEditor.php
@@ -196,7 +196,7 @@
->setMailReceiver($object);
}
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
return '[Releeph]';
}
diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
--- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
+++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
@@ -1858,7 +1858,7 @@
$template
->setFrom($this->getActingAsPHID())
- ->setSubjectPrefix($this->getMailSubjectPrefix())
+ ->setSubjectPrefix($this->getMailSubjectPrefix($object))
->setVarySubjectPrefix('['.$action.']')
->setThreadID($this->getMailThreadID($object), $this->getIsNewObject())
->setRelatedPHID($object->getPHID())
@@ -1931,7 +1931,7 @@
/**
* @task mail
*/
- protected function getMailSubjectPrefix() {
+ protected function getMailSubjectPrefix(PhabricatorLiskDAO $object) {
throw new Exception('Capability not supported.');
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 11:59 AM (20 h, 35 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6907252
Default Alt Text
D9342.diff (9 KB)
Attached To
Mode
D9342: Make Differential email subject more configurable.
Attached
Detach File
Event Timeline
Log In to Comment