Include the name/email in email body if not in envelope
If sendemail.from is configured to use a generic server account for all envelopes, include the actual user's name and email in the body of the message using a fake "From: " header that is similar to the RFC header used in the envelope, and similar to how git format-patch records an author in the body of the email. Bug: issue 475 Change-Id: Id2bbf12ec174f0a660c5f8bf380291b81941ce3d Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -18,5 +18,7 @@ import com.google.gerrit.reviewdb.Account;
|
|||||||
|
|
||||||
/** Constructs an address to send email from. */
|
/** Constructs an address to send email from. */
|
||||||
public interface FromAddressGenerator {
|
public interface FromAddressGenerator {
|
||||||
|
public boolean isGenericAddress(Account.Id fromId);
|
||||||
|
|
||||||
public Address from(Account.Id fromId);
|
public Address from(Account.Id fromId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,9 +41,8 @@ public class FromAddressGeneratorProvider implements
|
|||||||
final Address srvAddr = toAddress(myIdent);
|
final Address srvAddr = toAddress(myIdent);
|
||||||
|
|
||||||
if (from == null || "MIXED".equalsIgnoreCase(from)) {
|
if (from == null || "MIXED".equalsIgnoreCase(from)) {
|
||||||
final String name = "${user} (Code Review)";
|
ParamertizedString name = new ParamertizedString("${user} (Code Review)");
|
||||||
final String email = srvAddr.email;
|
generator = new PatternGen(srvAddr, accountCache, name, srvAddr.email);
|
||||||
generator = new PatternGen(srvAddr, accountCache, name, email);
|
|
||||||
|
|
||||||
} else if ("USER".equalsIgnoreCase(from)) {
|
} else if ("USER".equalsIgnoreCase(from)) {
|
||||||
generator = new UserGen(accountCache, srvAddr);
|
generator = new UserGen(accountCache, srvAddr);
|
||||||
@@ -53,7 +52,12 @@ public class FromAddressGeneratorProvider implements
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
final Address a = Address.parse(from);
|
final Address a = Address.parse(from);
|
||||||
generator = new PatternGen(srvAddr, accountCache, a.name, a.email);
|
final ParamertizedString name = new ParamertizedString(a.name);
|
||||||
|
if (name.getParameterNames().isEmpty()) {
|
||||||
|
generator = new ServerGen(a);
|
||||||
|
} else {
|
||||||
|
generator = new PatternGen(srvAddr, accountCache, name, a.email);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +79,11 @@ public class FromAddressGeneratorProvider implements
|
|||||||
this.srvAddr = srvAddr;
|
this.srvAddr = srvAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGenericAddress(Account.Id fromId) {
|
||||||
|
return from(fromId) != srvAddr;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Address from(final Account.Id fromId) {
|
public Address from(final Account.Id fromId) {
|
||||||
if (fromId != null) {
|
if (fromId != null) {
|
||||||
@@ -94,6 +103,11 @@ public class FromAddressGeneratorProvider implements
|
|||||||
this.srvAddr = srvAddr;
|
this.srvAddr = srvAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGenericAddress(Account.Id fromId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Address from(final Account.Id fromId) {
|
public Address from(final Account.Id fromId) {
|
||||||
return srvAddr;
|
return srvAddr;
|
||||||
@@ -107,11 +121,22 @@ public class FromAddressGeneratorProvider implements
|
|||||||
private final ParamertizedString namePattern;
|
private final ParamertizedString namePattern;
|
||||||
|
|
||||||
PatternGen(final Address serverAddress, final AccountCache accountCache,
|
PatternGen(final Address serverAddress, final AccountCache accountCache,
|
||||||
final String namePattern, final String senderEmail) {
|
final ParamertizedString namePattern, final String senderEmail) {
|
||||||
this.senderEmail = senderEmail;
|
this.senderEmail = senderEmail;
|
||||||
this.serverAddress = serverAddress;
|
this.serverAddress = serverAddress;
|
||||||
this.accountCache = accountCache;
|
this.accountCache = accountCache;
|
||||||
this.namePattern = new ParamertizedString(namePattern);
|
this.namePattern = namePattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGenericAddress(Account.Id fromId) {
|
||||||
|
if (fromId != null) {
|
||||||
|
final Account account = accountCache.get(fromId).getAccount();
|
||||||
|
final String name = account.getFullName();
|
||||||
|
return name == null || "".equals(name);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -253,6 +253,24 @@ public abstract class OutgoingEmail {
|
|||||||
body = new StringBuilder();
|
body = new StringBuilder();
|
||||||
inFooter = false;
|
inFooter = false;
|
||||||
|
|
||||||
|
if (fromId != null && fromAddressGenerator.isGenericAddress(fromId)) {
|
||||||
|
final Account account = 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (change != null && db != null) {
|
if (change != null && db != null) {
|
||||||
if (patchSet == null) {
|
if (patchSet == null) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user