use of com.zimbra.qa.unittest.MessageBuilder in project zm-mailbox by Zimbra.
the class MailSenderTest method updateReferenceHeaders.
@Test
public void updateReferenceHeaders() throws Exception {
MailSender sender = new MailSender();
Provisioning prov = Provisioning.getInstance();
Account account = prov.getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
String from = "sender@example.com";
String to = "recipient@example.com";
String subject = "test subject";
MessageBuilder builder = new MessageBuilder().withFrom(from).withToRecipient(to).withSubject(subject).withBody("test body");
String content = builder.create();
MimeMessage msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
//default
Assert.assertNull(msg.getHeader("Thread-Index"));
Assert.assertNull(msg.getHeader("Thread-Topic"));
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
//technically the normalized subject, but our test message already had normalized subject
Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
//index set by sending agent (bg 96107)
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
String presetIndex = "1234";
msg.setHeader("Thread-Index", presetIndex);
Assert.assertNull(msg.getHeader("Thread-Topic"));
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
//topic set by sending agent (bug 96107)
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
Assert.assertNull(msg.getHeader("Thread-Index"));
String presetTopic = "mytopic";
msg.setHeader("Thread-Topic", presetTopic);
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
//both
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
msg.setHeader("Thread-Topic", presetTopic);
msg.setHeader("Thread-Index", presetIndex);
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
//subject changed from orig parent subject (bug 96954)
String parentSubject = "parent subject";
builder = new MessageBuilder().withFrom(from).withToRecipient(to).withSubject(parentSubject).withBody("parent body");
String parentContent = builder.create();
MimeMessage parentMsg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(parentContent.getBytes()));
sender.updateReferenceHeaders(parentMsg, null, account);
ParsedMessage pm = new ParsedMessage(parentMsg, false);
Message mboxMessage = mbox.addMessage(null, pm, MailboxTest.STANDARD_DELIVERY_OPTIONS, null);
sender = new MailSender();
sender.setOriginalMessageId(new ItemId(mboxMessage));
sender.setReplyType(MailSender.MSGTYPE_REPLY);
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
//keep agent specified topic and/or index even when parent specified
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
msg.setHeader("Thread-Topic", presetTopic);
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
msg.setHeader("Thread-Index", presetIndex);
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
msg.setHeader("Thread-Topic", presetTopic);
msg.setHeader("Thread-Index", presetIndex);
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
}
Aggregations