use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class DbVolumeBlobsTest method blobsByMbox.
@Test
public void blobsByMbox() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
DeliveryOptions opt = new DeliveryOptions();
opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
ParsedMessage pm = new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false);
Message msg = mbox.addMessage(null, pm, opt, null);
Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
DbVolumeBlobs.addBlobReference(conn, mbox, vol, msg);
String digest = msg.getBlob().getDigest();
String path = msg.getBlob().getLocalBlob().getFile().getPath();
List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
Assert.assertEquals(1, blobs.size());
Assert.assertEquals(path, getPath(blobs.get(0)));
Account acct2 = Provisioning.getInstance().getAccount("test2@zimbra.com");
Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
Message msg2 = mbox2.addMessage(null, pm, opt, null);
DbVolumeBlobs.addBlobReference(conn, mbox2, vol, msg2);
blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
Set<String> paths = new HashSet<String>();
paths.add(path);
paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
Assert.assertEquals(2, blobs.size());
for (BlobReference ref : blobs) {
Assert.assertTrue(paths.remove(getPath(ref)));
}
Assert.assertTrue(paths.isEmpty());
DbVolumeBlobs.deleteBlobRef(conn, mbox);
blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
Assert.assertEquals(1, blobs.size());
BlobReference ref = blobs.get(0);
path = msg2.getBlob().getLocalBlob().getFile().getPath();
Assert.assertEquals(path, getPath(ref));
Assert.assertEquals(mbox2.getId(), ref.getMailboxId());
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class DbVolumeBlobsTest method dumpsterBlobs.
@Test
public void dumpsterBlobs() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
DeliveryOptions opt = new DeliveryOptions();
opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
Map<String, String> digestToPath = new HashMap<String, String>();
Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
for (int i = 0; i < 10; i++) {
Message msg = mbox.addMessage(null, new ParsedMessage(("From: from" + i + "@zimbra.com\r\nTo: to1@zimbra.com").getBytes(), false), opt, null);
digestToPath.put(msg.getDigest(), msg.getBlob().getLocalBlob().getFile().getPath());
mbox.delete(null, msg.getId(), msg.getType());
}
mbox.emptyFolder(null, Mailbox.ID_FOLDER_TRASH, false);
Iterable<MailboxBlobInfo> allBlobs = null;
allBlobs = DbMailItem.getAllBlobs(conn, mbox.getSchemaGroupId(), vol.getId(), -1, -1);
for (MailboxBlobInfo info : allBlobs) {
DbVolumeBlobs.addBlobReference(conn, info);
}
List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, vol);
Assert.assertEquals(digestToPath.size(), blobs.size());
for (BlobReference blob : blobs) {
String path = digestToPath.remove(blob.getDigest());
Assert.assertNotNull(path);
Assert.assertEquals(path, getPath(blob));
}
Assert.assertTrue(digestToPath.isEmpty());
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class TestContentTransferEncoding method testSimpleMimeMessage.
/*
* This tests the CTE header of a forwarded message being inferred from the existing message when the message is a simple MIME message
*/
@Ignore("disabled until bug 98015 is fixed")
@Test
public void testSimpleMimeMessage() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(getSimpleMimeString().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: Simple Test");
msgToSend.setMimePart(MimePartInfo.createForContentTypeAndContent("text/plain", "simple test"));
SendMsgRequest req = new SendMsgRequest();
req.setMsg(msgToSend);
MimeMessage parsed = sendForwardedMessage(req, msg);
assertEquals("test", parsed.getHeader("Content-Transfer-Encoding")[0]);
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class TestContentTransferEncoding method testNestedMultipartMessage.
/*
* Tests bug 103193, which is a regression introduced by bugfix for 98015.
* The problem seems to be that the MIME structure of the forwarded message doesn't match the structure
* of the original, which is assumed by the bugfix. Specifically, it lacks the top-level multipart/mixed parent.
*/
@Test
public void testNestedMultipartMessage() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(getNestedMimeString().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", "text content"));
mimeParts.add(MimePartInfo.createForContentTypeAndContent("text/html", "html content"));
mpi.setMimeParts(mimeParts);
msgToSend.setMimePart(mpi);
SendMsgRequest req = new SendMsgRequest();
req.setMsg(msgToSend);
try {
MimeMessage parsed = sendForwardedMessage(req, msg);
} catch (ArrayIndexOutOfBoundsException e) {
fail("could not build MIME message");
}
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class FlaggedTestTest method existing.
@Test
public void existing() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
OperationContext octx = new OperationContext(mbox);
Message msg = mbox.addMessage(octx, new ParsedMessage("From: sender@zimbra.com\nTo: test@zimbra.com\nSubject: test".getBytes(), false), new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_PRIORITY), new DeliveryContext());
boolean filtered = RuleManager.applyRulesToExistingMessage(new OperationContext(mbox), mbox, msg.getId(), RuleManager.parse("if flagged \"priority\" { stop; }\n" + "if header :contains \"Subject\" \"test\" { fileinto \"test\"; }"));
Assert.assertEquals(false, filtered);
Assert.assertEquals(Mailbox.ID_FOLDER_INBOX, mbox.getMessageById(octx, msg.getId()).getFolderId());
}
Aggregations