mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 09:08:49 -05:00
Use collections instead of arrays to enable stronger typing and reduce cruft
This commit is contained in:
parent
203dcfe2c3
commit
02c0b5f2a3
@ -338,7 +338,7 @@ public class Account implements BaseAccount {
|
||||
* Pick a nice Android guidelines color if we haven't used them all yet.
|
||||
*/
|
||||
private int pickColor(Context context) {
|
||||
Account[] accounts = Preferences.getPreferences(context).getAccounts();
|
||||
List<Account> accounts = Preferences.getPreferences(context).getAccounts();
|
||||
|
||||
List<Integer> availableColors = new ArrayList<Integer>(PREDEFINED_COLORS.length);
|
||||
Collections.addAll(availableColors, PREDEFINED_COLORS);
|
||||
@ -620,8 +620,8 @@ public class Account implements BaseAccount {
|
||||
}
|
||||
|
||||
public static List<Integer> getExistingAccountNumbers(Preferences preferences) {
|
||||
Account[] accounts = preferences.getAccounts();
|
||||
List<Integer> accountNumbers = new ArrayList<Integer>(accounts.length);
|
||||
List<Account> accounts = preferences.getAccounts();
|
||||
List<Integer> accountNumbers = new ArrayList<Integer>(accounts.size());
|
||||
for (Account a : accounts) {
|
||||
accountNumbers.add(a.getAccountNumber());
|
||||
}
|
||||
@ -679,10 +679,10 @@ public class Account implements BaseAccount {
|
||||
*
|
||||
* I bet there is a much smarter way to do this. Anyone like to suggest it?
|
||||
*/
|
||||
Account[] accounts = preferences.getAccounts();
|
||||
int[] accountNumbers = new int[accounts.length];
|
||||
for (int i = 0; i < accounts.length; i++) {
|
||||
accountNumbers[i] = accounts[i].getAccountNumber();
|
||||
List<Account> accounts = preferences.getAccounts();
|
||||
int[] accountNumbers = new int[accounts.size()];
|
||||
for (int i = 0; i < accounts.size(); i++) {
|
||||
accountNumbers[i] = accounts.get(i).getAccountNumber();
|
||||
}
|
||||
Arrays.sort(accountNumbers);
|
||||
for (int accountNumber : accountNumbers) {
|
||||
|
@ -3,6 +3,7 @@ package com.fsck.k9;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -18,11 +19,6 @@ import com.fsck.k9.preferences.Storage;
|
||||
|
||||
public class Preferences {
|
||||
|
||||
/**
|
||||
* Immutable empty {@link Account} array
|
||||
*/
|
||||
private static final Account[] EMPTY_ACCOUNT_ARRAY = new Account[0];
|
||||
|
||||
private static Preferences preferences;
|
||||
|
||||
public static synchronized Preferences getPreferences(Context context) {
|
||||
@ -75,12 +71,12 @@ public class Preferences {
|
||||
* registered the method returns an empty array.
|
||||
* @return all accounts
|
||||
*/
|
||||
public synchronized Account[] getAccounts() {
|
||||
public synchronized List<Account> getAccounts() {
|
||||
if (accounts == null) {
|
||||
loadAccounts();
|
||||
}
|
||||
|
||||
return accountsInOrder.toArray(EMPTY_ACCOUNT_ARRAY);
|
||||
return Collections.unmodifiableList(accountsInOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,7 +85,7 @@ public class Preferences {
|
||||
* @return all accounts with {@link Account#isAvailable(Context)}
|
||||
*/
|
||||
public synchronized Collection<Account> getAvailableAccounts() {
|
||||
Account[] allAccounts = getAccounts();
|
||||
List<Account> allAccounts = getAccounts();
|
||||
Collection<Account> retval = new ArrayList<Account>(accounts.size());
|
||||
for (Account account : allAccounts) {
|
||||
if (account.isEnabled() && account.isAvailable(mContext)) {
|
||||
|
@ -68,7 +68,7 @@ public abstract class AccountList extends K9ListActivity implements OnItemClickL
|
||||
* @param realAccounts
|
||||
* An array of accounts to display.
|
||||
*/
|
||||
public void populateListView(Account[] realAccounts) {
|
||||
public void populateListView(List<Account> realAccounts) {
|
||||
List<BaseAccount> accounts = new ArrayList<BaseAccount>();
|
||||
|
||||
if (displaySpecialAccounts() && !K9.isHideSpecialAccounts()) {
|
||||
@ -79,7 +79,7 @@ public abstract class AccountList extends K9ListActivity implements OnItemClickL
|
||||
accounts.add(allMessagesAccount);
|
||||
}
|
||||
|
||||
accounts.addAll(Arrays.asList(realAccounts));
|
||||
accounts.addAll(realAccounts);
|
||||
AccountsAdapter adapter = new AccountsAdapter(accounts);
|
||||
ListView listView = getListView();
|
||||
listView.setAdapter(adapter);
|
||||
@ -169,15 +169,15 @@ public abstract class AccountList extends K9ListActivity implements OnItemClickL
|
||||
/**
|
||||
* Load accounts in a background thread
|
||||
*/
|
||||
class LoadAccounts extends AsyncTask<Void, Void, Account[]> {
|
||||
class LoadAccounts extends AsyncTask<Void, Void, List<Account>> {
|
||||
@Override
|
||||
protected Account[] doInBackground(Void... params) {
|
||||
Account[] accounts = Preferences.getPreferences(getApplicationContext()).getAccounts();
|
||||
protected List<Account> doInBackground(Void... params) {
|
||||
List<Account> accounts = Preferences.getPreferences(getApplicationContext()).getAccounts();
|
||||
return accounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Account[] accounts) {
|
||||
protected void onPostExecute(List<Account> accounts) {
|
||||
populateListView(accounts);
|
||||
}
|
||||
}
|
||||
|
@ -102,11 +102,6 @@ import de.cketti.library.changelog.ChangeLog;
|
||||
|
||||
public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
|
||||
/**
|
||||
* Immutable empty {@link BaseAccount} array
|
||||
*/
|
||||
private static final BaseAccount[] EMPTY_BASE_ACCOUNT_ARRAY = new BaseAccount[0];
|
||||
|
||||
/**
|
||||
* URL used to open Android Market application
|
||||
*/
|
||||
@ -400,14 +395,14 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
createSpecialAccounts();
|
||||
}
|
||||
|
||||
Account[] accounts = Preferences.getPreferences(this).getAccounts();
|
||||
List<Account> accounts = Preferences.getPreferences(this).getAccounts();
|
||||
Intent intent = getIntent();
|
||||
//onNewIntent(intent);
|
||||
|
||||
// see if we should show the welcome message
|
||||
if (ACTION_IMPORT_SETTINGS.equals(intent.getAction())) {
|
||||
onImport();
|
||||
} else if (accounts.length < 1) {
|
||||
} else if (accounts.size() < 1) {
|
||||
WelcomeMessage.showWelcomeMessage(this);
|
||||
finish();
|
||||
return;
|
||||
@ -423,7 +418,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
onOpenAccount(mUnifiedInboxAccount);
|
||||
finish();
|
||||
return;
|
||||
} else if (startup && accounts.length == 1 && onOpenAccount(accounts[0])) {
|
||||
} else if (startup && accounts.size() == 1 && onOpenAccount(accounts.get(0))) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
@ -543,18 +538,18 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
return retain;
|
||||
}
|
||||
|
||||
private BaseAccount[] accounts = new BaseAccount[0];
|
||||
private List<BaseAccount> accounts = new ArrayList<BaseAccount>();
|
||||
private enum ACCOUNT_LOCATION {
|
||||
TOP, MIDDLE, BOTTOM;
|
||||
}
|
||||
private EnumSet<ACCOUNT_LOCATION> accountLocation(BaseAccount account) {
|
||||
EnumSet<ACCOUNT_LOCATION> accountLocation = EnumSet.of(ACCOUNT_LOCATION.MIDDLE);
|
||||
if (accounts.length > 0) {
|
||||
if (accounts[0].equals(account)) {
|
||||
if (accounts.size() > 0) {
|
||||
if (accounts.get(0).equals(account)) {
|
||||
accountLocation.remove(ACCOUNT_LOCATION.MIDDLE);
|
||||
accountLocation.add(ACCOUNT_LOCATION.TOP);
|
||||
}
|
||||
if (accounts[accounts.length - 1].equals(account)) {
|
||||
if (accounts.get(accounts.size() - 1).equals(account)) {
|
||||
accountLocation.remove(ACCOUNT_LOCATION.MIDDLE);
|
||||
accountLocation.add(ACCOUNT_LOCATION.BOTTOM);
|
||||
}
|
||||
@ -564,7 +559,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
|
||||
|
||||
private void refresh() {
|
||||
accounts = Preferences.getPreferences(this).getAccounts();
|
||||
accounts.clear();
|
||||
accounts.addAll(Preferences.getPreferences(this).getAccounts());
|
||||
|
||||
// see if we should show the welcome message
|
||||
// if (accounts.length < 1) {
|
||||
@ -573,22 +569,22 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
// }
|
||||
|
||||
List<BaseAccount> newAccounts;
|
||||
if (!K9.isHideSpecialAccounts() && accounts.length > 0) {
|
||||
if (!K9.isHideSpecialAccounts() && accounts.size() > 0) {
|
||||
if (mUnifiedInboxAccount == null || mAllMessagesAccount == null) {
|
||||
createSpecialAccounts();
|
||||
}
|
||||
|
||||
newAccounts = new ArrayList<BaseAccount>(accounts.length +
|
||||
newAccounts = new ArrayList<BaseAccount>(accounts.size() +
|
||||
SPECIAL_ACCOUNTS_COUNT);
|
||||
newAccounts.add(mUnifiedInboxAccount);
|
||||
newAccounts.add(mAllMessagesAccount);
|
||||
} else {
|
||||
newAccounts = new ArrayList<BaseAccount>(accounts.length);
|
||||
newAccounts = new ArrayList<BaseAccount>(accounts.size());
|
||||
}
|
||||
|
||||
newAccounts.addAll(Arrays.asList(accounts));
|
||||
newAccounts.addAll(accounts);
|
||||
|
||||
mAdapter = new AccountsAdapter(newAccounts.toArray(EMPTY_BASE_ACCOUNT_ARRAY));
|
||||
mAdapter = new AccountsAdapter(newAccounts);
|
||||
getListView().setAdapter(mAdapter);
|
||||
if (!newAccounts.isEmpty()) {
|
||||
mHandler.progress(Window.PROGRESS_START);
|
||||
@ -1737,7 +1733,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
}
|
||||
|
||||
class AccountsAdapter extends ArrayAdapter<BaseAccount> {
|
||||
public AccountsAdapter(BaseAccount[] accounts) {
|
||||
public AccountsAdapter(List<BaseAccount> accounts) {
|
||||
super(Accounts.this, 0, accounts);
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ public class ChooseFolder extends K9ListActivity {
|
||||
mHandler.progress(false);
|
||||
}
|
||||
@Override
|
||||
public void listFolders(Account account, Folder[] folders) {
|
||||
public void listFolders(Account account, List<? extends Folder> folders) {
|
||||
if (!account.equals(mAccount)) {
|
||||
return;
|
||||
}
|
||||
|
@ -740,7 +740,7 @@ public class FolderList extends K9ListActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listFolders(Account account, Folder[] folders) {
|
||||
public void listFolders(Account account, List<? extends Folder> folders) {
|
||||
if (account.equals(mAccount)) {
|
||||
|
||||
List<FolderInfoHolder> newFolders = new LinkedList<FolderInfoHolder>();
|
||||
|
@ -9,6 +9,7 @@ import java.nio.charset.Charset;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -191,8 +192,6 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
||||
private static final int CONTACT_PICKER_CC2 = 8;
|
||||
private static final int CONTACT_PICKER_BCC2 = 9;
|
||||
|
||||
private static final Account[] EMPTY_ACCOUNT_ARRAY = new Account[0];
|
||||
|
||||
private static final int REQUEST_CODE_SIGN_ENCRYPT = 12;
|
||||
|
||||
/**
|
||||
@ -3916,7 +3915,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
||||
|
||||
List<Object> items = new ArrayList<Object>();
|
||||
Preferences prefs = Preferences.getPreferences(context.getApplicationContext());
|
||||
Account[] accounts = prefs.getAvailableAccounts().toArray(EMPTY_ACCOUNT_ARRAY);
|
||||
Collection<Account> accounts = prefs.getAvailableAccounts();
|
||||
for (Account account : accounts) {
|
||||
items.add(account);
|
||||
List<Identity> identities = account.getIdentities();
|
||||
|
@ -451,10 +451,10 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
|
||||
|
||||
String[] accountUuids = mSearch.getAccountUuids();
|
||||
if (mSearch.searchAllAccounts()) {
|
||||
Account[] accounts = prefs.getAccounts();
|
||||
mSingleAccountMode = (accounts.length == 1);
|
||||
List<Account> accounts = prefs.getAccounts();
|
||||
mSingleAccountMode = (accounts.size() == 1);
|
||||
if (mSingleAccountMode) {
|
||||
mAccount = accounts[0];
|
||||
mAccount = accounts.get(0);
|
||||
}
|
||||
} else {
|
||||
mSingleAccountMode = (accountUuids.length == 1);
|
||||
|
@ -143,7 +143,7 @@ public class EmailProviderCache {
|
||||
}
|
||||
}
|
||||
|
||||
public void unhideMessages(Message[] messages) {
|
||||
public void unhideMessages(List<? extends Message> messages) {
|
||||
synchronized (mHiddenMessageCache) {
|
||||
for (Message message : messages) {
|
||||
LocalMessage localMessage = (LocalMessage) message;
|
||||
|
@ -8,6 +8,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@ -116,16 +117,6 @@ public class MessagingController implements Runnable {
|
||||
*/
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
/**
|
||||
* Immutable empty {@link Message} array
|
||||
*/
|
||||
private static final Message[] EMPTY_MESSAGE_ARRAY = new Message[0];
|
||||
|
||||
/**
|
||||
* Immutable empty {@link Folder} array
|
||||
*/
|
||||
private static final Folder[] EMPTY_FOLDER_ARRAY = new Folder[0];
|
||||
|
||||
/**
|
||||
* The maximum message size that we'll consider to be "small". A small message is downloaded
|
||||
* in full immediately instead of in pieces. Anything over this size will be downloaded in
|
||||
@ -321,8 +312,7 @@ public class MessagingController implements Runnable {
|
||||
// Key is accountNumber
|
||||
private final ConcurrentMap<Integer, NotificationData> notificationData = new ConcurrentHashMap<Integer, NotificationData>();
|
||||
|
||||
private static final Flag[] SYNC_FLAGS = new Flag[] { Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED, Flag.FORWARDED };
|
||||
|
||||
private static final Set<Flag> SYNC_FLAGS = EnumSet.of(Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED, Flag.FORWARDED);
|
||||
|
||||
private void suppressMessages(Account account, List<Message> messages) {
|
||||
EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid(),
|
||||
@ -330,7 +320,7 @@ public class MessagingController implements Runnable {
|
||||
cache.hideMessages(messages);
|
||||
}
|
||||
|
||||
private void unsuppressMessages(Account account, Message[] messages) {
|
||||
private void unsuppressMessages(Account account, List<? extends Message> messages) {
|
||||
EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid(),
|
||||
mApplication.getApplicationContext());
|
||||
cache.unhideMessages(messages);
|
||||
@ -574,7 +564,7 @@ public class MessagingController implements Runnable {
|
||||
Store localStore = account.getLocalStore();
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
|
||||
Folder[] folderArray = localFolders.toArray(EMPTY_FOLDER_ARRAY);
|
||||
List<? extends Folder> folderArray = localFolders;
|
||||
|
||||
if (refreshRemote || localFolders.isEmpty()) {
|
||||
doRefreshRemote(account, listener);
|
||||
@ -654,7 +644,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
Folder[] folderArray = localFolders.toArray(EMPTY_FOLDER_ARRAY);
|
||||
List<? extends Folder> folderArray = localFolders;
|
||||
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
l.listFolders(account, folderArray);
|
||||
@ -694,7 +684,7 @@ public class MessagingController implements Runnable {
|
||||
public void searchLocalMessagesSynchronous(final LocalSearch search, final MessagingListener listener) {
|
||||
final AccountStats stats = new AccountStats();
|
||||
final Set<String> uuidSet = new HashSet<String>(Arrays.asList(search.getAccountUuids()));
|
||||
Account[] accounts = Preferences.getPreferences(mApplication.getApplicationContext()).getAccounts();
|
||||
List<Account> accounts = Preferences.getPreferences(mApplication.getApplicationContext()).getAccounts();
|
||||
boolean allAccounts = uuidSet.contains(SearchSpecification.ALL_ACCOUNTS);
|
||||
|
||||
// for every account we want to search do the query in the localstore
|
||||
@ -755,7 +745,7 @@ public class MessagingController implements Runnable {
|
||||
|
||||
|
||||
public Future<?> searchRemoteMessages(final String acctUuid, final String folderName, final String query,
|
||||
final Flag[] requiredFlags, final Flag[] forbiddenFlags, final MessagingListener listener) {
|
||||
final Set<Flag> requiredFlags, final Set<Flag> forbiddenFlags, final MessagingListener listener) {
|
||||
if (K9.DEBUG) {
|
||||
String msg = "searchRemoteMessages ("
|
||||
+ "acct=" + acctUuid
|
||||
@ -773,7 +763,7 @@ public class MessagingController implements Runnable {
|
||||
});
|
||||
}
|
||||
public void searchRemoteMessagesSynchronous(final String acctUuid, final String folderName, final String query,
|
||||
final Flag[] requiredFlags, final Flag[] forbiddenFlags, final MessagingListener listener) {
|
||||
final Set<Flag> requiredFlags, final Set<Flag> forbiddenFlags, final MessagingListener listener) {
|
||||
final Account acct = Preferences.getPreferences(mApplication.getApplicationContext()).getAccount(acctUuid);
|
||||
|
||||
if (listener != null) {
|
||||
@ -885,10 +875,10 @@ public class MessagingController implements Runnable {
|
||||
LocalMessage localMsg = localFolder.getMessage(message.getUid());
|
||||
|
||||
if (localMsg == null) {
|
||||
remoteFolder.fetch(new Message [] {message}, header, null);
|
||||
remoteFolder.fetch(Collections.singletonList(message), header, null);
|
||||
//fun fact: ImapFolder.fetch can't handle getting STRUCTURE at same time as headers
|
||||
remoteFolder.fetch(new Message [] {message}, structure, null);
|
||||
localFolder.appendMessages(new Message [] {message});
|
||||
remoteFolder.fetch(Collections.singletonList(message), structure, null);
|
||||
localFolder.appendMessages(Collections.singletonList(message));
|
||||
localMsg = localFolder.getMessage(message.getUid());
|
||||
}
|
||||
|
||||
@ -992,7 +982,7 @@ public class MessagingController implements Runnable {
|
||||
final LocalFolder localFolder = tLocalFolder;
|
||||
localFolder.open(Folder.OPEN_MODE_RW);
|
||||
localFolder.updateLastUid();
|
||||
Message[] localMessages = localFolder.getMessages(null);
|
||||
List<? extends Message> localMessages = localFolder.getMessages(null);
|
||||
Map<String, Message> localUidMap = new HashMap<String, Message>();
|
||||
for (Message message : localMessages) {
|
||||
localUidMap.put(message.getUid(), message);
|
||||
@ -1058,7 +1048,6 @@ public class MessagingController implements Runnable {
|
||||
visibleLimit = K9.DEFAULT_VISIBLE_LIMIT;
|
||||
}
|
||||
|
||||
Message[] remoteMessageArray = EMPTY_MESSAGE_ARRAY;
|
||||
final List<Message> remoteMessages = new ArrayList<Message>();
|
||||
Map<String, Message> remoteUidMap = new HashMap<String, Message>();
|
||||
|
||||
@ -1086,9 +1075,9 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
remoteMessageArray = remoteFolder.getMessages(remoteStart, remoteEnd, earliestDate, null);
|
||||
List<? extends Message> remoteMessageArray = remoteFolder.getMessages(remoteStart, remoteEnd, earliestDate, null);
|
||||
|
||||
int messageCount = remoteMessageArray.length;
|
||||
int messageCount = remoteMessageArray.size();
|
||||
|
||||
for (Message thisMess : remoteMessageArray) {
|
||||
headerProgress.incrementAndGet();
|
||||
@ -1104,7 +1093,6 @@ public class MessagingController implements Runnable {
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "SYNC: Got " + remoteUidMap.size() + " messages for folder " + folder);
|
||||
|
||||
remoteMessageArray = null;
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
l.synchronizeMailboxHeadersFinished(account, folder, headerProgress.get(), remoteUidMap.size());
|
||||
}
|
||||
@ -1125,7 +1113,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
localFolder.destroyMessages(destroyMessages.toArray(EMPTY_MESSAGE_ARRAY));
|
||||
localFolder.destroyMessages(destroyMessages);
|
||||
|
||||
for (Message destroyMessage : destroyMessages) {
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
@ -1437,7 +1425,7 @@ public class MessagingController implements Runnable {
|
||||
Log.v(K9.LOG_TAG, "Message with uid " + message.getUid() + " is partially or fully downloaded");
|
||||
|
||||
// Store the updated message locally
|
||||
localFolder.appendMessages(new Message[] { message });
|
||||
localFolder.appendMessages(Collections.singletonList(message));
|
||||
|
||||
localMessage = localFolder.getMessage(message.getUid());
|
||||
|
||||
@ -1489,7 +1477,7 @@ public class MessagingController implements Runnable {
|
||||
*/
|
||||
final List<Message> chunk = new ArrayList<Message>(UNSYNC_CHUNK_SIZE);
|
||||
|
||||
remoteFolder.fetch(unsyncedMessages.toArray(EMPTY_MESSAGE_ARRAY), fp,
|
||||
remoteFolder.fetch(unsyncedMessages, fp,
|
||||
new MessageRetrievalListener() {
|
||||
@Override
|
||||
public void messageFinished(Message message, int number, int ofTotal) {
|
||||
@ -1578,7 +1566,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
try {
|
||||
// Store the new message locally
|
||||
localFolder.appendMessages(messages.toArray(new Message[messages.size()]));
|
||||
localFolder.appendMessages(messages);
|
||||
|
||||
for (final Message message : messages) {
|
||||
final Message localMessage = localFolder.getMessage(message.getUid());
|
||||
@ -1624,7 +1612,7 @@ public class MessagingController implements Runnable {
|
||||
if (K9.DEBUG)
|
||||
Log.d(K9.LOG_TAG, "SYNC: Fetching small messages for folder " + folder);
|
||||
|
||||
remoteFolder.fetch(smallMessages.toArray(new Message[smallMessages.size()]),
|
||||
remoteFolder.fetch(smallMessages,
|
||||
fp, new MessageRetrievalListener() {
|
||||
@Override
|
||||
public void messageFinished(final Message message, int number, int ofTotal) {
|
||||
@ -1703,7 +1691,7 @@ public class MessagingController implements Runnable {
|
||||
if (K9.DEBUG)
|
||||
Log.d(K9.LOG_TAG, "SYNC: Fetching large messages for folder " + folder);
|
||||
|
||||
remoteFolder.fetch(largeMessages.toArray(new Message[largeMessages.size()]), fp, null);
|
||||
remoteFolder.fetch(largeMessages, fp, null);
|
||||
for (Message message : largeMessages) {
|
||||
|
||||
if (!shouldImportMessage(account, folder, message, progress, earliestDate)) {
|
||||
@ -1726,10 +1714,10 @@ public class MessagingController implements Runnable {
|
||||
* they equal we can mark this SYNCHRONIZED instead of PARTIALLY_SYNCHRONIZED
|
||||
*/
|
||||
|
||||
remoteFolder.fetch(new Message[] { message }, fp, null);
|
||||
remoteFolder.fetch(Collections.singletonList(message), fp, null);
|
||||
|
||||
// Store the updated message locally
|
||||
localFolder.appendMessages(new Message[] { message });
|
||||
localFolder.appendMessages(Collections.singletonList(message));
|
||||
|
||||
Message localMessage = localFolder.getMessage(message.getUid());
|
||||
|
||||
@ -1770,7 +1758,7 @@ public class MessagingController implements Runnable {
|
||||
remoteFolder.fetchPart(message, part, null);
|
||||
}
|
||||
// Store the updated message locally
|
||||
localFolder.appendMessages(new Message[] { message });
|
||||
localFolder.appendMessages(Collections.singletonList(message));
|
||||
|
||||
Message localMessage = localFolder.getMessage(message.getUid());
|
||||
|
||||
@ -1836,7 +1824,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
remoteFolder.fetch(undeletedMessages.toArray(EMPTY_MESSAGE_ARRAY), fp, null);
|
||||
remoteFolder.fetch(undeletedMessages, fp, null);
|
||||
for (Message remoteMessage : syncFlagMessages) {
|
||||
Message localMessage = localFolder.getMessage(remoteMessage.getUid());
|
||||
boolean messageChanged = syncFlags(localMessage, remoteMessage);
|
||||
@ -2111,10 +2099,10 @@ public class MessagingController implements Runnable {
|
||||
*/
|
||||
FetchProfile fp = new FetchProfile();
|
||||
fp.add(FetchProfile.Item.BODY);
|
||||
localFolder.fetch(new Message[] { localMessage } , fp, null);
|
||||
localFolder.fetch(Collections.singletonList(localMessage) , fp, null);
|
||||
String oldUid = localMessage.getUid();
|
||||
localMessage.setFlag(Flag.X_REMOTE_COPY_STARTED, true);
|
||||
remoteFolder.appendMessages(new Message[] { localMessage });
|
||||
remoteFolder.appendMessages(Collections.singletonList(localMessage));
|
||||
|
||||
localFolder.changeUid(localMessage);
|
||||
for (MessagingListener l : getListeners()) {
|
||||
@ -2129,7 +2117,7 @@ public class MessagingController implements Runnable {
|
||||
*/
|
||||
FetchProfile fp = new FetchProfile();
|
||||
fp.add(FetchProfile.Item.ENVELOPE);
|
||||
remoteFolder.fetch(new Message[] { remoteMessage }, fp, null);
|
||||
remoteFolder.fetch(Collections.singletonList(remoteMessage), fp, null);
|
||||
Date localDate = localMessage.getInternalDate();
|
||||
Date remoteDate = remoteMessage.getInternalDate();
|
||||
if (remoteDate != null && remoteDate.compareTo(localDate) > 0) {
|
||||
@ -2146,12 +2134,12 @@ public class MessagingController implements Runnable {
|
||||
fp.clear();
|
||||
fp = new FetchProfile();
|
||||
fp.add(FetchProfile.Item.BODY);
|
||||
localFolder.fetch(new Message[] { localMessage }, fp, null);
|
||||
localFolder.fetch(Collections.singletonList(localMessage), fp, null);
|
||||
String oldUid = localMessage.getUid();
|
||||
|
||||
localMessage.setFlag(Flag.X_REMOTE_COPY_STARTED, true);
|
||||
|
||||
remoteFolder.appendMessages(new Message[] { localMessage });
|
||||
remoteFolder.appendMessages(Collections.singletonList(localMessage));
|
||||
localFolder.changeUid(localMessage);
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.messageUidChanged(account, folder, oldUid, localMessage.getUid());
|
||||
@ -2325,14 +2313,14 @@ public class MessagingController implements Runnable {
|
||||
if (K9.FOLDER_NONE.equals(destFolderName)) {
|
||||
destFolderName = null;
|
||||
}
|
||||
remoteSrcFolder.delete(messages.toArray(EMPTY_MESSAGE_ARRAY), destFolderName);
|
||||
remoteSrcFolder.delete(messages, destFolderName);
|
||||
} else {
|
||||
remoteDestFolder = remoteStore.getFolder(destFolder);
|
||||
|
||||
if (isCopy) {
|
||||
remoteUidMap = remoteSrcFolder.copyMessages(messages.toArray(EMPTY_MESSAGE_ARRAY), remoteDestFolder);
|
||||
remoteUidMap = remoteSrcFolder.copyMessages(messages, remoteDestFolder);
|
||||
} else {
|
||||
remoteUidMap = remoteSrcFolder.moveMessages(messages.toArray(EMPTY_MESSAGE_ARRAY), remoteDestFolder);
|
||||
remoteUidMap = remoteSrcFolder.moveMessages(messages, remoteDestFolder);
|
||||
}
|
||||
}
|
||||
if (!isCopy && Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy())) {
|
||||
@ -2425,7 +2413,7 @@ public class MessagingController implements Runnable {
|
||||
if (messages.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
remoteFolder.setFlags(messages.toArray(EMPTY_MESSAGE_ARRAY), new Flag[] { flag }, newState);
|
||||
remoteFolder.setFlags(messages, Collections.singletonList(flag), newState);
|
||||
} finally {
|
||||
closeFolder(remoteFolder);
|
||||
}
|
||||
@ -2571,9 +2559,9 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
|
||||
if (isCopy) {
|
||||
remoteSrcFolder.copyMessages(new Message[] { remoteMessage }, remoteDestFolder);
|
||||
remoteSrcFolder.copyMessages(Collections.singletonList(remoteMessage), remoteDestFolder);
|
||||
} else {
|
||||
remoteSrcFolder.moveMessages(new Message[] { remoteMessage }, remoteDestFolder);
|
||||
remoteSrcFolder.moveMessages(Collections.singletonList(remoteMessage), remoteDestFolder);
|
||||
}
|
||||
remoteSrcFolder.close();
|
||||
remoteDestFolder.close();
|
||||
@ -2587,7 +2575,7 @@ public class MessagingController implements Runnable {
|
||||
Store localStore = account.getLocalStore();
|
||||
localFolder = (LocalFolder) localStore.getFolder(folder);
|
||||
localFolder.open(Folder.OPEN_MODE_RW);
|
||||
Message[] messages = localFolder.getMessages(null, false);
|
||||
List<? extends Message> messages = localFolder.getMessages(null, false);
|
||||
for (Message message : messages) {
|
||||
if (!message.isSet(Flag.SEEN)) {
|
||||
message.setFlag(Flag.SEEN, true);
|
||||
@ -2617,7 +2605,7 @@ public class MessagingController implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
remoteFolder.setFlags(new Flag[] {Flag.SEEN}, true);
|
||||
remoteFolder.setFlags(Collections.singletonList(Flag.SEEN), true);
|
||||
remoteFolder.close();
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
Log.w(K9.LOG_TAG, "Could not mark all server-side as read because store doesn't support operation", uoe);
|
||||
@ -2727,7 +2715,7 @@ public class MessagingController implements Runnable {
|
||||
|
||||
Store localStore = account.getLocalStore();
|
||||
LocalFolder localFolder = (LocalFolder)localStore.getFolder(account.getErrorFolderName());
|
||||
Message[] messages = new Message[1];
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
MimeMessage message = new MimeMessage();
|
||||
|
||||
|
||||
@ -2740,7 +2728,7 @@ public class MessagingController implements Runnable {
|
||||
message.setInternalDate(nowDate);
|
||||
message.addSentDate(nowDate);
|
||||
message.setFrom(new Address(account.getEmail(), "K9mail internal"));
|
||||
messages[0] = message;
|
||||
messages.set(0, message);
|
||||
|
||||
localFolder.appendMessages(messages);
|
||||
|
||||
@ -2874,7 +2862,7 @@ public class MessagingController implements Runnable {
|
||||
* @param newState
|
||||
* {@code true}, if the flag should be set. {@code false} if it should be removed.
|
||||
*/
|
||||
public void setFlag(Account account, String folderName, Message[] messages, Flag flag,
|
||||
public void setFlag(Account account, String folderName, List<Message> messages, Flag flag,
|
||||
boolean newState) {
|
||||
// TODO: Put this into the background, but right now some callers depend on the message
|
||||
// objects being modified right after this method returns.
|
||||
@ -2896,7 +2884,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
|
||||
// Update the messages in the local store
|
||||
localFolder.setFlags(messages, new Flag[] {flag}, newState);
|
||||
localFolder.setFlags(messages, Collections.singletonList(flag), newState);
|
||||
|
||||
int unreadMessageCount = localFolder.getUnreadMessageCount();
|
||||
for (MessagingListener l : getListeners()) {
|
||||
@ -2914,9 +2902,9 @@ public class MessagingController implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] uids = new String[messages.length];
|
||||
String[] uids = new String[messages.size()];
|
||||
for (int i = 0, end = uids.length; i < end; i++) {
|
||||
uids[i] = messages[i].getUid();
|
||||
uids[i] = messages.get(i).getUid();
|
||||
}
|
||||
|
||||
queueSetFlag(account, folderName, Boolean.toString(newState), flag.toString(), uids);
|
||||
@ -2953,7 +2941,7 @@ public class MessagingController implements Runnable {
|
||||
|
||||
Message message = localFolder.getMessage(uid);
|
||||
if (message != null) {
|
||||
setFlag(account, folderName, new Message[] { message }, flag, newState);
|
||||
setFlag(account, folderName, Collections.singletonList(message), flag, newState);
|
||||
}
|
||||
} catch (MessagingException me) {
|
||||
addErrorMessage(account, null, me);
|
||||
@ -3026,7 +3014,7 @@ public class MessagingController implements Runnable {
|
||||
FetchProfile fp = new FetchProfile();
|
||||
fp.add(FetchProfile.Item.ENVELOPE);
|
||||
fp.add(FetchProfile.Item.BODY);
|
||||
localFolder.fetch(new Message[] { message }, fp, null);
|
||||
localFolder.fetch(Collections.singletonList(message), fp, null);
|
||||
} else {
|
||||
/*
|
||||
* At this point the message is not available, so we need to download it
|
||||
@ -3042,16 +3030,16 @@ public class MessagingController implements Runnable {
|
||||
FetchProfile fp = new FetchProfile();
|
||||
fp.add(FetchProfile.Item.BODY);
|
||||
|
||||
remoteFolder.fetch(new Message[] { remoteMessage }, fp, null);
|
||||
remoteFolder.fetch(Collections.singletonList(remoteMessage), fp, null);
|
||||
|
||||
// Store the message locally and load the stored message into memory
|
||||
localFolder.appendMessages(new Message[] { remoteMessage });
|
||||
localFolder.appendMessages(Collections.singletonList(remoteMessage));
|
||||
if (loadPartialFromSearch) {
|
||||
fp.add(FetchProfile.Item.BODY);
|
||||
}
|
||||
fp.add(FetchProfile.Item.ENVELOPE);
|
||||
message = localFolder.getMessage(uid);
|
||||
localFolder.fetch(new Message[] { message }, fp, null);
|
||||
localFolder.fetch(Collections.singletonList(message), fp, null);
|
||||
|
||||
// Mark that this message is now fully synched
|
||||
if (account.isMarkMessageAsReadOnView()) {
|
||||
@ -3124,9 +3112,7 @@ public class MessagingController implements Runnable {
|
||||
FetchProfile fp = new FetchProfile();
|
||||
fp.add(FetchProfile.Item.ENVELOPE);
|
||||
fp.add(FetchProfile.Item.BODY);
|
||||
localFolder.fetch(new Message[] {
|
||||
message
|
||||
}, fp, null);
|
||||
localFolder.fetch(Collections.singletonList(message), fp, null);
|
||||
localFolder.close();
|
||||
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
@ -3266,7 +3252,7 @@ public class MessagingController implements Runnable {
|
||||
LocalStore localStore = account.getLocalStore();
|
||||
LocalFolder localFolder = localStore.getFolder(account.getOutboxFolderName());
|
||||
localFolder.open(Folder.OPEN_MODE_RW);
|
||||
localFolder.appendMessages(new Message[] { message });
|
||||
localFolder.appendMessages(Collections.singletonList(message));
|
||||
Message localMessage = localFolder.getMessage(message.getUid());
|
||||
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
|
||||
localFolder.close();
|
||||
@ -3504,9 +3490,9 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
localFolder.open(Folder.OPEN_MODE_RW);
|
||||
|
||||
Message[] localMessages = localFolder.getMessages(null);
|
||||
List<? extends Message> localMessages = localFolder.getMessages(null);
|
||||
int progress = 0;
|
||||
int todo = localMessages.length;
|
||||
int todo = localMessages.size();
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.synchronizeMailboxProgress(account, account.getSentFolderName(), progress, todo);
|
||||
}
|
||||
@ -3545,7 +3531,7 @@ public class MessagingController implements Runnable {
|
||||
|
||||
|
||||
|
||||
localFolder.fetch(new Message[] { message }, fp, null);
|
||||
localFolder.fetch(Collections.singletonList(message), fp, null);
|
||||
try {
|
||||
|
||||
|
||||
@ -3576,7 +3562,7 @@ public class MessagingController implements Runnable {
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "Moving sent message to folder '" + account.getSentFolderName() + "' (" + localSentFolder.getId() + ") ");
|
||||
|
||||
localFolder.moveMessages(new Message[] { message }, localSentFolder);
|
||||
localFolder.moveMessages(Collections.singletonList(message), localSentFolder);
|
||||
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "Moved sent message to folder '" + account.getSentFolderName() + "' (" + localSentFolder.getId() + ") ");
|
||||
@ -3594,7 +3580,7 @@ public class MessagingController implements Runnable {
|
||||
// This is a complete hack, but is worlds better than the previous
|
||||
// "don't even bother" functionality
|
||||
if (getRootCauseMessage(e).startsWith("5")) {
|
||||
localFolder.moveMessages(new Message[] { message }, (LocalFolder) localStore.getFolder(account.getDraftsFolderName()));
|
||||
localFolder.moveMessages(Collections.singletonList(message), (LocalFolder) localStore.getFolder(account.getDraftsFolderName()));
|
||||
}
|
||||
|
||||
notifyUserIfCertificateProblem(mApplication, e, account, false);
|
||||
@ -3679,14 +3665,14 @@ public class MessagingController implements Runnable {
|
||||
|
||||
// Collect accounts that belong to the search
|
||||
String[] accountUuids = search.getAccountUuids();
|
||||
Account[] accounts;
|
||||
List<Account> accounts;
|
||||
if (search.searchAllAccounts()) {
|
||||
accounts = preferences.getAccounts();
|
||||
} else {
|
||||
accounts = new Account[accountUuids.length];
|
||||
accounts = new ArrayList<Account>(accountUuids.length);
|
||||
for (int i = 0, len = accountUuids.length; i < len; i++) {
|
||||
String accountUuid = accountUuids[i];
|
||||
accounts[i] = preferences.getAccount(accountUuid);
|
||||
accounts.set(i, preferences.getAccount(accountUuid));
|
||||
}
|
||||
}
|
||||
|
||||
@ -3895,8 +3881,8 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
Message[] messages = localSrcFolder.getMessages(uids.toArray(EMPTY_STRING_ARRAY), null);
|
||||
if (messages.length > 0) {
|
||||
List<? extends Message> messages = localSrcFolder.getMessages(uids.toArray(EMPTY_STRING_ARRAY), null);
|
||||
if (messages.size() > 0) {
|
||||
Map<String, Message> origUidMap = new HashMap<String, Message>();
|
||||
|
||||
for (Message message : messages) {
|
||||
@ -3905,7 +3891,7 @@ public class MessagingController implements Runnable {
|
||||
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "moveOrCopyMessageSynchronous: source folder = " + srcFolder
|
||||
+ ", " + messages.length + " messages, " + ", destination folder = " + destFolder + ", isCopy = " + isCopy);
|
||||
+ ", " + messages.size() + " messages, " + ", destination folder = " + destFolder + ", isCopy = " + isCopy);
|
||||
|
||||
if (isCopy) {
|
||||
FetchProfile fp = new FetchProfile();
|
||||
@ -4014,7 +4000,7 @@ public class MessagingController implements Runnable {
|
||||
List<Message> messagesToDelete = collectMessagesInThreads(account, messages);
|
||||
|
||||
deleteMessagesSynchronous(account, folderName,
|
||||
messagesToDelete.toArray(EMPTY_MESSAGE_ARRAY), null);
|
||||
messagesToDelete, null);
|
||||
} catch (MessagingException e) {
|
||||
Log.e(K9.LOG_TAG, "Something went wrong while deleting threads", e);
|
||||
}
|
||||
@ -4031,8 +4017,9 @@ public class MessagingController implements Runnable {
|
||||
long rootId = localMessage.getRootId();
|
||||
long threadId = (rootId == -1) ? localMessage.getThreadId() : rootId;
|
||||
|
||||
Message[] messagesInThread = localStore.getMessagesInThread(threadId);
|
||||
Collections.addAll(messagesInThreads, messagesInThread);
|
||||
List<? extends Message> messagesInThread = localStore.getMessagesInThread(threadId);
|
||||
|
||||
messagesInThreads.addAll(messagesInThread);
|
||||
}
|
||||
|
||||
return messagesInThreads;
|
||||
@ -4050,7 +4037,7 @@ public class MessagingController implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
deleteMessagesSynchronous(account, folder.getName(),
|
||||
accountMessages.toArray(EMPTY_MESSAGE_ARRAY), listener);
|
||||
accountMessages, listener);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -4059,7 +4046,7 @@ public class MessagingController implements Runnable {
|
||||
|
||||
}
|
||||
|
||||
private void deleteMessagesSynchronous(final Account account, final String folder, final Message[] messages,
|
||||
private void deleteMessagesSynchronous(final Account account, final String folder, final List<? extends Message> messages,
|
||||
MessagingListener listener) {
|
||||
Folder localFolder = null;
|
||||
Folder localTrashFolder = null;
|
||||
@ -4079,7 +4066,7 @@ public class MessagingController implements Runnable {
|
||||
if (K9.DEBUG)
|
||||
Log.d(K9.LOG_TAG, "Deleting messages in trash folder or trash set to -None-, not copying");
|
||||
|
||||
localFolder.setFlags(messages, new Flag[] { Flag.DELETED }, true);
|
||||
localFolder.setFlags(messages, Collections.singleton(Flag.DELETED), true);
|
||||
} else {
|
||||
localTrashFolder = localStore.getFolder(account.getTrashFolderName());
|
||||
if (!localTrashFolder.exists()) {
|
||||
@ -4147,10 +4134,10 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getUidsFromMessages(Message[] messages) {
|
||||
String[] uids = new String[messages.length];
|
||||
for (int i = 0; i < messages.length; i++) {
|
||||
uids[i] = messages[i].getUid();
|
||||
private String[] getUidsFromMessages(List <? extends Message> messages) {
|
||||
String[] uids = new String[messages.size()];
|
||||
for (int i = 0; i < messages.size(); i++) {
|
||||
uids[i] = messages.get(i).getUid();
|
||||
}
|
||||
return uids;
|
||||
}
|
||||
@ -4162,7 +4149,7 @@ public class MessagingController implements Runnable {
|
||||
try {
|
||||
if (remoteFolder.exists()) {
|
||||
remoteFolder.open(Folder.OPEN_MODE_RW);
|
||||
remoteFolder.setFlags(new Flag [] { Flag.DELETED }, true);
|
||||
remoteFolder.setFlags(Collections.singleton(Flag.DELETED), true);
|
||||
if (Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy())) {
|
||||
remoteFolder.expunge();
|
||||
}
|
||||
@ -4193,7 +4180,7 @@ public class MessagingController implements Runnable {
|
||||
if (isTrashLocalOnly) {
|
||||
localFolder.clearAllMessages();
|
||||
} else {
|
||||
localFolder.setFlags(new Flag[] { Flag.DELETED }, true);
|
||||
localFolder.setFlags(Collections.singleton(Flag.DELETED), true);
|
||||
}
|
||||
|
||||
for (MessagingListener l : getListeners()) {
|
||||
@ -5030,7 +5017,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
|
||||
private boolean skipAccountsInBackStack(Context context) {
|
||||
return Preferences.getPreferences(context).getAccounts().length == 1;
|
||||
return Preferences.getPreferences(context).getAccounts().size() == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -5112,9 +5099,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
|
||||
// Save the message to the store.
|
||||
localFolder.appendMessages(new Message[] {
|
||||
message
|
||||
});
|
||||
localFolder.appendMessages(Collections.singletonList(message));
|
||||
// Fetch the message back from the store. This is the Message that's returned to the caller.
|
||||
localMessage = localFolder.getMessage(message.getUid());
|
||||
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
|
||||
|
@ -33,7 +33,7 @@ public class MessagingListener {
|
||||
|
||||
public void listFoldersStarted(Account account) {}
|
||||
|
||||
public void listFolders(Account account, Folder[] folders) {}
|
||||
public void listFolders(Account account, List<? extends Folder> folders) {}
|
||||
|
||||
public void listFoldersFinished(Account account) {}
|
||||
|
||||
|
@ -960,16 +960,16 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
||||
accountUuids[0].equals(SearchSpecification.ALL_ACCOUNTS)) {
|
||||
mAllAccounts = true;
|
||||
|
||||
Account[] accounts = mPreferences.getAccounts();
|
||||
List<Account> accounts = mPreferences.getAccounts();
|
||||
|
||||
mAccountUuids = new String[accounts.length];
|
||||
for (int i = 0, len = accounts.length; i < len; i++) {
|
||||
mAccountUuids[i] = accounts[i].getUuid();
|
||||
mAccountUuids = new String[accounts.size()];
|
||||
for (int i = 0, len = accounts.size(); i < len; i++) {
|
||||
mAccountUuids[i] = accounts.get(i).getUuid();
|
||||
}
|
||||
|
||||
if (mAccountUuids.length == 1) {
|
||||
mSingleAccountMode = true;
|
||||
mAccount = accounts[0];
|
||||
mAccount = accounts.get(0);
|
||||
}
|
||||
} else {
|
||||
mAccountUuids = accountUuids;
|
||||
@ -1084,11 +1084,11 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
||||
mController.addListener(mListener);
|
||||
|
||||
//Cancel pending new mail notifications when we open an account
|
||||
Account[] accountsWithNotification;
|
||||
List<Account> accountsWithNotification;
|
||||
|
||||
Account account = mAccount;
|
||||
if (account != null) {
|
||||
accountsWithNotification = new Account[] { account };
|
||||
accountsWithNotification = Collections.singletonList(account);
|
||||
} else {
|
||||
accountsWithNotification = mPreferences.getAccounts();
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
|
||||
if (mMessage != null) {
|
||||
boolean newState = !mMessage.isSet(Flag.FLAGGED);
|
||||
mController.setFlag(mAccount, mMessage.getFolder().getName(),
|
||||
new Message[] { mMessage }, Flag.FLAGGED, newState);
|
||||
Collections.singletonList(mMessage), Flag.FLAGGED, newState);
|
||||
mMessageView.setHeaders(mMessage, mAccount);
|
||||
}
|
||||
}
|
||||
@ -485,7 +485,7 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
|
||||
public void onToggleRead() {
|
||||
if (mMessage != null) {
|
||||
mController.setFlag(mAccount, mMessage.getFolder().getName(),
|
||||
new Message[] { mMessage }, Flag.SEEN, !mMessage.isSet(Flag.SEEN));
|
||||
Collections.singletonList(mMessage), Flag.SEEN, !mMessage.isSet(Flag.SEEN));
|
||||
mMessageView.setHeaders(mMessage, mAccount);
|
||||
String subject = mMessage.getSubject();
|
||||
displayMessageSubject(subject);
|
||||
|
@ -105,6 +105,22 @@ public class Utility {
|
||||
return TextUtils.join(String.valueOf(separator), parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines the given Objects into a single String using
|
||||
* each Object's toString() method and the separator character
|
||||
* between each part.
|
||||
*
|
||||
* @param parts
|
||||
* @param separator
|
||||
* @return new String
|
||||
*/
|
||||
public static String combine(Iterable<?> parts, char separator) {
|
||||
if (parts == null) {
|
||||
return null;
|
||||
}
|
||||
return TextUtils.join(String.valueOf(separator), parts);
|
||||
}
|
||||
|
||||
public static String base64Decode(String encoded) {
|
||||
if (encoded == null) {
|
||||
return null;
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.fsck.k9.mail;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import android.util.Log;
|
||||
import com.fsck.k9.Account;
|
||||
@ -92,7 +94,7 @@ public abstract class Folder {
|
||||
* @return List of messages
|
||||
* @throws MessagingException
|
||||
*/
|
||||
public abstract Message[] getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener) throws MessagingException;
|
||||
public abstract List<? extends Message> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener) throws MessagingException;
|
||||
|
||||
/**
|
||||
* Fetches the given list of messages. The specified listener is notified as
|
||||
@ -102,36 +104,36 @@ public abstract class Folder {
|
||||
* @param listener Listener to notify as we download messages.
|
||||
* @return List of messages
|
||||
*/
|
||||
public abstract Message[] getMessages(MessageRetrievalListener listener) throws MessagingException;
|
||||
public abstract List<? extends Message> getMessages(MessageRetrievalListener listener) throws MessagingException;
|
||||
|
||||
public Message[] getMessages(MessageRetrievalListener listener, boolean includeDeleted) throws MessagingException {
|
||||
public List<? extends Message> getMessages(MessageRetrievalListener listener, boolean includeDeleted) throws MessagingException {
|
||||
return getMessages(listener);
|
||||
}
|
||||
|
||||
public abstract Message[] getMessages(String[] uids, MessageRetrievalListener listener)
|
||||
public abstract List<? extends Message> getMessages(String[] uids, MessageRetrievalListener listener)
|
||||
throws MessagingException;
|
||||
|
||||
public abstract Map<String, String> appendMessages(Message[] messages) throws MessagingException;
|
||||
public abstract Map<String, String> appendMessages(List<? extends Message> messages) throws MessagingException;
|
||||
|
||||
public Map<String, String> copyMessages(Message[] msgs, Folder folder) throws MessagingException {
|
||||
public Map<String, String> copyMessages(List<? extends Message> msgs, Folder folder) throws MessagingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<String, String> moveMessages(Message[] msgs, Folder folder) throws MessagingException {
|
||||
public Map<String, String> moveMessages(List<? extends Message> msgs, Folder folder) throws MessagingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void delete(Message[] msgs, String trashFolderName) throws MessagingException {
|
||||
public void delete(List<? extends Message> msgs, String trashFolderName) throws MessagingException {
|
||||
for (Message message : msgs) {
|
||||
Message myMessage = getMessage(message.getUid());
|
||||
myMessage.delete(trashFolderName);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void setFlags(Message[] messages, Flag[] flags, boolean value)
|
||||
public abstract void setFlags(List<? extends Message> messages, Collection<Flag> flags, boolean value)
|
||||
throws MessagingException;
|
||||
|
||||
public abstract void setFlags(Flag[] flags, boolean value) throws MessagingException;
|
||||
public abstract void setFlags(Collection<Flag> flags, boolean value) throws MessagingException;
|
||||
|
||||
public abstract String getUidFromMessageId(Message message) throws MessagingException;
|
||||
|
||||
@ -146,7 +148,7 @@ public abstract class Folder {
|
||||
* @param listener Listener to notify as we fetch messages.
|
||||
* @throws MessagingException
|
||||
*/
|
||||
public abstract void fetch(Message[] messages, FetchProfile fp,
|
||||
public abstract void fetch(List<? extends Message> messages, FetchProfile fp,
|
||||
MessageRetrievalListener listener) throws MessagingException;
|
||||
|
||||
public void fetchPart(Message message, Part part,
|
||||
@ -243,7 +245,7 @@ public abstract class Folder {
|
||||
return mAccount;
|
||||
}
|
||||
|
||||
public List<Message> search(String queryString, final Flag[] requiredFlags, final Flag[] forbiddenFlags)
|
||||
public List<Message> search(String queryString, final Set<Flag> requiredFlags, final Set<Flag> forbiddenFlags)
|
||||
throws MessagingException {
|
||||
throw new MessagingException("K-9 does not support searches on this folder type");
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
package com.fsck.k9.mail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@ -16,7 +18,6 @@ import com.fsck.k9.mail.store.UnavailableStorageException;
|
||||
|
||||
|
||||
public abstract class Message implements Part, CompositeBody {
|
||||
private static final Flag[] EMPTY_FLAG_ARRAY = new Flag[0];
|
||||
|
||||
private MessageReference mReference = null;
|
||||
|
||||
@ -208,8 +209,8 @@ public abstract class Message implements Part, CompositeBody {
|
||||
/*
|
||||
* TODO Refactor Flags at some point to be able to store user defined flags.
|
||||
*/
|
||||
public Flag[] getFlags() {
|
||||
return mFlags.toArray(EMPTY_FLAG_ARRAY);
|
||||
public Collection<Flag> getFlags() {
|
||||
return Collections.unmodifiableCollection(mFlags);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,7 +234,7 @@ public abstract class Message implements Part, CompositeBody {
|
||||
* @param flags
|
||||
* @param set
|
||||
*/
|
||||
public void setFlags(Flag[] flags, boolean set) throws MessagingException {
|
||||
public void setFlags(final Collection<Flag> flags, boolean set) throws MessagingException {
|
||||
for (Flag flag : flags) {
|
||||
setFlag(flag, set);
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ public abstract class Store {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void sendMessages(Message[] messages) throws MessagingException {
|
||||
public void sendMessages(List<? extends Message> messages) throws MessagingException {
|
||||
}
|
||||
|
||||
public Pusher getPusher(PushReceiver receiver) {
|
||||
|
@ -26,6 +26,7 @@ import java.security.Security;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Deque;
|
||||
@ -132,8 +133,6 @@ public class ImapStore extends Store {
|
||||
private static final String CAPABILITY_COMPRESS_DEFLATE = "COMPRESS=DEFLATE";
|
||||
private static final String COMMAND_COMPRESS_DEFLATE = "COMPRESS DEFLATE";
|
||||
|
||||
private static final Message[] EMPTY_MESSAGE_ARRAY = new Message[0];
|
||||
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
/**
|
||||
@ -1092,22 +1091,22 @@ public class ImapStore extends Store {
|
||||
* @return The mapping of original message UIDs to the new server UIDs.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> copyMessages(Message[] messages, Folder folder)
|
||||
public Map<String, String> copyMessages(List<? extends Message> messages, Folder folder)
|
||||
throws MessagingException {
|
||||
if (!(folder instanceof ImapFolder)) {
|
||||
throw new MessagingException("ImapFolder.copyMessages passed non-ImapFolder");
|
||||
}
|
||||
|
||||
if (messages.length == 0) {
|
||||
if (messages.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ImapFolder iFolder = (ImapFolder)folder;
|
||||
checkOpen(); //only need READ access
|
||||
|
||||
String[] uids = new String[messages.length];
|
||||
for (int i = 0, count = messages.length; i < count; i++) {
|
||||
uids[i] = messages[i].getUid();
|
||||
String[] uids = new String[messages.size()];
|
||||
for (int i = 0, count = messages.size(); i < count; i++) {
|
||||
uids[i] = messages.get(i).getUid();
|
||||
}
|
||||
|
||||
try {
|
||||
@ -1193,21 +1192,21 @@ public class ImapStore extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> moveMessages(Message[] messages, Folder folder) throws MessagingException {
|
||||
if (messages.length == 0)
|
||||
public Map<String, String> moveMessages(List<? extends Message> messages, Folder folder) throws MessagingException {
|
||||
if (messages.size() == 0)
|
||||
return null;
|
||||
Map<String, String> uidMap = copyMessages(messages, folder);
|
||||
setFlags(messages, new Flag[] { Flag.DELETED }, true);
|
||||
setFlags(messages, Collections.singleton(Flag.DELETED), true);
|
||||
return uidMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Message[] messages, String trashFolderName) throws MessagingException {
|
||||
if (messages.length == 0)
|
||||
public void delete(List<? extends Message> messages, String trashFolderName) throws MessagingException {
|
||||
if (messages.size() == 0)
|
||||
return;
|
||||
|
||||
if (trashFolderName == null || getName().equalsIgnoreCase(trashFolderName)) {
|
||||
setFlags(messages, new Flag[] { Flag.DELETED }, true);
|
||||
setFlags(messages, Collections.singleton(Flag.DELETED), true);
|
||||
} else {
|
||||
ImapFolder remoteTrashFolder = (ImapFolder)getStore().getFolder(trashFolderName);
|
||||
String remoteTrashName = encodeString(encodeFolderName(remoteTrashFolder.getPrefixedName()));
|
||||
@ -1223,7 +1222,7 @@ public class ImapStore extends Store {
|
||||
|
||||
if (exists(remoteTrashName)) {
|
||||
if (K9.DEBUG)
|
||||
Log.d(K9.LOG_TAG, "IMAPMessage.delete: copying remote " + messages.length + " messages to '" + trashFolderName + "' for " + getLogId());
|
||||
Log.d(K9.LOG_TAG, "IMAPMessage.delete: copying remote " + messages.size() + " messages to '" + trashFolderName + "' for " + getLogId());
|
||||
|
||||
moveMessages(messages, remoteTrashFolder);
|
||||
} else {
|
||||
@ -1278,9 +1277,9 @@ public class ImapStore extends Store {
|
||||
return executeSimpleCommand("UID SEARCH *:*");
|
||||
}
|
||||
};
|
||||
Message[] messages = search(searcher, null).toArray(EMPTY_MESSAGE_ARRAY);
|
||||
if (messages.length > 0) {
|
||||
return Long.parseLong(messages[0].getUid());
|
||||
List<? extends Message> messages = search(searcher, null);
|
||||
if (messages.size() > 0) {
|
||||
return Long.parseLong(messages.get(0).getUid());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(K9.LOG_TAG, "Unable to find highest UID in folder " + getName(), e);
|
||||
@ -1301,12 +1300,12 @@ public class ImapStore extends Store {
|
||||
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
|
||||
public List<? extends Message> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
return getMessages(start, end, earliestDate, false, listener);
|
||||
}
|
||||
|
||||
protected Message[] getMessages(final int start, final int end, Date earliestDate, final boolean includeDeleted, final MessageRetrievalListener listener)
|
||||
protected List<? extends Message> getMessages(final int start, final int end, Date earliestDate, final boolean includeDeleted, final MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
if (start < 1 || end < 1 || end < start) {
|
||||
throw new MessagingException(
|
||||
@ -1328,10 +1327,10 @@ public class ImapStore extends Store {
|
||||
return executeSimpleCommand(String.format(Locale.US, "UID SEARCH %d:%d%s%s", start, end, dateSearchString, includeDeleted ? "" : " NOT DELETED"));
|
||||
}
|
||||
};
|
||||
return search(searcher, listener).toArray(EMPTY_MESSAGE_ARRAY);
|
||||
return search(searcher, listener);
|
||||
|
||||
}
|
||||
protected Message[] getMessages(final List<Long> mesgSeqs, final boolean includeDeleted, final MessageRetrievalListener listener)
|
||||
protected List<? extends Message> getMessages(final List<Long> mesgSeqs, final boolean includeDeleted, final MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
ImapSearcher searcher = new ImapSearcher() {
|
||||
@Override
|
||||
@ -1339,10 +1338,10 @@ public class ImapStore extends Store {
|
||||
return executeSimpleCommand(String.format("UID SEARCH %s%s", Utility.combine(mesgSeqs.toArray(), ','), includeDeleted ? "" : " NOT DELETED"));
|
||||
}
|
||||
};
|
||||
return search(searcher, listener).toArray(EMPTY_MESSAGE_ARRAY);
|
||||
return search(searcher, listener);
|
||||
}
|
||||
|
||||
protected Message[] getMessagesFromUids(final List<String> mesgUids, final boolean includeDeleted, final MessageRetrievalListener listener)
|
||||
protected List<? extends Message> getMessagesFromUids(final List<String> mesgUids, final boolean includeDeleted, final MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
ImapSearcher searcher = new ImapSearcher() {
|
||||
@Override
|
||||
@ -1350,7 +1349,7 @@ public class ImapStore extends Store {
|
||||
return executeSimpleCommand(String.format("UID SEARCH UID %s%s", Utility.combine(mesgUids.toArray(), ','), includeDeleted ? "" : " NOT DELETED"));
|
||||
}
|
||||
};
|
||||
return search(searcher, listener).toArray(EMPTY_MESSAGE_ARRAY);
|
||||
return search(searcher, listener);
|
||||
}
|
||||
|
||||
private List<Message> search(ImapSearcher searcher, MessageRetrievalListener listener) throws MessagingException {
|
||||
@ -1395,12 +1394,12 @@ public class ImapStore extends Store {
|
||||
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(MessageRetrievalListener listener) throws MessagingException {
|
||||
public List<? extends Message> getMessages(MessageRetrievalListener listener) throws MessagingException {
|
||||
return getMessages(null, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(String[] uids, MessageRetrievalListener listener)
|
||||
public List<? extends Message> getMessages(String[] uids, MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
checkOpen(); //only need READ access
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
@ -1430,18 +1429,18 @@ public class ImapStore extends Store {
|
||||
} catch (IOException ioe) {
|
||||
throw ioExceptionHandler(mConnection, ioe);
|
||||
}
|
||||
return messages.toArray(EMPTY_MESSAGE_ARRAY);
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetch(Message[] messages, FetchProfile fp, MessageRetrievalListener listener)
|
||||
public void fetch(List<? extends Message> messages, FetchProfile fp, MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
if (messages == null || messages.length == 0) {
|
||||
if (messages == null || messages.size() == 0) {
|
||||
return;
|
||||
}
|
||||
checkOpen(); //only need READ access
|
||||
List<String> uids = new ArrayList<String>(messages.length);
|
||||
Map<String, Message> messageMap = new HashMap<String, Message>();
|
||||
List<String> uids = new ArrayList<String>(messages.size());
|
||||
HashMap<String, Message> messageMap = new HashMap<String, Message>();
|
||||
for (Message msg : messages) {
|
||||
String uid = msg.getUid();
|
||||
uids.add(uid);
|
||||
@ -1482,8 +1481,8 @@ public class ImapStore extends Store {
|
||||
|
||||
|
||||
|
||||
for (int windowStart = 0; windowStart < messages.length; windowStart += (FETCH_WINDOW_SIZE)) {
|
||||
List<String> uidWindow = uids.subList(windowStart, Math.min((windowStart + FETCH_WINDOW_SIZE), messages.length));
|
||||
for (int windowStart = 0; windowStart < messages.size(); windowStart += (FETCH_WINDOW_SIZE)) {
|
||||
List<String> uidWindow = uids.subList(windowStart, Math.min((windowStart + FETCH_WINDOW_SIZE), messages.size()));
|
||||
|
||||
try {
|
||||
mConnection.sendCommand(String.format("UID FETCH %s (%s)",
|
||||
@ -1965,7 +1964,7 @@ public class ImapStore extends Store {
|
||||
* @return The mapping of original message UIDs to the new server UIDs.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> appendMessages(Message[] messages) throws MessagingException {
|
||||
public Map<String, String> appendMessages(List<? extends Message> messages) throws MessagingException {
|
||||
open(OPEN_MODE_RW);
|
||||
checkOpen();
|
||||
try {
|
||||
@ -2088,7 +2087,7 @@ public class ImapStore extends Store {
|
||||
}
|
||||
}
|
||||
|
||||
private String combineFlags(Flag[] flags) {
|
||||
private String combineFlags(Iterable<Flag> flags) {
|
||||
List<String> flagNames = new ArrayList<String>();
|
||||
for (Flag flag : flags) {
|
||||
if (flag == Flag.SEEN) {
|
||||
@ -2110,7 +2109,7 @@ public class ImapStore extends Store {
|
||||
|
||||
|
||||
@Override
|
||||
public void setFlags(Flag[] flags, boolean value)
|
||||
public void setFlags(Collection<Flag> flags, boolean value)
|
||||
throws MessagingException {
|
||||
open(OPEN_MODE_RW);
|
||||
checkOpen();
|
||||
@ -2145,13 +2144,13 @@ public class ImapStore extends Store {
|
||||
|
||||
|
||||
@Override
|
||||
public void setFlags(Message[] messages, Flag[] flags, boolean value)
|
||||
public void setFlags(List<? extends Message> messages, final Collection<Flag> flags, boolean value)
|
||||
throws MessagingException {
|
||||
open(OPEN_MODE_RW);
|
||||
checkOpen();
|
||||
String[] uids = new String[messages.length];
|
||||
for (int i = 0, count = messages.length; i < count; i++) {
|
||||
uids[i] = messages[i].getUid();
|
||||
String[] uids = new String[messages.size()];
|
||||
for (int i = 0, count = messages.size(); i < count; i++) {
|
||||
uids[i] = messages.get(i).getUid();
|
||||
}
|
||||
try {
|
||||
executeSimpleCommand(String.format("UID STORE %s %sFLAGS.SILENT (%s)",
|
||||
@ -2212,7 +2211,7 @@ public class ImapStore extends Store {
|
||||
* @throws MessagingException On any error.
|
||||
*/
|
||||
@Override
|
||||
public List<Message> search(final String queryString, final Flag[] requiredFlags, final Flag[] forbiddenFlags)
|
||||
public List<Message> search(final String queryString, final Set<Flag> requiredFlags, final Set<Flag> forbiddenFlags)
|
||||
throws MessagingException {
|
||||
|
||||
if (!mAccount.allowRemoteSearch()) {
|
||||
@ -2911,12 +2910,12 @@ public class ImapStore extends Store {
|
||||
@Override
|
||||
public void setFlag(Flag flag, boolean set) throws MessagingException {
|
||||
super.setFlag(flag, set);
|
||||
mFolder.setFlags(new Message[] { this }, new Flag[] { flag }, set);
|
||||
mFolder.setFlags(Collections.singletonList(this), Collections.singletonList(flag), set);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String trashFolderName) throws MessagingException {
|
||||
getFolder().delete(new Message[] { this }, trashFolderName);
|
||||
getFolder().delete(Collections.singletonList(this), trashFolderName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3209,9 +3208,9 @@ public class ImapStore extends Store {
|
||||
Log.e(K9.LOG_TAG, "Unable to get oldUidNext for " + getLogId(), e);
|
||||
}
|
||||
|
||||
Message[] messageArray = getMessages(end, end, null, true, null);
|
||||
if (messageArray != null && messageArray.length > 0) {
|
||||
long newUid = Long.parseLong(messageArray[0].getUid());
|
||||
List<? extends Message> messageArray = getMessages(end, end, null, true, null);
|
||||
if (messageArray != null && messageArray.size() > 0) {
|
||||
long newUid = Long.parseLong(messageArray.get(0).getUid());
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "Got newUid " + newUid + " for message " + end + " on " + getLogId());
|
||||
long startUid = oldUidNext;
|
||||
@ -3239,12 +3238,10 @@ public class ImapStore extends Store {
|
||||
|
||||
private void syncMessages(List<Long> flagSyncMsgSeqs) {
|
||||
try {
|
||||
Message[] messageArray = null;
|
||||
|
||||
messageArray = getMessages(flagSyncMsgSeqs, true, null);
|
||||
List<? extends Message> messageArray = getMessages(flagSyncMsgSeqs, true, null);
|
||||
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
messages.addAll(Arrays.asList(messageArray));
|
||||
messages.addAll(messageArray);
|
||||
pushMessages(messages, false);
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -3256,7 +3253,7 @@ public class ImapStore extends Store {
|
||||
List<Message> messages = new ArrayList<Message>(removeUids.size());
|
||||
|
||||
try {
|
||||
Message[] existingMessages = getMessagesFromUids(removeUids, true, null);
|
||||
List<? extends Message> existingMessages = getMessagesFromUids(removeUids, true, null);
|
||||
for (Message existingMessage : existingMessages) {
|
||||
needsPoll.set(true);
|
||||
msgSeqUidMap.clear();
|
||||
|
@ -24,6 +24,8 @@ import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.HashMap;
|
||||
@ -566,7 +568,7 @@ public class Pop3Store extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
|
||||
public List<? extends Message> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
if (start < 1 || end < 1 || end < start) {
|
||||
throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d",
|
||||
@ -599,7 +601,7 @@ public class Pop3Store extends Store {
|
||||
listener.messageFinished(message, i++, (end - start) + 1);
|
||||
}
|
||||
}
|
||||
return messages.toArray(new Message[messages.size()]);
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -741,12 +743,12 @@ public class Pop3Store extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(MessageRetrievalListener listener) throws MessagingException {
|
||||
public List<? extends Message> getMessages(MessageRetrievalListener listener) throws MessagingException {
|
||||
throw new UnsupportedOperationException("Pop3: No getMessages");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(String[] uids, MessageRetrievalListener listener)
|
||||
public List<? extends Message> getMessages(String[] uids, MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
throw new UnsupportedOperationException("Pop3: No getMessages by uids");
|
||||
}
|
||||
@ -759,9 +761,9 @@ public class Pop3Store extends Store {
|
||||
* @throws MessagingException
|
||||
*/
|
||||
@Override
|
||||
public void fetch(Message[] messages, FetchProfile fp, MessageRetrievalListener listener)
|
||||
public void fetch(List<? extends Message> messages, FetchProfile fp, MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
if (messages == null || messages.length == 0) {
|
||||
if (messages == null || messages.size() == 0) {
|
||||
return;
|
||||
}
|
||||
List<String> uids = new ArrayList<String>();
|
||||
@ -786,8 +788,8 @@ public class Pop3Store extends Store {
|
||||
} catch (IOException ioe) {
|
||||
throw new MessagingException("fetch", ioe);
|
||||
}
|
||||
for (int i = 0, count = messages.length; i < count; i++) {
|
||||
Message message = messages[i];
|
||||
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");
|
||||
}
|
||||
@ -825,7 +827,7 @@ public class Pop3Store extends Store {
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchEnvelope(Message[] messages,
|
||||
private void fetchEnvelope(List<? extends Message> messages,
|
||||
MessageRetrievalListener listener) throws IOException, MessagingException {
|
||||
int unsizedMessages = 0;
|
||||
for (Message message : messages) {
|
||||
@ -841,8 +843,8 @@ public class Pop3Store extends Store {
|
||||
* In extreme cases we'll do a command per message instead of a bulk request
|
||||
* to hopefully save some time and bandwidth.
|
||||
*/
|
||||
for (int i = 0, count = messages.length; i < count; i++) {
|
||||
Message message = messages[i];
|
||||
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");
|
||||
}
|
||||
@ -865,7 +867,7 @@ public class Pop3Store extends Store {
|
||||
for (Message message : messages) {
|
||||
msgUidIndex.add(message.getUid());
|
||||
}
|
||||
int i = 0, count = messages.length;
|
||||
int i = 0, count = messages.size();
|
||||
String response = executeSimpleCommand(LIST_COMMAND);
|
||||
while ((response = readLine()) != null) {
|
||||
if (response.equals(".")) {
|
||||
@ -956,7 +958,7 @@ public class Pop3Store extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> appendMessages(Message[] messages) throws MessagingException {
|
||||
public Map<String, String> appendMessages(List<? extends Message> messages) throws MessagingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -965,8 +967,8 @@ public class Pop3Store extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Message[] msgs, String trashFolderName) throws MessagingException {
|
||||
setFlags(msgs, new Flag[] { Flag.DELETED }, true);
|
||||
public void delete(List<? extends Message> msgs, String trashFolderName) throws MessagingException {
|
||||
setFlags(msgs, Collections.singleton(Flag.DELETED), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -975,14 +977,14 @@ public class Pop3Store extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlags(Flag[] flags, boolean value) throws MessagingException {
|
||||
throw new UnsupportedOperationException("POP3: No setFlags(Flag[],boolean)");
|
||||
public void setFlags(final Collection<Flag> flags, boolean value) throws MessagingException {
|
||||
throw new UnsupportedOperationException("POP3: No setFlags(Collection<Flag>,boolean)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlags(Message[] messages, Flag[] flags, boolean value)
|
||||
public void setFlags(List<? extends Message> messages, final Collection<Flag> flags, boolean value)
|
||||
throws MessagingException {
|
||||
if (!value || !Utility.arrayContains(flags, Flag.DELETED)) {
|
||||
if (!value || !flags.contains(Flag.DELETED)) {
|
||||
/*
|
||||
* The only flagging we support is setting the Deleted flag.
|
||||
*/
|
||||
@ -1185,7 +1187,7 @@ public class Pop3Store extends Store {
|
||||
@Override
|
||||
public void setFlag(Flag flag, boolean set) throws MessagingException {
|
||||
super.setFlag(flag, set);
|
||||
mFolder.setFlags(new Message[] { this }, new Flag[] { flag }, set);
|
||||
mFolder.setFlags(Collections.singletonList(this), Collections.singletonList(flag), set);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,8 +65,6 @@ public class WebDavStore extends Store {
|
||||
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
private static final Message[] EMPTY_MESSAGE_ARRAY = new Message[0];
|
||||
|
||||
// These are the ids used from Exchange server to identify the special folders
|
||||
// http://social.technet.microsoft.com/Forums/en/exchangesvrdevelopment/thread/1cd2e98c-8a12-44bd-a3e3-9c5ee9e4e14d
|
||||
private static final String DAV_MAIL_INBOX_FOLDER = "inbox";
|
||||
@ -1197,11 +1195,11 @@ public class WebDavStore extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessages(Message[] messages) throws MessagingException {
|
||||
public void sendMessages(List<? extends Message> messages) throws MessagingException {
|
||||
WebDavFolder tmpFolder = (WebDavStore.WebDavFolder) getFolder(mAccount.getDraftsFolderName());
|
||||
try {
|
||||
tmpFolder.open(Folder.OPEN_MODE_RW);
|
||||
Message[] retMessages = tmpFolder.appendWebDavMessages(messages);
|
||||
List<? extends Message> retMessages = tmpFolder.appendWebDavMessages(messages);
|
||||
|
||||
tmpFolder.moveMessages(retMessages, getSendSpoolFolder());
|
||||
} finally {
|
||||
@ -1270,28 +1268,28 @@ public class WebDavStore extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> copyMessages(Message[] messages, Folder folder) throws MessagingException {
|
||||
public Map<String, String> copyMessages(List<? extends Message> messages, Folder folder) throws MessagingException {
|
||||
moveOrCopyMessages(messages, folder.getName(), false);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> moveMessages(Message[] messages, Folder folder) throws MessagingException {
|
||||
public Map<String, String> moveMessages(List<? extends Message> messages, Folder folder) throws MessagingException {
|
||||
moveOrCopyMessages(messages, folder.getName(), true);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Message[] msgs, String trashFolderName) throws MessagingException {
|
||||
public void delete(List<? extends Message> msgs, String trashFolderName) throws MessagingException {
|
||||
moveOrCopyMessages(msgs, trashFolderName, true);
|
||||
}
|
||||
|
||||
private void moveOrCopyMessages(Message[] messages, String folderName, boolean isMove)
|
||||
private void moveOrCopyMessages(List<? extends Message> messages, String folderName, boolean isMove)
|
||||
throws MessagingException {
|
||||
String[] uids = new String[messages.length];
|
||||
String[] uids = new String[messages.size()];
|
||||
|
||||
for (int i = 0, count = messages.length; i < count; i++) {
|
||||
uids[i] = messages[i].getUid();
|
||||
for (int i = 0, count = messages.size(); i < count; i++) {
|
||||
uids[i] = messages.get(i).getUid();
|
||||
}
|
||||
String messageBody = "";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
@ -1300,8 +1298,8 @@ public class WebDavStore extends Store {
|
||||
|
||||
for (int i = 0, count = uids.length; i < count; i++) {
|
||||
urls[i] = uidToUrl.get(uids[i]);
|
||||
if (urls[i] == null && messages[i] instanceof WebDavMessage) {
|
||||
WebDavMessage wdMessage = (WebDavMessage) messages[i];
|
||||
if (urls[i] == null && messages.get(i) instanceof WebDavMessage) {
|
||||
WebDavMessage wdMessage = (WebDavMessage) messages.get(i);
|
||||
urls[i] = wdMessage.getUrl();
|
||||
}
|
||||
}
|
||||
@ -1312,7 +1310,7 @@ public class WebDavStore extends Store {
|
||||
headers.put("Brief", "t");
|
||||
headers.put("If-Match", "*");
|
||||
String action = (isMove ? "BMOVE" : "BCOPY");
|
||||
Log.i(K9.LOG_TAG, "Moving " + messages.length + " messages to " + destFolder.mFolderUrl);
|
||||
Log.i(K9.LOG_TAG, "Moving " + messages.size() + " messages to " + destFolder.mFolderUrl);
|
||||
|
||||
processRequest(mFolderUrl, action, messageBody, headers, false);
|
||||
}
|
||||
@ -1404,7 +1402,7 @@ public class WebDavStore extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
|
||||
public List<? extends Message> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
String[] uids;
|
||||
@ -1450,22 +1448,22 @@ public class WebDavStore extends Store {
|
||||
}
|
||||
}
|
||||
|
||||
return messages.toArray(EMPTY_MESSAGE_ARRAY);
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(MessageRetrievalListener listener) throws MessagingException {
|
||||
public List<? extends Message> getMessages(MessageRetrievalListener listener) throws MessagingException {
|
||||
return getMessages(null, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(String[] uids, MessageRetrievalListener listener) throws MessagingException {
|
||||
public List<? extends Message> getMessages(String[] uids, MessageRetrievalListener listener) throws MessagingException {
|
||||
List<Message> messageList = new ArrayList<Message>();
|
||||
Message[] messages;
|
||||
List<? extends Message> messages;
|
||||
|
||||
if (uids == null ||
|
||||
uids.length == 0) {
|
||||
return messageList.toArray(EMPTY_MESSAGE_ARRAY);
|
||||
return messageList;
|
||||
}
|
||||
|
||||
for (int i = 0, count = uids.length; i < count; i++) {
|
||||
@ -1480,7 +1478,7 @@ public class WebDavStore extends Store {
|
||||
listener.messageFinished(message, i, count);
|
||||
}
|
||||
}
|
||||
messages = messageList.toArray(EMPTY_MESSAGE_ARRAY);
|
||||
messages = messageList;
|
||||
|
||||
return messages;
|
||||
}
|
||||
@ -1500,10 +1498,10 @@ public class WebDavStore extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetch(Message[] messages, FetchProfile fp, MessageRetrievalListener listener)
|
||||
public void fetch(List<? extends Message> messages, FetchProfile fp, MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
if (messages == null ||
|
||||
messages.length == 0) {
|
||||
messages.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1535,7 +1533,7 @@ public class WebDavStore extends Store {
|
||||
/**
|
||||
* Fetches the full messages or up to lines lines and passes them to the message parser.
|
||||
*/
|
||||
private void fetchMessages(Message[] messages, MessageRetrievalListener listener, int lines)
|
||||
private void fetchMessages(List<? extends Message> messages, MessageRetrievalListener listener, int lines)
|
||||
throws MessagingException {
|
||||
WebDavHttpClient httpclient;
|
||||
httpclient = getHttpClient();
|
||||
@ -1543,15 +1541,15 @@ public class WebDavStore extends Store {
|
||||
/**
|
||||
* We can't hand off to processRequest() since we need the stream to parse.
|
||||
*/
|
||||
for (int i = 0, count = messages.length; i < count; i++) {
|
||||
for (int i = 0, count = messages.size(); i < count; i++) {
|
||||
WebDavMessage wdMessage;
|
||||
int statusCode = 0;
|
||||
|
||||
if (!(messages[i] instanceof WebDavMessage)) {
|
||||
if (!(messages.get(i) instanceof WebDavMessage)) {
|
||||
throw new MessagingException("WebDavStore fetch called with non-WebDavMessage");
|
||||
}
|
||||
|
||||
wdMessage = (WebDavMessage) messages[i];
|
||||
wdMessage = (WebDavMessage) messages.get(i);
|
||||
|
||||
if (listener != null) {
|
||||
listener.messageStarted(wdMessage.getUid(), i, count);
|
||||
@ -1649,36 +1647,36 @@ public class WebDavStore extends Store {
|
||||
* Fetches and sets the message flags for the supplied messages. The idea is to have this be recursive so that
|
||||
* we do a series of medium calls instead of one large massive call or a large number of smaller calls.
|
||||
*/
|
||||
private void fetchFlags(Message[] startMessages, MessageRetrievalListener listener) throws MessagingException {
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
private void fetchFlags(List<? extends Message> startMessages, MessageRetrievalListener listener) throws MessagingException {
|
||||
HashMap<String, String> headers = new HashMap<String, String>();
|
||||
String messageBody = "";
|
||||
Message[] messages = new Message[20];
|
||||
List<Message> messages = new ArrayList<Message>(20);
|
||||
String[] uids;
|
||||
|
||||
if (startMessages == null ||
|
||||
startMessages.length == 0) {
|
||||
startMessages.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (startMessages.length > 20) {
|
||||
Message[] newMessages = new Message[startMessages.length - 20];
|
||||
for (int i = 0, count = startMessages.length; i < count; i++) {
|
||||
if (startMessages.size() > 20) {
|
||||
List<Message> newMessages = new ArrayList<Message>(startMessages.size() - 20);
|
||||
for (int i = 0, count = startMessages.size(); i < count; i++) {
|
||||
if (i < 20) {
|
||||
messages[i] = startMessages[i];
|
||||
messages.set(i, startMessages.get(i));
|
||||
} else {
|
||||
newMessages[i - 20] = startMessages[i];
|
||||
newMessages.set(i - 20, startMessages.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
fetchFlags(newMessages, listener);
|
||||
} else {
|
||||
messages = startMessages;
|
||||
messages.addAll(startMessages);
|
||||
}
|
||||
|
||||
uids = new String[messages.length];
|
||||
uids = new String[messages.size()];
|
||||
|
||||
for (int i = 0, count = messages.length; i < count; i++) {
|
||||
uids[i] = messages[i].getUid();
|
||||
for (int i = 0, count = messages.size(); i < count; i++) {
|
||||
uids[i] = messages.get(i).getUid();
|
||||
}
|
||||
|
||||
messageBody = getMessageFlagsXml(uids);
|
||||
@ -1691,11 +1689,11 @@ public class WebDavStore extends Store {
|
||||
|
||||
Map<String, Boolean> uidToReadStatus = dataset.getUidToRead();
|
||||
|
||||
for (int i = 0, count = messages.length; i < count; i++) {
|
||||
if (!(messages[i] instanceof WebDavMessage)) {
|
||||
for (int i = 0, count = messages.size(); i < count; i++) {
|
||||
if (!(messages.get(i) instanceof WebDavMessage)) {
|
||||
throw new MessagingException("WebDavStore fetch called with non-WebDavMessage");
|
||||
}
|
||||
WebDavMessage wdMessage = (WebDavMessage) messages[i];
|
||||
WebDavMessage wdMessage = (WebDavMessage) messages.get(i);
|
||||
|
||||
if (listener != null) {
|
||||
listener.messageStarted(wdMessage.getUid(), i, count);
|
||||
@ -1718,37 +1716,37 @@ public class WebDavStore extends Store {
|
||||
* 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(Message[] startMessages, MessageRetrievalListener listener)
|
||||
private void fetchEnvelope(List<? extends Message> startMessages, MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
String messageBody = "";
|
||||
String[] uids;
|
||||
Message[] messages = new Message[10];
|
||||
List<Message> messages = new ArrayList<Message>(10);
|
||||
|
||||
if (startMessages == null ||
|
||||
startMessages.length == 0) {
|
||||
startMessages.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (startMessages.length > 10) {
|
||||
Message[] newMessages = new Message[startMessages.length - 10];
|
||||
for (int i = 0, count = startMessages.length; i < count; i++) {
|
||||
if (startMessages.size() > 10) {
|
||||
List<Message> newMessages = new ArrayList<Message>(startMessages.size() - 10);
|
||||
for (int i = 0, count = startMessages.size(); i < count; i++) {
|
||||
if (i < 10) {
|
||||
messages[i] = startMessages[i];
|
||||
messages.set(i, startMessages.get(i));
|
||||
} else {
|
||||
newMessages[i - 10] = startMessages[i];
|
||||
newMessages.set(i - 10,startMessages.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
fetchEnvelope(newMessages, listener);
|
||||
} else {
|
||||
messages = startMessages;
|
||||
messages.addAll(startMessages);
|
||||
}
|
||||
|
||||
uids = new String[messages.length];
|
||||
uids = new String[messages.size()];
|
||||
|
||||
for (int i = 0, count = messages.length; i < count; i++) {
|
||||
uids[i] = messages[i].getUid();
|
||||
for (int i = 0, count = messages.size(); i < count; i++) {
|
||||
uids[i] = messages.get(i).getUid();
|
||||
}
|
||||
|
||||
messageBody = getMessageEnvelopeXml(uids);
|
||||
@ -1757,15 +1755,15 @@ public class WebDavStore extends Store {
|
||||
|
||||
Map<String, ParsedMessageEnvelope> envelopes = dataset.getMessageEnvelopes();
|
||||
|
||||
int count = messages.length;
|
||||
for (int i = messages.length - 1; i >= 0; i--) {
|
||||
if (!(messages[i] instanceof WebDavMessage)) {
|
||||
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[i];
|
||||
WebDavMessage wdMessage = (WebDavMessage) messages.get(i);
|
||||
|
||||
if (listener != null) {
|
||||
listener.messageStarted(messages[i].getUid(), i, count);
|
||||
listener.messageStarted(messages.get(i).getUid(), i, count);
|
||||
}
|
||||
|
||||
ParsedMessageEnvelope envelope = envelopes.get(wdMessage.getUid());
|
||||
@ -1777,18 +1775,18 @@ public class WebDavStore extends Store {
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
listener.messageFinished(messages[i], i, count);
|
||||
listener.messageFinished(messages.get(i), i, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlags(Message[] messages, Flag[] flags, boolean value)
|
||||
public void setFlags(List<? extends Message> messages, final Collection<Flag> flags, boolean value)
|
||||
throws MessagingException {
|
||||
String[] uids = new String[messages.length];
|
||||
String[] uids = new String[messages.size()];
|
||||
|
||||
for (int i = 0, count = messages.length; i < count; i++) {
|
||||
uids[i] = messages[i].getUid();
|
||||
for (int i = 0, count = messages.size(); i < count; i++) {
|
||||
uids[i] = messages.get(i).getUid();
|
||||
}
|
||||
|
||||
for (Flag flag : flags) {
|
||||
@ -1848,13 +1846,13 @@ public class WebDavStore extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> appendMessages(Message[] messages) throws MessagingException {
|
||||
public Map<String, String> appendMessages(List<? extends Message> messages) throws MessagingException {
|
||||
appendWebDavMessages(messages);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Message[] appendWebDavMessages(Message[] messages) throws MessagingException {
|
||||
Message[] retMessages = new Message[messages.length];
|
||||
public List<? extends Message> appendWebDavMessages(List<? extends Message> messages) throws MessagingException {
|
||||
List<Message> retMessages = new ArrayList<Message>(messages.size());
|
||||
int ind = 0;
|
||||
|
||||
WebDavHttpClient httpclient = getHttpClient();
|
||||
@ -1909,7 +1907,7 @@ public class WebDavStore extends Store {
|
||||
WebDavMessage retMessage = new WebDavMessage(message.getUid(), this);
|
||||
|
||||
retMessage.setUrl(messageURL);
|
||||
retMessages[ind++] = retMessage;
|
||||
retMessages.set(ind++, retMessage);
|
||||
} catch (Exception e) {
|
||||
throw new MessagingException("Unable to append", e);
|
||||
}
|
||||
@ -1931,9 +1929,9 @@ public class WebDavStore extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlags(Flag[] flags, boolean value) throws MessagingException {
|
||||
public void setFlags(final Collection<Flag> flags, boolean value) throws MessagingException {
|
||||
Log.e(K9.LOG_TAG,
|
||||
"Unimplemented method setFlags(Flag[], boolean) breaks markAllMessagesAsRead and EmptyTrash");
|
||||
"Unimplemented method setFlags(Collection<Flag>, boolean) breaks markAllMessagesAsRead and EmptyTrash");
|
||||
// Try to make this efficient by not retrieving all of the messages
|
||||
}
|
||||
}
|
||||
@ -2025,13 +2023,13 @@ public class WebDavStore extends Store {
|
||||
public void delete(String trashFolderName) throws MessagingException {
|
||||
WebDavFolder wdFolder = (WebDavFolder) getFolder();
|
||||
Log.i(K9.LOG_TAG, "Deleting message by moving to " + trashFolderName);
|
||||
wdFolder.moveMessages(new Message[] { this }, wdFolder.getStore().getFolder(trashFolderName));
|
||||
wdFolder.moveMessages(Collections.singletonList(this), wdFolder.getStore().getFolder(trashFolderName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlag(Flag flag, boolean set) throws MessagingException {
|
||||
super.setFlag(flag, set);
|
||||
mFolder.setFlags(new Message[] { this }, new Flag[] { flag }, set);
|
||||
mFolder.setFlags(Collections.singletonList(this), Collections.singletonList(flag), set);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,8 @@ import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -370,12 +372,12 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
return ;
|
||||
}
|
||||
open(OPEN_MODE_RW);
|
||||
Message[] messages = getMessages(null, false);
|
||||
for (int i = mVisibleLimit; i < messages.length; i++) {
|
||||
List<? extends Message> messages = getMessages(null, false);
|
||||
for (int i = mVisibleLimit; i < messages.size(); i++) {
|
||||
if (listener != null) {
|
||||
listener.messageRemoved(messages[i]);
|
||||
listener.messageRemoved(messages.get(i));
|
||||
}
|
||||
messages[i].destroy();
|
||||
messages.get(i).destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -597,7 +599,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetch(final Message[] messages, final FetchProfile fp, final MessageRetrievalListener listener)
|
||||
public void fetch(final List<? extends Message> messages, final FetchProfile fp, final MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
try {
|
||||
this.localStore.database.execute(false, new DbCallback<Void>() {
|
||||
@ -798,7 +800,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
|
||||
public List<? extends Message> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
open(OPEN_MODE_RW);
|
||||
throw new MessagingException(
|
||||
@ -813,7 +815,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
* The messages whose headers should be loaded.
|
||||
* @throws UnavailableStorageException
|
||||
*/
|
||||
void populateHeaders(final List<LocalMessage> messages) throws UnavailableStorageException {
|
||||
void populateHeaders(final List<? extends Message> messages) throws UnavailableStorageException {
|
||||
this.localStore.database.execute(false, new DbCallback<Void>() {
|
||||
@Override
|
||||
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
|
||||
@ -831,7 +833,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
questions.append(", ");
|
||||
}
|
||||
questions.append("?");
|
||||
LocalMessage message = messages.get(i);
|
||||
LocalMessage message = (LocalMessage)messages.get(i);
|
||||
Long id = message.getId();
|
||||
ids.add(Long.toString(id));
|
||||
popMessages.put(id, message);
|
||||
@ -931,16 +933,16 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(MessageRetrievalListener listener) throws MessagingException {
|
||||
public List<? extends Message> getMessages(MessageRetrievalListener listener) throws MessagingException {
|
||||
return getMessages(listener, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(final MessageRetrievalListener listener, final boolean includeDeleted) throws MessagingException {
|
||||
public List<? extends Message> getMessages(final MessageRetrievalListener listener, final boolean includeDeleted) throws MessagingException {
|
||||
try {
|
||||
return this.localStore.database.execute(false, new DbCallback<Message[]>() {
|
||||
return this.localStore.database.execute(false, new DbCallback<List<? extends Message>>() {
|
||||
@Override
|
||||
public Message[] doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
|
||||
public List<? extends Message> doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
|
||||
try {
|
||||
open(OPEN_MODE_RW);
|
||||
return LocalFolder.this.localStore.getMessages(
|
||||
@ -965,7 +967,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message[] getMessages(String[] uids, MessageRetrievalListener listener)
|
||||
public List<? extends Message> getMessages(String[] uids, MessageRetrievalListener listener)
|
||||
throws MessagingException {
|
||||
open(OPEN_MODE_RW);
|
||||
if (uids == null) {
|
||||
@ -978,11 +980,11 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
messages.add(message);
|
||||
}
|
||||
}
|
||||
return messages.toArray(LocalStore.EMPTY_MESSAGE_ARRAY);
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> copyMessages(Message[] msgs, Folder folder) throws MessagingException {
|
||||
public Map<String, String> copyMessages(List<? extends Message> msgs, Folder folder) throws MessagingException {
|
||||
if (!(folder instanceof LocalFolder)) {
|
||||
throw new MessagingException("copyMessages called with incorrect Folder");
|
||||
}
|
||||
@ -990,7 +992,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> moveMessages(final Message[] msgs, final Folder destFolder) throws MessagingException {
|
||||
public Map<String, String> moveMessages(final List<? extends Message> msgs, final Folder destFolder) throws MessagingException {
|
||||
if (!(destFolder instanceof LocalFolder)) {
|
||||
throw new MessagingException("moveMessages called with non-LocalFolder");
|
||||
}
|
||||
@ -1128,7 +1130,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
@Override
|
||||
public Message doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
|
||||
try {
|
||||
appendMessages(new Message[] { message });
|
||||
appendMessages(Collections.singletonList(message));
|
||||
final String uid = message.getUid();
|
||||
final Message result = getMessage(uid);
|
||||
runnable.run();
|
||||
@ -1154,11 +1156,11 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
* message, retrieve the appropriate local message instance first (if it already exists).
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> appendMessages(Message[] messages) throws MessagingException {
|
||||
public Map<String, String> appendMessages(List<? extends Message> messages) throws MessagingException {
|
||||
return appendMessages(messages, false);
|
||||
}
|
||||
|
||||
public void destroyMessages(final Message[] messages) {
|
||||
public void destroyMessages(final List<? extends Message> messages) {
|
||||
try {
|
||||
this.localStore.database.execute(true, new DbCallback<Void>() {
|
||||
@Override
|
||||
@ -1221,7 +1223,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
* @param copy
|
||||
* @return Map<String, String> uidMap of srcUids -> destUids
|
||||
*/
|
||||
private Map<String, String> appendMessages(final Message[] messages, final boolean copy) throws MessagingException {
|
||||
private Map<String, String> appendMessages(final List<? extends Message> messages, final boolean copy) throws MessagingException {
|
||||
open(OPEN_MODE_RW);
|
||||
try {
|
||||
final Map<String, String> uidMap = new HashMap<String, String>();
|
||||
@ -1490,12 +1492,12 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
// Remember that all headers for this message have been saved, so it is
|
||||
// not necessary to download them again in case the user wants to see all headers.
|
||||
List<Flag> appendedFlags = new ArrayList<Flag>();
|
||||
appendedFlags.addAll(Arrays.asList(message.getFlags()));
|
||||
appendedFlags.addAll(message.getFlags());
|
||||
appendedFlags.add(Flag.X_GOT_ALL_HEADERS);
|
||||
|
||||
db.execSQL("UPDATE messages " + "SET flags = ? " + " WHERE id = ?",
|
||||
new Object[]
|
||||
{ LocalFolder.this.localStore.serializeFlags(appendedFlags.toArray(LocalStore.EMPTY_FLAG_ARRAY)), id });
|
||||
{ LocalFolder.this.localStore.serializeFlags(appendedFlags), id });
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -1722,7 +1724,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlags(final Message[] messages, final Flag[] flags, final boolean value)
|
||||
public void setFlags(final List<? extends Message> messages, final Collection<Flag> flags, final boolean value)
|
||||
throws MessagingException {
|
||||
open(OPEN_MODE_RW);
|
||||
|
||||
@ -1750,7 +1752,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlags(Flag[] flags, boolean value)
|
||||
public void setFlags(final Collection<Flag> flags, boolean value)
|
||||
throws MessagingException {
|
||||
open(OPEN_MODE_RW);
|
||||
for (Message message : getMessages(null)) {
|
||||
@ -1766,7 +1768,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
public void clearMessagesOlderThan(long cutoff) throws MessagingException {
|
||||
open(OPEN_MODE_RO);
|
||||
|
||||
Message[] messages = this.localStore.getMessages(
|
||||
List<? extends Message> messages = this.localStore.getMessages(
|
||||
null,
|
||||
this,
|
||||
"SELECT " + LocalStore.GET_MESSAGES_COLS +
|
||||
@ -1841,7 +1843,7 @@ public class LocalFolder extends Folder implements Serializable {
|
||||
try {
|
||||
// We need to open the folder first to make sure we've got it's id
|
||||
open(OPEN_MODE_RO);
|
||||
Message[] messages = getMessages(null);
|
||||
List<? extends Message> messages = getMessages(null);
|
||||
for (Message message : messages) {
|
||||
deleteAttachments(message.getUid());
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ package com.fsck.k9.mail.store.local;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -55,9 +56,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5142141896809423072L;
|
||||
|
||||
static final Message[] EMPTY_MESSAGE_ARRAY = new Message[0];
|
||||
static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
static final Flag[] EMPTY_FLAG_ARRAY = new Flag[0];
|
||||
static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
||||
|
||||
/*
|
||||
@ -523,7 +522,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Message[] searchForMessages(MessageRetrievalListener retrievalListener,
|
||||
public List<LocalMessage> searchForMessages(MessageRetrievalListener retrievalListener,
|
||||
LocalSearch search) throws MessagingException {
|
||||
|
||||
StringBuilder query = new StringBuilder();
|
||||
@ -554,7 +553,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
* Given a query string, actually do the query for the messages and
|
||||
* call the MessageRetrievalListener for each one
|
||||
*/
|
||||
Message[] getMessages(
|
||||
List<LocalMessage> getMessages(
|
||||
final MessageRetrievalListener listener,
|
||||
final LocalFolder folder,
|
||||
final String queryString, final String[] placeHolders
|
||||
@ -603,11 +602,11 @@ public class LocalStore extends Store implements Serializable {
|
||||
listener.messagesFinished(j);
|
||||
}
|
||||
|
||||
return messages.toArray(EMPTY_MESSAGE_ARRAY);
|
||||
return Collections.unmodifiableList(messages);
|
||||
|
||||
}
|
||||
|
||||
public Message[] getMessagesInThread(final long rootId) throws MessagingException {
|
||||
public List<LocalMessage> getMessagesInThread(final long rootId) throws MessagingException {
|
||||
String rootIdString = Long.toString(rootId);
|
||||
|
||||
LocalSearch search = new LocalSearch();
|
||||
@ -706,7 +705,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
}
|
||||
|
||||
|
||||
String serializeFlags(Flag[] flags) {
|
||||
String serializeFlags(Iterable<Flag> flags) {
|
||||
List<Flag> extraFlags = new ArrayList<Flag>();
|
||||
|
||||
for (Flag flag : flags) {
|
||||
@ -724,7 +723,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
return Utility.combine(extraFlags.toArray(EMPTY_FLAG_ARRAY), ',').toUpperCase(Locale.US);
|
||||
return Utility.combine(extraFlags, ',').toUpperCase(Locale.US);
|
||||
}
|
||||
|
||||
public LockableDatabase getDatabase() {
|
||||
|
@ -309,9 +309,9 @@ class StoreSchemaDefinition implements LockableDatabase.SchemaDefinition {
|
||||
LocalFolder obsoleteOutbox = new LocalFolder(this.localStore, localizedOutbox);
|
||||
if (obsoleteOutbox.exists()) {
|
||||
// Get all messages from the localized outbox ...
|
||||
Message[] messages = obsoleteOutbox.getMessages(null, false);
|
||||
List<? extends Message> messages = obsoleteOutbox.getMessages(null, false);
|
||||
|
||||
if (messages.length > 0) {
|
||||
if (messages.size() > 0) {
|
||||
// ... and move them to the drafts folder (we don't want to
|
||||
// surprise the user by sending potentially very old messages)
|
||||
LocalFolder drafts = new LocalFolder(this.localStore, this.localStore.getAccount().getDraftsFolderName());
|
||||
@ -424,7 +424,7 @@ class StoreSchemaDefinition implements LockableDatabase.SchemaDefinition {
|
||||
}
|
||||
|
||||
|
||||
cv.put("flags", this.localStore.serializeFlags(extraFlags.toArray(LocalStore.EMPTY_FLAG_ARRAY)));
|
||||
cv.put("flags", this.localStore.serializeFlags(extraFlags));
|
||||
cv.put("read", read);
|
||||
cv.put("flagged", flagged);
|
||||
cv.put("answered", answered);
|
||||
|
@ -11,6 +11,8 @@ import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.Transport;
|
||||
import com.fsck.k9.mail.store.WebDavStore;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class WebDavTransport extends Transport {
|
||||
public static final String TRANSPORT_TYPE = WebDavStore.STORE_TYPE;
|
||||
|
||||
@ -66,6 +68,6 @@ public class WebDavTransport extends Transport {
|
||||
|
||||
@Override
|
||||
public void sendMessage(Message message) throws MessagingException {
|
||||
store.sendMessages(new Message[] { message });
|
||||
store.sendMessages(Collections.singletonList(message));
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ public class SettingsExporter {
|
||||
|
||||
Set<String> exportAccounts;
|
||||
if (accountUuids == null) {
|
||||
Account[] accounts = preferences.getAccounts();
|
||||
List<Account> accounts = preferences.getAccounts();
|
||||
exportAccounts = new HashSet<String>();
|
||||
for (Account account : accounts) {
|
||||
exportAccounts.add(account.getUuid());
|
||||
|
@ -340,7 +340,7 @@ public class SettingsImporter {
|
||||
AccountDescription original = new AccountDescription(account.name, account.uuid);
|
||||
|
||||
Preferences prefs = Preferences.getPreferences(context);
|
||||
Account[] accounts = prefs.getAccounts();
|
||||
List<Account> accounts = prefs.getAccounts();
|
||||
|
||||
String uuid = account.uuid;
|
||||
Account existingAccount = prefs.getAccount(uuid);
|
||||
@ -357,7 +357,7 @@ public class SettingsImporter {
|
||||
if (isAccountNameUsed(accountName, accounts)) {
|
||||
// Account name is already in use. So generate a new one by appending " (x)", where x
|
||||
// is the first number >= 1 that results in an unused account name.
|
||||
for (int i = 1; i <= accounts.length; i++) {
|
||||
for (int i = 1; i <= accounts.size(); i++) {
|
||||
accountName = account.name + " (" + i + ")";
|
||||
if (!isAccountNameUsed(accountName, accounts)) {
|
||||
break;
|
||||
@ -605,7 +605,7 @@ public class SettingsImporter {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isAccountNameUsed(String name, Account[] accounts) {
|
||||
private static boolean isAccountNameUsed(String name, List<Account> accounts) {
|
||||
for (Account account : accounts) {
|
||||
if (account == null) {
|
||||
continue;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.fsck.k9.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import android.app.Service;
|
||||
@ -186,8 +187,8 @@ public class DatabaseUpgradeService extends Service {
|
||||
private void upgradeDatabases() {
|
||||
Preferences preferences = Preferences.getPreferences(this);
|
||||
|
||||
Account[] accounts = preferences.getAccounts();
|
||||
mProgressEnd = accounts.length;
|
||||
List<Account> accounts = preferences.getAccounts();
|
||||
mProgressEnd = accounts.size();
|
||||
mProgress = 0;
|
||||
|
||||
for (Account account : accounts) {
|
||||
|
@ -11,6 +11,8 @@ import com.fsck.k9.K9;
|
||||
import com.fsck.k9.remotecontrol.K9RemoteControl;
|
||||
import com.fsck.k9.Preferences;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.fsck.k9.remotecontrol.K9RemoteControl.*;
|
||||
|
||||
public class RemoteControlReceiver extends CoreReceiver {
|
||||
@ -25,12 +27,12 @@ public class RemoteControlReceiver extends CoreReceiver {
|
||||
} else if (K9RemoteControl.K9_REQUEST_ACCOUNTS.equals(intent.getAction())) {
|
||||
try {
|
||||
Preferences preferences = Preferences.getPreferences(context);
|
||||
Account[] accounts = preferences.getAccounts();
|
||||
String[] uuids = new String[accounts.length];
|
||||
String[] descriptions = new String[accounts.length];
|
||||
for (int i = 0; i < accounts.length; i++) {
|
||||
List<Account> accounts = preferences.getAccounts();
|
||||
String[] uuids = new String[accounts.size()];
|
||||
String[] descriptions = new String[accounts.size()];
|
||||
for (int i = 0; i < accounts.size(); i++) {
|
||||
//warning: account may not be isAvailable()
|
||||
Account account = accounts[i];
|
||||
Account account = accounts.get(i);
|
||||
|
||||
uuids[i] = account.getUuid();
|
||||
descriptions[i] = account.getDescription();
|
||||
|
@ -17,6 +17,8 @@ import android.content.SharedPreferences.Editor;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RemoteControlService extends CoreService {
|
||||
private final static String RESCHEDULE_ACTION = "com.fsck.k9.service.RemoteControlService.RESCHEDULE_ACTION";
|
||||
private final static String PUSH_RESTART_ACTION = "com.fsck.k9.service.RemoteControlService.PUSH_RESTART_ACTION";
|
||||
@ -65,7 +67,7 @@ public class RemoteControlService extends CoreService {
|
||||
Log.i(K9.LOG_TAG, "RemoteControlService changing settings for account with UUID " + uuid);
|
||||
}
|
||||
}
|
||||
Account[] accounts = preferences.getAccounts();
|
||||
List<Account> accounts = preferences.getAccounts();
|
||||
for (Account account : accounts) {
|
||||
//warning: account may not be isAvailable()
|
||||
if (allAccounts || account.getUuid().equals(uuid)) {
|
||||
|
Loading…
Reference in New Issue
Block a user