use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class MigrateAttributesTest method testMigrateAlreadyMigratedAccount.
@Test
public void testMigrateAlreadyMigratedAccount() throws Exception {
Provisioning prov = Provisioning.getInstance();
//create a new account that will not have any data to migrate
Account acct = prov.createAccount("user2", "test123", new HashMap<String, Object>());
EntrySource source = new DummyEntrySource(acct);
Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
List<EphemeralInput> results = new LinkedList<EphemeralInput>();
List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
DummyMigrationCallback callback = new DummyMigrationCallback(results, deletedAttrs);
callback.throwErrorDuringMigration = false;
AttributeMigration migration = new AttributeMigration(attrsToMigrate, source, callback, null);
migration.migrateAllAccounts();
assertTrue(results.isEmpty());
}
use of com.zimbra.cs.account.Account 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.account.Account 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.account.Account 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.account.Account 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