Search in sources :

Example 1 with Threader

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

the class ImapFolderSync method refetchPurgedMsgsInConversation.

protected void refetchPurgedMsgsInConversation(ParsedMessage pm) throws ServiceException, IOException {
    if (!mailbox.getAccount().isFeatureDataSourcePurgingEnabled()) {
        return;
    }
    Threader threader = pm.getThreader(ds.getMailbox());
    List<PurgedConversation> purgedConvs = threader.lookupPurgedConversations(ds);
    if (purgedConvs.size() == 0) {
        return;
    } else {
        for (PurgedConversation conv : purgedConvs) {
            ImapConnection conn;
            try {
                conn = getRefetchConnection();
            } catch (ServiceException e) {
                ZimbraLog.datasource.warn("could not establish IMAP connection to refetch purged messages");
                return;
            }
            for (PurgedMessage msg : conv.getMessages()) {
                String remoteFolderId = msg.getRemoteFolder();
                String msgUid = msg.getUid();
                final Integer folderId = msg.getLocalFolderId();
                ZimbraLog.datasource.info("restoring message " + msgUid + " in remote folder " + remoteFolderId);
                conn.select(remoteFolderId);
                final Map<Long, MessageData> msgFlags = conn.uidFetch(msgUid, "(FLAGS INTERNALDATE)");
                FetchResponseHandler handler = new FetchResponseHandler() {

                    @Override
                    public void handleFetchResponse(MessageData md) throws Exception {
                        long uid = md.getUid();
                        IOExceptionHandler.getInstance().trackSyncItem(mailbox, uid);
                        try {
                            handleFetch(md, msgFlags, folderId, false, false);
                            clearError(uid);
                        } catch (OutOfMemoryError e) {
                            Zimbra.halt("Out of memory", e);
                        } catch (Exception e) {
                            if (!IOExceptionHandler.getInstance().isRecoverable(mailbox, uid, "Exception re-fetching UID " + uid, e)) {
                                syncFailed("re-fetch failed for uid " + uid, e);
                                SyncErrorManager.incrementErrorCount(ds, remoteId(uid));
                            }
                        }
                    }
                };
                conn.uidFetch(msgUid, "BODY.PEEK[]", handler);
            }
            conv.unpurge();
        }
    }
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) Threader(com.zimbra.cs.mailbox.Threader) ImapConnection(com.zimbra.cs.mailclient.imap.ImapConnection) MailException(com.zimbra.cs.mailclient.MailException) ServiceException(com.zimbra.common.service.ServiceException) SQLException(java.sql.SQLException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) IOException(java.io.IOException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) RemoteServiceException(com.zimbra.common.service.RemoteServiceException) PurgedConversation(com.zimbra.cs.db.DbDataSource.PurgedConversation) PurgedMessage(com.zimbra.cs.db.DbDataSource.PurgedMessage) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) RemoteServiceException(com.zimbra.common.service.RemoteServiceException) FetchResponseHandler(com.zimbra.cs.mailclient.imap.FetchResponseHandler)

Example 2 with Threader

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

the class ParsedMessage method getThreader.

/**
 * {@link Threader} is cached per mailbox as {@link ParsedMessage} is shared by multiple mailboxes in shared
 * delivery.
 */
public Threader getThreader(Mailbox mbox) throws ServiceException {
    Threader threader = threaders.get(mbox);
    if (threader == null) {
        threader = new Threader(mbox, this);
        threaders.put(mbox, threader);
    }
    return threader;
}
Also used : Threader(com.zimbra.cs.mailbox.Threader)

Example 3 with Threader

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

the class DataSourcePurge method partiallyPurgeConversation.

private void partiallyPurgeConversation(OperationContext octxt, String dataSourceId, Conversation conversation, Set<Integer> ids) throws ServiceException {
    Integer convId = conversation.getId();
    for (Message msg : mbox.getMessagesByConversation(null, conversation.getId())) {
        if (ids.contains(msg.getId())) {
            ParsedMessage pm = msg.getParsedMessage();
            Threader threader = pm.getThreader(mbox);
            threader.storePurgedConversationHashes(convId, dataSourceId);
            mbox.purgeDataSourceMessage(octxt, msg, dataSourceId);
            mbox.delete(null, msg.getId(), MailItem.Type.MESSAGE);
        }
    }
}
Also used : Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Threader(com.zimbra.cs.mailbox.Threader)

Aggregations

Threader (com.zimbra.cs.mailbox.Threader)3 RemoteServiceException (com.zimbra.common.service.RemoteServiceException)1 ServiceException (com.zimbra.common.service.ServiceException)1 PurgedConversation (com.zimbra.cs.db.DbDataSource.PurgedConversation)1 PurgedMessage (com.zimbra.cs.db.DbDataSource.PurgedMessage)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 Message (com.zimbra.cs.mailbox.Message)1 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)1 MailException (com.zimbra.cs.mailclient.MailException)1 FetchResponseHandler (com.zimbra.cs.mailclient.imap.FetchResponseHandler)1 ImapConnection (com.zimbra.cs.mailclient.imap.ImapConnection)1 MessageData (com.zimbra.cs.mailclient.imap.MessageData)1 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1