mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Tighten types in Folder#fetch(…)
This commit is contained in:
parent
98c1935c85
commit
e214dbbd99
@ -1439,7 +1439,7 @@ public class MessagingController implements Runnable {
|
||||
|
||||
private <T extends Message> void fetchUnsyncedMessages(final Account account, final Folder<T> remoteFolder,
|
||||
final LocalFolder localFolder,
|
||||
List<Message> unsyncedMessages,
|
||||
List<T> unsyncedMessages,
|
||||
final List<Message> smallMessages,
|
||||
final List<Message> largeMessages,
|
||||
final AtomicInteger progress,
|
||||
@ -1669,7 +1669,7 @@ public class MessagingController implements Runnable {
|
||||
Log.d(K9.LOG_TAG, "SYNC: Fetching large messages for folder " + folder);
|
||||
|
||||
remoteFolder.fetch(largeMessages, fp, null);
|
||||
for (Message message : largeMessages) {
|
||||
for (T message : largeMessages) {
|
||||
|
||||
if (!shouldImportMessage(account, folder, message, progress, earliestDate)) {
|
||||
progress.incrementAndGet();
|
||||
@ -2959,7 +2959,7 @@ public class MessagingController implements Runnable {
|
||||
localFolder = localStore.getFolder(folder);
|
||||
localFolder.open(Folder.OPEN_MODE_RW);
|
||||
|
||||
Message message = localFolder.getMessage(uid);
|
||||
LocalMessage message = localFolder.getMessage(uid);
|
||||
|
||||
if (uid.startsWith(K9.LOCAL_UID_PREFIX)) {
|
||||
Log.w(K9.LOG_TAG, "Message has local UID so cannot download fully.");
|
||||
|
@ -138,7 +138,7 @@ public abstract class Folder<T extends Message> {
|
||||
* @param listener Listener to notify as we fetch messages.
|
||||
* @throws MessagingException
|
||||
*/
|
||||
public abstract void fetch(List<? extends Message> messages, FetchProfile fp,
|
||||
public abstract void fetch(List<T> messages, FetchProfile fp,
|
||||
MessageRetrievalListener<T> listener) throws MessagingException;
|
||||
|
||||
public void fetchPart(Message message, Part part,
|
||||
@ -162,7 +162,6 @@ public abstract class Folder<T extends Message> {
|
||||
protected boolean mCanCreateKeywords = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param oldPushState
|
||||
* @param message
|
||||
* @return empty string to clear the pushState, null to leave the state as-is
|
||||
|
@ -1326,7 +1326,7 @@ public class ImapStore extends RemoteStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetch(List<? extends Message> messages, FetchProfile fp, MessageRetrievalListener<ImapMessage> listener)
|
||||
public void fetch(List<ImapMessage> messages, FetchProfile fp, MessageRetrievalListener<ImapMessage> listener)
|
||||
throws MessagingException {
|
||||
if (messages == null || messages.isEmpty()) {
|
||||
return;
|
||||
|
@ -151,7 +151,7 @@ public class Pop3Store extends RemoteStore {
|
||||
*
|
||||
* @return A Pop3Store URI that holds the same information as the {@code server} parameter.
|
||||
*
|
||||
* @see Account#getStoreUri()
|
||||
* @see StoreConfig#getStoreUri()
|
||||
* @see Pop3Store#decodeUri(String)
|
||||
*/
|
||||
public static String createUri(ServerSettings server) {
|
||||
@ -572,7 +572,7 @@ public class Pop3Store extends RemoteStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Message> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
|
||||
public List<Pop3Message> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<Pop3Message> listener)
|
||||
throws MessagingException {
|
||||
if (start < 1 || end < 1 || end < start) {
|
||||
throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d",
|
||||
@ -583,7 +583,7 @@ public class Pop3Store extends RemoteStore {
|
||||
} catch (IOException ioe) {
|
||||
throw new MessagingException("getMessages", ioe);
|
||||
}
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
List<Pop3Message> messages = new ArrayList<Pop3Message>();
|
||||
int i = 0;
|
||||
for (int msgNum = start; msgNum <= end; msgNum++) {
|
||||
Pop3Message message = mMsgNumToMsgMap.get(msgNum);
|
||||
@ -765,7 +765,7 @@ public class Pop3Store extends RemoteStore {
|
||||
* @throws MessagingException
|
||||
*/
|
||||
@Override
|
||||
public void fetch(List<? extends Message> messages, FetchProfile fp, MessageRetrievalListener<Pop3Message> listener)
|
||||
public void fetch(List<Pop3Message> messages, FetchProfile fp, MessageRetrievalListener<Pop3Message> listener)
|
||||
throws MessagingException {
|
||||
if (messages == null || messages.isEmpty()) {
|
||||
return;
|
||||
@ -793,11 +793,7 @@ public class Pop3Store extends RemoteStore {
|
||||
throw new MessagingException("fetch", ioe);
|
||||
}
|
||||
for (int i = 0, count = messages.size(); i < count; i++) {
|
||||
Message message = messages.get(i);
|
||||
if (!(message instanceof Pop3Message)) {
|
||||
throw new MessagingException("Pop3Store.fetch called with non-Pop3 Message");
|
||||
}
|
||||
Pop3Message pop3Message = (Pop3Message)message;
|
||||
Pop3Message pop3Message = messages.get(i);
|
||||
try {
|
||||
if (listener != null && !fp.contains(FetchProfile.Item.ENVELOPE)) {
|
||||
listener.messageStarted(pop3Message.getUid(), i, count);
|
||||
@ -831,8 +827,8 @@ public class Pop3Store extends RemoteStore {
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchEnvelope(List<? extends Message> messages,
|
||||
MessageRetrievalListener listener) throws IOException, MessagingException {
|
||||
private void fetchEnvelope(List<Pop3Message> messages,
|
||||
MessageRetrievalListener<Pop3Message> listener) throws IOException, MessagingException {
|
||||
int unsizedMessages = 0;
|
||||
for (Message message : messages) {
|
||||
if (message.getSize() == -1) {
|
||||
@ -848,22 +844,18 @@ public class Pop3Store extends RemoteStore {
|
||||
* to hopefully save some time and bandwidth.
|
||||
*/
|
||||
for (int i = 0, count = messages.size(); i < count; i++) {
|
||||
Message message = messages.get(i);
|
||||
if (!(message instanceof Pop3Message)) {
|
||||
throw new MessagingException("Pop3Store.fetch called with non-Pop3 Message");
|
||||
}
|
||||
Pop3Message pop3Message = (Pop3Message)message;
|
||||
Pop3Message message = messages.get(i);
|
||||
if (listener != null) {
|
||||
listener.messageStarted(pop3Message.getUid(), i, count);
|
||||
listener.messageStarted(message.getUid(), i, count);
|
||||
}
|
||||
String response = executeSimpleCommand(String.format(Locale.US, LIST_COMMAND + " %d",
|
||||
mUidToMsgNumMap.get(pop3Message.getUid())));
|
||||
mUidToMsgNumMap.get(message.getUid())));
|
||||
String[] listParts = response.split(" ");
|
||||
//int msgNum = Integer.parseInt(listParts[1]);
|
||||
int msgSize = Integer.parseInt(listParts[2]);
|
||||
pop3Message.setSize(msgSize);
|
||||
message.setSize(msgSize);
|
||||
if (listener != null) {
|
||||
listener.messageFinished(pop3Message, i, count);
|
||||
listener.messageFinished(message, i, count);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1459,9 +1459,8 @@ public class WebDavStore extends RemoteStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Message> getMessages(String[] uids, MessageRetrievalListener listener) throws MessagingException {
|
||||
List<Message> messageList = new ArrayList<Message>();
|
||||
List<? extends Message> messages;
|
||||
public List<WebDavMessage> getMessages(String[] uids, MessageRetrievalListener<WebDavMessage> listener) throws MessagingException {
|
||||
List<WebDavMessage> messageList = new ArrayList<WebDavMessage>();
|
||||
|
||||
if (uids == null ||
|
||||
uids.length == 0) {
|
||||
@ -1480,9 +1479,7 @@ public class WebDavStore extends RemoteStore {
|
||||
listener.messageFinished(message, i, count);
|
||||
}
|
||||
}
|
||||
messages = messageList;
|
||||
|
||||
return messages;
|
||||
return messageList;
|
||||
}
|
||||
|
||||
private Map<String, String> getMessageUrls(String[] uids) throws MessagingException {
|
||||
@ -1494,13 +1491,12 @@ public class WebDavStore extends RemoteStore {
|
||||
headers.put("Brief", "t");
|
||||
|
||||
DataSet dataset = processRequest(this.mFolderUrl, "SEARCH", messageBody, headers);
|
||||
Map<String, String> uidToUrl = dataset.getUidToUrl();
|
||||
|
||||
return uidToUrl;
|
||||
return dataset.getUidToUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetch(List<? extends Message> messages, FetchProfile fp, MessageRetrievalListener<WebDavMessage> listener)
|
||||
public void fetch(List<WebDavMessage> messages, FetchProfile fp, MessageRetrievalListener<WebDavMessage> listener)
|
||||
throws MessagingException {
|
||||
if (messages == null ||
|
||||
messages.isEmpty()) {
|
||||
@ -1718,12 +1714,12 @@ public class WebDavStore extends RemoteStore {
|
||||
* that we do a series of medium calls instead of one large massive call or a large number of smaller calls.
|
||||
* Call it a happy balance
|
||||
*/
|
||||
private void fetchEnvelope(List<? extends Message> startMessages, MessageRetrievalListener listener)
|
||||
private void fetchEnvelope(List<WebDavMessage> startMessages, MessageRetrievalListener<WebDavMessage> listener)
|
||||
throws MessagingException {
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
String messageBody = "";
|
||||
String[] uids;
|
||||
List<Message> messages = new ArrayList<Message>(10);
|
||||
List<WebDavMessage> messages = new ArrayList<WebDavMessage>(10);
|
||||
|
||||
if (startMessages == null ||
|
||||
startMessages.isEmpty()) {
|
||||
@ -1731,7 +1727,7 @@ public class WebDavStore extends RemoteStore {
|
||||
}
|
||||
|
||||
if (startMessages.size() > 10) {
|
||||
List<Message> newMessages = new ArrayList<Message>(startMessages.size() - 10);
|
||||
List<WebDavMessage> newMessages = new ArrayList<WebDavMessage>(startMessages.size() - 10);
|
||||
for (int i = 0, count = startMessages.size(); i < count; i++) {
|
||||
if (i < 10) {
|
||||
messages.set(i, startMessages.get(i));
|
||||
@ -1759,21 +1755,17 @@ public class WebDavStore extends RemoteStore {
|
||||
|
||||
int count = messages.size();
|
||||
for (int i = messages.size() - 1; i >= 0; i--) {
|
||||
if (!(messages.get(i) instanceof WebDavMessage)) {
|
||||
throw new MessagingException("WebDavStore fetch called with non-WebDavMessage");
|
||||
}
|
||||
WebDavMessage wdMessage = (WebDavMessage) messages.get(i);
|
||||
|
||||
WebDavMessage message = messages.get(i);
|
||||
if (listener != null) {
|
||||
listener.messageStarted(messages.get(i).getUid(), i, count);
|
||||
}
|
||||
|
||||
ParsedMessageEnvelope envelope = envelopes.get(wdMessage.getUid());
|
||||
ParsedMessageEnvelope envelope = envelopes.get(message.getUid());
|
||||
if (envelope != null) {
|
||||
wdMessage.setNewHeaders(envelope);
|
||||
wdMessage.setFlagInternal(Flag.SEEN, envelope.getReadStatus());
|
||||
message.setNewHeaders(envelope);
|
||||
message.setFlagInternal(Flag.SEEN, envelope.getReadStatus());
|
||||
} else {
|
||||
Log.e(LOG_TAG,"Asked to get metadata for a non-existent message: "+wdMessage.getUid());
|
||||
Log.e(LOG_TAG, "Asked to get metadata for a non-existent message: " + message.getUid());
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
@ -1801,7 +1793,7 @@ public class WebDavStore extends RemoteStore {
|
||||
}
|
||||
|
||||
private void markServerMessagesRead(String[] uids, boolean read) throws MessagingException {
|
||||
String messageBody = "";
|
||||
String messageBody;
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
Map<String, String> uidToUrl = getMessageUrls(uids);
|
||||
String[] urls = new String[uids.length];
|
||||
@ -1842,9 +1834,8 @@ public class WebDavStore extends RemoteStore {
|
||||
private String generateDeleteUrl(String startUrl) {
|
||||
String[] urlParts = startUrl.split("/");
|
||||
String filename = urlParts[urlParts.length - 1];
|
||||
String finalUrl = WebDavStore.this.mUrl + "Deleted%20Items/" + filename;
|
||||
|
||||
return finalUrl;
|
||||
return WebDavStore.this.mUrl + "Deleted%20Items/" + filename;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2169,7 +2160,7 @@ public class WebDavStore extends RemoteStore {
|
||||
|
||||
public void finish() {
|
||||
String uid = mUid.toString();
|
||||
if (uid != null && mTempData != null) {
|
||||
if (mTempData != null) {
|
||||
mData.put(uid, mTempData);
|
||||
} else if (mTempData != null) {
|
||||
/*
|
||||
|
@ -609,7 +609,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetch(final List<? extends Message> messages, final FetchProfile fp, final MessageRetrievalListener<LocalMessage> listener)
|
||||
public void fetch(final List<LocalMessage> messages, final FetchProfile fp, final MessageRetrievalListener<LocalMessage> listener)
|
||||
throws MessagingException {
|
||||
try {
|
||||
this.localStore.database.execute(false, new DbCallback<Void>() {
|
||||
@ -785,8 +785,8 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
// SpamAssassin rules.
|
||||
localMessage.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain");
|
||||
localMessage.setBody(new TextBody(""));
|
||||
} else if (mp.getCount() == 1 && (mp.getBodyPart(0) instanceof LocalAttachmentBodyPart) == false)
|
||||
|
||||
} else if (mp.getCount() == 1 &&
|
||||
!(mp.getBodyPart(0) instanceof LocalAttachmentBodyPart))
|
||||
{
|
||||
// If we have only one part, drop the MimeMultipart container.
|
||||
BodyPart part = mp.getBodyPart(0);
|
||||
@ -810,7 +810,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Message> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
|
||||
public List<LocalMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<LocalMessage> listener)
|
||||
throws MessagingException {
|
||||
open(OPEN_MODE_RW);
|
||||
throw new MessagingException(
|
||||
@ -943,16 +943,16 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Message> getMessages(MessageRetrievalListener listener) throws MessagingException {
|
||||
public List<LocalMessage> getMessages(MessageRetrievalListener listener) throws MessagingException {
|
||||
return getMessages(listener, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Message> getMessages(final MessageRetrievalListener listener, final boolean includeDeleted) throws MessagingException {
|
||||
public List<LocalMessage> getMessages(final MessageRetrievalListener listener, final boolean includeDeleted) throws MessagingException {
|
||||
try {
|
||||
return this.localStore.database.execute(false, new DbCallback<List<? extends Message>>() {
|
||||
return localStore.database.execute(false, new DbCallback<List<LocalMessage>>() {
|
||||
@Override
|
||||
public List<? extends Message> doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
|
||||
public List<LocalMessage> doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
|
||||
try {
|
||||
open(OPEN_MODE_RW);
|
||||
return LocalFolder.this.localStore.getMessages(
|
||||
@ -977,15 +977,15 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Message> getMessages(String[] uids, MessageRetrievalListener listener)
|
||||
public List<LocalMessage> getMessages(String[] uids, MessageRetrievalListener<LocalMessage> listener)
|
||||
throws MessagingException {
|
||||
open(OPEN_MODE_RW);
|
||||
if (uids == null) {
|
||||
return getMessages(listener);
|
||||
}
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
List<LocalMessage> messages = new ArrayList<LocalMessage>();
|
||||
for (String uid : uids) {
|
||||
Message message = getMessage(uid);
|
||||
LocalMessage message = getMessage(uid);
|
||||
if (message != null) {
|
||||
messages.add(message);
|
||||
}
|
||||
@ -1231,7 +1231,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
* message, retrieve the appropriate local message instance first (if it already exists).
|
||||
* @param messages
|
||||
* @param copy
|
||||
* @return Map<String, String> uidMap of srcUids -> destUids
|
||||
* @return uidMap of srcUids -> destUids
|
||||
*/
|
||||
private Map<String, String> appendMessages(final List<? extends Message> messages, final boolean copy) throws MessagingException {
|
||||
open(OPEN_MODE_RW);
|
||||
@ -1242,10 +1242,6 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
|
||||
try {
|
||||
for (Message message : messages) {
|
||||
if (!(message instanceof MimeMessage)) {
|
||||
throw new Error("LocalStore can only store Messages that extend MimeMessage");
|
||||
}
|
||||
|
||||
long oldMessageId = -1;
|
||||
String uid = message.getUid();
|
||||
if (uid == null || copy) {
|
||||
|
Loading…
Reference in New Issue
Block a user