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();
}
}
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();
}
}
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);
}
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());
}
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();
}
Aggregations