Search in sources :

Example 1 with Literal

use of com.zimbra.cs.mailclient.imap.Literal in project zm-mailbox by Zimbra.

the class ImapAppender method append.

private long append(MessageInfo mi) throws IOException, ServiceException {
    InputStream is = mi.data.getInputStream();
    Literal lit = new Literal(is, mi.data.getSize());
    try {
        return hasAppendUid ? append(mi, lit) : appendSlow(mi, lit);
    } catch (MessagingException e) {
        throw ServiceException.FAILURE("Parsing error", e);
    } finally {
        is.close();
    }
}
Also used : MessagingException(javax.mail.MessagingException) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) InputStream(java.io.InputStream) Literal(com.zimbra.cs.mailclient.imap.Literal)

Example 2 with Literal

use of com.zimbra.cs.mailclient.imap.Literal in project zm-mailbox by Zimbra.

the class TestImapClient method uidAppend.

private long uidAppend(MimeMessage msg, Flags flags, Date date) throws IOException {
    String name = connection.getMailboxInfo().getName();
    File tmp = null;
    OutputStream os = null;
    try {
        File dir = connection.getImapConfig().getLiteralDataDir();
        tmp = File.createTempFile("lit", null, dir);
        os = new FileOutputStream(tmp);
        msg.writeTo(os);
        os.close();
        AppendResult res = connection.append(name, flags, date, new Literal(tmp));
        return res != null ? res.getUid() : -1;
    } catch (MessagingException e) {
        throw new MailException("Error appending message", e);
    } finally {
        if (os != null)
            os.close();
        if (tmp != null)
            tmp.delete();
    }
}
Also used : MessagingException(javax.mail.MessagingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Literal(com.zimbra.cs.mailclient.imap.Literal) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) MailException(com.zimbra.cs.mailclient.MailException) File(java.io.File)

Example 3 with Literal

use of com.zimbra.cs.mailclient.imap.Literal in project zm-mailbox by Zimbra.

the class TestImapClient method testAppend.

@Test
public void testAppend() throws Exception {
    login();
    MailboxInfo mb = connection.select("INBOX");
    long exists = mb.getExists();
    Date date = new Date((System.currentTimeMillis() / 1000) * 1000);
    Flags flags = Flags.fromSpec("fs");
    AppendResult res = connection.append("INBOX", Flags.fromSpec("fs"), date, new Literal(Ascii.getBytes(MESSAGE)));
    assertNotNull(res);
    mb = connection.select("INBOX");
    assertEquals(1, mb.getExists() - exists);
    MessageData md = connection.uidFetch(res.getUid(), "(FLAGS BODY.PEEK[] INTERNALDATE)");
    assertNotNull(md);
    assertEquals(date, md.getInternalDate());
    assertEquals(res.getUid(), md.getUid());
    assertEquals(flags, md.getFlags());
    Body[] parts = md.getBodySections();
    assertNotNull(parts);
    assertEquals(1, parts.length);
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) Literal(com.zimbra.cs.mailclient.imap.Literal) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Flags(com.zimbra.cs.mailclient.imap.Flags) Body(com.zimbra.cs.mailclient.imap.Body) Date(java.util.Date) Test(org.junit.Test)

Example 4 with Literal

use of com.zimbra.cs.mailclient.imap.Literal in project zm-mailbox by Zimbra.

the class TestImapClient method testDelete.

@Test
public void testDelete() throws Exception {
    login();
    MailboxInfo mb = connection.select("INBOX");
    long exists = mb.getExists();
    AppendResult res = connection.append("INBOX", Flags.fromSpec("fs"), new Date(System.currentTimeMillis()), new Literal(Ascii.getBytes(MESSAGE)));
    assertNotNull(res);
    mb = connection.select("INBOX");
    assertEquals(exists, mb.getExists() - 1);
    connection.uidStore(String.valueOf(res.getUid()), "+FLAGS.SILENT", Flags.fromSpec("d"));
    mb = connection.select("INBOX");
    assertEquals(exists, mb.getExists() - 1);
    connection.expunge();
    mb = connection.select("INBOX");
    assertEquals(exists, mb.getExists());
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Date(java.util.Date) Test(org.junit.Test)

Example 5 with Literal

use of com.zimbra.cs.mailclient.imap.Literal in project zm-mailbox by Zimbra.

the class TestImap method appendInvalidFlag.

private void appendInvalidFlag(String flag) throws IOException {
    Literal msg = message(10);
    Flags flags = Flags.fromSpec("afs");
    flags.set(flag);
    Date date = new Date(System.currentTimeMillis());
    try {
        AppendResult res = connection.append("INBOX", flags, date, msg);
        fail("server allowed client to set system flag " + flag);
    } catch (CommandFailedException e) {
    //expected
    } finally {
        msg.dispose();
    }
    //do a no-op so we don't hit max consecutive error limit
    connection.noop();
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.sql.Date) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException)

Aggregations

Literal (com.zimbra.cs.mailclient.imap.Literal)17 Flags (com.zimbra.cs.mailclient.imap.Flags)12 Test (org.junit.Test)12 Date (java.sql.Date)11 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)9 AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)6 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)4 File (java.io.File)3 ServiceException (com.zimbra.common.service.ServiceException)2 MessageData (com.zimbra.cs.mailclient.imap.MessageData)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 Date (java.util.Date)2 MessagingException (javax.mail.MessagingException)2 ZFolder (com.zimbra.client.ZFolder)1 ZMailbox (com.zimbra.client.ZMailbox)1 ZTag (com.zimbra.client.ZTag)1 ZSharedFileInputStream (com.zimbra.common.zmime.ZSharedFileInputStream)1 MailException (com.zimbra.cs.mailclient.MailException)1 Body (com.zimbra.cs.mailclient.imap.Body)1