diff options
Diffstat (limited to 'gerrit-server/src/main/java/com/google/gerrit/server/mail/MailUtil.java')
-rw-r--r-- | gerrit-server/src/main/java/com/google/gerrit/server/mail/MailUtil.java | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/mail/MailUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/mail/MailUtil.java index b6d7fa8558..0487cc0347 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/mail/MailUtil.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/mail/MailUtil.java @@ -20,10 +20,10 @@ import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER; import com.google.gerrit.common.FooterConstants; import com.google.gerrit.common.errors.NoSuchAccountException; import com.google.gerrit.reviewdb.client.Account; -import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.ReviewerSet; import com.google.gerrit.server.account.AccountResolver; import com.google.gwtorm.server.OrmException; +import java.io.IOException; import java.time.format.DateTimeFormatter; import java.util.Collections; import java.util.HashSet; @@ -38,24 +38,18 @@ public class MailUtil { DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss ZZZ"); public static MailRecipients getRecipientsFromFooters( - ReviewDb db, - AccountResolver accountResolver, - boolean draftPatchSet, - List<FooterLine> footerLines) - throws OrmException { + AccountResolver accountResolver, List<FooterLine> footerLines) + throws OrmException, IOException { MailRecipients recipients = new MailRecipients(); - if (!draftPatchSet) { - for (FooterLine footerLine : footerLines) { - try { - if (isReviewer(footerLine)) { - recipients.reviewers.add( - toAccountId(db, accountResolver, footerLine.getValue().trim())); - } else if (footerLine.matches(FooterKey.CC)) { - recipients.cc.add(toAccountId(db, accountResolver, footerLine.getValue().trim())); - } - } catch (NoSuchAccountException e) { - continue; + for (FooterLine footerLine : footerLines) { + try { + if (isReviewer(footerLine)) { + recipients.reviewers.add(toAccountId(accountResolver, footerLine.getValue().trim())); + } else if (footerLine.matches(FooterKey.CC)) { + recipients.cc.add(toAccountId(accountResolver, footerLine.getValue().trim())); } + } catch (NoSuchAccountException e) { + continue; } } return recipients; @@ -68,17 +62,16 @@ public class MailUtil { return recipients; } - private static Account.Id toAccountId( - ReviewDb db, AccountResolver accountResolver, String nameOrEmail) - throws OrmException, NoSuchAccountException { - Account a = accountResolver.findByNameOrEmail(db, nameOrEmail); + private static Account.Id toAccountId(AccountResolver accountResolver, String nameOrEmail) + throws OrmException, NoSuchAccountException, IOException { + Account a = accountResolver.findByNameOrEmail(nameOrEmail); if (a == null) { throw new NoSuchAccountException("\"" + nameOrEmail + "\" is not registered"); } return a.getId(); } - private static boolean isReviewer(final FooterLine candidateFooterLine) { + private static boolean isReviewer(FooterLine candidateFooterLine) { return candidateFooterLine.matches(FooterKey.SIGNED_OFF_BY) || candidateFooterLine.matches(FooterKey.ACKED_BY) || candidateFooterLine.matches(FooterConstants.REVIEWED_BY) @@ -94,17 +87,17 @@ public class MailUtil { this.cc = new HashSet<>(); } - public MailRecipients(final Set<Account.Id> reviewers, final Set<Account.Id> cc) { + public MailRecipients(Set<Account.Id> reviewers, Set<Account.Id> cc) { this.reviewers = new HashSet<>(reviewers); this.cc = new HashSet<>(cc); } - public void add(final MailRecipients recipients) { + public void add(MailRecipients recipients) { reviewers.addAll(recipients.reviewers); cc.addAll(recipients.cc); } - public void remove(final Account.Id toRemove) { + public void remove(Account.Id toRemove) { reviewers.remove(toRemove); cc.remove(toRemove); } |