Search in sources :

Example 1 with Pop3Message

use of com.fsck.k9.mail.store.pop3.Pop3Message in project k-9 by k9mail.

the class Pop3Folder method getMessages.

public List<Pop3Message> getMessages(int start, int end, MessageRetrievalListener<Pop3Message> listener) throws MessagingException {
    if (start < 1 || end < 1 || end < start) {
        throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d", start, end));
    }
    try {
        indexMsgNums(start, end);
    } catch (IOException ioe) {
        throw new MessagingException("getMessages", ioe);
    }
    List<Pop3Message> messages = new ArrayList<>();
    int i = 0;
    for (int msgNum = start; msgNum <= end; msgNum++) {
        Pop3Message message = msgNumToMsgMap.get(msgNum);
        if (message == null) {
            /*
                 * There could be gaps in the message numbers or malformed
                 * responses which lead to "gaps" in msgNumToMsgMap.
                 *
                 * See issue 2252
                 */
            continue;
        }
        if (listener != null) {
            listener.messageStarted(message.getUid(), i++, (end - start) + 1);
        }
        messages.add(message);
        if (listener != null) {
            listener.messageFinished(message, i++, (end - start) + 1);
        }
    }
    return messages;
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint)

Example 2 with Pop3Message

use of com.fsck.k9.mail.store.pop3.Pop3Message in project k-9 by k9mail.

the class Pop3FolderTest method fetch_withEnvelopeProfile_setsSizeOfMessage.

@Test
public void fetch_withEnvelopeProfile_setsSizeOfMessage() throws MessagingException, IOException {
    folder.open();
    List<Pop3Message> messageList = setupMessageFromServer();
    FetchProfile fetchProfile = new FetchProfile();
    fetchProfile.add(Item.ENVELOPE);
    when(mockConnection.readLine()).thenReturn("1 100").thenReturn(".");
    folder.fetch(messageList, fetchProfile, mockListener, MAX_DOWNLOAD_SIZE);
    assertEquals(100, messageList.get(0).getSize());
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) Test(org.junit.Test)

Example 3 with Pop3Message

use of com.fsck.k9.mail.store.pop3.Pop3Message in project zm-mailbox by Zimbra.

the class DbMailItem method loadPop3Folder.

public static List<Pop3Message> loadPop3Folder(Set<Folder> folders, Date popSince) throws ServiceException {
    assert !folders.isEmpty() : folders;
    Mailbox mbox = Iterables.get(folders, 0).getMailbox();
    long popDate = popSince == null ? -1 : Math.max(popSince.getTime(), -1);
    List<Pop3Message> result = new ArrayList<Pop3Message>();
    DbConnection conn = mbox.getOperationConnection();
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        String dateConstraint = popDate < 0 ? "" : " AND date > ?";
        stmt = conn.prepareStatement("SELECT mi.id, mi.size, mi.blob_digest FROM " + getMailItemTableName(mbox, " mi") + " WHERE " + IN_THIS_MAILBOX_AND + DbUtil.whereIn("folder_id", folders.size()) + " AND type = " + MailItem.Type.MESSAGE.toByte() + " AND " + Db.getInstance().bitAND("flags", String.valueOf(Flag.BITMASK_DELETED | Flag.BITMASK_POPPED)) + " = 0" + dateConstraint);
        if (getTotalFolderSize(folders) > RESULTS_STREAMING_MIN_ROWS) {
            // TODO: Because of POPPED flag, the folder size no longer represent the count.
            Db.getInstance().enableStreaming(stmt);
        }
        int pos = 1;
        pos = setMailboxId(stmt, mbox, pos);
        for (Folder folder : folders) {
            stmt.setInt(pos++, folder.getId());
        }
        if (popDate >= 0) {
            stmt.setInt(pos++, (int) (popDate / 1000L));
        }
        rs = stmt.executeQuery();
        while (rs.next()) {
            result.add(new Pop3Message(rs.getInt(1), rs.getLong(2), rs.getString(3)));
        }
        return result;
    } catch (SQLException e) {
        throw ServiceException.FAILURE("loading POP3 folder data: " + folders, e);
    } finally {
        DbPool.closeResults(rs);
        DbPool.closeStatement(stmt);
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Pop3Message(com.zimbra.cs.pop3.Pop3Message) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Folder(com.zimbra.cs.mailbox.Folder) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Example 4 with Pop3Message

use of com.fsck.k9.mail.store.pop3.Pop3Message in project zm-mailbox by Zimbra.

the class Mailbox method openPop3Folder.

public List<Pop3Message> openPop3Folder(OperationContext octxt, Set<Integer> folderIds, Date popSince) throws ServiceException {
    boolean success = false;
    try {
        beginTransaction("openPop3Folder", octxt);
        ImmutableSet.Builder<Folder> folders = ImmutableSet.builder();
        for (int folderId : folderIds) {
            folders.add(getFolderById(folderId));
        }
        List<Pop3Message> p3list = DbMailItem.loadPop3Folder(folders.build(), popSince);
        success = true;
        return p3list;
    } finally {
        endTransaction(success);
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Pop3Message(com.zimbra.cs.pop3.Pop3Message) CreateFolder(com.zimbra.cs.redolog.op.CreateFolder) ZFolder(com.zimbra.client.ZFolder) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint)

Example 5 with Pop3Message

use of com.fsck.k9.mail.store.pop3.Pop3Message in project k-9 by k9mail.

the class Pop3Sync method downloadSaneBody.

private void downloadSaneBody(SyncConfig syncConfig, Pop3Folder remoteFolder, BackendFolder backendFolder, Pop3Message message) throws MessagingException {
    /*
         * The provider was unable to get the structure of the message, so
         * we'll download a reasonable portion of the messge and mark it as
         * incomplete so the entire thing can be downloaded later if the user
         * wishes to download it.
         */
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY_SANE);
    /*
         *  TODO a good optimization here would be to make sure that all Stores set
         *  the proper size after this fetch and compare the before and after size. If
         *  they equal we can mark this SYNCHRONIZED instead of PARTIALLY_SYNCHRONIZED
         */
    int maxDownloadSize = syncConfig.getMaximumAutoDownloadMessageSize();
    remoteFolder.fetch(Collections.singletonList(message), fp, null, maxDownloadSize);
    boolean completeMessage = false;
    // Certain (POP3) servers give you the whole message even when you ask for only the first x Kb
    if (!message.isSet(Flag.X_DOWNLOADED_FULL)) {
        /*
             * Mark the message as fully downloaded if the message size is smaller than
             * the account's autodownload size limit, otherwise mark as only a partial
             * download.  This will prevent the system from downloading the same message
             * twice.
             *
             * If there is no limit on autodownload size, that's the same as the message
             * being smaller than the max size
             */
        if (syncConfig.getMaximumAutoDownloadMessageSize() == 0 || message.getSize() < syncConfig.getMaximumAutoDownloadMessageSize()) {
            completeMessage = true;
        }
    }
    // Store the updated message locally
    if (completeMessage) {
        backendFolder.saveMessage(message, MessageDownloadState.FULL);
    } else {
        backendFolder.saveMessage(message, MessageDownloadState.PARTIAL);
    }
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile)

Aggregations

ArrayList (java.util.ArrayList)6 Pop3Message (com.fsck.k9.mail.store.pop3.Pop3Message)5 FetchProfile (com.fsck.k9.mail.FetchProfile)4 MessagingException (com.fsck.k9.mail.MessagingException)4 Date (java.util.Date)3 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)2 Pop3Folder (com.fsck.k9.mail.store.pop3.Pop3Folder)2 Pop3Message (com.zimbra.cs.pop3.Pop3Message)2 IOException (java.io.IOException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 SuppressLint (android.annotation.SuppressLint)1 BackendFolder (com.fsck.k9.backend.api.BackendFolder)1 MoreMessages (com.fsck.k9.backend.api.BackendFolder.MoreMessages)1 Flag (com.fsck.k9.mail.Flag)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ZFolder (com.zimbra.client.ZFolder)1 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)1 Folder (com.zimbra.cs.mailbox.Folder)1 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)1