Use a template to set the footer on ChangeEmails.
Add an admin editable ChangeFooter.vm template used to
format the footer in ChangeEmails.
Change-Id: I8f6f80b7a3e1fdb39ee1ea20aa84738286bce826
diff --git a/Documentation/config-mail.txt b/Documentation/config-mail.txt
index 3f891c9..5d38ed7 100644
--- a/Documentation/config-mail.txt
+++ b/Documentation/config-mail.txt
@@ -25,6 +25,12 @@
one to set the subject line, and one to set the footer which gets appended to
all the change emails (see `ChangeSubject.vm` and `ChangeFooter.vm` below.)
+ChangeFooter.vm
+~~~~~~~~~~~~~~~
+
+The `ChangeFooter.vm` template will determine the contents of the footer
+text that will be appended to emails related to changes (all `ChangeEmails)`.
+
ChangeSubject.vm
~~~~~~~~~~~~~~~~
diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java
index a36a2a7..44fd88a 100644
--- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java
+++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java
@@ -85,6 +85,7 @@
extract(site.gerrit_sh, Init.class, "gerrit.sh");
chmod(0755, site.gerrit_sh);
+ extractMailExample("ChangeFooter.vm");
extractMailExample("ChangeSubject.vm");
extractMailExample("Merged.vm");
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/mail/ChangeEmail.java b/gerrit-server/src/main/java/com/google/gerrit/server/mail/ChangeEmail.java
index b8a0ae5..3c78e17 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/mail/ChangeEmail.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/mail/ChangeEmail.java
@@ -52,7 +52,6 @@
private ProjectState projectState;
protected ChangeData changeData;
- private boolean inFooter;
protected ChangeEmail(EmailArguments ea, final Change c, final String mc) {
super(ea, mc);
@@ -76,29 +75,7 @@
/** Format the message body by calling {@link #appendText(String)}. */
protected void format() throws EmailException {
formatChange();
- if (getChangeUrl() != null) {
- openFooter();
- appendText("To view visit ");
- appendText(getChangeUrl());
- appendText("\n");
- }
- if (getSettingsUrl() != null) {
- openFooter();
- appendText("To unsubscribe, visit ");
- appendText(getSettingsUrl());
- appendText("\n");
- }
-
- if (inFooter) {
- appendText("\n");
- } else {
- openFooter();
- }
- appendText("Gerrit-MessageType: " + messageClass + "\n");
- appendText("Gerrit-Project: " + projectName + "\n");
- appendText("Gerrit-Branch: " + change.getDest().getShortName() + "\n");
- appendText("Gerrit-Owner: " + getNameEmailFor(change.getOwner()) + "\n");
-
+ appendText(velocifyFile("ChangeFooter.vm"));
try {
HashSet<Account.Id> reviewers = new HashSet<Account.Id>();
for (PatchSetApproval p : args.db.get().patchSetApprovals().byChange(
@@ -158,8 +135,6 @@
setListIdHeader();
setChangeUrlHeader();
setCommitIdHeader();
-
- inFooter = false;
}
private void setListIdHeader() {
@@ -223,13 +198,6 @@
return r.toString();
}
- private void openFooter() {
- if (!inFooter) {
- inFooter = true;
- appendText("-- \n");
- }
- }
-
/** Format the sender's "cover letter", {@link #getCoverLetter()}. */
protected void formatCoverLetter() {
final String cover = getCoverLetter();
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java b/gerrit-server/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java
index 288b182..44e1063 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java
@@ -168,7 +168,7 @@
}
}
- protected String getGerritHost() {
+ public String getGerritHost() {
if (getGerritUrl() != null) {
try {
return new URL(getGerritUrl()).getHost();
@@ -194,7 +194,7 @@
return null;
}
- protected String getGerritUrl() {
+ public String getGerritUrl() {
return args.urlProvider.get();
}
@@ -237,7 +237,7 @@
return name;
}
- protected String getNameEmailFor(Account.Id accountId) {
+ public String getNameEmailFor(Account.Id accountId) {
AccountState who = args.accountCache.get(accountId);
String name = who.getAccount().getFullName();
String email = who.getAccount().getPreferredEmail();
diff --git a/gerrit-server/src/main/resources/com/google/gerrit/server/mail/ChangeFooter.vm b/gerrit-server/src/main/resources/com/google/gerrit/server/mail/ChangeFooter.vm
new file mode 100644
index 0000000..c15d6ef
--- /dev/null
+++ b/gerrit-server/src/main/resources/com/google/gerrit/server/mail/ChangeFooter.vm
@@ -0,0 +1,49 @@
+## Copyright (C) 2010 The Android Open Source Project
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+##
+##
+## Template Type:
+## -------------
+## This is a velocity mail template, see: http://velocity.apache.org and the
+## gerrit-docs:config-mail.txt for more info on modifying gerrit mail templates.
+##
+## Template File Names and extensions:
+## ----------------------------------
+## Gerrit will use templates ending in ".vm" but will ignore templates ending
+## in ".vm.example". If a .vm template does not exist, the default internal
+## gerrit template which is the same as the .vm.example will be used. If you
+## want to override the default template, copy the .vm.exmaple file to a .vm
+## file and edit it appropriately.
+##
+## This Template:
+## --------------
+## The ChangeFooter.vm template will determine the contents of the footer
+## text that will be appended to ALL emails related to changes.
+##
+--
+#if ($email.changeUrl)
+To view, visit $email.changeUrl
+#set ($notblank = 1)
+#end
+#if ($email.settingsUrl)
+To unsubscribe, visit $email.settingsUrl
+#set ($notblank = 1)
+#end
+#if ($notblank == 1)
+
+#end
+Gerrit-MessageType: $messageClass
+Gerrit-Project: $projectName
+Gerrit-Branch: $branch.shortName
+Gerrit-Owner: $email.getNameEmailFor($change.owner)