Search in sources :

Example 1 with StringEmailHeader

use of com.google.gerrit.entities.EmailHeader.StringEmailHeader in project gerrit by GerritCodeReview.

the class MailSenderIT method headerString.

private String headerString(Map<String, EmailHeader> headers, String name) {
    EmailHeader header = headers.get(name);
    assertThat(header).isInstanceOf(StringEmailHeader.class);
    return ((StringEmailHeader) header).getString();
}
Also used : StringEmailHeader(com.google.gerrit.entities.EmailHeader.StringEmailHeader) EmailHeader(com.google.gerrit.entities.EmailHeader) StringEmailHeader(com.google.gerrit.entities.EmailHeader.StringEmailHeader)

Example 2 with StringEmailHeader

use of com.google.gerrit.entities.EmailHeader.StringEmailHeader in project gerrit by GerritCodeReview.

the class MailProcessorIT method validateChangeMessage_rejected.

@Test
public void validateChangeMessage_rejected() throws Exception {
    String changeId = createChangeWithReview();
    ChangeInfo changeInfo = gApi.changes().id(changeId).get();
    String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(gApi.changes().id(changeId).get().updated.toInstant(), ZoneId.of("UTC")));
    setupFailValidation(CommentForValidation.CommentType.CHANGE_MESSAGE, changeInfo.project, changeInfo._number);
    MailMessage.Builder b = messageBuilderWithDefaultFields();
    String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", COMMENT_TEXT, null, null);
    b.textContent(txt + textFooterForChange(changeInfo._number, ts));
    List<CommentInfo> commentsBefore = testCommentHelper.getPublishedComments(changeId);
    mailProcessor.process(b.build());
    assertThat(testCommentHelper.getPublishedComments(changeId)).isEqualTo(commentsBefore);
    assertNotifyTo(user);
    Message message = sender.nextMessage();
    assertThat(message.body()).contains("rejected one or more comments");
    // ensure the message header contains a valid message id.
    assertThat(((StringEmailHeader) message.headers().get("Message-ID")).getString()).containsMatch("<someid-REJECTION-HTML@" + new URL(canonicalWebUrl.get()).getHost() + ">");
}
Also used : MailMessage(com.google.gerrit.mail.MailMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) MailMessage(com.google.gerrit.mail.MailMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) StringEmailHeader(com.google.gerrit.entities.EmailHeader.StringEmailHeader) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) URL(java.net.URL) Test(org.junit.Test)

Example 3 with StringEmailHeader

use of com.google.gerrit.entities.EmailHeader.StringEmailHeader in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method assertMailNotReplyTo.

protected void assertMailNotReplyTo(Message message, String email) throws Exception {
    assertThat(message.headers()).containsKey("Reply-To");
    StringEmailHeader replyTo = (StringEmailHeader) message.headers().get("Reply-To");
    assertThat(replyTo.getString()).doesNotContain(email);
}
Also used : StringEmailHeader(com.google.gerrit.entities.EmailHeader.StringEmailHeader)

Example 4 with StringEmailHeader

use of com.google.gerrit.entities.EmailHeader.StringEmailHeader in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method assertMailReplyTo.

protected void assertMailReplyTo(Message message, String email) throws Exception {
    assertThat(message.headers()).containsKey("Reply-To");
    StringEmailHeader replyTo = (StringEmailHeader) message.headers().get("Reply-To");
    assertThat(replyTo.getString()).contains(email);
}
Also used : StringEmailHeader(com.google.gerrit.entities.EmailHeader.StringEmailHeader)

Example 5 with StringEmailHeader

use of com.google.gerrit.entities.EmailHeader.StringEmailHeader in project gerrit by GerritCodeReview.

the class OutgoingEmail method addMessageId.

// All message ids must start with < and end with >. Also, they must have @domain and no spaces.
private void addMessageId(OutgoingEmailValidationListener.Args va, String suffix) {
    if (messageId != null) {
        String message = "<" + messageId.id() + suffix + "@" + getGerritHost() + ">";
        message = message.replaceAll("\\s", "");
        va.headers.put(FieldName.MESSAGE_ID, new StringEmailHeader(message));
    }
}
Also used : StringEmailHeader(com.google.gerrit.entities.EmailHeader.StringEmailHeader)

Aggregations

StringEmailHeader (com.google.gerrit.entities.EmailHeader.StringEmailHeader)5 EmailHeader (com.google.gerrit.entities.EmailHeader)1 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)1 MailMessage (com.google.gerrit.mail.MailMessage)1 Message (com.google.gerrit.testing.FakeEmailSender.Message)1 URL (java.net.URL)1 Test (org.junit.Test)1