use of com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart in project zm-mailbox by Zimbra.
the class TestDraftCount method testSomeDraftsHaveRecipients.
@Test
public void testSomeDraftsHaveRecipients() throws Exception {
for (int i = 0; i < numMsgs; i++) {
ZOutgoingMessage msg = new ZOutgoingMessage();
msg.setMessagePart(new MessagePart("text/plain", "test body " + i));
msg.setSubject("test message " + i);
List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
if (i % 2 == 0) {
addresses.add(new ZEmailAddress("testuser" + i, null, null, "t"));
msg.setAddresses(addresses);
}
ZMessage saved = mbox.saveDraft(msg, null, "6");
}
checkMessageCount("in:drafts", numMsgs);
deleteFromQuery("in:drafts");
}
use of com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart in project zm-mailbox by Zimbra.
the class TestDraftCount method testAllDraftsHaveRecipients.
@Test
public void testAllDraftsHaveRecipients() throws Exception {
for (int i = 0; i < numMsgs; i++) {
ZOutgoingMessage msg = new ZOutgoingMessage();
msg.setMessagePart(new MessagePart("text/plain", "test body " + i));
msg.setSubject("test message " + i);
List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
addresses.add(new ZEmailAddress("testuser" + i, null, null, "t"));
msg.setAddresses(addresses);
ZMessage saved = mbox.saveDraft(msg, null, "6");
}
checkMessageCount("in:drafts", numMsgs);
deleteFromQuery("in:drafts");
}
use of com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart in project zm-mailbox by Zimbra.
the class TestMessageIntercept method testIntercept.
public void testIntercept() throws Exception {
// Turn on legal intercept for recipient account
String interceptorAddress = TestUtil.getAddress(INTERCEPTOR1_NAME);
String senderAddress = TestUtil.getAddress(SENDER_NAME);
TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptAddress, interceptorAddress);
TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptSendHeadersOnly, LdapConstants.LDAP_FALSE);
// Send message to recipient account and make sure it's intercepted
ZMailbox interceptorMbox = TestUtil.getZMailbox(INTERCEPTOR1_NAME);
ZMailbox tappedMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
String tappedAddress = TestUtil.getAddress(RECIPIENT_NAME);
String subject = NAME_PREFIX + " testIntercept-receive";
TestUtil.addMessageLmtp(subject, tappedAddress, senderAddress);
ZMessage tappedMsg = TestUtil.getMessage(tappedMbox, "subject:\"" + subject + "\"");
ZMessage interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:\"" + subject + "\"");
verifyInterceptMessage(interceptMsg, "add message", "Inbox", Integer.toString(Mailbox.ID_FOLDER_INBOX));
compareContent(tappedMbox, tappedMsg, interceptorMbox, interceptMsg);
// Confirm that saving a draft is intercepted. The first draft calls Mailbox.addMessage().
ZOutgoingMessage outgoing = new ZOutgoingMessage();
List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
addresses.add(new ZEmailAddress(TestUtil.getAddress(INTERCEPTOR1_NAME), null, null, ZEmailAddress.EMAIL_TYPE_TO));
outgoing.setAddresses(addresses);
subject = NAME_PREFIX + " testIntercept-draft-1";
outgoing.setSubject(subject);
outgoing.setMessagePart(new MessagePart("text/plain", "I always feel like somebody's watching me."));
tappedMbox.saveDraft(outgoing, null, Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
tappedMsg = TestUtil.getMessage(tappedMbox, "in:drafts subject:\"" + subject + "\"");
interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:\"" + subject + "\"");
verifyInterceptMessage(interceptMsg, "add message", "Drafts", Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
compareContent(tappedMbox, tappedMsg, interceptorMbox, interceptMsg);
// Save draft again. This time Mailbox.saveDraft() gets called.
ZMessage draft = TestUtil.getMessage(tappedMbox, "in:drafts subject:\"" + subject + "\"");
subject = NAME_PREFIX + " testIntercept-draft-2";
outgoing.setSubject(subject);
tappedMbox.saveDraft(outgoing, draft.getId(), null);
tappedMsg = TestUtil.getMessage(tappedMbox, "in:drafts subject:\"" + subject + "\"");
interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:\"" + subject + "\"");
verifyInterceptMessage(interceptMsg, "save draft", "Drafts", Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
compareContent(tappedMbox, tappedMsg, interceptorMbox, interceptMsg);
// Send message with save-to-sent turned on.
TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraPrefSaveToSent, LdapConstants.LDAP_TRUE);
subject = NAME_PREFIX + " testIntercept-send-1";
TestUtil.sendMessage(tappedMbox, INTERCEPTOR1_NAME, subject);
tappedMsg = TestUtil.waitForMessage(tappedMbox, "in:sent subject:\"" + subject + "\"");
interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:intercepted subject:\"" + subject + "\"");
verifyInterceptMessage(interceptMsg, "add message", "Sent", Integer.toString(Mailbox.ID_FOLDER_SENT));
compareContent(tappedMbox, tappedMsg, interceptorMbox, interceptMsg);
// Send message with save-to-sent turned off.
TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraPrefSaveToSent, LdapConstants.LDAP_FALSE);
subject = NAME_PREFIX + " testIntercept-send-2";
TestUtil.sendMessage(tappedMbox, INTERCEPTOR1_NAME, subject);
interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:intercepted subject:\"" + subject + "\"");
verifyInterceptMessage(interceptMsg, "send message", "none", "none");
// Check intercepting headers only.
TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptSendHeadersOnly, LdapConstants.LDAP_TRUE);
subject = NAME_PREFIX + " testIntercept-headers-only";
TestUtil.sendMessage(interceptorMbox, RECIPIENT_NAME, subject);
tappedMsg = TestUtil.waitForMessage(tappedMbox, "in:inbox subject:\"" + subject + "\"");
interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:intercepted subject:\"" + subject + "\"");
verifyInterceptMessage(interceptMsg, "add message", "Inbox", Integer.toString(Mailbox.ID_FOLDER_INBOX));
compareContent(tappedMbox, tappedMsg, interceptorMbox, interceptMsg);
}
use of com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart in project zm-mailbox by Zimbra.
the class TestDraftCount method testMixedFolderCount.
@Test
public void testMixedFolderCount() throws Exception {
//some inbox messages
for (int i = 0; i < numMsgs; i++) {
TestUtil.addMessage(mbox, "test content " + i, "2");
}
//and some drafts, some of which have no recipients
for (int i = 0; i < numMsgs; i++) {
ZOutgoingMessage msg = new ZOutgoingMessage();
msg.setMessagePart(new MessagePart("text/plain", "test body " + i));
msg.setSubject("test message " + i);
List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
if (i % 2 == 0) {
addresses.add(new ZEmailAddress("testuser" + i, null, null, "t"));
msg.setAddresses(addresses);
}
ZMessage saved = mbox.saveDraft(msg, null, "6");
}
checkMessageCount("in:inbox OR in:drafts", numMsgs * 2);
deleteFromQuery("in:inbox OR in:drafts");
}
use of com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart in project zm-mailbox by Zimbra.
the class TestSendAndReceive method testMalformedContentType.
/**
* Confirms that we can forward attachments with a malformed content type (bug 42452).
*/
@Test
public void testMalformedContentType() throws Exception {
TestUtil.createAccount(USER_NAME);
// Generate original message.
String subject = NAME_PREFIX + " testMalformedContentType";
MessageBuilder builder = new MessageBuilder().withFrom(USER_NAME).withToRecipient(USER_NAME).withSubject(subject).withAttachment("This is an attachment", "test.txt", MimeConstants.CT_TEXT_PLAIN);
// Hack Content-Type so that it's invalid.
BufferedReader reader = new BufferedReader(new StringReader(builder.create()));
StringBuilder msgBuf = new StringBuilder();
String line = reader.readLine();
boolean replaced = false;
while (line != null) {
if (line.matches("Content-Type.*test.txt.*")) {
line = line.replace("Content-Type: text/plain;", "Content-Type: text/plain;;");
Assert.assertTrue("Unexpected line: " + line, line.contains(";;"));
replaced = true;
}
msgBuf.append(line).append("\r\n");
line = reader.readLine();
}
Assert.assertTrue("Could not find text/plain attachment.", replaced);
// Add message to the mailbox.
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, msgBuf.toString());
// Forward the attachment in a new message.
ZMessage srcMsg = TestUtil.getMessage(mbox, "subject:\"" + subject + "\"");
ZMimePart srcAttachPart = srcMsg.getMimeStructure().getChildren().get(1);
Assert.assertEquals("test.txt", srcAttachPart.getFileName());
ZOutgoingMessage outgoing = new ZOutgoingMessage();
outgoing.setMessagePart(new MessagePart(MimeConstants.CT_TEXT_PLAIN, "Forwarding attachment."));
outgoing.setMessagePartsToAttach(Arrays.asList(new AttachedMessagePart(srcMsg.getId(), srcAttachPart.getPartName(), null)));
String address = TestUtil.getAddress(USER_NAME);
ZEmailAddress sender = new ZEmailAddress(address, null, null, ZEmailAddress.EMAIL_TYPE_FROM);
ZEmailAddress recipient = new ZEmailAddress(address, null, null, ZEmailAddress.EMAIL_TYPE_TO);
outgoing.setAddresses(Arrays.asList(sender, recipient));
String fwdSubject = NAME_PREFIX + " testMalformedContentType forward";
outgoing.setSubject(fwdSubject);
mbox.sendMessage(outgoing, null, false);
// Make sure the forwarded message arrives.
ZMessage fwd = TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + fwdSubject + "\"");
ZMimePart fwdAttachPart = fwd.getMimeStructure().getChildren().get(1);
Assert.assertEquals("test.txt", fwdAttachPart.getFileName());
}
Aggregations