Use internal templates to simplify minor formatting commands.

Use internal templates in getChangeMessageThreadId, and to set
the listId headers.  These are not admin editable templates
(they are not in files), they simply make the code a bit more
readable and editable at very little cost since we already
support velocity templating in emails.  Additionaly, factor
out the fromline creation to its own function.

Change-Id: I197b239e657e1dd604b07510c4430675f05d84eb
This commit is contained in:
Martin Fick
2010-07-20 14:16:20 -06:00
parent 679fc379c8
commit 6d28ded562
2 changed files with 32 additions and 39 deletions

View File

@@ -137,23 +137,19 @@ public abstract class ChangeEmail extends OutgoingEmail {
setCommitIdHeader();
}
private void setListIdHeader() {
private void setListIdHeader() throws EmailException {
// Set a reasonable list id so that filters can be used to sort messages
//
final StringBuilder listid = new StringBuilder();
listid.append("gerrit-");
listid.append(projectName.replace('/', '-'));
listid.append("@");
listid.append(getGerritHost());
final String listidStr = listid.toString();
setHeader("Mailing-List", "list " + listidStr);
setHeader("List-Id", "<" + listidStr.replace('@', '.') + ">");
setVHeader("Mailing-List", "list $email.listId");
setVHeader("List-Id", "<$email.listId.replace('@', '.')>");
if (getSettingsUrl() != null) {
setHeader("List-Unsubscribe", "<" + getSettingsUrl() + ">");
setVHeader("List-Unsubscribe", "<$email.settingsUrl>");
}
}
public String getListId() throws EmailException {
return velocify("gerrit-$projectName.replace('/', '-')@$email.gerritHost");
}
private void setChangeUrlHeader() {
final String u = getChangeUrl();
if (u != null) {
@@ -184,18 +180,9 @@ public abstract class ChangeEmail extends OutgoingEmail {
return null;
}
protected String getChangeMessageThreadId() {
final StringBuilder r = new StringBuilder();
r.append('<');
r.append("gerrit");
r.append('.');
r.append(change.getCreatedOn().getTime());
r.append('.');
r.append(change.getKey().get());
r.append('@');
r.append(getGerritHost());
r.append('>');
return r.toString();
public String getChangeMessageThreadId() throws EmailException {
return velocify("<gerrit.${change.createdOn.time}.$change.key.get()" +
"@$email.gerritHost>");
}
/** Format the sender's "cover letter", {@link #getCoverLetter()}. */

View File

@@ -150,24 +150,30 @@ public abstract class OutgoingEmail {
body = new StringBuilder();
if (fromId != null && args.fromAddressGenerator.isGenericAddress(fromId)) {
final Account account = args.accountCache.get(fromId).getAccount();
final String name = account.getFullName();
final String email = account.getPreferredEmail();
if ((name != null && !name.isEmpty())
|| (email != null && !email.isEmpty())) {
body.append("From");
if (name != null && !name.isEmpty()) {
body.append(" ").append(name);
}
if (email != null && !email.isEmpty()) {
body.append(" <").append(email).append(">");
}
body.append(":\n\n");
}
appendText(getFromLine());
}
}
protected String getFromLine() {
final Account account = args.accountCache.get(fromId).getAccount();
final String name = account.getFullName();
final String email = account.getPreferredEmail();
StringBuilder f = new StringBuilder();
if ((name != null && !name.isEmpty())
|| (email != null && !email.isEmpty())) {
f.append("From");
if (name != null && !name.isEmpty()) {
f.append(" ").append(name);
}
if (email != null && !email.isEmpty()) {
f.append(" <").append(email).append(">");
}
f.append(":\n\n");
}
return f.toString();
}
public String getGerritHost() {
if (getGerritUrl() != null) {
try {