use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class DbVolumeBlobsTest method blobsByVolume.
@Test
public void blobsByVolume() 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 volPath = vol.getRootPath().replace("store", "store2");
File volFile = new File(volPath);
volFile.mkdirs();
Volume vol2 = Volume.builder().setPath(volFile.getAbsolutePath(), true).setType(Volume.TYPE_MESSAGE).setName("volume2").build();
vol2 = VolumeManager.getInstance().create(vol2);
VolumeManager.getInstance().setCurrentVolume(Volume.TYPE_MESSAGE, vol2.getId());
Message msg2 = mbox.addMessage(null, pm, opt, null);
DbVolumeBlobs.addBlobReference(conn, mbox, vol2, msg2);
String digest = msg.getBlob().getDigest();
//add same msg to two different volumes
List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, vol);
Assert.assertEquals(1, blobs.size());
Set<String> paths = new HashSet<String>();
paths.add(msg.getBlob().getLocalBlob().getFile().getPath());
for (BlobReference ref : blobs) {
Assert.assertTrue(paths.remove(getPath(ref)));
Assert.assertEquals(vol.getId(), ref.getVolumeId());
}
blobs = DbVolumeBlobs.getBlobReferences(conn, vol2);
Assert.assertEquals(1, blobs.size());
paths = new HashSet<String>();
paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
for (BlobReference ref : blobs) {
Assert.assertTrue(paths.remove(getPath(ref)));
Assert.assertEquals(vol2.getId(), ref.getVolumeId());
}
blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
paths = new HashSet<String>();
paths.add(msg.getBlob().getLocalBlob().getFile().getPath());
Assert.assertEquals(1, blobs.size());
for (BlobReference ref : blobs) {
Assert.assertTrue(paths.remove(getPath(ref)));
}
blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol2);
paths = new HashSet<String>();
paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
Assert.assertEquals(1, blobs.size());
for (BlobReference ref : blobs) {
Assert.assertTrue(paths.remove(getPath(ref)));
}
//delete from vol1
DbVolumeBlobs.deleteBlobRef(conn, vol);
blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol2);
paths = new HashSet<String>();
paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
Assert.assertEquals(1, blobs.size());
for (BlobReference ref : blobs) {
Assert.assertTrue(paths.remove(getPath(ref)));
}
blobs = DbVolumeBlobs.getBlobReferences(conn, vol);
Assert.assertEquals(0, blobs.size());
blobs = DbVolumeBlobs.getBlobReferences(conn, vol2);
Assert.assertEquals(1, blobs.size());
paths = new HashSet<String>();
paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
for (BlobReference ref : blobs) {
Assert.assertTrue(paths.remove(getPath(ref)));
}
blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol2);
paths = new HashSet<String>();
paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
Assert.assertEquals(1, blobs.size());
for (BlobReference ref : blobs) {
Assert.assertTrue(paths.remove(getPath(ref)));
}
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class ConversationTestTest method started.
@Test
public void started() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if conversation :where \"started\" { tag \"started\"; }");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
mbox.addMessage(new OperationContext(mbox), new ParsedMessage("From: test1@zimbra.com\nSubject: test".getBytes(), false), MailboxTest.STANDARD_DELIVERY_OPTIONS, new DeliveryContext());
DeliveryOptions dopt = new DeliveryOptions();
dopt.setFolderId(Mailbox.ID_FOLDER_SENT);
dopt.setFlags(Flag.BITMASK_FROM_ME);
mbox.addMessage(new OperationContext(mbox), new ParsedMessage("From: test@zimbra.com\nSubject: Re: test".getBytes(), false), dopt, new DeliveryContext());
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@zimbra.com\nSubject: Re: test".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals(0, msg.getTags().length);
dopt = new DeliveryOptions();
dopt.setFolderId(Mailbox.ID_FOLDER_SENT);
dopt.setFlags(Flag.BITMASK_FROM_ME);
mbox.addMessage(new OperationContext(mbox), new ParsedMessage("From: test@zimbra.com\nSubject: test1".getBytes(), false), dopt, new DeliveryContext());
ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@zimbra.com\nSubject: Re: test1".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("started", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class ConversationTestTest method participated.
@Test
public void participated() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if conversation :where \"participated\" { tag \"participated\"; }");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
mbox.addMessage(new OperationContext(mbox), new ParsedMessage("From: test1@zimbra.com\nSubject: test".getBytes(), false), MailboxTest.STANDARD_DELIVERY_OPTIONS, new DeliveryContext());
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@zimbra.com\nSubject: Re: test".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals(0, msg.getTags().length);
DeliveryOptions dopt = new DeliveryOptions();
dopt.setFolderId(Mailbox.ID_FOLDER_SENT);
dopt.setFlags(Flag.BITMASK_FROM_ME);
mbox.addMessage(new OperationContext(mbox), new ParsedMessage("From: test@zimbra.com\nSubject: Re: test".getBytes(), false), dopt, new DeliveryContext());
ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@zimbra.com\nSubject: Re: test".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("participated", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class DeleteHeaderTest method testDeleteHeaderXTestHeaderAll.
/*
* Delete all X-Test-Header
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteHeaderXTestHeaderAll() {
String[] expected = { "Received: from edge01e.zimbra.com ([127.0.0.1])\r\n" + "\tby localhost (edge01e.zimbra.com [127.0.0.1]) (amavisd-new, port 10032)\r\n" + "\twith ESMTP id DN6rfD1RkHD7; Fri, 24 Jun 2016 01:45:31 -0400 (EDT)", "Received: from localhost (localhost [127.0.0.1])\r\n" + "\tby edge01e.zimbra.com (Postfix) with ESMTP id 9245B13575C;\r\n" + "\tFri, 24 Jun 2016 01:45:31 -0400 (EDT)", "X-Test-Header-non-ascii: =?utf-8?B?5pel5pys6Kqe44Gu5Lu25ZCN?=", "X-Numeric-Header: 2", "X-Numeric-Header: 3", "X-Numeric-Header: 4", "X-Dummy-Header: ABC", "X-Dummy-Header: 123", "X-Dummy-Header: abc", "X-Dummy-Header: \"\"", "X-Dummy-Header: xyz", "X-Dummy-Header: ", "X-Dummy-Header: test", "X-Dummy-Header: ''", "X-Dummy-Header: a1b2c3", "from: test2@zimbra.com", "Subject: example", "to: test@zimbra.com", "Content-Transfer-Encoding: 7bit", "MIME-Version: 1.0", "Message-ID:" };
try {
String filterScript = "require [\"editheader\"];\n" + " deleteheader \"X-Test-Header\" \r\n" + " ;\n";
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
RuleManager.clearCachedRules(acct1);
acct1.setMailSieveScript(filterScript);
RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleBaseMsg.getBytes(), false), 0, acct1.getName(), null, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Integer itemId = mbox1.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message message = mbox1.getMessageById(null, itemId);
boolean headerDeleted = true;
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements(); ) {
Header temp = enumeration.nextElement();
if ("X-Test-Header".equals(temp.getName())) {
headerDeleted = false;
break;
}
}
Assert.assertTrue(headerDeleted);
// Verify the order of the message header
MimeMessage mm = message.getMimeMessage();
List<MPartInfo> parts = Mime.getParts(mm);
Set<MPartInfo> bodies = Mime.getBody(parts, false);
Assert.assertEquals(1, bodies.size());
for (MPartInfo body : bodies) {
Enumeration e = body.getMimePart().getAllHeaderLines();
int i = 0;
while (e.hasMoreElements()) {
String header = (String) e.nextElement();
if (header.startsWith("Message-ID:")) {
header = "Message-ID:";
}
Assert.assertEquals(expected[i++], header);
}
}
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class DeleteHeaderTest method testDeleteHeaderUsingMatchesWildcardNonASCII.
/*
* Delete header using matches wild-card
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteHeaderUsingMatchesWildcardNonASCII() {
try {
String filterScript = "require [\"editheader\"];\n" + "deleteheader :matches \"X-Test-Header-non-ascii\" \"*\";\n";
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
RuleManager.clearCachedRules(acct1);
acct1.setMailSieveScript(filterScript);
RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleBaseMsg.getBytes(), false), 0, acct1.getName(), null, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Integer itemId = mbox1.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message message = mbox1.getMessageById(null, itemId);
boolean matchFound = false;
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements(); ) {
Header header = enumeration.nextElement();
if ("X-Test-Header-non-ascii".equals(header.getName())) {
matchFound = true;
break;
}
}
Assert.assertFalse(matchFound);
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
Aggregations