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