use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.
the class Reviewers method parse.
@Override
public ReviewerResource parse(ChangeResource rsrc, IdString id) throws OrmException, ResourceNotFoundException, AuthException {
Address address = Address.tryParse(id.get());
Account.Id accountId = null;
try {
accountId = accounts.parse(TopLevelResource.INSTANCE, id).getUser().getAccountId();
} catch (ResourceNotFoundException e) {
if (address == null) {
throw e;
}
}
// See if the id exists as a reviewer for this change
if (accountId != null && fetchAccountIds(rsrc).contains(accountId)) {
return resourceFactory.create(rsrc, accountId);
}
// See if the address exists as a reviewer on the change
if (address != null && rsrc.getNotes().getReviewersByEmail().all().contains(address)) {
return new ReviewerResource(rsrc, address);
}
throw new ResourceNotFoundException(id);
}
use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.
the class ProjectWatchIT method noNotificationForDraftPatchSetsForWatchersInNotifyConfig.
@Test
public void noNotificationForDraftPatchSetsForWatchersInNotifyConfig() throws Exception {
Address addr = new Address("Watcher", "watcher@example.com");
NotifyConfig nc = new NotifyConfig();
nc.addEmail(addr);
nc.setName("team");
nc.setHeader(NotifyConfig.Header.TO);
nc.setTypes(EnumSet.of(NotifyType.NEW_PATCHSETS, NotifyType.ALL_COMMENTS));
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
cfg.putNotifyConfig("team", nc);
saveProjectConfig(project, cfg);
PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), testRepo, "subject", "a", "a1").to("refs/for/master");
r.assertOkStatus();
sender.clear();
r = pushFactory.create(db, admin.getIdent(), testRepo, "subject", "a", "a2", r.getChangeId()).to("refs/for/master%draft");
r.assertOkStatus();
assertThat(sender.getMessages()).isEmpty();
setApiUser(admin);
ReviewInput in = new ReviewInput();
in.message = "comment";
gApi.changes().id(r.getChangeId()).current().review(in);
assertThat(sender.getMessages()).isEmpty();
}
use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.
the class RawMailParser method parse.
/**
* Parses a MailMessage from a string.
*
* @param raw String as received over the wire
* @return Parsed MailMessage
* @throws MailParsingException
*/
public static MailMessage parse(String raw) throws MailParsingException {
MailMessage.Builder messageBuilder = MailMessage.builder();
messageBuilder.rawContentUTF(raw);
Message mimeMessage;
try {
MessageBuilder builder = new DefaultMessageBuilder();
mimeMessage = builder.parseMessage(new ByteArrayInputStream(raw.getBytes(UTF_8)));
} catch (IOException | MimeException e) {
throw new MailParsingException("Can't parse email", e);
}
// Add general headers
if (mimeMessage.getMessageId() != null) {
messageBuilder.id(mimeMessage.getMessageId());
}
if (mimeMessage.getSubject() != null) {
messageBuilder.subject(mimeMessage.getSubject());
}
messageBuilder.dateReceived(new DateTime(mimeMessage.getDate()));
// Add From, To and Cc
if (mimeMessage.getFrom() != null && mimeMessage.getFrom().size() > 0) {
Mailbox from = mimeMessage.getFrom().get(0);
messageBuilder.from(new Address(from.getName(), from.getAddress()));
}
if (mimeMessage.getTo() != null) {
for (Mailbox m : mimeMessage.getTo().flatten()) {
messageBuilder.addTo(new Address(m.getName(), m.getAddress()));
}
}
if (mimeMessage.getCc() != null) {
for (Mailbox m : mimeMessage.getCc().flatten()) {
messageBuilder.addCc(new Address(m.getName(), m.getAddress()));
}
}
// Add additional headers
mimeMessage.getHeader().getFields().stream().filter(f -> !MAIN_HEADERS.contains(f.getName().toLowerCase())).forEach(f -> messageBuilder.addAdditionalHeader(f.getName() + ": " + f.getBody()));
// Add text and html body parts
StringBuilder textBuilder = new StringBuilder();
StringBuilder htmlBuilder = new StringBuilder();
try {
handleMimePart(mimeMessage, textBuilder, htmlBuilder);
} catch (IOException e) {
throw new MailParsingException("Can't parse email", e);
}
messageBuilder.textContent(Strings.emptyToNull(textBuilder.toString()));
messageBuilder.htmlContent(Strings.emptyToNull(htmlBuilder.toString()));
try {
// required attributes are missing, so that the caller doesn't fall over.
return messageBuilder.build();
} catch (IllegalStateException e) {
throw new MailParsingException("Missing required attributes after email was parsed", e);
}
}
use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.
the class RegisterNewEmailSender method init.
@Override
protected void init() throws EmailException {
super.init();
setHeader("Subject", "[Gerrit Code Review] Email Verification");
add(RecipientType.TO, new Address(addr));
}
use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.
the class AttachmentMessage method expectedMailMessage.
@Override
public MailMessage expectedMailMessage() {
System.out.println("😛 test");
MailMessage.Builder expect = MailMessage.builder();
expect.id("<CAM7sg=3meaAVUxW3KXeJEVs8sv_ADw1BnvpcHHiYVR2TQQi__w@mail.gmail.com>").from(new Address("Patrick Hiesel", "hiesel@google.com")).addTo(new Address("Patrick Hiesel", "hiesel@google.com")).textContent("Contains unwanted attachment").htmlContent("<div dir=\"ltr\">Contains unwanted attachment</div>").subject("Test Subject").addAdditionalHeader("MIME-Version: 1.0").dateReceived(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
return expect.build();
}
Aggregations