use of com.zimbra.common.zmime.ZMimeMessage in project zm-mailbox by Zimbra.
the class TestContentTransferEncoding method testBug98015.
/*
* Tests that the message from bug 98015 retains the correct Content Transfer Encoding via the mechanism of
* inferring it from the existing message referenced by the "origid" parameter.
* This scenario also happens to test the case when a CTE header on a sub-part is inherited from the top-level.
*/
@Ignore("disabled until bug 98015 is fixed")
@Test
public void testBug98015() throws Exception {
MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(getBug98015MimeString().getBytes()));
ParsedMessage pm = new ParsedMessage(mimeMsg, true);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
Message msg = mbox.addMessage(null, pm, dopt, null);
MsgToSend msgToSend = new MsgToSend();
msgToSend.setOrigId(String.valueOf(msg.getId()));
msgToSend.setReplyType("w");
msgToSend.setSubject("Fwd: QP bug");
msgToSend.setMimePart(MimePartInfo.createForContentTypeAndContent("text/plain", "\n\n----- Forwarded Message -----\nSubject: QP Bug\n\n\\รถ/\nid=577281"));
AttachmentsInfo attach = new AttachmentsInfo();
attach.addAttachment(new MimePartAttachSpec(String.valueOf(msg.getId()), "2"));
msgToSend.setAttachments(attach);
SendMsgRequest req = new SendMsgRequest();
req.setMsg(msgToSend);
MimeMessage parsed = sendForwardedMessage(req, msg);
ZMimeMultipart mmp = (ZMimeMultipart) parsed.getContent();
assertEquals("8bit", mmp.getBodyPart(0).getHeader("Content-Transfer-Encoding")[0]);
assertEquals("base64", mmp.getBodyPart(1).getHeader("Content-Transfer-Encoding")[0]);
}
use of com.zimbra.common.zmime.ZMimeMessage in project zm-mailbox by Zimbra.
the class TestContentTransferEncoding method testMultipartMimeMessage.
/*
* This tests the CTE header of a forwarded message being inferred from the existing message when the message is a multipart message.
*/
@Ignore("disabled until bug 98015 is fixed")
@Test
public void testMultipartMimeMessage() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(getMultipartMimeString().getBytes()));
ParsedMessage pm = new ParsedMessage(mimeMsg, true);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
Message msg = mbox.addMessage(null, pm, dopt, null);
MsgToSend msgToSend = new MsgToSend();
msgToSend.setOrigId(String.valueOf(msg.getId()));
msgToSend.setReplyType("w");
msgToSend.setSubject("Fwd: Multipart Test");
MimePartInfo mpi = new MimePartInfo();
mpi.setContentType("multipart/alternative");
List<MimePartInfo> mimeParts = new LinkedList<MimePartInfo>();
mimeParts.add(MimePartInfo.createForContentTypeAndContent("text/plain", "multipart test"));
mimeParts.add(MimePartInfo.createForContentTypeAndContent("text/html", "multipart test"));
mpi.setMimeParts(mimeParts);
msgToSend.setMimePart(mpi);
SendMsgRequest req = new SendMsgRequest();
req.setMsg(msgToSend);
MimeMessage parsed = sendForwardedMessage(req, msg);
ZMimeMultipart mmp = (ZMimeMultipart) parsed.getContent();
assertEquals("test1", mmp.getBodyPart(0).getHeader("Content-Transfer-Encoding")[0]);
assertEquals("test2", mmp.getBodyPart(1).getHeader("Content-Transfer-Encoding")[0]);
}
use of com.zimbra.common.zmime.ZMimeMessage in project zm-mailbox by Zimbra.
the class SpamExtract method writeAttachedMessages.
private static void writeAttachedMessages(MimeMessage mm, File outdir, String msgUri) throws IOException, MessagingException {
// Not raw - ignore the spam report and extract messages that are in attachments...
if (!(mm.getContent() instanceof MimeMultipart)) {
LOG.warn("Spam/notspam messages must have attachments (skipping " + msgUri + ")");
return;
}
MimeMultipart mmp = (MimeMultipart) mm.getContent();
int nAttachments = mmp.getCount();
boolean foundAtleastOneAttachedMessage = false;
for (int i = 0; i < nAttachments; i++) {
BodyPart bp = mmp.getBodyPart(i);
if (!bp.isMimeType("message/rfc822")) {
// Let's ignore all parts that are not messages.
continue;
}
foundAtleastOneAttachedMessage = true;
// the actual message
Part msg = (Part) bp.getContent();
File file = new File(outdir, mOutputPrefix + "-" + mExtractIndex++);
OutputStream os = null;
try {
os = new BufferedOutputStream(new FileOutputStream(file));
if (msg instanceof MimeMessage) {
//bug 74435 clone into newMsg so our parser has a chance to handle headers which choke javamail
ZMimeMessage newMsg = new ZMimeMessage((MimeMessage) msg);
newMsg.writeTo(os);
} else {
msg.writeTo(os);
}
} finally {
os.close();
}
if (verbose)
LOG.info("Wrote: " + file);
}
if (!foundAtleastOneAttachedMessage) {
String msgid = mm.getHeader("Message-ID", " ");
LOG.warn("message uri=" + msgUri + " message-id=" + msgid + " had no attachments");
}
}
use of com.zimbra.common.zmime.ZMimeMessage in project zm-mailbox by Zimbra.
the class TestImapClient method newTestMessage.
private static MimeMessage newTestMessage(int num) throws MessagingException {
MimeMessage mm = new ZMimeMessage(JMSession.getSession());
mm.setHeader("Message-Id", "<test-" + num + "@foo.com>");
mm.setHeader("To", "nobody@foo.com");
mm.setHeader("From", "nobody@bar.com");
mm.setSubject("Test message " + num);
mm.setSentDate(new Date(System.currentTimeMillis()));
mm.setContent("This is test message " + num, "text/plain");
return mm;
}
use of com.zimbra.common.zmime.ZMimeMessage in project zm-mailbox by Zimbra.
the class TestSmtpClient method testMimeMessage.
@Test
public void testMimeMessage() throws Exception {
TestUtil.createAccount(USER_NAME);
TestUtil.createAccount(USER2_NAME);
// Assemble the message.
MimeMessage mm = new ZMimeMessage(JMSession.getSession());
InternetAddress addr = new JavaMailInternetAddress(TestUtil.getAddress(USER_NAME));
mm.setFrom(addr);
mm.setRecipient(RecipientType.TO, addr);
String subject = NAME_PREFIX + " testMimeMessage";
mm.setSubject(subject);
mm.setText("testMimeMessage");
mm.saveChanges();
// Initialize SMTP client.
SmtpConfig config = new SmtpConfig(mHost, mPort, "localhost");
SmtpConnection conn = new SmtpConnection(config);
conn.sendMessage(mm);
// Make sure it arrived.
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
// Send the same message to a different envelope recipient.
conn.sendMessage(addr.getAddress(), new String[] { TestUtil.getAddress(USER2_NAME) }, mm);
mbox = TestUtil.getZMailbox(USER2_NAME);
TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
}
Aggregations