Search in sources :

Example 76 with Account

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());
}
Also used : Account(com.zimbra.cs.account.Account) EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) Provisioning(com.zimbra.cs.account.Provisioning) LinkedList(java.util.LinkedList) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) Test(org.junit.Test)

Example 77 with Account

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()));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test) MailboxTest(com.zimbra.cs.mailbox.MailboxTest)

Example 78 with Account

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()));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test) MailboxTest(com.zimbra.cs.mailbox.MailboxTest)

Example 79 with Account

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());
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Enumeration(java.util.Enumeration) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) MPartInfo(com.zimbra.cs.mime.MPartInfo) Mailbox(com.zimbra.cs.mailbox.Mailbox) Header(javax.mail.Header) MimeMessage(javax.mail.internet.MimeMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Example 80 with Account

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());
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Header(javax.mail.Header) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Aggregations

Account (com.zimbra.cs.account.Account)1244 Test (org.junit.Test)520 Mailbox (com.zimbra.cs.mailbox.Mailbox)389 OperationContext (com.zimbra.cs.mailbox.OperationContext)292 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)274 Message (com.zimbra.cs.mailbox.Message)255 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)242 Provisioning (com.zimbra.cs.account.Provisioning)222 Element (com.zimbra.common.soap.Element)220 ItemId (com.zimbra.cs.service.util.ItemId)219 ServiceException (com.zimbra.common.service.ServiceException)201 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)158 HashMap (java.util.HashMap)154 Domain (com.zimbra.cs.account.Domain)145 MimeMessage (javax.mail.internet.MimeMessage)104 GuestAccount (com.zimbra.cs.account.GuestAccount)98 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)92 AccountServiceException (com.zimbra.cs.account.AccountServiceException)77 ZMailbox (com.zimbra.client.ZMailbox)72 Header (javax.mail.Header)67