use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class BulkTestTest method unsubscribe.
@Test
public void unsubscribe() throws Exception {
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox, new ParsedMessage("To: list@zimbra.com\nList-Unsubscribe: test\nSubject: bulk".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mailbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals(0, msg.getTags().length);
ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox, new ParsedMessage("To: test@zimbra.com\nList-Unsubscribe: test\nSubject: bulk".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
msg = mailbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("bulk", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class CommunityTestTest method doRequest.
public void doRequest(String rule, String headerValue, String tag) throws Exception {
account.setMailSieveScript("if " + rule + " { tag \"" + tag + "\"; }");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(("From: \"in.Telligent\" <noreply@in.telligent.com>\n" + "X-Zimbra-Community-Notification-Type: " + headerValue + "\n").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(tag, ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class BodyTest method test.
private void test(String script, String message) throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
account.setMailSieveScript(script);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(message.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.assertTrue(msg.isTagged(FlagInfo.FLAGGED));
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class BulkTestTest method zimbraOOO.
@Test
public void zimbraOOO() throws Exception {
//negative test; don't mark these as bulk
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox, new ParsedMessage("From: sender@zimbra.com\nPrecedence: bulk\nAuto-Submitted: auto-replied (zimbra; vacation)\nSubject: bulk".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mailbox.getMessageById(null, ids.get(0).getId());
Assert.assertNull(ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class AddHeaderTest method testAddHeaderSameHeaderNameMultipleHeaderValues1.
/*
* Add the headers with "X-Dummy-Header: new value"
* Verify that the order of the header fields does not change.
*/
@SuppressWarnings("unchecked")
@Test
public void testAddHeaderSameHeaderNameMultipleHeaderValues1() {
StringBuffer triggeringMsg = new StringBuffer();
for (String line : sampleBaseMsg2) {
triggeringMsg.append(line).append("\r\n");
}
try {
String filterScript = "require [\"editheader\"];\n" + "addheader \"X-Dummy-Header\" \"new value\"; ";
Account account = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(triggeringMsg.toString().getBytes(), false), 0, account.getName(), null, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Enumeration e = msg.getMimeMessage().getAllHeaderLines();
Assert.assertTrue(e.hasMoreElements());
// The 1st and 2nd line of the headers
Assert.assertEquals("Return-Path: user1@domain1.zimbra.com", (String) e.nextElement());
Assert.assertEquals("X-Dummy-Header: new value", (String) e.nextElement());
// The rest of the headers
int index = 1;
while (e.hasMoreElements() && index < sampleBaseMsg2.length) {
String value = (String) e.nextElement();
Assert.assertEquals(sampleBaseMsg2[index++], value);
}
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
Aggregations