Search in sources :

Example 1 with MailException

use of com.zimbra.cs.mailclient.MailException 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 2 with MailException

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

the class ImapInputStream method readFetchData.

public Object readFetchData() throws IOException {
    DataHandler handler = getDataHandler();
    if (handler == null) {
        return readNStringData();
    }
    ImapData as = peek() == '{' ? readLiteral(false) : readNStringData();
    try {
        return handler.handleData(as);
    } catch (Throwable e) {
        throw new MailException("Exception in data handler", e);
    } finally {
        if (as.isLiteral()) {
            skipRemaining(as.getInputStream());
        }
    }
}
Also used : MailException(com.zimbra.cs.mailclient.MailException)

Example 3 with MailException

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

the class ImapFolderSync method handleFetch.

private void handleFetch(MessageData md, Map<Long, MessageData> flagsByUid, int folderId, boolean storeSync, boolean restorePurged) throws ServiceException, IOException {
    long uid = md.getUid();
    if (uid == -1) {
        throw new MailException("Missing UID in FETCH response");
    }
    MessageData flagsData = flagsByUid.get(uid);
    remoteFolder.debug("Found new IMAP message with uid %d", uid);
    // Parse the message data
    Date date = flagsData.getInternalDate();
    Long receivedDate = date != null ? date.getTime() : null;
    int zflags = SyncUtil.imapToZimbraFlags(flagsData.getFlags());
    MessageContent mc = getContent(md);
    Message msg;
    try {
        ParsedMessage pm = mc.getParsedMessage(receivedDate, mailbox.attachmentsIndexingEnabled());
        if (pm == null) {
            remoteFolder.warn("Empty message body for UID %d. Must be ignored.", uid);
            return;
        }
        pm.setDataSourceId(ds.getId());
        if (restorePurged) {
            try {
                refetchPurgedMsgsInConversation(pm);
            } catch (ServiceException e) {
                // refetching error should not halt import
                ZimbraLog.datasource.error("error refetching purged message", e);
            }
        }
        msg = imapSync.addMessage(null, pm, mc.getSize(), folderId, zflags, mc.getDeliveryContext());
    } finally {
        mc.cleanup();
    }
    if (msg != null && msg.getFolderId() == folderId) {
        storeImapMessage(uid, msg.getId(), zflags, storeSync);
        stats.msgsAddedLocally++;
    } else {
        // Message was filtered and discarded or moved to another folder.
        // This can only happen for messages fetched from INBOX which is
        // always imported first. Mark remote message for deletion and
        // do not create a local tracker. If message was moved to another
        // folder we will append it to the remote folder when we sync
        // that folder.
        addDeletedUid(uid);
    }
}
Also used : MessageContent(com.zimbra.cs.datasource.MessageContent) PurgedMessage(com.zimbra.cs.db.DbDataSource.PurgedMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) RemoteServiceException(com.zimbra.common.service.RemoteServiceException) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) MailException(com.zimbra.cs.mailclient.MailException) Date(java.util.Date)

Aggregations

MailException (com.zimbra.cs.mailclient.MailException)3 RemoteServiceException (com.zimbra.common.service.RemoteServiceException)1 ServiceException (com.zimbra.common.service.ServiceException)1 MessageContent (com.zimbra.cs.datasource.MessageContent)1 PurgedMessage (com.zimbra.cs.db.DbDataSource.PurgedMessage)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 Message (com.zimbra.cs.mailbox.Message)1 AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)1 Literal (com.zimbra.cs.mailclient.imap.Literal)1 MessageData (com.zimbra.cs.mailclient.imap.MessageData)1 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 MessagingException (javax.mail.MessagingException)1