2010-05-19 14:17:06 -04:00
package com.fsck.k9.controller ;
2008-11-01 17:32:06 -04:00
2010-09-11 07:20:50 -04:00
import java.io.CharArrayWriter ;
import java.io.PrintWriter ;
2012-03-05 15:04:34 -05:00
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Collection ;
import java.util.Collections ;
import java.util.Comparator ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.HashSet ;
import java.util.Iterator ;
import java.util.LinkedList ;
import java.util.List ;
import java.util.Map ;
2012-12-05 23:25:41 -05:00
import java.util.Map.Entry ;
2012-03-05 15:04:34 -05:00
import java.util.Set ;
2012-09-25 18:46:30 -04:00
import java.util.concurrent.* ;
2010-01-16 11:22:20 -05:00
import java.util.concurrent.atomic.AtomicBoolean ;
import java.util.concurrent.atomic.AtomicInteger ;
2010-09-01 18:37:11 -04:00
2008-11-01 17:32:06 -04:00
import android.app.Application ;
2010-09-01 18:26:36 -04:00
import android.app.KeyguardManager ;
2008-12-19 17:30:55 -05:00
import android.app.NotificationManager ;
import android.app.PendingIntent ;
2012-12-06 23:29:05 -05:00
import android.content.ContentResolver ;
2008-11-01 17:32:06 -04:00
import android.content.Context ;
2008-12-19 17:30:55 -05:00
import android.content.Intent ;
2012-12-06 23:29:05 -05:00
import android.database.Cursor ;
2009-10-21 20:41:06 -04:00
import android.net.Uri ;
2012-07-18 20:23:09 -04:00
import android.os.Build ;
2009-03-31 23:25:16 -04:00
import android.os.PowerManager ;
2009-12-09 22:16:42 -05:00
import android.os.Process ;
2013-01-01 06:37:14 -05:00
import android.support.v4.app.NotificationCompat ;
2013-01-01 06:48:31 -05:00
import android.text.SpannableStringBuilder ;
2009-10-21 20:41:06 -04:00
import android.text.TextUtils ;
2013-01-01 06:48:31 -05:00
import android.text.style.TextAppearanceSpan ;
2008-11-01 17:32:06 -04:00
import android.util.Log ;
2010-03-29 22:58:21 -04:00
2010-05-19 14:17:06 -04:00
import com.fsck.k9.Account ;
import com.fsck.k9.AccountStats ;
import com.fsck.k9.K9 ;
2012-08-01 19:41:40 -04:00
import com.fsck.k9.K9.NotificationHideSubject ;
2012-03-05 15:04:34 -05:00
import com.fsck.k9.K9.Intents ;
2013-01-04 02:24:03 -05:00
import com.fsck.k9.K9.NotificationQuickDelete ;
2010-09-19 16:54:43 -04:00
import com.fsck.k9.NotificationSetting ;
2010-05-19 14:17:06 -04:00
import com.fsck.k9.Preferences ;
import com.fsck.k9.R ;
2010-01-28 22:57:37 -05:00
import com.fsck.k9.activity.FolderList ;
2010-01-27 19:29:27 -05:00
import com.fsck.k9.activity.MessageList ;
2013-01-03 04:07:21 -05:00
import com.fsck.k9.activity.MessageReference ;
2013-01-04 02:24:03 -05:00
import com.fsck.k9.activity.NotificationDeleteConfirmation ;
2013-01-17 09:24:22 -05:00
import com.fsck.k9.activity.setup.AccountSetupIncoming ;
import com.fsck.k9.activity.setup.AccountSetupOutgoing ;
2013-02-18 22:45:14 -05:00
import com.fsck.k9.cache.EmailProviderCache ;
2013-01-02 10:13:27 -05:00
import com.fsck.k9.helper.Contacts ;
2013-02-20 17:55:46 -05:00
import com.fsck.k9.helper.NotificationBuilder ;
2010-05-16 20:30:32 -04:00
import com.fsck.k9.helper.power.TracingPowerManager ;
import com.fsck.k9.helper.power.TracingPowerManager.TracingWakeLock ;
2010-01-16 11:22:20 -05:00
import com.fsck.k9.mail.Address ;
import com.fsck.k9.mail.FetchProfile ;
import com.fsck.k9.mail.Flag ;
import com.fsck.k9.mail.Folder ;
2010-09-01 18:37:11 -04:00
import com.fsck.k9.mail.Folder.FolderType ;
import com.fsck.k9.mail.Folder.OpenMode ;
2010-01-16 11:22:20 -05:00
import com.fsck.k9.mail.Message ;
2012-03-05 15:04:34 -05:00
import com.fsck.k9.mail.Message.RecipientType ;
2013-01-17 09:24:22 -05:00
import com.fsck.k9.mail.CertificateValidationException ;
2010-02-17 22:28:31 -05:00
import com.fsck.k9.mail.MessagingException ;
2010-01-16 11:22:20 -05:00
import com.fsck.k9.mail.Part ;
import com.fsck.k9.mail.PushReceiver ;
import com.fsck.k9.mail.Pusher ;
import com.fsck.k9.mail.Store ;
import com.fsck.k9.mail.Transport ;
2009-12-14 21:50:53 -05:00
import com.fsck.k9.mail.internet.MimeMessage ;
import com.fsck.k9.mail.internet.MimeUtility ;
import com.fsck.k9.mail.internet.TextBody ;
import com.fsck.k9.mail.store.LocalStore ;
import com.fsck.k9.mail.store.LocalStore.LocalFolder ;
import com.fsck.k9.mail.store.LocalStore.LocalMessage ;
import com.fsck.k9.mail.store.LocalStore.PendingCommand ;
2012-03-05 15:04:34 -05:00
import com.fsck.k9.mail.store.UnavailableAccountException ;
import com.fsck.k9.mail.store.UnavailableStorageException ;
2012-12-06 23:29:05 -05:00
import com.fsck.k9.provider.EmailProvider ;
import com.fsck.k9.provider.EmailProvider.StatsColumns ;
import com.fsck.k9.search.ConditionsTreeNode ;
2012-10-13 08:53:00 -04:00
import com.fsck.k9.search.LocalSearch ;
2012-12-06 23:29:05 -05:00
import com.fsck.k9.search.SearchAccount ;
2012-10-12 06:30:26 -04:00
import com.fsck.k9.search.SearchSpecification ;
2012-12-06 23:29:05 -05:00
import com.fsck.k9.search.SqlQueryBuilder ;
2013-01-02 08:07:41 -05:00
import com.fsck.k9.service.NotificationActionService ;
2009-12-09 22:16:42 -05:00
2010-03-03 23:00:30 -05:00
2008-11-01 17:32:06 -04:00
/ * *
* Starts a long running ( application ) Thread that will run through commands
* that require remote mailbox access . This class is used to serialize and
* prioritize these commands . Each method that will submit a command requires a
* MessagingListener instance to be provided . It is expected that that listener
* has also been added as a registered listener using addListener ( ) . When a
* command is to be executed , if the listener that was provided with the command
* is no longer registered the command is skipped . The design idea for the above
* is that when an Activity starts it registers as a listener . When it is paused
* it removes itself . Thus , any commands that that activity submitted are
* removed from the queue once the activity is no longer active .
* /
2011-02-06 17:09:48 -05:00
public class MessagingController implements Runnable {
2012-01-21 23:14:58 -05:00
public static final long INVALID_MESSAGE_ID = - 1 ;
2010-08-02 07:55:31 -04:00
/ * *
* Immutable empty { @link String } array
* /
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 ] ;
2008-11-01 17:32:06 -04:00
/ * *
* 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
* pieces with attachments being left off completely and downloaded on demand .
*
*
* 25k for a " small " message was picked by educated trial and error .
* http : //answers.google.com/answers/threadview?id=312463 claims that the
* average size of an email is 59k , which I feel is too large for our
* blind download . The following tests were performed on a download of
* 25 random messages .
* < pre >
* 5k - 61 seconds ,
* 25k - 51 seconds ,
* 55k - 53 seconds ,
* < / pre >
* So 25k gives good performance and a reasonable data footprint . Sounds good to me .
* /
2009-12-14 21:50:53 -05:00
private static final String PENDING_COMMAND_MOVE_OR_COPY = " com.fsck.k9.MessagingController.moveOrCopy " ;
private static final String PENDING_COMMAND_MOVE_OR_COPY_BULK = " com.fsck.k9.MessagingController.moveOrCopyBulk " ;
2012-02-16 19:59:04 -05:00
private static final String PENDING_COMMAND_MOVE_OR_COPY_BULK_NEW = " com.fsck.k9.MessagingController.moveOrCopyBulkNew " ;
2009-12-14 21:50:53 -05:00
private static final String PENDING_COMMAND_EMPTY_TRASH = " com.fsck.k9.MessagingController.emptyTrash " ;
private static final String PENDING_COMMAND_SET_FLAG_BULK = " com.fsck.k9.MessagingController.setFlagBulk " ;
private static final String PENDING_COMMAND_SET_FLAG = " com.fsck.k9.MessagingController.setFlag " ;
private static final String PENDING_COMMAND_APPEND = " com.fsck.k9.MessagingController.append " ;
private static final String PENDING_COMMAND_MARK_ALL_AS_READ = " com.fsck.k9.MessagingController.markAllAsRead " ;
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
private static final String PENDING_COMMAND_EXPUNGE = " com.fsck.k9.MessagingController.expunge " ;
2008-11-01 17:32:06 -04:00
2012-03-05 15:04:34 -05:00
public static class UidReverseComparator implements Comparator < Message > {
@Override
public int compare ( Message o1 , Message o2 ) {
if ( o1 = = null | | o2 = = null | | o1 . getUid ( ) = = null | | o2 . getUid ( ) = = null ) {
return 0 ;
}
int id1 , id2 ;
try {
id1 = Integer . parseInt ( o1 . getUid ( ) ) ;
id2 = Integer . parseInt ( o2 . getUid ( ) ) ;
} catch ( NumberFormatException e ) {
return 0 ;
}
//reversed intentionally.
if ( id1 < id2 )
return 1 ;
if ( id1 > id2 )
return - 1 ;
return 0 ;
}
}
2010-12-19 06:51:54 -05:00
/ * *
* Maximum number of unsynced messages to store at once
* /
private static final int UNSYNC_CHUNK_SIZE = 5 ;
2008-11-01 17:32:06 -04:00
private static MessagingController inst = null ;
2009-10-21 20:41:06 -04:00
private BlockingQueue < Command > mCommands = new PriorityBlockingQueue < Command > ( ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2008-11-01 17:32:06 -04:00
private Thread mThread ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
private Set < MessagingListener > mListeners = new CopyOnWriteArraySet < MessagingListener > ( ) ;
2009-11-24 19:40:29 -05:00
2010-11-30 22:03:22 -05:00
private final ConcurrentHashMap < String , AtomicInteger > sendCount = new ConcurrentHashMap < String , AtomicInteger > ( ) ;
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
ConcurrentHashMap < Account , Pusher > pushers = new ConcurrentHashMap < Account , Pusher > ( ) ;
2009-11-24 19:40:29 -05:00
2010-10-02 03:45:11 -04:00
private final ExecutorService threadPool = Executors . newCachedThreadPool ( ) ;
2009-01-11 18:43:32 -05:00
private MessagingListener checkMailListener = null ;
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
private MemorizingListener memorizingListener = new MemorizingListener ( ) ;
2009-11-24 19:40:29 -05:00
2008-11-01 17:32:06 -04:00
private boolean mBusy ;
2010-12-06 04:25:23 -05:00
/ * *
* { @link K9 }
* /
2008-11-01 17:32:06 -04:00
private Application mApplication ;
2009-11-24 19:40:29 -05:00
2013-01-08 06:52:56 -05:00
/ * *
* A holder class for pending notification data
*
* This class holds all pieces of information for constructing
* a notification with message preview .
* /
2013-01-01 06:48:31 -05:00
private static class NotificationData {
2013-01-08 06:52:56 -05:00
/** Number of unread messages before constructing the notification */
int unreadBeforeNotification ;
/ * *
* List of messages that should be used for the inbox - style overview .
* It ' s sorted from newest to oldest message .
* Don ' t modify this list directly , but use { @link addMessage } and
* { @link removeMatchingMessage } instead .
* /
LinkedList < Message > messages ;
/ * *
* List of references for messages that the user is still to be notified of ,
* but which don ' t fit into the inbox style anymore . It ' s sorted from newest
* to oldest message .
* /
LinkedList < MessageReference > droppedMessages ;
2013-01-01 06:48:31 -05:00
2013-01-08 06:52:56 -05:00
/ * *
* Maximum number of messages to keep for the inbox - style overview .
* As of Jellybean , phone notifications show a maximum of 5 lines , while tablet
* notifications show 7 lines . To make sure no lines are silently dropped ,
* we default to 5 lines .
* /
2013-01-01 06:48:31 -05:00
private final static int MAX_MESSAGES = 5 ;
2013-01-08 06:52:56 -05:00
/ * *
* Constructs a new data instance .
*
* @param unread Number of unread messages prior to instance construction
* /
2013-01-01 06:48:31 -05:00
public NotificationData ( int unread ) {
unreadBeforeNotification = unread ;
2013-01-03 04:07:21 -05:00
droppedMessages = new LinkedList < MessageReference > ( ) ;
2013-01-08 03:27:28 -05:00
messages = new LinkedList < Message > ( ) ;
}
2013-01-08 06:52:56 -05:00
/ * *
* Adds a new message to the list of pending messages for this notification .
*
* The implementation will take care of keeping a meaningful amount of
* messages in { @link # messages } .
*
* @param m The new message to add .
* /
2013-01-08 03:27:28 -05:00
public void addMessage ( Message m ) {
while ( messages . size ( ) > = MAX_MESSAGES ) {
Message dropped = messages . removeLast ( ) ;
droppedMessages . addFirst ( dropped . makeMessageReference ( ) ) ;
}
messages . addFirst ( m ) ;
}
2013-01-08 06:52:56 -05:00
/ * *
* Remove a certain message from the message list .
*
* @param context A context .
* @param ref Reference of the message to remove
* @return true if message was found and removed , false otherwise
* /
2013-01-08 04:06:01 -05:00
public boolean removeMatchingMessage ( Context context , MessageReference ref ) {
for ( MessageReference dropped : droppedMessages ) {
if ( dropped . equals ( ref ) ) {
droppedMessages . remove ( dropped ) ;
return true ;
}
}
for ( Message message : messages ) {
if ( message . makeMessageReference ( ) . equals ( ref ) ) {
if ( messages . remove ( message ) & & ! droppedMessages . isEmpty ( ) ) {
Message restoredMessage = droppedMessages . getFirst ( ) . restoreToLocalMessage ( context ) ;
if ( restoredMessage ! = null ) {
messages . addLast ( restoredMessage ) ;
droppedMessages . removeFirst ( ) ;
}
}
return true ;
2013-01-01 06:48:31 -05:00
}
2013-01-08 03:27:28 -05:00
}
2013-01-08 04:06:01 -05:00
return false ;
2013-01-01 06:48:31 -05:00
}
2013-01-03 04:07:21 -05:00
2013-01-08 06:52:56 -05:00
/ * *
* Gets a list of references for all pending messages for the notification .
*
* @return Message reference list
* /
2013-01-04 02:24:03 -05:00
public ArrayList < MessageReference > getAllMessageRefs ( ) {
ArrayList < MessageReference > refs = new ArrayList < MessageReference > ( ) ;
for ( Message m : messages ) {
refs . add ( m . makeMessageReference ( ) ) ;
}
2013-01-04 10:11:39 -05:00
refs . addAll ( droppedMessages ) ;
2013-01-04 02:24:03 -05:00
return refs ;
}
2013-01-08 06:52:56 -05:00
/ * *
* Gets the total number of messages the user is to be notified of .
*
* @return Amount of new messages the notification notifies for
* /
2013-01-03 04:07:21 -05:00
public int getNewMessageCount ( ) {
return messages . size ( ) + droppedMessages . size ( ) ;
}
2013-01-01 06:48:31 -05:00
} ;
// Key is accountNumber
private ConcurrentHashMap < Integer , NotificationData > notificationData = new ConcurrentHashMap < Integer , NotificationData > ( ) ;
2012-08-30 11:47:58 -04:00
private static final Flag [ ] SYNC_FLAGS = new Flag [ ] { Flag . SEEN , Flag . FLAGGED , Flag . ANSWERED , Flag . FORWARDED } ;
2012-08-20 22:09:34 -04:00
2013-02-18 22:45:14 -05:00
private void suppressMessages ( Account account , List < Message > messages ) {
EmailProviderCache cache = EmailProviderCache . getCache ( account . getUuid ( ) ,
mApplication . getApplicationContext ( ) ) ;
cache . hideMessages ( messages ) ;
2009-11-24 19:40:29 -05:00
}
2013-02-18 22:45:14 -05:00
private void unsuppressMessages ( Account account , Message [ ] messages ) {
EmailProviderCache cache = EmailProviderCache . getCache ( account . getUuid ( ) ,
mApplication . getApplicationContext ( ) ) ;
cache . unhideMessages ( messages ) ;
2009-11-24 19:40:29 -05:00
}
2013-02-18 22:45:14 -05:00
private boolean isMessageSuppressed ( Account account , Message message ) {
LocalMessage localMessage = ( LocalMessage ) message ;
String accountUuid = account . getUuid ( ) ;
long messageId = localMessage . getId ( ) ;
long folderId = ( ( LocalFolder ) localMessage . getFolder ( ) ) . getId ( ) ;
2009-11-24 19:40:29 -05:00
2013-02-18 22:45:14 -05:00
EmailProviderCache cache = EmailProviderCache . getCache ( accountUuid ,
mApplication . getApplicationContext ( ) ) ;
return cache . isMessageHidden ( messageId , folderId ) ;
2009-11-24 19:40:29 -05:00
}
2013-02-18 22:45:14 -05:00
private void setFlagInCache ( final Account account , final List < Long > messageIds ,
final Flag flag , final boolean newState ) {
EmailProviderCache cache = EmailProviderCache . getCache ( account . getUuid ( ) ,
mApplication . getApplicationContext ( ) ) ;
String columnName = LocalStore . getColumnNameForFlag ( flag ) ;
String value = Integer . toString ( ( newState ) ? 1 : 0 ) ;
cache . setValueForMessages ( messageIds , columnName , value ) ;
2009-11-24 19:40:29 -05:00
}
2013-02-18 22:45:14 -05:00
private void removeFlagFromCache ( final Account account , final List < Long > messageIds ,
final Flag flag ) {
2009-11-24 19:40:29 -05:00
2013-02-18 22:45:14 -05:00
EmailProviderCache cache = EmailProviderCache . getCache ( account . getUuid ( ) ,
mApplication . getApplicationContext ( ) ) ;
String columnName = LocalStore . getColumnNameForFlag ( flag ) ;
cache . removeValueForMessages ( messageIds , columnName ) ;
}
2010-01-02 20:50:41 -05:00
2013-02-18 22:45:14 -05:00
private void setFlagForThreadsInCache ( final Account account , final List < Long > threadRootIds ,
final Flag flag , final boolean newState ) {
2010-07-06 06:29:26 -04:00
2013-02-18 22:45:14 -05:00
EmailProviderCache cache = EmailProviderCache . getCache ( account . getUuid ( ) ,
mApplication . getApplicationContext ( ) ) ;
String columnName = LocalStore . getColumnNameForFlag ( flag ) ;
String value = Integer . toString ( ( newState ) ? 1 : 0 ) ;
cache . setValueForThreads ( threadRootIds , columnName , value ) ;
2009-01-29 08:35:43 -05:00
}
2009-11-24 19:40:29 -05:00
2013-02-18 22:45:14 -05:00
private void removeFlagForThreadsFromCache ( final Account account , final List < Long > messageIds ,
final Flag flag ) {
EmailProviderCache cache = EmailProviderCache . getCache ( account . getUuid ( ) ,
mApplication . getApplicationContext ( ) ) ;
String columnName = LocalStore . getColumnNameForFlag ( flag ) ;
cache . removeValueForThreads ( messageIds , columnName ) ;
}
2010-12-06 04:25:23 -05:00
/ * *
* @param application { @link K9 }
* /
2011-02-06 17:09:48 -05:00
private MessagingController ( Application application ) {
2008-11-01 17:32:06 -04:00
mApplication = application ;
mThread = new Thread ( this ) ;
2010-12-06 04:25:23 -05:00
mThread . setName ( " MessagingController " ) ;
2008-11-01 17:32:06 -04:00
mThread . start ( ) ;
2011-02-06 17:09:48 -05:00
if ( memorizingListener ! = null ) {
2009-10-21 20:41:06 -04:00
addListener ( memorizingListener ) ;
}
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -05:00
2008-11-01 17:32:06 -04:00
/ * *
* Gets or creates the singleton instance of MessagingController . Application is used to
* provide a Context to classes that need it .
2010-12-06 04:25:23 -05:00
* @param application { @link K9 }
2008-11-01 17:32:06 -04:00
* @return
* /
2011-02-06 17:09:48 -05:00
public synchronized static MessagingController getInstance ( Application application ) {
if ( inst = = null ) {
2008-11-01 17:32:06 -04:00
inst = new MessagingController ( application ) ;
}
return inst ;
}
2011-02-06 17:09:48 -05:00
public boolean isBusy ( ) {
2008-11-01 17:32:06 -04:00
return mBusy ;
}
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2008-11-01 17:32:06 -04:00
Process . setThreadPriority ( Process . THREAD_PRIORITY_BACKGROUND ) ;
2011-02-06 17:09:48 -05:00
while ( true ) {
2009-11-24 19:40:29 -05:00
String commandDescription = null ;
2011-02-06 17:09:48 -05:00
try {
2010-11-13 16:40:56 -05:00
final Command command = mCommands . take ( ) ;
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
if ( command ! = null ) {
2009-11-24 19:40:29 -05:00
commandDescription = command . description ;
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Running " + ( command . isForeground ? " Foreground " : " Background " ) + " command ' " + command . description + " ', seq = " + command . sequence ) ;
2009-11-24 19:40:29 -05:00
mBusy = true ;
2011-02-06 17:09:48 -05:00
try {
2010-11-13 16:40:56 -05:00
command . runnable . run ( ) ;
2011-02-06 17:09:48 -05:00
} catch ( UnavailableAccountException e ) {
2010-11-13 16:40:56 -05:00
// retry later
2011-02-06 17:09:48 -05:00
new Thread ( ) {
2010-11-13 16:40:56 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
try {
2010-11-13 16:40:56 -05:00
sleep ( 30 * 1000 ) ;
mCommands . put ( command ) ;
2011-02-06 17:09:48 -05:00
} catch ( InterruptedException e ) {
2010-11-13 16:40:56 -05:00
Log . e ( K9 . LOG_TAG , " interrupted while putting a pending command for "
+ " an unavailable account back into the queue. "
+ " THIS SHOULD NEVER HAPPEN. " ) ;
}
}
} . start ( ) ;
}
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , ( command . isForeground ? " Foreground " : " Background " ) +
" Command ' " + command . description + " ' completed " ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( command . listener ) ) {
2011-10-06 12:28:14 -04:00
l . controllerCommandCompleted ( ! mCommands . isEmpty ( ) ) ;
2009-11-24 19:40:29 -05:00
}
}
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Error running command ' " + commandDescription + " ' " , e ) ;
2008-11-01 17:32:06 -04:00
}
mBusy = false ;
}
}
2011-02-06 17:09:48 -05:00
private void put ( String description , MessagingListener listener , Runnable runnable ) {
2009-10-21 20:41:06 -04:00
putCommand ( mCommands , description , listener , runnable , true ) ;
}
2009-09-16 23:43:02 -04:00
2011-02-06 17:09:48 -05:00
private void putBackground ( String description , MessagingListener listener , Runnable runnable ) {
2009-10-21 20:41:06 -04:00
putCommand ( mCommands , description , listener , runnable , false ) ;
}
2011-02-06 17:09:48 -05:00
private void putCommand ( BlockingQueue < Command > queue , String description , MessagingListener listener , Runnable runnable , boolean isForeground ) {
2009-10-21 20:41:06 -04:00
int retries = 10 ;
Exception e = null ;
2011-02-06 17:09:48 -05:00
while ( retries - - > 0 ) {
try {
2009-10-21 20:41:06 -04:00
Command command = new Command ( ) ;
command . listener = listener ;
command . runnable = runnable ;
command . description = description ;
command . isForeground = isForeground ;
2009-09-16 23:43:02 -04:00
queue . put ( command ) ;
2009-10-21 20:41:06 -04:00
return ;
2011-02-06 17:09:48 -05:00
} catch ( InterruptedException ie ) {
try {
2009-10-21 20:41:06 -04:00
Thread . sleep ( 200 ) ;
2011-02-06 17:09:48 -05:00
} catch ( InterruptedException ne ) {
2009-10-21 20:41:06 -04:00
}
e = ie ;
}
}
throw new Error ( e ) ;
r62972@17h: jesse | 2009-05-07 10:49:32 -0400
First stab at a folderlist that doesn't know or care about messages
r62973@17h: jesse | 2009-05-07 10:50:11 -0400
A very broken first stab at a message list that only knows about one folder.
r62974@17h: jesse | 2009-05-07 10:50:44 -0400
When you go from an account list to an individual account, open a folderlist, not an fml
r62975@17h: jesse | 2009-05-07 10:51:24 -0400
Update Welcome activity to open an ml instead of an fml
r62976@17h: jesse | 2009-05-07 10:51:59 -0400
When setting up accounts is over, open an fl instead of an fml
r62977@17h: jesse | 2009-05-07 10:52:51 -0400
Update MessageView to use folderinfoholders and messageinfoholders from the 'correct' classes.
r62978@17h: jesse | 2009-05-07 10:59:07 -0400
MailService now notifies the fl instead of the fml. Not sure if it should also notify the ml. - will require testing
r62979@17h: jesse | 2009-05-07 11:01:09 -0400
Switch MessagingController's notifications from notifying the FML to notifying an ML
r62980@17h: jesse | 2009-05-07 11:25:22 -0400
Update AndroidManifest to know about the new world order
r62981@17h: jesse | 2009-05-07 11:26:11 -0400
Try to follow the android sdk docs for intent creation
r62982@17h: jesse | 2009-05-07 11:28:30 -0400
reset MessageList for another try at the conversion
r62983@17h: jesse | 2009-05-07 11:47:33 -0400
This version doesn't crash and has a working 'folder' layer. now to clean up the message list layer
r62984@17h: jesse | 2009-05-07 15:18:04 -0400
move step 1
r62985@17h: jesse | 2009-05-07 15:18:37 -0400
move step 1
r62986@17h: jesse | 2009-05-07 15:22:47 -0400
rename step 1
r62987@17h: jesse | 2009-05-07 17:38:02 -0400
checkpoint to move
r62988@17h: jesse | 2009-05-07 17:40:01 -0400
checkpointing a state with a working folder list and a message list that doesn't explode
r62989@17h: jesse | 2009-05-07 17:40:26 -0400
Remove debugging cruft from Welcome
r62990@17h: jesse | 2009-05-07 22:00:12 -0400
Basic functionality works.
r62991@17h: jesse | 2009-05-08 04:19:52 -0400
added a tool to build a K-9 "Beta"
r62992@17h: jesse | 2009-05-08 04:20:03 -0400
remove a disused file
r62993@17h: jesse | 2009-05-09 06:07:02 -0400
upgrading build infrastructure for the 1.5 sdk
r62994@17h: jesse | 2009-05-09 06:22:02 -0400
further refine onOpenMessage, removing more folder assumptions
r62995@17h: jesse | 2009-05-09 20:07:20 -0400
Make the Welcome activity open the autoexpandfolder rather than INBOX
r62996@17h: jesse | 2009-05-09 20:14:10 -0400
MessageList now stores the Folder name it was working with across pause-reload
r62997@17h: jesse | 2009-05-09 20:14:26 -0400
Removing dead code from FolderList
r63060@17h: jesse | 2009-05-10 00:07:33 -0400
Replace the old message list refreshing code which cleared and rebuilt the list from scratch with code which updates or deletes existing messages.
Add "go back to folder list" code
r63061@17h: jesse | 2009-05-10 00:07:50 -0400
fix message list menus for new world order
r63062@17h: jesse | 2009-05-10 00:08:11 -0400
Remove message list options from folder list menus
r63063@17h: jesse | 2009-05-10 00:10:02 -0400
remove more message list options from the folder list
r63064@17h: jesse | 2009-05-10 00:10:19 -0400
fix build.xml for the new android world order
r63065@17h: jesse | 2009-05-10 00:39:23 -0400
reformatted in advance of bug tracing
r63066@17h: jesse | 2009-05-10 05:53:28 -0400
fix our 'close' behavior to not leave extra activities around
clean up more vestigal code
r63067@17h: jesse | 2009-05-10 18:44:25 -0400
Improve "back button / accounts" workflow from FolderList -> AccountList
r63068@17h: jesse | 2009-05-10 19:11:47 -0400
* Add required code for the 'k9beta' build
r63069@17h: jesse | 2009-05-10 19:12:05 -0400
Make the folder list white backgrounded.
r63070@17h: jesse | 2009-05-10 19:12:26 -0400
* Include our required libraries in build.xml
r63071@17h: jesse | 2009-05-10 19:13:07 -0400
Added directories for our built code and our generated code
r63072@17h: jesse | 2009-05-10 19:13:36 -0400
Added a "back" button image
r63073@17h: jesse | 2009-05-10 20:13:50 -0400
Switch next/prev buttons to triangles for I18N and eventual "more easy-to-hit buttons" win
r63074@17h: jesse | 2009-05-10 20:17:18 -0400
Tidy Accounts.java for some perf hacking.
r63081@17h: jesse | 2009-05-10 22:13:33 -0400
First pass reformatting of the MessagingController
r63082@17h: jesse | 2009-05-10 23:50:28 -0400
MessageList now correctly updates when a background sync happens
r63083@17h: jesse | 2009-05-10 23:50:53 -0400
Tidying FolderList
r63084@17h: jesse | 2009-05-10 23:51:09 -0400
tidy
r63085@17h: jesse | 2009-05-10 23:51:27 -0400
tidy
r63086@17h: jesse | 2009-05-11 00:17:06 -0400
Properly update unread counts in the FolderList after sync
r63087@17h: jesse | 2009-05-11 01:38:14 -0400
Minor refactoring for readability. replace a boolean with a constant.
r63090@17h: jesse | 2009-05-11 02:58:31 -0400
now that the foreground of message lists is light, we don't need the light messagebox
r63091@17h: jesse | 2009-05-11 17:15:02 -0400
Added a string for "back to folder list"
r63092@17h: jesse | 2009-05-11 17:15:24 -0400
Added a message list header with a back button
r63093@17h: jesse | 2009-05-11 17:15:54 -0400
Remove the "folder list" button from the options menu. no sense duplicating it
r63094@17h: jesse | 2009-05-11 17:17:06 -0400
Refactored views, adding our replacement scrollable header
r63184@17h: jesse | 2009-05-12 07:07:15 -0400
fix weird bug where message lists could show a header element for a child
r63185@17h: jesse | 2009-05-12 07:08:12 -0400
Add new-style headers to folder lists. reimplement "get folder by name" to not use a bloody for loop
r63211@17h: jesse | 2009-05-12 18:37:48 -0400
Restore the former glory of the "load more messages" widget. it still needs an overhaul
r63296@17h: jesse | 2009-05-12 23:23:21 -0400
Get the indeterminate progress bar to show up again when you click "get more messages"
r63297@17h: jesse | 2009-05-13 02:40:39 -0400
Fixed off-by-one errors in click and keybindings for messagelist
r63298@17h: jesse | 2009-05-13 06:04:01 -0400
Put the folder title in the name of the folderSettings popup
r63299@17h: jesse | 2009-05-13 06:04:49 -0400
Reformatting. Removing debug logging
r63300@17h: jesse | 2009-05-13 06:05:32 -0400
Fixing "wrong item selected" bugs in the FolderList
r63328@17h: jesse | 2009-05-13 13:20:00 -0400
Update MessageView for 1.5
r63329@17h: jesse | 2009-05-13 13:50:29 -0400
A couple fixes to "picking the right item"
Titles on the message context menu
r63330@17h: jesse | 2009-05-13 13:58:37 -0400
Added an "open" context menu item to the folder list
r63347@17h: jesse | 2009-05-13 18:00:02 -0400
Try to get folderlists to sort in a stable way, so they jump around less in the ui
r63349@17h: jesse | 2009-05-13 20:37:19 -0400
Switch to using non-message-passing based notifications for redisplay of message lists, cut down redisplay frequency to not overload the display
r63432@17h: jesse | 2009-05-16 13:38:49 -0400
Android 1.5 no longer gives us apache.commons.codec by default and apache.commons.logging by default. Import them so we have em.
There's probably something smarter to do here.
r63438@17h: jesse | 2009-05-16 14:12:06 -0400
removed dead code
r63439@17h: jesse | 2009-05-16 14:30:57 -0400
Minor tidy
r63440@17h: jesse | 2009-05-16 14:39:34 -0400
First pass implementation making MessageList streamy for faster startup
r63441@17h: jesse | 2009-05-16 21:57:41 -0400
There's no reason for the FolderList to list local messages
r63442@17h: jesse | 2009-05-16 21:58:57 -0400
Switch to actually refreshing the message list after each item is loaded
r63450@17h: jesse | 2009-05-16 22:34:18 -0400
Default to pulling items out of the LocalStore by date, descending. (since that's the uneditable default ordering)
This makes our messages come out of the store in the order the user should see them
r63451@17h: jesse | 2009-05-16 22:34:44 -0400
Set some new defaults for the FolderList
r63452@17h: jesse | 2009-05-16 22:35:43 -0400
set some new message list item defaults
r63456@17h: jesse | 2009-05-17 12:56:10 -0400
It's not clear that Pop and WebDav actually set us an InternalDate. I'd rather use that so that spam doesn't topsort. But I also want this to _work_
r63457@17h: jesse | 2009-05-17 12:56:47 -0400
actually check to make sure we have a message to remove before removing it.
r63458@17h: jesse | 2009-05-17 13:10:07 -0400
Flip "security type" to before the port number, since changing security type is the thing more users are likely to know/care about and resets port number
r63469@17h: jesse | 2009-05-17 18:42:39 -0400
Provisional fix for "see the FoldeRList twice" bug
r63471@17h: jesse | 2009-05-17 20:47:41 -0400
Remove title bar from the message view
r63544@17h: jesse | 2009-05-20 23:53:38 -0400
folderlist tidying before i dig into the jumpy ordering bug
r63545@17h: jesse | 2009-05-20 23:56:00 -0400
Killing dead variables
r63546@17h: jesse | 2009-05-21 00:58:36 -0400
make the whole title section clicky
r63556@17h: jesse | 2009-05-21 01:48:13 -0400
Fix where we go when someone deletes a message
r63558@17h: jesse | 2009-05-21 22:44:46 -0400
Working toward switchable themes
r63563@17h: jesse | 2009-05-21 23:53:09 -0400
Make the MessageList's colors actually just inherit from the theme, rather than hardcoding black
r63567@17h: jesse | 2009-05-22 10:14:13 -0400
Kill a now-redundant comment
r63571@17h: jesse | 2009-05-22 19:43:30 -0400
further theme-independence work
r63572@17h: jesse | 2009-05-22 19:55:23 -0400
gete -> get (typo fix)
r63573@17h: jesse | 2009-05-22 22:48:49 -0400
First cut of a global prefs system as well as a theme preference. not that it works yet
r63577@17h: jesse | 2009-05-24 14:49:52 -0400
Once a user has actually put in valid user credentials, start syncing mail and folders in the background instantly.
This gives us a much better "new startup" experience
r63578@17h: jesse | 2009-05-24 14:55:00 -0400
MessageList doesn't need FolderUpdateWorker
r63579@17h: jesse | 2009-05-24 17:57:15 -0400
Fix "get message by uid"
Switch to showing messages 10 by 10, rather than 1 by 1 for huge loadtime performance improvements
r63587@17h: jesse | 2009-05-24 19:19:56 -0400
Cut down LocalMessage creation to not generate a MessageId or date formatter.
r63589@17h: jesse | 2009-05-24 22:22:32 -0400
Switch to null-escaping email address boundaries, rather than a VERY expensive URL-encoding
r63590@17h: jesse | 2009-05-24 22:23:21 -0400
Clean up our "auto-refresh the list when adding messages after a sync"
r63593@17h: jesse | 2009-05-24 22:53:45 -0400
replace isDateToday with a "rolling 18 hour window" variant that's more likely to give the user a useful answer and is 30x faster.
r63595@17h: jesse | 2009-05-24 23:54:14 -0400
When instantiating messges from the LocalStore, there's no need to clear headers before setting them, nor is there a need to set a generated message id
r63596@17h: jesse | 2009-05-24 23:54:39 -0400
make an overridable setGeneratedMessageId
r63597@17h: jesse | 2009-05-24 23:54:55 -0400
Remove new lies from comments
r63598@17h: jesse | 2009-05-24 23:55:35 -0400
Replace insanely expensive message header "name" part quoting with something consistent and cheap that does its work on the way INTO the database
r63605@17h: jesse | 2009-05-25 17:28:24 -0400
bring back the 1.1 sdk build.xml
r63606@17h: jesse | 2009-05-25 22:32:11 -0400
Actually enable switchable themese and compilation on 1.1
r63692@17h: jesse | 2009-05-29 23:55:17 -0400
Switch back to having titles for folder and message lists.
Restore auto-open-folder functionality
r63694@17h: jesse | 2009-05-30 18:50:39 -0400
Remove several off-by-one errors introduced by yesterday's return to android titlebars
r63696@17h: jesse | 2009-05-30 23:45:03 -0400
use convertView properly for performance and memory imrpovement in FolderList and MessageList
r63698@17h: jesse | 2009-05-31 19:42:59 -0400
Switch to using background shading to indicate "not yet fetched"
r63701@17h: jesse | 2009-05-31 21:28:47 -0400
Remving code we don't actually need these bits of apache commons on 1.1
2009-05-31 21:35:05 -04:00
}
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2008-11-01 17:32:06 -04:00
2011-02-06 17:09:48 -05:00
public void addListener ( MessagingListener listener ) {
2008-11-01 17:32:06 -04:00
mListeners . add ( listener ) ;
2009-10-21 20:41:06 -04:00
refreshListener ( listener ) ;
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
public void refreshListener ( MessagingListener listener ) {
if ( memorizingListener ! = null & & listener ! = null ) {
2009-10-21 20:41:06 -04:00
memorizingListener . refreshOther ( listener ) ;
}
2008-11-01 17:32:06 -04:00
}
2011-02-06 17:09:48 -05:00
public void removeListener ( MessagingListener listener ) {
2008-11-01 17:32:06 -04:00
mListeners . remove ( listener ) ;
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
public Set < MessagingListener > getListeners ( ) {
2009-11-24 19:40:29 -05:00
return mListeners ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
}
2008-11-01 17:32:06 -04:00
2010-07-13 17:17:10 -04:00
2011-02-06 17:09:48 -05:00
public Set < MessagingListener > getListeners ( MessagingListener listener ) {
if ( listener = = null ) {
2010-07-14 23:42:05 -04:00
return mListeners ;
2010-07-13 17:17:10 -04:00
}
2010-07-14 23:42:05 -04:00
2010-07-15 20:38:32 -04:00
Set < MessagingListener > listeners = new HashSet < MessagingListener > ( mListeners ) ;
2010-07-14 23:42:05 -04:00
listeners . add ( listener ) ;
2010-07-13 17:17:10 -04:00
return listeners ;
}
2008-11-01 17:32:06 -04:00
/ * *
* Lists folders that are available locally and remotely . This method calls
* listFoldersCallback for local folders before it returns , and then for
* remote folders at some later point . If there are no local folders
* includeRemote is forced by this method . This method should be called from
2009-11-24 19:40:29 -05:00
* a Thread as it may take several seconds to list the local folders .
2008-11-01 17:34:50 -04:00
* TODO this needs to cache the remote folder list
2008-11-01 17:32:06 -04:00
*
* @param account
* @param listener
* @throws MessagingException
* /
2011-02-06 17:09:48 -05:00
public void listFolders ( final Account account , final boolean refreshRemote , final MessagingListener listener ) {
threadPool . execute ( new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2010-10-23 21:03:29 -04:00
listFoldersSynchronous ( account , refreshRemote , listener ) ;
}
} ) ;
}
2009-11-24 19:40:29 -05:00
2010-10-23 21:03:29 -04:00
/ * *
* Lists folders that are available locally and remotely . This method calls
* listFoldersCallback for local folders before it returns , and then for
* remote folders at some later point . If there are no local folders
* includeRemote is forced by this method . This method is called in the
* foreground .
* TODO this needs to cache the remote folder list
*
* @param account
* @param listener
* @throws MessagingException
* /
2011-02-06 17:09:48 -05:00
public void listFoldersSynchronous ( final Account account , final boolean refreshRemote , final MessagingListener listener ) {
for ( MessagingListener l : getListeners ( listener ) ) {
2010-10-23 21:03:29 -04:00
l . listFoldersStarted ( account ) ;
}
2011-02-06 17:09:48 -05:00
List < ? extends Folder > localFolders = null ;
if ( ! account . isAvailable ( mApplication ) ) {
2010-11-13 16:40:56 -05:00
Log . i ( K9 . LOG_TAG , " not listing folders of unavailable account " ) ;
2011-02-06 17:09:48 -05:00
} else {
try {
2010-11-13 16:40:56 -05:00
Store localStore = account . getLocalStore ( ) ;
localFolders = localStore . getPersonalNamespaces ( false ) ;
2010-04-21 22:20:35 -04:00
2010-11-13 16:40:56 -05:00
Folder [ ] folderArray = localFolders . toArray ( EMPTY_FOLDER_ARRAY ) ;
2010-07-13 17:17:10 -04:00
2011-10-06 12:28:14 -04:00
if ( refreshRemote | | localFolders . isEmpty ( ) ) {
2010-11-13 16:40:56 -05:00
doRefreshRemote ( account , listener ) ;
return ;
}
2010-07-13 17:17:10 -04:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
2010-11-13 16:40:56 -05:00
l . listFolders ( account , folderArray ) ;
}
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
for ( MessagingListener l : getListeners ( listener ) ) {
2010-11-13 16:40:56 -05:00
l . listFoldersFailed ( account , e . getMessage ( ) ) ;
}
2010-10-23 21:03:29 -04:00
2010-11-13 16:40:56 -05:00
addErrorMessage ( account , null , e ) ;
return ;
2011-02-06 17:09:48 -05:00
} finally {
if ( localFolders ! = null ) {
for ( Folder localFolder : localFolders ) {
2010-11-28 15:28:58 -05:00
closeFolder ( localFolder ) ;
2010-01-16 11:22:20 -05:00
}
}
2009-11-24 19:40:29 -05:00
}
2010-10-23 21:03:29 -04:00
}
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
2010-10-23 21:03:29 -04:00
l . listFoldersFinished ( account ) ;
}
2008-11-01 17:34:50 -04:00
}
2012-03-18 17:43:47 -04:00
private void doRefreshRemote ( final Account account , final MessagingListener listener ) {
2011-02-06 17:09:48 -05:00
put ( " doRefreshRemote " , listener , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
List < ? extends Folder > localFolders = null ;
try {
2010-03-03 23:00:30 -05:00
Store store = account . getRemoteStore ( ) ;
2008-11-01 17:32:06 -04:00
2011-02-06 17:09:48 -05:00
List < ? extends Folder > remoteFolders = store . getPersonalNamespaces ( false ) ;
2008-11-01 17:32:06 -04:00
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
2009-11-24 19:40:29 -05:00
HashSet < String > remoteFolderNames = new HashSet < String > ( ) ;
2011-02-04 07:26:14 -05:00
List < LocalFolder > foldersToCreate = new LinkedList < LocalFolder > ( ) ;
localFolders = localStore . getPersonalNamespaces ( false ) ;
HashSet < String > localFolderNames = new HashSet < String > ( ) ;
2011-02-06 17:09:48 -05:00
for ( Folder localFolder : localFolders ) {
2011-02-04 07:26:14 -05:00
localFolderNames . add ( localFolder . getName ( ) ) ;
}
2011-02-06 17:09:48 -05:00
for ( Folder remoteFolder : remoteFolders ) {
if ( localFolderNames . contains ( remoteFolder . getName ( ) ) = = false ) {
2011-02-04 07:26:14 -05:00
LocalFolder localFolder = localStore . getFolder ( remoteFolder . getName ( ) ) ;
foldersToCreate . add ( localFolder ) ;
2008-11-01 17:32:06 -04:00
}
2011-02-04 07:26:14 -05:00
remoteFolderNames . add ( remoteFolder . getName ( ) ) ;
2009-11-24 19:40:29 -05:00
}
2011-02-04 07:26:14 -05:00
localStore . createFolders ( foldersToCreate , account . getDisplayCount ( ) ) ;
2008-11-01 17:32:06 -04:00
2010-05-30 12:56:50 -04:00
localFolders = localStore . getPersonalNamespaces ( false ) ;
2008-11-01 17:32:06 -04:00
2009-11-24 19:40:29 -05:00
/ *
* Clear out any folders that are no longer on the remote store .
* /
2011-02-06 17:09:48 -05:00
for ( Folder localFolder : localFolders ) {
2009-11-24 19:40:29 -05:00
String localFolderName = localFolder . getName ( ) ;
2011-02-06 17:09:48 -05:00
if ( ! account . isSpecialFolder ( localFolderName ) & & ! remoteFolderNames . contains ( localFolderName ) ) {
2009-11-24 19:40:29 -05:00
localFolder . delete ( false ) ;
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -05:00
}
2008-11-01 17:32:06 -04:00
2010-05-30 12:56:50 -04:00
localFolders = localStore . getPersonalNamespaces ( false ) ;
2010-08-02 07:55:31 -04:00
Folder [ ] folderArray = localFolders . toArray ( EMPTY_FOLDER_ARRAY ) ;
2008-11-01 17:32:06 -04:00
2012-03-18 17:43:47 -04:00
for ( MessagingListener l : getListeners ( listener ) ) {
2010-04-21 22:20:35 -04:00
l . listFolders ( account , folderArray ) ;
2008-11-01 17:32:06 -04:00
}
2012-03-18 17:43:47 -04:00
for ( MessagingListener l : getListeners ( listener ) ) {
2009-11-24 19:40:29 -05:00
l . listFoldersFinished ( account ) ;
2008-11-01 17:32:06 -04:00
}
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2012-03-18 17:43:47 -04:00
for ( MessagingListener l : getListeners ( listener ) ) {
2009-11-24 19:40:29 -05:00
l . listFoldersFailed ( account , " " ) ;
}
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , e ) ;
2011-02-06 17:09:48 -05:00
} finally {
if ( localFolders ! = null ) {
for ( Folder localFolder : localFolders ) {
2010-11-28 15:28:58 -05:00
closeFolder ( localFolder ) ;
2010-01-16 11:22:20 -05:00
}
}
}
2009-11-24 19:40:29 -05:00
}
} ) ;
2008-11-01 17:32:06 -04:00
}
2009-12-27 11:53:59 -05:00
/ * *
* Find all messages in any local account which match the query ' query '
* @throws MessagingException
* /
2012-10-13 08:53:00 -04:00
public void searchLocalMessages ( final LocalSearch search , final MessagingListener listener ) {
2011-02-06 17:09:48 -05:00
threadPool . execute ( new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2012-10-13 08:53:00 -04:00
searchLocalMessagesSynchronous ( search , listener ) ;
2010-10-23 11:19:47 -04:00
}
} ) ;
}
2012-10-16 16:42:51 -04:00
2012-10-13 08:53:00 -04:00
public void searchLocalMessagesSynchronous ( final LocalSearch search , final MessagingListener listener ) {
2010-10-23 11:19:47 -04:00
final AccountStats stats = new AccountStats ( ) ;
2012-10-13 08:53:00 -04:00
final HashSet < String > uuidSet = new HashSet < String > ( Arrays . asList ( search . getAccountUuids ( ) ) ) ;
Account [ ] accounts = Preferences . getPreferences ( mApplication . getApplicationContext ( ) ) . getAccounts ( ) ;
boolean allAccounts = uuidSet . contains ( SearchSpecification . ALL_ACCOUNTS ) ;
2012-10-16 16:42:51 -04:00
// for every account we want to search do the query in the localstore
for ( final Account account : accounts ) {
if ( ! allAccounts & & ! uuidSet . contains ( account . getUuid ( ) ) ) {
continue ;
}
2012-10-13 08:53:00 -04:00
// Collecting statistics of the search result
2011-02-06 17:09:48 -05:00
MessageRetrievalListener retrievalListener = new MessageRetrievalListener ( ) {
2010-12-20 16:34:01 -05:00
@Override
2010-10-23 11:19:47 -04:00
public void messageStarted ( String message , int number , int ofTotal ) { }
2010-12-20 16:34:01 -05:00
@Override
2012-10-13 08:53:00 -04:00
public void messagesFinished ( int number ) { }
@Override
2011-02-06 17:09:48 -05:00
public void messageFinished ( Message message , int number , int ofTotal ) {
2013-02-18 22:45:14 -05:00
if ( ! isMessageSuppressed ( message . getFolder ( ) . getAccount ( ) , message ) ) {
2010-10-23 11:19:47 -04:00
List < Message > messages = new ArrayList < Message > ( ) ;
2010-04-29 00:59:14 -04:00
2010-10-23 11:19:47 -04:00
messages . add ( message ) ;
stats . unreadMessageCount + = ( ! message . isSet ( Flag . SEEN ) ) ? 1 : 0 ;
stats . flaggedMessageCount + = ( message . isSet ( Flag . FLAGGED ) ) ? 1 : 0 ;
2011-02-06 17:09:48 -05:00
if ( listener ! = null ) {
2010-10-23 11:19:47 -04:00
listener . listLocalMessagesAddMessages ( account , null , messages ) ;
2010-04-16 23:32:17 -04:00
}
2009-12-27 12:22:51 -05:00
}
2010-10-23 11:19:47 -04:00
}
} ;
2012-10-16 16:42:51 -04:00
// alert everyone the search has started
2012-10-13 08:53:00 -04:00
if ( listener ! = null ) {
listener . listLocalMessagesStarted ( account , null ) ;
}
2012-10-16 16:42:51 -04:00
2012-10-13 08:53:00 -04:00
// build and do the query in the localstore
2011-02-06 17:09:48 -05:00
try {
2012-10-16 16:42:51 -04:00
LocalStore localStore = account . getLocalStore ( ) ;
2012-10-13 08:53:00 -04:00
localStore . searchForMessages ( retrievalListener , search ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
if ( listener ! = null ) {
2010-10-23 11:19:47 -04:00
listener . listLocalMessagesFailed ( account , null , e . getMessage ( ) ) ;
2009-12-27 11:53:59 -05:00
}
2010-10-23 11:19:47 -04:00
addErrorMessage ( account , null , e ) ;
2011-02-06 17:09:48 -05:00
} finally {
if ( listener ! = null ) {
2010-10-23 11:19:47 -04:00
listener . listLocalMessagesFinished ( account , null ) ;
2010-04-22 00:58:50 -04:00
}
2009-12-27 11:53:59 -05:00
}
2012-10-16 16:42:51 -04:00
}
// publish the total search statistics
2011-02-06 17:09:48 -05:00
if ( listener ! = null ) {
2010-10-23 11:19:47 -04:00
listener . searchStats ( stats ) ;
}
2009-12-27 11:53:59 -05:00
}
2012-03-05 15:04:34 -05:00
2013-02-04 05:18:49 -05:00
public Future < ? > searchRemoteMessages ( final String acctUuid , final String folderName , final String query ,
final Flag [ ] requiredFlags , final Flag [ ] forbiddenFlags , final MessagingListener listener ) {
2012-03-05 15:04:34 -05:00
if ( K9 . DEBUG ) {
String msg = " searchRemoteMessages ( "
+ " acct= " + acctUuid
+ " , folderName = " + folderName
+ " , query = " + query
+ " ) " ;
Log . i ( K9 . LOG_TAG , msg ) ;
}
2012-09-25 18:46:30 -04:00
return threadPool . submit ( new Runnable ( ) {
2012-03-05 15:04:34 -05:00
@Override
public void run ( ) {
searchRemoteMessagesSynchronous ( acctUuid , folderName , query , requiredFlags , forbiddenFlags , listener ) ;
}
} ) ;
}
public void searchRemoteMessagesSynchronous ( final String acctUuid , final String folderName , final String query ,
final Flag [ ] requiredFlags , final Flag [ ] forbiddenFlags , final MessagingListener listener ) {
final Account acct = Preferences . getPreferences ( mApplication . getApplicationContext ( ) ) . getAccount ( acctUuid ) ;
if ( listener ! = null ) {
listener . remoteSearchStarted ( acct , folderName ) ;
}
List < Message > extraResults = new ArrayList < Message > ( ) ;
try {
Store remoteStore = acct . getRemoteStore ( ) ;
LocalStore localStore = acct . getLocalStore ( ) ;
if ( remoteStore = = null | | localStore = = null ) {
throw new MessagingException ( " Could not get store " ) ;
}
Folder remoteFolder = remoteStore . getFolder ( folderName ) ;
LocalFolder localFolder = localStore . getFolder ( folderName ) ;
if ( remoteFolder = = null | | localFolder = = null ) {
throw new MessagingException ( " Folder not found " ) ;
}
2012-09-25 17:34:59 -04:00
List < Message > messages = remoteFolder . search ( query , requiredFlags , forbiddenFlags ) ;
2012-03-05 15:04:34 -05:00
if ( K9 . DEBUG ) {
Log . i ( " Remote Search " , " Remote search got " + messages . size ( ) + " results " ) ;
}
2012-11-15 15:05:45 -05:00
// There's no need to fetch messages already completely downloaded
List < Message > remoteMessages = localFolder . extractNewMessages ( messages ) ;
messages . clear ( ) ;
if ( listener ! = null ) {
listener . remoteSearchServerQueryComplete ( acct , folderName , remoteMessages . size ( ) ) ;
}
2012-03-05 15:04:34 -05:00
2012-11-15 15:05:45 -05:00
Collections . sort ( remoteMessages , new UidReverseComparator ( ) ) ;
2012-03-05 15:04:34 -05:00
int resultLimit = acct . getRemoteSearchNumResults ( ) ;
2012-11-15 15:05:45 -05:00
if ( resultLimit > 0 & & remoteMessages . size ( ) > resultLimit ) {
extraResults = remoteMessages . subList ( resultLimit , remoteMessages . size ( ) ) ;
remoteMessages = remoteMessages . subList ( 0 , resultLimit ) ;
2012-03-05 15:04:34 -05:00
}
2012-11-15 15:05:45 -05:00
loadSearchResultsSynchronous ( remoteMessages , localFolder , remoteFolder , listener ) ;
2012-03-05 15:04:34 -05:00
} catch ( Exception e ) {
2012-09-25 18:46:30 -04:00
if ( Thread . currentThread ( ) . isInterrupted ( ) ) {
Log . i ( K9 . LOG_TAG , " Caught exception on aborted remote search; safe to ignore. " , e ) ;
} else {
Log . e ( K9 . LOG_TAG , " Could not complete remote search " , e ) ;
if ( listener ! = null ) {
listener . remoteSearchFailed ( acct , null , e . getMessage ( ) ) ;
}
addErrorMessage ( acct , null , e ) ;
2012-03-05 15:04:34 -05:00
}
} finally {
if ( listener ! = null ) {
listener . remoteSearchFinished ( acct , folderName , 0 , extraResults ) ;
}
}
}
public void loadSearchResults ( final Account account , final String folderName , final List < Message > messages , final MessagingListener listener ) {
threadPool . execute ( new Runnable ( ) {
@Override
public void run ( ) {
2013-01-12 18:02:09 -05:00
if ( listener ! = null ) {
listener . enableProgressIndicator ( true ) ;
}
2012-03-05 15:04:34 -05:00
try {
Store remoteStore = account . getRemoteStore ( ) ;
LocalStore localStore = account . getLocalStore ( ) ;
if ( remoteStore = = null | | localStore = = null ) {
throw new MessagingException ( " Could not get store " ) ;
}
Folder remoteFolder = remoteStore . getFolder ( folderName ) ;
LocalFolder localFolder = localStore . getFolder ( folderName ) ;
if ( remoteFolder = = null | | localFolder = = null ) {
throw new MessagingException ( " Folder not found " ) ;
}
loadSearchResultsSynchronous ( messages , localFolder , remoteFolder , listener ) ;
} catch ( MessagingException e ) {
Log . e ( K9 . LOG_TAG , " Exception in loadSearchResults: " + e ) ;
addErrorMessage ( account , null , e ) ;
2013-01-12 18:02:09 -05:00
} finally {
if ( listener ! = null ) {
listener . enableProgressIndicator ( false ) ;
}
2012-03-05 15:04:34 -05:00
}
}
} ) ;
}
public void loadSearchResultsSynchronous ( List < Message > messages , LocalFolder localFolder , Folder remoteFolder , MessagingListener listener ) throws MessagingException {
2012-09-25 10:50:10 -04:00
final FetchProfile header = new FetchProfile ( ) ;
header . add ( FetchProfile . Item . FLAGS ) ;
header . add ( FetchProfile . Item . ENVELOPE ) ;
final FetchProfile structure = new FetchProfile ( ) ;
structure . add ( FetchProfile . Item . STRUCTURE ) ;
2012-03-05 15:04:34 -05:00
int i = 0 ;
for ( Message message : messages ) {
i + + ;
LocalMessage localMsg = localFolder . getMessage ( message . getUid ( ) ) ;
if ( localMsg = = null ) {
2012-09-25 10:50:10 -04:00
remoteFolder . fetch ( new Message [ ] { message } , header , null ) ;
2012-03-05 15:04:34 -05:00
//fun fact: ImapFolder.fetch can't handle getting STRUCTURE at same time as headers
2012-09-25 10:50:10 -04:00
remoteFolder . fetch ( new Message [ ] { message } , structure , null ) ;
2012-03-05 15:04:34 -05:00
localFolder . appendMessages ( new Message [ ] { message } ) ;
localMsg = localFolder . getMessage ( message . getUid ( ) ) ;
}
if ( listener ! = null ) {
listener . remoteSearchAddMessage ( remoteFolder . getAccount ( ) , remoteFolder . getName ( ) , localMsg , i , messages . size ( ) ) ;
}
}
}
2011-02-06 17:09:48 -05:00
public void loadMoreMessages ( Account account , String folder , MessagingListener listener ) {
try {
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
LocalFolder localFolder = localStore . getFolder ( folder ) ;
2011-02-06 17:09:48 -05:00
if ( localFolder . getVisibleLimit ( ) > 0 ) {
2013-01-16 15:24:43 -05:00
localFolder . setVisibleLimit ( localFolder . getVisibleLimit ( ) + account . getDisplayCount ( ) ) ;
2010-11-12 18:41:43 -05:00
}
2010-05-15 15:35:07 -04:00
synchronizeMailbox ( account , folder , listener , null ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , me ) ;
2009-11-24 19:40:29 -05:00
throw new RuntimeException ( " Unable to set visible limit on folder " , me ) ;
}
2008-11-01 17:32:06 -04:00
}
2011-02-06 17:09:48 -05:00
public void resetVisibleLimits ( Collection < Account > accounts ) {
for ( Account account : accounts ) {
2010-11-12 18:41:33 -05:00
account . resetVisibleLimits ( ) ;
2008-11-01 17:32:06 -04:00
}
}
/ * *
* Start background synchronization of the specified folder .
* @param account
* @param folder
* @param listener
2010-05-15 15:35:07 -04:00
* @param providedRemoteFolder TODO
2008-11-01 17:32:06 -04:00
* /
2011-02-06 17:09:48 -05:00
public void synchronizeMailbox ( final Account account , final String folder , final MessagingListener listener , final Folder providedRemoteFolder ) {
putBackground ( " synchronizeMailbox " , listener , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2010-05-15 15:35:07 -04:00
synchronizeMailboxSynchronous ( account , folder , listener , providedRemoteFolder ) ;
2008-11-01 17:32:06 -04:00
}
} ) ;
}
/ * *
* Start foreground synchronization of the specified folder . This is generally only called
* by synchronizeMailbox .
* @param account
* @param folder
*
* TODO Break this method up into smaller chunks .
2010-05-15 15:35:07 -04:00
* @param providedRemoteFolder TODO
2008-11-01 17:32:06 -04:00
* /
2011-02-06 17:09:48 -05:00
private void synchronizeMailboxSynchronous ( final Account account , final String folder , final MessagingListener listener , Folder providedRemoteFolder ) {
2010-01-16 11:22:20 -05:00
Folder remoteFolder = null ;
LocalFolder tLocalFolder = null ;
2010-05-11 22:51:59 -04:00
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Synchronizing folder " + account . getDescription ( ) + " : " + folder ) ;
2009-05-10 01:47:26 -04:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
2008-11-01 17:32:06 -04:00
l . synchronizeMailboxStarted ( account , folder ) ;
}
2010-05-09 11:27:41 -04:00
/ *
* We don ' t ever sync the Outbox or errors folder
* /
2011-02-06 17:09:48 -05:00
if ( folder . equals ( account . getOutboxFolderName ( ) ) | | folder . equals ( account . getErrorFolderName ( ) ) ) {
for ( MessagingListener l : getListeners ( listener ) ) {
2010-05-09 11:27:41 -04:00
l . synchronizeMailboxFinished ( account , folder , 0 , 0 ) ;
}
return ;
}
2010-01-17 19:11:02 -05:00
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
Exception commandException = null ;
2011-02-06 17:09:48 -05:00
try {
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
2011-01-23 22:27:26 -05:00
Log . d ( K9 . LOG_TAG , " SYNC: About to process pending commands for account " + account . getDescription ( ) ) ;
2010-01-02 20:50:41 -05:00
2011-02-06 17:09:48 -05:00
try {
2009-05-10 01:47:26 -04:00
processPendingCommandsSynchronous ( account ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , e ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Failure processing command, but allow message sync attempt " , e ) ;
2009-05-10 01:47:26 -04:00
commandException = e ;
}
2008-11-01 17:32:06 -04:00
/ *
* Get the message list from the local store and create an index of
* the uids within the list .
* /
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " SYNC: About to get local folder " + folder ) ;
2010-01-02 20:50:41 -05:00
2010-03-03 23:00:30 -05:00
final LocalStore localStore = account . getLocalStore ( ) ;
tLocalFolder = localStore . getFolder ( folder ) ;
2009-05-10 01:47:26 -04:00
final LocalFolder localFolder = tLocalFolder ;
2008-11-01 17:32:06 -04:00
localFolder . open ( OpenMode . READ_WRITE ) ;
2011-01-02 04:01:23 -05:00
localFolder . updateLastUid ( ) ;
2008-11-01 17:32:06 -04:00
Message [ ] localMessages = localFolder . getMessages ( null ) ;
HashMap < String , Message > localUidMap = new HashMap < String , Message > ( ) ;
2011-02-06 17:09:48 -05:00
for ( Message message : localMessages ) {
2008-11-01 17:32:06 -04:00
localUidMap . put ( message . getUid ( ) , message ) ;
}
2011-02-06 17:09:48 -05:00
if ( providedRemoteFolder ! = null ) {
2010-05-15 15:35:07 -04:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " SYNC: using providedRemoteFolder " + folder ) ;
remoteFolder = providedRemoteFolder ;
2011-02-06 17:09:48 -05:00
} else {
2010-05-15 15:35:07 -04:00
Store remoteStore = account . getRemoteStore ( ) ;
2010-07-10 12:41:34 -04:00
2010-05-15 15:35:07 -04:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " SYNC: About to get remote folder " + folder ) ;
remoteFolder = remoteStore . getFolder ( folder ) ;
2008-11-01 17:32:06 -04:00
2011-02-06 17:09:48 -05:00
if ( ! verifyOrCreateRemoteSpecialFolder ( account , folder , remoteFolder , listener ) ) {
2010-07-10 12:41:34 -04:00
return ;
2008-11-01 17:32:06 -04:00
}
2010-07-10 12:41:34 -04:00
2010-05-15 15:46:16 -04:00
/ *
* Synchronization process :
2011-01-23 22:27:26 -05:00
*
2010-05-15 15:46:16 -04:00
Open the folder
Upload any local messages that are marked as PENDING_UPLOAD ( Drafts , Sent , Trash )
Get the message count
Get the list of the newest K9 . DEFAULT_VISIBLE_LIMIT messages
getMessages ( messageCount - K9 . DEFAULT_VISIBLE_LIMIT , messageCount )
See if we have each message locally , if not fetch it ' s flags and envelope
Get and update the unread count for the folder
2011-01-23 22:27:26 -05:00
Update the remote flags of any messages we have locally with an internal date newer than the remote message .
2010-05-15 15:46:16 -04:00
Get the current flags for any messages we have locally but did not just download
Update local flags
2011-01-23 22:27:26 -05:00
For any message we have locally but not remotely , delete the local message to keep cache clean .
2010-05-15 15:46:16 -04:00
Download larger parts of any new messages .
( Optional ) Download small attachments in the background .
* /
2008-11-01 17:32:06 -04:00
2010-05-15 15:46:16 -04:00
/ *
* Open the remote folder . This pre - loads certain metadata like message count .
* /
2010-05-15 15:35:07 -04:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " SYNC: About to open remote folder " + folder ) ;
2010-05-15 15:46:16 -04:00
2010-05-15 15:35:07 -04:00
remoteFolder . open ( OpenMode . READ_WRITE ) ;
2011-02-06 17:09:48 -05:00
if ( Account . EXPUNGE_ON_POLL . equals ( account . getExpungePolicy ( ) ) ) {
2010-05-30 17:20:47 -04:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " SYNC: Expunging folder " + account . getDescription ( ) + " : " + folder ) ;
remoteFolder . expunge ( ) ;
}
2009-12-27 12:22:51 -05:00
2010-05-30 17:20:47 -04:00
}
2010-07-06 06:29:26 -04:00
2008-11-01 17:32:06 -04:00
/ *
* Get the remote message count .
* /
int remoteMessageCount = remoteFolder . getMessageCount ( ) ;
int visibleLimit = localFolder . getVisibleLimit ( ) ;
2011-02-06 17:09:48 -05:00
if ( visibleLimit < 0 ) {
2010-07-06 06:29:26 -04:00
visibleLimit = K9 . DEFAULT_VISIBLE_LIMIT ;
2010-06-07 22:37:18 -04:00
}
2010-08-02 07:55:31 -04:00
Message [ ] remoteMessageArray = EMPTY_MESSAGE_ARRAY ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
final ArrayList < Message > remoteMessages = new ArrayList < Message > ( ) ;
2008-11-01 17:32:06 -04:00
HashMap < String , Message > remoteUidMap = new HashMap < String , Message > ( ) ;
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
2010-01-02 20:50:41 -05:00
Log . v ( K9 . LOG_TAG , " SYNC: Remote message count for folder " + folder + " is " + remoteMessageCount ) ;
2010-05-30 17:20:47 -04:00
final Date earliestDate = account . getEarliestPollDate ( ) ;
2011-01-23 22:27:26 -05:00
2011-02-06 17:09:48 -05:00
if ( remoteMessageCount > 0 ) {
2011-01-23 22:27:26 -05:00
/* Message numbers start at 1. */
2010-11-12 18:41:43 -05:00
int remoteStart ;
2011-02-06 17:09:48 -05:00
if ( visibleLimit > 0 ) {
2010-11-12 18:41:43 -05:00
remoteStart = Math . max ( 0 , remoteMessageCount - visibleLimit ) + 1 ;
2011-02-06 17:09:48 -05:00
} else {
2010-11-12 18:41:43 -05:00
remoteStart = 1 ;
}
2008-11-01 17:32:06 -04:00
int remoteEnd = remoteMessageCount ;
2009-05-10 01:47:26 -04:00
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " SYNC: About to get messages " + remoteStart + " through " + remoteEnd + " for folder " + folder ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2010-07-13 19:59:14 -04:00
final AtomicInteger headerProgress = new AtomicInteger ( 0 ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
2010-07-13 19:59:14 -04:00
l . synchronizeMailboxHeadersStarted ( account , folder ) ;
}
2010-05-30 17:20:47 -04:00
remoteMessageArray = remoteFolder . getMessages ( remoteStart , remoteEnd , earliestDate , null ) ;
2010-07-13 19:59:14 -04:00
int messageCount = remoteMessageArray . length ;
2011-02-06 17:09:48 -05:00
for ( Message thisMess : remoteMessageArray ) {
2010-07-13 19:59:14 -04:00
headerProgress . incrementAndGet ( ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
2010-07-13 19:59:14 -04:00
l . synchronizeMailboxHeadersProgress ( account , folder , headerProgress . get ( ) , messageCount ) ;
}
2010-05-30 17:20:47 -04:00
Message localMessage = localUidMap . get ( thisMess . getUid ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( localMessage = = null | | ! localMessage . olderThan ( earliestDate ) ) {
2010-05-30 17:20:47 -04:00
remoteMessages . add ( thisMess ) ;
remoteUidMap . put ( thisMess . getUid ( ) , thisMess ) ;
}
2009-05-10 01:47:26 -04:00
}
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " SYNC: Got " + remoteUidMap . size ( ) + " messages for folder " + folder ) ;
2010-01-02 20:50:41 -05:00
2009-05-20 00:27:51 -04:00
remoteMessageArray = null ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
2010-07-13 19:59:14 -04:00
l . synchronizeMailboxHeadersFinished ( account , folder , headerProgress . get ( ) , remoteUidMap . size ( ) ) ;
}
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2011-02-06 17:09:48 -05:00
} else if ( remoteMessageCount < 0 ) {
2009-05-10 01:47:26 -04:00
throw new Exception ( " Message count " + remoteMessageCount + " for folder " + folder ) ;
2009-04-21 00:22:02 -04:00
}
2008-11-01 17:32:06 -04:00
/ *
2010-05-30 17:20:47 -04:00
* Remove any messages that are in the local store but no longer on the remote store or are too old
2008-11-01 17:32:06 -04:00
* /
2011-02-06 17:09:48 -05:00
if ( account . syncRemoteDeletions ( ) ) {
2011-02-09 07:27:24 -05:00
ArrayList < Message > destroyMessages = new ArrayList < Message > ( ) ;
2011-02-06 17:09:48 -05:00
for ( Message localMessage : localMessages ) {
if ( remoteUidMap . get ( localMessage . getUid ( ) ) = = null ) {
2011-02-09 07:27:24 -05:00
destroyMessages . add ( localMessage ) ;
}
}
2010-07-06 06:29:26 -04:00
2011-02-09 07:27:24 -05:00
localFolder . destroyMessages ( destroyMessages . toArray ( EMPTY_MESSAGE_ARRAY ) ) ;
for ( Message destroyMessage : destroyMessages ) {
for ( MessagingListener l : getListeners ( listener ) ) {
l . synchronizeMailboxRemovedMessage ( account , folder , destroyMessage ) ;
2009-10-21 20:41:06 -04:00
}
2008-11-01 17:32:06 -04:00
}
}
2009-05-20 00:27:51 -04:00
localMessages = null ;
2009-11-24 19:40:29 -05:00
2008-11-01 17:32:06 -04:00
/ *
* Now we download the actual content of messages .
* /
2009-11-26 00:10:12 -05:00
int newMessages = downloadMessages ( account , remoteFolder , localFolder , remoteMessages , false ) ;
2009-11-24 19:40:29 -05:00
2012-12-07 09:45:36 -05:00
int unreadMessageCount = localFolder . getUnreadMessageCount ( ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2010-01-02 20:50:51 -05:00
l . folderStatusChanged ( account , folder , unreadMessageCount ) ;
}
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2011-01-23 22:27:26 -05:00
/* Notify listeners that we're finally done. */
2008-11-01 17:32:06 -04:00
2009-10-21 20:41:06 -04:00
localFolder . setLastChecked ( System . currentTimeMillis ( ) ) ;
localFolder . setStatus ( null ) ;
2008-11-01 17:32:06 -04:00
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
2011-01-23 22:27:26 -05:00
Log . d ( K9 . LOG_TAG , " Done synchronizing folder " + account . getDescription ( ) + " : " + folder +
" @ " + new Date ( ) + " with " + newMessages + " new messages " ) ;
2009-05-10 01:47:26 -04:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
2009-11-24 19:40:29 -05:00
l . synchronizeMailboxFinished ( account , folder , remoteMessageCount , newMessages ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
}
2009-05-10 01:47:26 -04:00
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
if ( commandException ! = null ) {
2009-05-10 01:47:26 -04:00
String rootMessage = getRootCauseMessage ( commandException ) ;
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Root cause failure in " + account . getDescription ( ) + " : " +
2009-11-24 19:40:29 -05:00
tLocalFolder . getName ( ) + " was ' " + rootMessage + " ' " ) ;
2009-05-10 01:47:26 -04:00
localFolder . setStatus ( rootMessage ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
2009-11-24 19:40:29 -05:00
l . synchronizeMailboxFailed ( account , folder , rootMessage ) ;
2009-05-10 01:47:26 -04:00
}
}
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Done synchronizing folder " + account . getDescription ( ) + " : " + folder ) ;
2009-05-10 01:47:26 -04:00
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " synchronizeMailbox " , e ) ;
2009-05-10 01:47:26 -04:00
// If we don't set the last checked, it can try too often during
// failure conditions
String rootMessage = getRootCauseMessage ( e ) ;
2011-02-06 17:09:48 -05:00
if ( tLocalFolder ! = null ) {
try {
2009-05-10 01:47:26 -04:00
tLocalFolder . setStatus ( rootMessage ) ;
tLocalFolder . setLastChecked ( System . currentTimeMillis ( ) ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Could not set last checked on folder " + account . getDescription ( ) + " : " +
2009-11-24 19:40:29 -05:00
tLocalFolder . getName ( ) , e ) ;
2009-05-10 01:47:26 -04:00
}
}
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
l . synchronizeMailboxFailed ( account , folder , rootMessage ) ;
2008-11-01 17:32:06 -04:00
}
2013-01-17 09:24:22 -05:00
notifyUserIfCertificateProblem ( mApplication , e , account , true ) ;
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , e ) ;
2011-01-23 22:27:26 -05:00
Log . e ( K9 . LOG_TAG , " Failed synchronizing folder " + account . getDescription ( ) + " : " + folder + " @ " + new Date ( ) ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2011-02-06 17:09:48 -05:00
} finally {
if ( providedRemoteFolder = = null ) {
2010-11-28 15:28:58 -05:00
closeFolder ( remoteFolder ) ;
2010-01-16 11:22:20 -05:00
}
2010-11-28 15:28:58 -05:00
closeFolder ( tLocalFolder ) ;
2010-01-16 11:22:20 -05:00
}
2009-05-10 01:47:26 -04:00
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
}
2009-11-24 19:40:29 -05:00
2010-11-28 15:28:58 -05:00
2011-02-06 17:09:48 -05:00
private void closeFolder ( Folder f ) {
if ( f ! = null ) {
2010-11-28 15:28:58 -05:00
f . close ( ) ;
}
}
2010-07-10 12:41:34 -04:00
/ *
* If the folder is a " special " folder we need to see if it exists
* on the remote server . It if does not exist we ' ll try to create it . If we
* can ' t create we ' ll abort . This will happen on every single Pop3 folder as
* designed and on Imap folders during error conditions . This allows us
* to treat Pop3 and Imap the same in this code .
* /
2011-02-06 17:09:48 -05:00
private boolean verifyOrCreateRemoteSpecialFolder ( final Account account , final String folder , final Folder remoteFolder , final MessagingListener listener ) throws MessagingException {
2010-07-10 12:41:34 -04:00
if ( folder . equals ( account . getTrashFolderName ( ) ) | |
folder . equals ( account . getSentFolderName ( ) ) | |
2011-02-06 17:09:48 -05:00
folder . equals ( account . getDraftsFolderName ( ) ) ) {
if ( ! remoteFolder . exists ( ) ) {
if ( ! remoteFolder . create ( FolderType . HOLDS_MESSAGES ) ) {
for ( MessagingListener l : getListeners ( listener ) ) {
2010-07-10 12:41:34 -04:00
l . synchronizeMailboxFinished ( account , folder , 0 , 0 ) ;
}
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Done synchronizing folder " + folder ) ;
return false ;
}
}
}
return true ;
}
2009-11-24 19:40:29 -05:00
2011-05-20 18:33:43 -04:00
/ * *
* Fetches the messages described by inputMessages from the remote store and writes them to
* local storage .
*
* @param account
* The account the remote store belongs to .
* @param remoteFolder
* The remote folder to download messages from .
* @param localFolder
* The { @link LocalFolder } instance corresponding to the remote folder .
* @param inputMessages
* A list of messages objects that store the UIDs of which messages to download .
* @param flagSyncOnly
* Only flags will be fetched from the remote store if this is { @code true } .
*
* @return The number of downloaded messages that are not flagged as { @link Flag # SEEN } .
*
* @throws MessagingException
* /
2009-11-24 19:40:29 -05:00
private int downloadMessages ( final Account account , final Folder remoteFolder ,
2011-05-20 18:33:43 -04:00
final LocalFolder localFolder , List < Message > inputMessages ,
boolean flagSyncOnly ) throws MessagingException {
2010-05-30 17:20:47 -04:00
final Date earliestDate = account . getEarliestPollDate ( ) ;
2011-01-23 22:27:14 -05:00
Date downloadStarted = new Date ( ) ; // now
2011-02-06 17:09:48 -05:00
if ( earliestDate ! = null ) {
if ( K9 . DEBUG ) {
2010-05-30 17:20:47 -04:00
Log . d ( K9 . LOG_TAG , " Only syncing messages after " + earliestDate ) ;
}
}
2009-10-21 20:41:06 -04:00
final String folder = remoteFolder . getName ( ) ;
2009-11-24 19:40:29 -05:00
2010-08-08 15:14:52 -04:00
int unreadBeforeStart = 0 ;
2011-02-06 17:09:48 -05:00
try {
2010-08-08 15:14:52 -04:00
AccountStats stats = account . getStats ( mApplication ) ;
unreadBeforeStart = stats . unreadMessageCount ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException e ) {
2010-08-08 15:14:52 -04:00
Log . e ( K9 . LOG_TAG , " Unable to getUnreadMessageCount for account: " + account , e ) ;
}
2009-10-21 20:41:06 -04:00
ArrayList < Message > syncFlagMessages = new ArrayList < Message > ( ) ;
2009-11-26 00:10:12 -05:00
List < Message > unsyncedMessages = new ArrayList < Message > ( ) ;
2009-10-21 20:41:06 -04:00
final AtomicInteger newMessages = new AtomicInteger ( 0 ) ;
List < Message > messages = new ArrayList < Message > ( inputMessages ) ;
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
for ( Message message : messages ) {
evaluateMessageForDownload ( message , folder , localFolder , remoteFolder , account , unsyncedMessages , syncFlagMessages , flagSyncOnly ) ;
2009-10-21 20:41:06 -04:00
}
2009-12-20 00:41:43 -05:00
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
final AtomicInteger progress = new AtomicInteger ( 0 ) ;
final int todo = unsyncedMessages . size ( ) + syncFlagMessages . size ( ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
l . synchronizeMailboxProgress ( account , folder , progress . get ( ) , todo ) ;
}
2009-10-21 20:41:06 -04:00
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " SYNC: Have " + unsyncedMessages . size ( ) + " unsynced messages " ) ;
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
messages . clear ( ) ;
final ArrayList < Message > largeMessages = new ArrayList < Message > ( ) ;
final ArrayList < Message > smallMessages = new ArrayList < Message > ( ) ;
2011-10-06 12:28:14 -04:00
if ( ! unsyncedMessages . isEmpty ( ) ) {
2009-10-21 20:41:06 -04:00
/ *
* Reverse the order of the messages . Depending on the server this may get us
* fetch results for newest to oldest . If not , no harm done .
* /
2012-03-05 15:04:34 -05:00
Collections . sort ( unsyncedMessages , new UidReverseComparator ( ) ) ;
2009-11-26 00:10:12 -05:00
int visibleLimit = localFolder . getVisibleLimit ( ) ;
int listSize = unsyncedMessages . size ( ) ;
2011-02-06 17:09:48 -05:00
if ( ( visibleLimit > 0 ) & & ( listSize > visibleLimit ) ) {
2012-03-05 15:04:34 -05:00
unsyncedMessages = unsyncedMessages . subList ( 0 , visibleLimit ) ;
2009-11-26 00:10:12 -05:00
}
2009-10-21 20:41:06 -04:00
FetchProfile fp = new FetchProfile ( ) ;
2011-02-06 17:09:48 -05:00
if ( remoteFolder . supportsFetchingFlags ( ) ) {
2009-10-21 20:41:06 -04:00
fp . add ( FetchProfile . Item . FLAGS ) ;
}
fp . add ( FetchProfile . Item . ENVELOPE ) ;
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
2010-07-10 12:40:55 -04:00
Log . d ( K9 . LOG_TAG , " SYNC: About to fetch " + unsyncedMessages . size ( ) + " unsynced messages for folder " + folder ) ;
2009-10-21 20:41:06 -04:00
2011-02-06 17:09:48 -05:00
fetchUnsyncedMessages ( account , remoteFolder , localFolder , unsyncedMessages , smallMessages , largeMessages , progress , todo , fp ) ;
2009-10-21 20:41:06 -04:00
// If a message didn't exist, messageFinished won't be called, but we shouldn't try again
// If we got here, nothing failed
2011-02-06 17:09:48 -05:00
for ( Message message : unsyncedMessages ) {
2009-10-21 20:41:06 -04:00
String newPushState = remoteFolder . getNewPushState ( localFolder . getPushState ( ) , message ) ;
2011-02-06 17:09:48 -05:00
if ( newPushState ! = null ) {
2009-10-21 20:41:06 -04:00
localFolder . setPushState ( newPushState ) ;
}
}
2011-02-06 17:09:48 -05:00
if ( K9 . DEBUG ) {
2010-01-02 20:50:41 -05:00
Log . d ( K9 . LOG_TAG , " SYNC: Synced unsynced messages for folder " + folder ) ;
}
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
}
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " SYNC: Have "
+ largeMessages . size ( ) + " large messages and "
+ smallMessages . size ( ) + " small messages out of "
+ unsyncedMessages . size ( ) + " unsynced messages " ) ;
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
unsyncedMessages . clear ( ) ;
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
/ *
* Grab the content of the small messages first . This is going to
* be very fast and at very worst will be a single up of a few bytes and a single
* download of 625k .
* /
FetchProfile fp = new FetchProfile ( ) ;
fp . add ( FetchProfile . Item . BODY ) ;
// fp.add(FetchProfile.Item.FLAGS);
// fp.add(FetchProfile.Item.ENVELOPE);
2010-08-08 14:50:31 -04:00
downloadSmallMessages ( account , remoteFolder , localFolder , smallMessages , progress , unreadBeforeStart , newMessages , todo , fp ) ;
2010-07-10 12:42:39 -04:00
smallMessages . clear ( ) ;
/ *
* Now do the large messages that require more round trips .
* /
fp . clear ( ) ;
fp . add ( FetchProfile . Item . STRUCTURE ) ;
2010-08-08 14:50:31 -04:00
downloadLargeMessages ( account , remoteFolder , localFolder , largeMessages , progress , unreadBeforeStart , newMessages , todo , fp ) ;
2010-07-10 12:42:39 -04:00
largeMessages . clear ( ) ;
/ *
* Refresh the flags for any messages in the local store that we didn ' t just
* download .
* /
2011-02-06 17:09:48 -05:00
refreshLocalMessageFlags ( account , remoteFolder , localFolder , syncFlagMessages , progress , todo ) ;
2010-07-10 12:42:39 -04:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " SYNC: Synced remote messages for folder " + folder + " , " + newMessages . get ( ) + " new messages " ) ;
2011-02-06 17:09:48 -05:00
localFolder . purgeToVisibleLimit ( new MessageRemovalListener ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void messageRemoved ( Message message ) {
for ( MessagingListener l : getListeners ( ) ) {
2010-07-10 12:42:39 -04:00
l . synchronizeMailboxRemovedMessage ( account , folder , message ) ;
}
}
} ) ;
2011-01-23 22:27:14 -05:00
// If the oldest message seen on this sync is newer than
// the oldest message seen on the previous sync, then
// we want to move our high-water mark forward
// this is all here just for pop which only syncs inbox
// this would be a little wrong for IMAP (we'd want a folder-level pref, not an account level pref.)
// fortunately, we just don't care.
Long oldestMessageTime = localFolder . getOldestMessageDate ( ) ;
2011-02-06 17:09:48 -05:00
if ( oldestMessageTime ! = null ) {
2011-01-23 22:27:14 -05:00
Date oldestExtantMessage = new Date ( oldestMessageTime ) ;
2011-02-06 17:09:48 -05:00
if ( oldestExtantMessage . before ( downloadStarted ) & &
oldestExtantMessage . after ( new Date ( account . getLatestOldMessageSeenTime ( ) ) ) ) {
2011-01-23 22:27:14 -05:00
account . setLatestOldMessageSeenTime ( oldestExtantMessage . getTime ( ) ) ;
account . save ( Preferences . getPreferences ( mApplication . getApplicationContext ( ) ) ) ;
}
}
2010-07-10 12:42:39 -04:00
return newMessages . get ( ) ;
}
2010-11-28 15:28:50 -05:00
private void evaluateMessageForDownload ( final Message message , final String folder ,
final LocalFolder localFolder ,
final Folder remoteFolder ,
final Account account ,
2011-01-18 18:54:49 -05:00
final List < Message > unsyncedMessages ,
final ArrayList < Message > syncFlagMessages ,
2011-02-06 17:09:48 -05:00
boolean flagSyncOnly ) throws MessagingException {
if ( message . isSet ( Flag . DELETED ) ) {
2010-11-28 15:28:50 -05:00
syncFlagMessages . add ( message ) ;
2010-11-28 15:28:53 -05:00
return ;
}
2010-11-28 15:28:50 -05:00
2010-11-28 15:28:53 -05:00
Message localMessage = localFolder . getMessage ( message . getUid ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( localMessage = = null ) {
if ( ! flagSyncOnly ) {
if ( ! message . isSet ( Flag . X_DOWNLOADED_FULL ) & & ! message . isSet ( Flag . X_DOWNLOADED_PARTIAL ) ) {
2010-11-28 15:28:53 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " Message with uid " + message . getUid ( ) + " has not yet been downloaded " ) ;
2010-11-28 15:28:50 -05:00
2010-11-28 15:28:53 -05:00
unsyncedMessages . add ( message ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-11-28 15:28:53 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " Message with uid " + message . getUid ( ) + " is partially or fully downloaded " ) ;
2010-11-28 15:28:50 -05:00
2010-11-28 15:28:53 -05:00
// Store the updated message locally
localFolder . appendMessages ( new Message [ ] { message } ) ;
2010-11-28 15:28:50 -05:00
2010-11-28 15:28:53 -05:00
localMessage = localFolder . getMessage ( message . getUid ( ) ) ;
2010-11-28 15:28:50 -05:00
2010-11-28 15:28:53 -05:00
localMessage . setFlag ( Flag . X_DOWNLOADED_FULL , message . isSet ( Flag . X_DOWNLOADED_FULL ) ) ;
localMessage . setFlag ( Flag . X_DOWNLOADED_PARTIAL , message . isSet ( Flag . X_DOWNLOADED_PARTIAL ) ) ;
2010-11-28 15:28:50 -05:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2010-11-28 15:28:53 -05:00
l . synchronizeMailboxAddOrUpdateMessage ( account , folder , localMessage ) ;
2011-02-06 17:09:48 -05:00
if ( ! localMessage . isSet ( Flag . SEEN ) ) {
2010-11-28 15:28:53 -05:00
l . synchronizeMailboxNewMessage ( account , folder , localMessage ) ;
2010-11-28 15:28:50 -05:00
}
}
}
}
2011-02-06 17:09:48 -05:00
} else if ( ! localMessage . isSet ( Flag . DELETED ) ) {
2010-11-28 15:28:53 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " Message with uid " + message . getUid ( ) + " is present in the local store " ) ;
2011-02-06 17:09:48 -05:00
if ( ! localMessage . isSet ( Flag . X_DOWNLOADED_FULL ) & & ! localMessage . isSet ( Flag . X_DOWNLOADED_PARTIAL ) ) {
2010-11-28 15:28:50 -05:00
if ( K9 . DEBUG )
2010-11-28 15:28:53 -05:00
Log . v ( K9 . LOG_TAG , " Message with uid " + message . getUid ( )
+ " is not downloaded, even partially; trying again " ) ;
2010-11-28 15:28:50 -05:00
2010-11-28 15:28:53 -05:00
unsyncedMessages . add ( message ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-11-28 15:28:53 -05:00
String newPushState = remoteFolder . getNewPushState ( localFolder . getPushState ( ) , message ) ;
2011-02-06 17:09:48 -05:00
if ( newPushState ! = null ) {
2010-11-28 15:28:53 -05:00
localFolder . setPushState ( newPushState ) ;
2010-11-28 15:28:50 -05:00
}
2010-11-28 15:28:53 -05:00
syncFlagMessages . add ( message ) ;
2010-11-28 15:28:50 -05:00
}
}
}
2010-07-10 12:42:39 -04:00
2010-07-10 13:10:24 -04:00
private void fetchUnsyncedMessages ( final Account account , final Folder remoteFolder ,
final LocalFolder localFolder ,
List < Message > unsyncedMessages ,
final ArrayList < Message > smallMessages ,
final ArrayList < Message > largeMessages ,
final AtomicInteger progress ,
final int todo ,
2011-02-06 17:09:48 -05:00
FetchProfile fp ) throws MessagingException {
2010-07-10 13:10:24 -04:00
final String folder = remoteFolder . getName ( ) ;
final Date earliestDate = account . getEarliestPollDate ( ) ;
2010-12-19 06:51:54 -05:00
/ *
* Messages to be batch written
* /
final List < Message > chunk = new ArrayList < Message > ( UNSYNC_CHUNK_SIZE ) ;
2010-08-02 07:55:31 -04:00
remoteFolder . fetch ( unsyncedMessages . toArray ( EMPTY_MESSAGE_ARRAY ) , fp ,
2011-02-06 17:09:48 -05:00
new MessageRetrievalListener ( ) {
2010-12-19 06:51:54 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void messageFinished ( Message message , int number , int ofTotal ) {
try {
2010-07-10 13:10:24 -04:00
String newPushState = remoteFolder . getNewPushState ( localFolder . getPushState ( ) , message ) ;
2011-02-06 17:09:48 -05:00
if ( newPushState ! = null ) {
2010-07-10 13:10:24 -04:00
localFolder . setPushState ( newPushState ) ;
}
2011-02-06 17:09:48 -05:00
if ( message . isSet ( Flag . DELETED ) | | message . olderThan ( earliestDate ) ) {
2010-07-10 13:10:24 -04:00
2011-02-06 17:09:48 -05:00
if ( K9 . DEBUG ) {
if ( message . isSet ( Flag . DELETED ) ) {
2010-07-10 13:10:24 -04:00
Log . v ( K9 . LOG_TAG , " Newly downloaded message " + account + " : " + folder + " : " + message . getUid ( )
+ " was marked deleted on server, skipping " ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-07-10 13:10:24 -04:00
Log . d ( K9 . LOG_TAG , " Newly downloaded message " + message . getUid ( ) + " is older than "
+ earliestDate + " , skipping " ) ;
}
}
progress . incrementAndGet ( ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2010-07-10 13:10:24 -04:00
l . synchronizeMailboxProgress ( account , folder , progress . get ( ) , todo ) ;
}
return ;
}
2011-07-02 15:29:49 -04:00
if ( account . getMaximumAutoDownloadMessageSize ( ) > 0 & &
message . getSize ( ) > account . getMaximumAutoDownloadMessageSize ( ) ) {
2010-07-10 13:10:24 -04:00
largeMessages . add ( message ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-07-10 13:10:24 -04:00
smallMessages . add ( message ) ;
}
// And include it in the view
2011-02-06 17:09:48 -05:00
if ( message . getSubject ( ) ! = null & & message . getFrom ( ) ! = null ) {
2010-07-10 13:10:24 -04:00
/ *
* We check to make sure that we got something worth
* showing ( subject and from ) because some protocols
* ( POP ) may not be able to give us headers for
* ENVELOPE , only size .
* /
2010-12-19 06:51:54 -05:00
2013-02-18 22:45:14 -05:00
// keep message for delayed storing
chunk . add ( message ) ;
if ( chunk . size ( ) > = UNSYNC_CHUNK_SIZE ) {
writeUnsyncedMessages ( chunk , localFolder , account , folder ) ;
chunk . clear ( ) ;
2010-07-10 13:10:24 -04:00
}
}
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2010-07-10 13:10:24 -04:00
Log . e ( K9 . LOG_TAG , " Error while storing downloaded message. " , e ) ;
addErrorMessage ( account , null , e ) ;
}
}
2010-12-19 06:51:54 -05:00
@Override
2010-11-28 15:28:58 -05:00
public void messageStarted ( String uid , int number , int ofTotal ) { }
2010-12-19 06:51:54 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void messagesFinished ( int total ) {
2010-12-19 06:51:54 -05:00
// FIXME this method is almost never invoked by various Stores! Don't rely on it unless fixed!!
}
2010-07-10 13:10:24 -04:00
} ) ;
2011-10-06 12:28:14 -04:00
if ( ! chunk . isEmpty ( ) ) {
2010-12-19 06:51:54 -05:00
writeUnsyncedMessages ( chunk , localFolder , account , folder ) ;
chunk . clear ( ) ;
}
}
/ * *
* Actual storing of messages
2010-12-24 13:55:05 -05:00
*
2010-12-19 06:51:54 -05:00
* < br >
* FIXME : < strong > This method should really be moved in the above MessageRetrievalListener once { @link MessageRetrievalListener # messagesFinished ( int ) } is properly invoked by various stores < / strong >
2010-12-24 13:55:05 -05:00
*
2010-12-19 06:51:54 -05:00
* @param messages Never < code > null < / code > .
* @param localFolder
* @param account
* @param folder
* /
2011-02-06 17:09:48 -05:00
private void writeUnsyncedMessages ( final List < Message > messages , final LocalFolder localFolder , final Account account , final String folder ) {
if ( K9 . DEBUG ) {
2010-12-19 06:51:54 -05:00
Log . v ( K9 . LOG_TAG , " Batch writing " + Integer . toString ( messages . size ( ) ) + " messages " ) ;
}
2011-02-06 17:09:48 -05:00
try {
2010-12-19 06:51:54 -05:00
// Store the new message locally
localFolder . appendMessages ( messages . toArray ( new Message [ messages . size ( ) ] ) ) ;
2010-12-24 13:55:05 -05:00
2011-02-06 17:09:48 -05:00
for ( final Message message : messages ) {
2010-12-19 06:51:54 -05:00
final Message localMessage = localFolder . getMessage ( message . getUid ( ) ) ;
syncFlags ( localMessage , message ) ;
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " About to notify listeners that we got a new unsynced message "
+ account + " : " + folder + " : " + message . getUid ( ) ) ;
2011-02-06 17:09:48 -05:00
for ( final MessagingListener l : getListeners ( ) ) {
2010-12-19 06:51:54 -05:00
l . synchronizeMailboxAddOrUpdateMessage ( account , folder , localMessage ) ;
}
}
2011-02-06 17:09:48 -05:00
} catch ( final Exception e ) {
2010-12-19 06:51:54 -05:00
Log . e ( K9 . LOG_TAG , " Error while storing downloaded message. " , e ) ;
addErrorMessage ( account , null , e ) ;
}
2010-07-10 13:10:24 -04:00
}
2010-07-13 17:17:04 -04:00
2011-02-06 17:09:48 -05:00
private boolean shouldImportMessage ( final Account account , final String folder , final Message message , final AtomicInteger progress , final Date earliestDate ) {
2010-07-13 17:17:04 -04:00
2011-07-12 21:47:37 -04:00
if ( account . isSearchByDateCapable ( ) & & message . olderThan ( earliestDate ) ) {
2011-02-06 17:09:48 -05:00
if ( K9 . DEBUG ) {
2010-07-13 17:17:04 -04:00
Log . d ( K9 . LOG_TAG , " Message " + message . getUid ( ) + " is older than "
+ earliestDate + " , hence not saving " ) ;
}
return false ;
}
return true ;
}
2010-07-10 12:42:39 -04:00
private void downloadSmallMessages ( final Account account , final Folder remoteFolder ,
final LocalFolder localFolder ,
ArrayList < Message > smallMessages ,
final AtomicInteger progress ,
2010-08-08 14:50:31 -04:00
final int unreadBeforeStart ,
2010-07-10 12:42:39 -04:00
final AtomicInteger newMessages ,
final int todo ,
2011-02-06 17:09:48 -05:00
FetchProfile fp ) throws MessagingException {
2010-07-10 12:42:39 -04:00
final String folder = remoteFolder . getName ( ) ;
final Date earliestDate = account . getEarliestPollDate ( ) ;
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " SYNC: Fetching small messages for folder " + folder ) ;
2009-10-21 20:41:06 -04:00
remoteFolder . fetch ( smallMessages . toArray ( new Message [ smallMessages . size ( ) ] ) ,
2011-02-06 17:09:48 -05:00
fp , new MessageRetrievalListener ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-05-20 18:33:43 -04:00
public void messageFinished ( final Message message , int number , int ofTotal ) {
2011-02-06 17:09:48 -05:00
try {
2010-07-08 11:49:26 -04:00
2011-02-06 17:09:48 -05:00
if ( ! shouldImportMessage ( account , folder , message , progress , earliestDate ) ) {
2010-05-30 17:20:47 -04:00
progress . incrementAndGet ( ) ;
2010-07-06 06:29:26 -04:00
2010-05-30 17:20:47 -04:00
return ;
}
2009-10-21 20:41:06 -04:00
// Store the updated message locally
2011-02-06 17:09:48 -05:00
final Message localMessage = localFolder . storeSmallMessage ( message , new Runnable ( ) {
2010-12-18 05:12:52 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2010-12-18 05:12:52 -05:00
progress . incrementAndGet ( ) ;
}
} ) ;
2011-05-20 18:33:43 -04:00
// Increment the number of "new messages" if the newly downloaded message is
// not marked as read.
if ( ! localMessage . isSet ( Flag . SEEN ) ) {
newMessages . incrementAndGet ( ) ;
}
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " About to notify listeners that we got a new small message "
2009-11-24 19:40:29 -05:00
+ account + " : " + folder + " : " + message . getUid ( ) ) ;
2010-01-02 20:50:41 -05:00
2009-10-21 20:41:06 -04:00
// Update the listener with what we've found
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2009-11-24 19:40:29 -05:00
l . synchronizeMailboxAddOrUpdateMessage ( account , folder , localMessage ) ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
l . synchronizeMailboxProgress ( account , folder , progress . get ( ) , todo ) ;
2011-02-06 17:09:48 -05:00
if ( ! localMessage . isSet ( Flag . SEEN ) ) {
2009-11-08 22:52:59 -05:00
l . synchronizeMailboxNewMessage ( account , folder , localMessage ) ;
}
2009-10-21 20:41:06 -04:00
}
2010-07-14 23:42:09 -04:00
// Send a notification of this message
2010-07-14 23:42:13 -04:00
2011-02-06 17:09:48 -05:00
if ( shouldNotifyForMessage ( account , localFolder , message ) ) {
2013-01-08 02:19:07 -05:00
// Notify with the localMessage so that we don't have to recalculate the content preview.
notifyAccount ( mApplication , account , localMessage , unreadBeforeStart ) ;
2010-08-08 14:50:31 -04:00
}
2009-10-21 20:41:06 -04:00
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , me ) ;
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " SYNC: fetch small messages " , me ) ;
2009-10-21 20:41:06 -04:00
}
}
2010-12-20 16:34:01 -05:00
@Override
2010-11-28 15:28:58 -05:00
public void messageStarted ( String uid , int number , int ofTotal ) { }
2009-10-21 20:41:06 -04:00
2010-12-20 16:34:01 -05:00
@Override
2009-10-21 20:41:06 -04:00
public void messagesFinished ( int total ) { }
} ) ;
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " SYNC: Done fetching small messages for folder " + folder ) ;
2010-07-10 12:42:39 -04:00
}
2010-01-02 20:50:41 -05:00
2010-07-10 12:42:12 -04:00
private void downloadLargeMessages ( final Account account , final Folder remoteFolder ,
final LocalFolder localFolder ,
ArrayList < Message > largeMessages ,
final AtomicInteger progress ,
2010-08-08 14:50:31 -04:00
final int unreadBeforeStart ,
2010-07-10 12:42:12 -04:00
final AtomicInteger newMessages ,
final int todo ,
2011-02-06 17:09:48 -05:00
FetchProfile fp ) throws MessagingException {
2010-07-10 12:42:12 -04:00
final String folder = remoteFolder . getName ( ) ;
final Date earliestDate = account . getEarliestPollDate ( ) ;
2010-07-14 23:42:13 -04:00
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " SYNC: Fetching large messages for folder " + folder ) ;
2009-10-21 20:41:06 -04:00
remoteFolder . fetch ( largeMessages . toArray ( new Message [ largeMessages . size ( ) ] ) , fp , null ) ;
2011-02-06 17:09:48 -05:00
for ( Message message : largeMessages ) {
2010-07-13 17:17:04 -04:00
2011-02-06 17:09:48 -05:00
if ( ! shouldImportMessage ( account , folder , message , progress , earliestDate ) ) {
2010-05-30 17:20:47 -04:00
progress . incrementAndGet ( ) ;
continue ;
}
2010-07-13 17:17:04 -04:00
2011-02-06 17:09:48 -05:00
if ( message . getBody ( ) = = null ) {
2009-10-21 20:41:06 -04:00
/ *
* The provider was unable to get the structure of the message , so
* we ' ll download a reasonable portion of the messge and mark it as
* incomplete so the entire thing can be downloaded later if the user
* wishes to download it .
* /
fp . clear ( ) ;
fp . add ( FetchProfile . Item . BODY_SANE ) ;
/ *
* TODO a good optimization here would be to make sure that all Stores set
* the proper size after this fetch and compare the before and after size . If
* they equal we can mark this SYNCHRONIZED instead of PARTIALLY_SYNCHRONIZED
* /
remoteFolder . fetch ( new Message [ ] { message } , fp , null ) ;
2010-07-06 06:29:26 -04:00
2009-10-21 20:41:06 -04:00
// Store the updated message locally
localFolder . appendMessages ( new Message [ ] { message } ) ;
Message localMessage = localFolder . getMessage ( message . getUid ( ) ) ;
2010-02-07 01:05:11 -05:00
// Certain (POP3) servers give you the whole message even when you ask for only the first x Kb
2011-02-06 17:09:48 -05:00
if ( ! message . isSet ( Flag . X_DOWNLOADED_FULL ) ) {
2010-02-07 01:05:11 -05:00
/ *
* Mark the message as fully downloaded if the message size is smaller than
2010-07-11 07:59:14 -04:00
* the account ' s autodownload size limit , otherwise mark as only a partial
2010-02-07 01:05:11 -05:00
* download . This will prevent the system from downloading the same message
* twice .
2011-07-02 15:29:49 -04:00
*
* If there is no limit on autodownload size , that ' s the same as the message
* being smaller than the max size
2010-02-07 01:05:11 -05:00
* /
2011-07-02 15:29:49 -04:00
if ( account . getMaximumAutoDownloadMessageSize ( ) = = 0 | | message . getSize ( ) < account . getMaximumAutoDownloadMessageSize ( ) ) {
2010-02-07 01:05:11 -05:00
localMessage . setFlag ( Flag . X_DOWNLOADED_FULL , true ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-02-07 01:05:11 -05:00
// Set a flag indicating that the message has been partially downloaded and
// is ready for view.
localMessage . setFlag ( Flag . X_DOWNLOADED_PARTIAL , true ) ;
}
2009-10-21 20:41:06 -04:00
}
2011-02-06 17:09:48 -05:00
} else {
2009-10-21 20:41:06 -04:00
/ *
* We have a structure to deal with , from which
* we can pull down the parts we want to actually store .
* Build a list of parts we are interested in . Text parts will be downloaded
* right now , attachments will be left for later .
* /
2012-02-13 17:11:59 -05:00
Set < Part > viewables = MimeUtility . collectTextParts ( message ) ;
2009-10-21 20:41:06 -04:00
/ *
* Now download the parts we ' re interested in storing .
* /
2011-02-06 17:09:48 -05:00
for ( Part part : viewables ) {
2010-05-19 09:31:48 -04:00
remoteFolder . fetchPart ( message , part , null ) ;
2009-10-21 20:41:06 -04:00
}
// Store the updated message locally
localFolder . appendMessages ( new Message [ ] { message } ) ;
Message localMessage = localFolder . getMessage ( message . getUid ( ) ) ;
// Set a flag indicating this message has been fully downloaded and can be
// viewed.
localMessage . setFlag ( Flag . X_DOWNLOADED_PARTIAL , true ) ;
}
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " About to notify listeners that we got a new large message "
2009-11-24 19:40:29 -05:00
+ account + " : " + folder + " : " + message . getUid ( ) ) ;
2010-01-02 20:50:41 -05:00
2009-10-21 20:41:06 -04:00
// Update the listener with what we've found
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
progress . incrementAndGet ( ) ;
2013-01-08 02:19:07 -05:00
// TODO do we need to re-fetch this here?
2010-05-22 18:00:06 -04:00
Message localMessage = localFolder . getMessage ( message . getUid ( ) ) ;
2011-05-20 18:33:43 -04:00
// Increment the number of "new messages" if the newly downloaded message is
// not marked as read.
if ( ! localMessage . isSet ( Flag . SEEN ) ) {
newMessages . incrementAndGet ( ) ;
}
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2009-11-24 19:40:29 -05:00
l . synchronizeMailboxAddOrUpdateMessage ( account , folder , localMessage ) ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
l . synchronizeMailboxProgress ( account , folder , progress . get ( ) , todo ) ;
2011-02-06 17:09:48 -05:00
if ( ! localMessage . isSet ( Flag . SEEN ) ) {
2009-11-08 22:52:59 -05:00
l . synchronizeMailboxNewMessage ( account , folder , localMessage ) ;
}
2009-10-21 20:41:06 -04:00
}
2010-07-14 23:42:09 -04:00
// Send a notification of this message
2011-02-06 17:09:48 -05:00
if ( shouldNotifyForMessage ( account , localFolder , message ) ) {
2013-01-08 02:19:07 -05:00
// Notify with the localMessage so that we don't have to recalculate the content preview.
notifyAccount ( mApplication , account , localMessage , unreadBeforeStart ) ;
2010-05-22 18:00:06 -04:00
}
2011-09-27 00:03:13 -04:00
} //for large messages
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " SYNC: Done fetching large messages for folder " + folder ) ;
2009-10-21 20:41:06 -04:00
2009-11-24 19:40:29 -05:00
}
2010-07-10 12:42:54 -04:00
private void refreshLocalMessageFlags ( final Account account , final Folder remoteFolder ,
final LocalFolder localFolder ,
ArrayList < Message > syncFlagMessages ,
final AtomicInteger progress ,
final int todo
2011-02-06 17:09:48 -05:00
) throws MessagingException {
2010-07-10 12:42:54 -04:00
final String folder = remoteFolder . getName ( ) ;
2011-02-06 17:09:48 -05:00
if ( remoteFolder . supportsFetchingFlags ( ) ) {
2010-07-10 12:42:54 -04:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " SYNC: About to sync flags for "
+ syncFlagMessages . size ( ) + " remote messages for folder " + folder ) ;
FetchProfile fp = new FetchProfile ( ) ;
fp . add ( FetchProfile . Item . FLAGS ) ;
List < Message > undeletedMessages = new LinkedList < Message > ( ) ;
2011-02-06 17:09:48 -05:00
for ( Message message : syncFlagMessages ) {
if ( ! message . isSet ( Flag . DELETED ) ) {
2010-07-10 12:42:54 -04:00
undeletedMessages . add ( message ) ;
}
}
2010-08-02 07:55:31 -04:00
remoteFolder . fetch ( undeletedMessages . toArray ( EMPTY_MESSAGE_ARRAY ) , fp , null ) ;
2011-02-06 17:09:48 -05:00
for ( Message remoteMessage : syncFlagMessages ) {
2010-07-10 12:42:54 -04:00
Message localMessage = localFolder . getMessage ( remoteMessage . getUid ( ) ) ;
boolean messageChanged = syncFlags ( localMessage , remoteMessage ) ;
2011-02-06 17:09:48 -05:00
if ( messageChanged ) {
2013-01-03 04:07:21 -05:00
boolean shouldBeNotifiedOf = false ;
2013-02-18 22:45:14 -05:00
if ( localMessage . isSet ( Flag . DELETED ) | | isMessageSuppressed ( account , localMessage ) ) {
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2010-07-10 12:42:54 -04:00
l . synchronizeMailboxRemovedMessage ( account , folder , localMessage ) ;
}
2011-02-06 17:09:48 -05:00
} else {
for ( MessagingListener l : getListeners ( ) ) {
2010-07-10 12:42:54 -04:00
l . synchronizeMailboxAddOrUpdateMessage ( account , folder , localMessage ) ;
}
2013-01-03 04:07:21 -05:00
if ( shouldNotifyForMessage ( account , localFolder , localMessage ) ) {
shouldBeNotifiedOf = true ;
}
2010-07-10 12:42:54 -04:00
}
2013-01-08 04:06:01 -05:00
// we're only interested in messages that need removing
if ( ! shouldBeNotifiedOf ) {
2013-01-08 06:52:56 -05:00
NotificationData data = getNotificationData ( account , null ) ;
2013-01-08 04:06:01 -05:00
if ( data ! = null ) {
synchronized ( data ) {
MessageReference ref = localMessage . makeMessageReference ( ) ;
if ( data . removeMatchingMessage ( mApplication , ref ) ) {
notifyAccountWithDataLocked ( mApplication , account , null , data ) ;
2013-01-03 04:07:21 -05:00
}
}
}
}
2010-07-10 12:42:54 -04:00
}
progress . incrementAndGet ( ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2010-07-10 12:42:54 -04:00
l . synchronizeMailboxProgress ( account , folder , progress . get ( ) , todo ) ;
}
}
}
}
2011-02-06 17:09:48 -05:00
private boolean syncFlags ( Message localMessage , Message remoteMessage ) throws MessagingException {
2009-10-21 20:41:06 -04:00
boolean messageChanged = false ;
2011-02-06 17:09:48 -05:00
if ( localMessage = = null | | localMessage . isSet ( Flag . DELETED ) ) {
2009-10-21 20:41:06 -04:00
return false ;
}
2011-02-06 17:09:48 -05:00
if ( remoteMessage . isSet ( Flag . DELETED ) ) {
if ( localMessage . getFolder ( ) . getAccount ( ) . syncRemoteDeletions ( ) ) {
2010-07-03 09:10:38 -04:00
localMessage . setFlag ( Flag . DELETED , true ) ;
messageChanged = true ;
}
2011-02-06 17:09:48 -05:00
} else {
2012-08-30 11:47:58 -04:00
for ( Flag flag : MessagingController . SYNC_FLAGS ) {
2011-02-06 17:09:48 -05:00
if ( remoteMessage . isSet ( flag ) ! = localMessage . isSet ( flag ) ) {
2010-07-03 09:10:38 -04:00
localMessage . setFlag ( flag , remoteMessage . isSet ( flag ) ) ;
messageChanged = true ;
}
2009-10-21 20:41:06 -04:00
}
}
return messageChanged ;
}
2011-02-06 17:09:48 -05:00
private String getRootCauseMessage ( Throwable t ) {
2009-11-24 19:40:29 -05:00
Throwable rootCause = t ;
Throwable nextCause = rootCause ;
2011-02-06 17:09:48 -05:00
do {
2009-11-24 19:40:29 -05:00
nextCause = rootCause . getCause ( ) ;
2011-02-06 17:09:48 -05:00
if ( nextCause ! = null ) {
2009-11-24 19:40:29 -05:00
rootCause = nextCause ;
}
2011-02-06 17:09:48 -05:00
} while ( nextCause ! = null ) ;
2011-03-09 22:43:36 -05:00
if ( rootCause instanceof MessagingException ) {
return rootCause . getMessage ( ) ;
} else {
2013-01-03 00:31:58 -05:00
// Remove the namespace on the exception so we have a fighting chance of seeing more of the error in the
// notification.
2013-01-06 15:40:03 -05:00
return ( rootCause . getLocalizedMessage ( ) ! = null )
? ( rootCause . getClass ( ) . getSimpleName ( ) + " : " + rootCause . getLocalizedMessage ( ) )
: rootCause . getClass ( ) . getSimpleName ( ) ;
2011-03-09 22:43:36 -05:00
}
2009-11-24 19:40:29 -05:00
}
2011-02-06 17:09:48 -05:00
private void queuePendingCommand ( Account account , PendingCommand command ) {
try {
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
2008-11-01 17:32:06 -04:00
localStore . addPendingCommand ( command ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , e ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2008-11-01 17:32:06 -04:00
throw new RuntimeException ( " Unable to enqueue pending command " , e ) ;
}
}
2011-02-06 17:09:48 -05:00
private void processPendingCommands ( final Account account ) {
putBackground ( " processPendingCommands " , null , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
try {
2008-11-01 17:32:06 -04:00
processPendingCommandsSynchronous ( account ) ;
2011-02-06 17:09:48 -05:00
} catch ( UnavailableStorageException e ) {
2010-11-13 16:40:56 -05:00
Log . i ( K9 . LOG_TAG , " Failed to process pending command because storage is not available - trying again later. " ) ;
throw new UnavailableAccountException ( e ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " processPendingCommands " , me ) ;
2009-11-24 19:40:29 -05:00
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , me ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2008-11-01 17:32:06 -04:00
/ *
* Ignore any exceptions from the commands . Commands will be processed
* on the next round .
* /
}
}
} ) ;
}
2009-12-20 00:41:43 -05:00
2011-02-06 17:09:48 -05:00
private void processPendingCommandsSynchronous ( Account account ) throws MessagingException {
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
2008-11-01 17:32:06 -04:00
ArrayList < PendingCommand > commands = localStore . getPendingCommands ( ) ;
2009-12-20 00:41:43 -05:00
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
int progress = 0 ;
int todo = commands . size ( ) ;
2011-02-06 17:09:48 -05:00
if ( todo = = 0 ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
return ;
}
2009-12-20 00:41:43 -05:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
l . pendingCommandsProcessing ( account ) ;
l . synchronizeMailboxProgress ( account , null , progress , todo ) ;
}
2009-12-20 00:41:43 -05:00
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
PendingCommand processingCommand = null ;
2011-02-06 17:09:48 -05:00
try {
for ( PendingCommand command : commands ) {
2009-11-24 19:40:29 -05:00
processingCommand = command ;
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Processing pending command ' " + command + " ' " ) ;
2010-01-02 20:50:41 -05:00
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
String [ ] components = command . command . split ( " \\ . " ) ;
String commandTitle = components [ components . length - 1 ] ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
l . pendingCommandStarted ( account , commandTitle ) ;
}
2009-11-24 19:40:29 -05:00
/ *
* We specifically do not catch any exceptions here . If a command fails it is
* most likely due to a server or IO error and it must be retried before any
* other command processes . This maintains the order of the commands .
* /
2011-02-06 17:09:48 -05:00
try {
if ( PENDING_COMMAND_APPEND . equals ( command . command ) ) {
2009-11-24 19:40:29 -05:00
processPendingAppend ( command , account ) ;
2011-02-06 17:09:48 -05:00
} else if ( PENDING_COMMAND_SET_FLAG_BULK . equals ( command . command ) ) {
2009-11-24 19:40:29 -05:00
processPendingSetFlag ( command , account ) ;
2011-02-06 17:09:48 -05:00
} else if ( PENDING_COMMAND_SET_FLAG . equals ( command . command ) ) {
2009-12-05 09:17:32 -05:00
processPendingSetFlagOld ( command , account ) ;
2011-02-06 17:09:48 -05:00
} else if ( PENDING_COMMAND_MARK_ALL_AS_READ . equals ( command . command ) ) {
2009-11-24 19:40:29 -05:00
processPendingMarkAllAsRead ( command , account ) ;
2011-02-06 17:09:48 -05:00
} else if ( PENDING_COMMAND_MOVE_OR_COPY_BULK . equals ( command . command ) ) {
2012-02-16 19:59:04 -05:00
processPendingMoveOrCopyOld2 ( command , account ) ;
} else if ( PENDING_COMMAND_MOVE_OR_COPY_BULK_NEW . equals ( command . command ) ) {
2009-11-24 19:40:29 -05:00
processPendingMoveOrCopy ( command , account ) ;
2011-02-06 17:09:48 -05:00
} else if ( PENDING_COMMAND_MOVE_OR_COPY . equals ( command . command ) ) {
2009-12-05 09:17:32 -05:00
processPendingMoveOrCopyOld ( command , account ) ;
2011-02-06 17:09:48 -05:00
} else if ( PENDING_COMMAND_EMPTY_TRASH . equals ( command . command ) ) {
2009-11-24 19:40:29 -05:00
processPendingEmptyTrash ( command , account ) ;
2011-02-06 17:09:48 -05:00
} else if ( PENDING_COMMAND_EXPUNGE . equals ( command . command ) ) {
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
processPendingExpunge ( command , account ) ;
}
2009-11-24 19:40:29 -05:00
localStore . removePendingCommand ( command ) ;
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Done processing pending command ' " + command + " ' " ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
if ( me . isPermanentFailure ( ) ) {
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , me ) ;
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Failure of command ' " + command + " ' was permanent, removing command from queue " ) ;
2009-11-24 19:40:29 -05:00
localStore . removePendingCommand ( processingCommand ) ;
2011-02-06 17:09:48 -05:00
} else {
2009-11-24 19:40:29 -05:00
throw me ;
}
2011-02-06 17:09:48 -05:00
} finally {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
progress + + ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
l . synchronizeMailboxProgress ( account , null , progress , todo ) ;
l . pendingCommandCompleted ( account , commandTitle ) ;
}
}
2009-11-24 19:40:29 -05:00
}
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2013-01-17 09:24:22 -05:00
notifyUserIfCertificateProblem ( mApplication , me , account , true ) ;
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , me ) ;
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Could not process command ' " + processingCommand + " ' " , me ) ;
2009-11-24 19:40:29 -05:00
throw me ;
2011-02-06 17:09:48 -05:00
} finally {
for ( MessagingListener l : getListeners ( ) ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
l . pendingCommandsFinished ( account ) ;
}
}
2008-11-01 17:32:06 -04:00
}
/ * *
* Process a pending append message command . This command uploads a local message to the
* server , first checking to be sure that the server message is not newer than
* the local message . Once the local message is successfully processed it is deleted so
* that the server message will be synchronized down without an additional copy being
* created .
* TODO update the local message UID instead of deleteing it
*
* @param command arguments = ( String folder , String uid )
* @param account
* @throws MessagingException
* /
private void processPendingAppend ( PendingCommand command , Account account )
2011-02-06 17:09:48 -05:00
throws MessagingException {
2010-01-16 11:22:20 -05:00
Folder remoteFolder = null ;
LocalFolder localFolder = null ;
2011-02-06 17:09:48 -05:00
try {
2009-11-24 19:40:29 -05:00
2010-01-16 11:22:20 -05:00
String folder = command . arguments [ 0 ] ;
String uid = command . arguments [ 1 ] ;
2010-01-17 19:11:02 -05:00
2011-02-06 17:09:48 -05:00
if ( account . getErrorFolderName ( ) . equals ( folder ) ) {
2009-11-24 19:40:29 -05:00
return ;
2008-11-01 17:32:06 -04:00
}
2010-01-17 19:11:02 -05:00
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
localFolder = localStore . getFolder ( folder ) ;
2012-03-05 15:04:34 -05:00
LocalMessage localMessage = localFolder . getMessage ( uid ) ;
2010-01-17 19:11:02 -05:00
2011-02-06 17:09:48 -05:00
if ( localMessage = = null ) {
2010-01-16 11:22:20 -05:00
return ;
}
2010-01-17 19:11:02 -05:00
2010-03-03 23:00:30 -05:00
Store remoteStore = account . getRemoteStore ( ) ;
2010-01-16 11:22:20 -05:00
remoteFolder = remoteStore . getFolder ( folder ) ;
2011-02-06 17:09:48 -05:00
if ( ! remoteFolder . exists ( ) ) {
if ( ! remoteFolder . create ( FolderType . HOLDS_MESSAGES ) ) {
2009-11-24 19:40:29 -05:00
return ;
}
}
2010-01-16 11:22:20 -05:00
remoteFolder . open ( OpenMode . READ_WRITE ) ;
2011-02-06 17:09:48 -05:00
if ( remoteFolder . getMode ( ) ! = OpenMode . READ_WRITE ) {
2010-01-16 11:22:20 -05:00
return ;
2008-11-01 17:32:06 -04:00
}
2010-01-17 19:11:02 -05:00
2010-01-16 11:22:20 -05:00
Message remoteMessage = null ;
2011-02-06 17:09:48 -05:00
if ( ! localMessage . getUid ( ) . startsWith ( K9 . LOCAL_UID_PREFIX ) ) {
2010-01-16 11:22:20 -05:00
remoteMessage = remoteFolder . getMessage ( localMessage . getUid ( ) ) ;
2008-11-01 17:32:06 -04:00
}
2010-01-17 19:11:02 -05:00
2011-02-06 17:09:48 -05:00
if ( remoteMessage = = null ) {
if ( localMessage . isSet ( Flag . X_REMOTE_COPY_STARTED ) ) {
2010-01-16 11:22:20 -05:00
Log . w ( K9 . LOG_TAG , " Local message with uid " + localMessage . getUid ( ) +
" has flag " + Flag . X_REMOTE_COPY_STARTED + " already set, checking for remote message with " +
" same message id " ) ;
String rUid = remoteFolder . getUidFromMessageId ( localMessage ) ;
2011-02-06 17:09:48 -05:00
if ( rUid ! = null ) {
2010-01-16 11:22:20 -05:00
Log . w ( K9 . LOG_TAG , " Local message has flag " + Flag . X_REMOTE_COPY_STARTED + " already set, and there is a remote message with " +
" uid " + rUid + " , assuming message was already copied and aborting this copy " ) ;
2010-01-17 19:11:02 -05:00
2010-01-16 11:22:20 -05:00
String oldUid = localMessage . getUid ( ) ;
localMessage . setUid ( rUid ) ;
localFolder . changeUid ( localMessage ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2010-01-16 11:22:20 -05:00
l . messageUidChanged ( account , folder , oldUid , localMessage . getUid ( ) ) ;
}
return ;
2011-02-06 17:09:48 -05:00
} else {
2010-01-16 11:22:20 -05:00
Log . w ( K9 . LOG_TAG , " No remote message with message-id found, proceeding with append " ) ;
}
}
2010-01-17 19:11:02 -05:00
2008-11-01 17:32:06 -04:00
/ *
2010-01-16 11:22:20 -05:00
* If the message does not exist remotely we just upload it and then
* update our local copy with the new uid .
2008-11-01 17:32:06 -04:00
* /
2010-01-16 11:22:20 -05:00
FetchProfile fp = new FetchProfile ( ) ;
2008-11-01 17:32:06 -04:00
fp . add ( FetchProfile . Item . BODY ) ;
2010-11-28 15:28:58 -05:00
localFolder . fetch ( new Message [ ] { localMessage } , fp , null ) ;
2008-11-01 17:32:06 -04:00
String oldUid = localMessage . getUid ( ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
localMessage . setFlag ( Flag . X_REMOTE_COPY_STARTED , true ) ;
2008-11-01 17:32:06 -04:00
remoteFolder . appendMessages ( new Message [ ] { localMessage } ) ;
2010-01-17 19:11:02 -05:00
2008-11-01 17:32:06 -04:00
localFolder . changeUid ( localMessage ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2008-11-01 17:32:06 -04:00
l . messageUidChanged ( account , folder , oldUid , localMessage . getUid ( ) ) ;
}
2011-02-06 17:09:48 -05:00
} else {
2010-01-16 11:22:20 -05:00
/ *
* If the remote message exists we need to determine which copy to keep .
* /
/ *
* See if the remote message is newer than ours .
* /
FetchProfile fp = new FetchProfile ( ) ;
fp . add ( FetchProfile . Item . ENVELOPE ) ;
remoteFolder . fetch ( new Message [ ] { remoteMessage } , fp , null ) ;
Date localDate = localMessage . getInternalDate ( ) ;
Date remoteDate = remoteMessage . getInternalDate ( ) ;
2011-02-06 17:09:48 -05:00
if ( remoteDate ! = null & & remoteDate . compareTo ( localDate ) > 0 ) {
2010-01-16 11:22:20 -05:00
/ *
* If the remote message is newer than ours we ' ll just
* delete ours and move on . A sync will get the server message
* if we need to be able to see it .
* /
2010-11-12 16:38:02 -05:00
localMessage . destroy ( ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-01-16 11:22:20 -05:00
/ *
* Otherwise we ' ll upload our message and then delete the remote message .
* /
fp . clear ( ) ;
fp = new FetchProfile ( ) ;
fp . add ( FetchProfile . Item . BODY ) ;
localFolder . fetch ( new Message [ ] { localMessage } , fp , null ) ;
String oldUid = localMessage . getUid ( ) ;
2010-01-17 19:11:02 -05:00
2010-01-16 11:22:20 -05:00
localMessage . setFlag ( Flag . X_REMOTE_COPY_STARTED , true ) ;
2010-01-17 19:11:02 -05:00
2010-01-16 11:22:20 -05:00
remoteFolder . appendMessages ( new Message [ ] { localMessage } ) ;
localFolder . changeUid ( localMessage ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2010-01-16 11:22:20 -05:00
l . messageUidChanged ( account , folder , oldUid , localMessage . getUid ( ) ) ;
}
2011-02-06 17:09:48 -05:00
if ( remoteDate ! = null ) {
2010-04-14 23:17:25 -04:00
remoteMessage . setFlag ( Flag . DELETED , true ) ;
2011-02-06 17:09:48 -05:00
if ( Account . EXPUNGE_IMMEDIATELY . equals ( account . getExpungePolicy ( ) ) ) {
2010-04-14 23:17:25 -04:00
remoteFolder . expunge ( ) ;
}
}
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
}
2008-11-01 17:32:06 -04:00
}
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( remoteFolder ) ;
closeFolder ( localFolder ) ;
2010-01-16 11:22:20 -05:00
}
2008-11-01 17:32:06 -04:00
}
2011-02-06 17:09:48 -05:00
private void queueMoveOrCopy ( Account account , String srcFolder , String destFolder , boolean isCopy , String uids [ ] ) {
if ( account . getErrorFolderName ( ) . equals ( srcFolder ) ) {
2009-12-01 23:09:51 -05:00
return ;
}
2009-11-29 13:07:34 -05:00
PendingCommand command = new PendingCommand ( ) ;
2012-02-16 19:59:04 -05:00
command . command = PENDING_COMMAND_MOVE_OR_COPY_BULK_NEW ;
2009-12-06 19:56:06 -05:00
2012-03-22 23:20:29 -04:00
int length = 4 + uids . length ;
2009-11-29 13:07:34 -05:00
command . arguments = new String [ length ] ;
command . arguments [ 0 ] = srcFolder ;
command . arguments [ 1 ] = destFolder ;
command . arguments [ 2 ] = Boolean . toString ( isCopy ) ;
2011-06-28 07:20:48 -04:00
command . arguments [ 3 ] = Boolean . toString ( false ) ;
System . arraycopy ( uids , 0 , command . arguments , 4 , uids . length ) ;
2009-11-29 13:07:34 -05:00
queuePendingCommand ( account , command ) ;
}
2011-06-28 07:20:48 -04:00
private void queueMoveOrCopy ( Account account , String srcFolder , String destFolder , boolean isCopy , String uids [ ] , Map < String , String > uidMap ) {
if ( uidMap = = null | | uidMap . isEmpty ( ) ) {
queueMoveOrCopy ( account , srcFolder , destFolder , isCopy , uids ) ;
} else {
if ( account . getErrorFolderName ( ) . equals ( srcFolder ) ) {
return ;
}
PendingCommand command = new PendingCommand ( ) ;
2012-02-16 19:59:04 -05:00
command . command = PENDING_COMMAND_MOVE_OR_COPY_BULK_NEW ;
2011-06-28 07:20:48 -04:00
int length = 4 + uidMap . keySet ( ) . size ( ) + uidMap . values ( ) . size ( ) ;
command . arguments = new String [ length ] ;
command . arguments [ 0 ] = srcFolder ;
command . arguments [ 1 ] = destFolder ;
command . arguments [ 2 ] = Boolean . toString ( isCopy ) ;
command . arguments [ 3 ] = Boolean . toString ( true ) ;
System . arraycopy ( uidMap . keySet ( ) . toArray ( ) , 0 , command . arguments , 4 , uidMap . keySet ( ) . size ( ) ) ;
System . arraycopy ( uidMap . values ( ) . toArray ( ) , 0 , command . arguments , 4 + uidMap . keySet ( ) . size ( ) , uidMap . values ( ) . size ( ) ) ;
queuePendingCommand ( account , command ) ;
}
}
2012-02-16 19:59:04 -05:00
/ * *
* Convert pending command to new format and call
* { @link # processPendingMoveOrCopy ( PendingCommand , Account ) } .
*
* < p >
* TODO : This method is obsolete and is only for transition from K - 9 4 . 0 to K - 9 4 . 2
* Eventually , it should be removed .
* < / p >
*
* @param command
* Pending move / copy command in old format .
* @param account
* The account the pending command belongs to .
*
* @throws MessagingException
* In case of an error .
* /
private void processPendingMoveOrCopyOld2 ( PendingCommand command , Account account )
throws MessagingException {
PendingCommand newCommand = new PendingCommand ( ) ;
int len = command . arguments . length ;
newCommand . command = PENDING_COMMAND_MOVE_OR_COPY_BULK_NEW ;
newCommand . arguments = new String [ len + 1 ] ;
newCommand . arguments [ 0 ] = command . arguments [ 0 ] ;
newCommand . arguments [ 1 ] = command . arguments [ 1 ] ;
newCommand . arguments [ 2 ] = command . arguments [ 2 ] ;
newCommand . arguments [ 3 ] = Boolean . toString ( false ) ;
System . arraycopy ( command . arguments , 3 , newCommand . arguments , 4 , len - 3 ) ;
processPendingMoveOrCopy ( newCommand , account ) ;
}
2008-11-01 17:32:06 -04:00
/ * *
* Process a pending trash message command .
*
* @param command arguments = ( String folder , String uid )
* @param account
* @throws MessagingException
* /
2009-03-05 02:32:45 -05:00
private void processPendingMoveOrCopy ( PendingCommand command , Account account )
2011-02-06 17:09:48 -05:00
throws MessagingException {
2009-11-29 13:07:34 -05:00
Folder remoteSrcFolder = null ;
Folder remoteDestFolder = null ;
2011-07-02 02:29:00 -04:00
LocalFolder localDestFolder = null ;
2011-02-06 17:09:48 -05:00
try {
2009-11-29 13:07:34 -05:00
String srcFolder = command . arguments [ 0 ] ;
2011-02-06 17:09:48 -05:00
if ( account . getErrorFolderName ( ) . equals ( srcFolder ) ) {
2009-12-01 23:09:51 -05:00
return ;
}
2009-11-29 13:07:34 -05:00
String destFolder = command . arguments [ 1 ] ;
String isCopyS = command . arguments [ 2 ] ;
2011-06-28 07:20:48 -04:00
String hasNewUidsS = command . arguments [ 3 ] ;
boolean hasNewUids = false ;
if ( hasNewUidsS ! = null ) {
hasNewUids = Boolean . parseBoolean ( hasNewUidsS ) ;
}
2010-03-03 23:00:30 -05:00
Store remoteStore = account . getRemoteStore ( ) ;
2009-11-29 13:07:34 -05:00
remoteSrcFolder = remoteStore . getFolder ( srcFolder ) ;
2009-12-06 19:56:06 -05:00
2011-06-28 07:20:48 -04:00
Store localStore = account . getLocalStore ( ) ;
2011-07-02 02:29:00 -04:00
localDestFolder = ( LocalFolder ) localStore . getFolder ( destFolder ) ;
2009-11-29 13:07:34 -05:00
List < Message > messages = new ArrayList < Message > ( ) ;
2011-06-28 07:20:48 -04:00
/ *
* We split up the localUidMap into two parts while sending the command , here we assemble it back .
* /
Map < String , String > localUidMap = new HashMap < String , String > ( ) ;
if ( hasNewUids ) {
int offset = ( command . arguments . length - 4 ) / 2 ;
for ( int i = 4 ; i < 4 + offset ; i + + ) {
localUidMap . put ( command . arguments [ i ] , command . arguments [ i + offset ] ) ;
String uid = command . arguments [ i ] ;
if ( ! uid . startsWith ( K9 . LOCAL_UID_PREFIX ) ) {
messages . add ( remoteSrcFolder . getMessage ( uid ) ) ;
}
}
} else {
for ( int i = 4 ; i < command . arguments . length ; i + + ) {
String uid = command . arguments [ i ] ;
if ( ! uid . startsWith ( K9 . LOCAL_UID_PREFIX ) ) {
messages . add ( remoteSrcFolder . getMessage ( uid ) ) ;
}
2009-11-29 13:07:34 -05:00
}
}
2009-12-06 19:56:06 -05:00
2009-11-29 13:07:34 -05:00
boolean isCopy = false ;
2011-02-06 17:09:48 -05:00
if ( isCopyS ! = null ) {
2009-11-29 13:07:34 -05:00
isCopy = Boolean . parseBoolean ( isCopyS ) ;
}
2009-12-06 19:56:06 -05:00
2011-02-06 17:09:48 -05:00
if ( ! remoteSrcFolder . exists ( ) ) {
2009-11-29 13:07:34 -05:00
throw new MessagingException ( " processingPendingMoveOrCopy: remoteFolder " + srcFolder + " does not exist " , true ) ;
}
remoteSrcFolder . open ( OpenMode . READ_WRITE ) ;
2011-02-06 17:09:48 -05:00
if ( remoteSrcFolder . getMode ( ) ! = OpenMode . READ_WRITE ) {
2009-11-29 13:07:34 -05:00
throw new MessagingException ( " processingPendingMoveOrCopy: could not open remoteSrcFolder " + srcFolder + " read/write " , true ) ;
}
2009-12-06 19:56:06 -05:00
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " processingPendingMoveOrCopy: source folder = " + srcFolder
2009-11-29 13:07:34 -05:00
+ " , " + messages . size ( ) + " messages, destination folder = " + destFolder + " , isCopy = " + isCopy ) ;
2010-01-02 20:50:41 -05:00
2012-02-16 16:36:57 -05:00
Map < String , String > remoteUidMap = null ;
2011-06-28 07:20:48 -04:00
2011-02-06 17:09:48 -05:00
if ( ! isCopy & & destFolder . equals ( account . getTrashFolderName ( ) ) ) {
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " processingPendingMoveOrCopy doing special case for deleting message " ) ;
2010-01-02 20:50:41 -05:00
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
String destFolderName = destFolder ;
2011-02-06 17:09:48 -05:00
if ( K9 . FOLDER_NONE . equals ( destFolderName ) ) {
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
destFolderName = null ;
}
2010-08-02 07:55:31 -04:00
remoteSrcFolder . delete ( messages . toArray ( EMPTY_MESSAGE_ARRAY ) , destFolderName ) ;
2011-02-06 17:09:48 -05:00
} else {
2009-11-29 13:07:34 -05:00
remoteDestFolder = remoteStore . getFolder ( destFolder ) ;
2009-12-06 19:56:06 -05:00
2011-02-06 17:09:48 -05:00
if ( isCopy ) {
2011-06-28 07:20:48 -04:00
remoteUidMap = remoteSrcFolder . copyMessages ( messages . toArray ( EMPTY_MESSAGE_ARRAY ) , remoteDestFolder ) ;
2011-02-06 17:09:48 -05:00
} else {
2011-06-28 07:20:48 -04:00
remoteUidMap = remoteSrcFolder . moveMessages ( messages . toArray ( EMPTY_MESSAGE_ARRAY ) , remoteDestFolder ) ;
2009-11-29 13:07:34 -05:00
}
}
2011-02-06 17:09:48 -05:00
if ( ! isCopy & & Account . EXPUNGE_IMMEDIATELY . equals ( account . getExpungePolicy ( ) ) ) {
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " processingPendingMoveOrCopy expunging folder " + account . getDescription ( ) + " : " + srcFolder ) ;
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
remoteSrcFolder . expunge ( ) ;
}
2011-06-28 07:20:48 -04:00
/ *
* This next part is used to bring the local UIDs of the local destination folder
* upto speed with the remote UIDs of remote destionation folder .
* /
2012-02-16 16:36:57 -05:00
if ( ! localUidMap . isEmpty ( ) & & remoteUidMap ! = null & & ! remoteUidMap . isEmpty ( ) ) {
2012-07-06 09:00:25 -04:00
Set < Map . Entry < String , String > > remoteSrcEntries = remoteUidMap . entrySet ( ) ;
Iterator < Map . Entry < String , String > > remoteSrcEntriesIterator = remoteSrcEntries . iterator ( ) ;
2011-06-28 07:20:48 -04:00
2012-07-06 09:00:25 -04:00
while ( remoteSrcEntriesIterator . hasNext ( ) ) {
Map . Entry < String , String > entry = remoteSrcEntriesIterator . next ( ) ;
String remoteSrcUid = entry . getKey ( ) ;
2011-06-28 07:20:48 -04:00
String localDestUid = localUidMap . get ( remoteSrcUid ) ;
2012-07-06 09:00:25 -04:00
String newUid = entry . getValue ( ) ;
2011-06-28 07:20:48 -04:00
Message localDestMessage = localDestFolder . getMessage ( localDestUid ) ;
2012-03-26 13:41:21 -04:00
if ( localDestMessage ! = null ) {
localDestMessage . setUid ( newUid ) ;
localDestFolder . changeUid ( ( LocalMessage ) localDestMessage ) ;
for ( MessagingListener l : getListeners ( ) ) {
l . messageUidChanged ( account , destFolder , localDestUid , newUid ) ;
}
2012-02-16 16:34:50 -05:00
}
2011-06-28 07:20:48 -04:00
}
}
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( remoteSrcFolder ) ;
closeFolder ( remoteDestFolder ) ;
2009-03-05 02:32:45 -05:00
}
2008-11-01 17:32:06 -04:00
}
2009-12-06 19:56:06 -05:00
2011-02-06 17:09:48 -05:00
private void queueSetFlag ( final Account account , final String folderName , final String newState , final String flag , final String [ ] uids ) {
putBackground ( " queueSetFlag " + account . getDescription ( ) + " : " + folderName , null , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
PendingCommand command = new PendingCommand ( ) ;
command . command = PENDING_COMMAND_SET_FLAG_BULK ;
int length = 3 + uids . length ;
command . arguments = new String [ length ] ;
command . arguments [ 0 ] = folderName ;
command . arguments [ 1 ] = newState ;
command . arguments [ 2 ] = flag ;
2010-11-30 22:04:57 -05:00
System . arraycopy ( uids , 0 , command . arguments , 3 , uids . length ) ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
queuePendingCommand ( account , command ) ;
processPendingCommands ( account ) ;
}
} ) ;
2009-11-29 11:55:35 -05:00
}
2008-11-01 17:32:06 -04:00
/ * *
* Processes a pending mark read or unread command .
*
* @param command arguments = ( String folder , String uid , boolean read )
* @param account
* /
2009-01-13 00:52:37 -05:00
private void processPendingSetFlag ( PendingCommand command , Account account )
2011-02-06 17:09:48 -05:00
throws MessagingException {
2008-11-01 17:32:06 -04:00
String folder = command . arguments [ 0 ] ;
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
if ( account . getErrorFolderName ( ) . equals ( folder ) ) {
2009-11-24 19:40:29 -05:00
return ;
}
2009-11-29 11:55:35 -05:00
boolean newState = Boolean . parseBoolean ( command . arguments [ 1 ] ) ;
2009-11-24 19:40:29 -05:00
2009-11-29 11:55:35 -05:00
Flag flag = Flag . valueOf ( command . arguments [ 2 ] ) ;
2008-11-01 17:32:06 -04:00
2010-03-03 23:00:30 -05:00
Store remoteStore = account . getRemoteStore ( ) ;
2008-11-01 17:32:06 -04:00
Folder remoteFolder = remoteStore . getFolder ( folder ) ;
2011-05-14 17:19:24 -04:00
if ( ! remoteFolder . exists ( ) | | ! remoteFolder . isFlagSupported ( flag ) ) {
2010-08-28 17:15:23 -04:00
return ;
}
2011-02-06 17:09:48 -05:00
try {
2009-11-29 11:55:35 -05:00
remoteFolder . open ( OpenMode . READ_WRITE ) ;
2011-02-06 17:09:48 -05:00
if ( remoteFolder . getMode ( ) ! = OpenMode . READ_WRITE ) {
2009-11-29 11:55:35 -05:00
return ;
}
List < Message > messages = new ArrayList < Message > ( ) ;
2011-02-06 17:09:48 -05:00
for ( int i = 3 ; i < command . arguments . length ; i + + ) {
2009-11-29 11:55:35 -05:00
String uid = command . arguments [ i ] ;
2011-02-06 17:09:48 -05:00
if ( ! uid . startsWith ( K9 . LOCAL_UID_PREFIX ) ) {
2009-11-29 11:55:35 -05:00
messages . add ( remoteFolder . getMessage ( uid ) ) ;
}
}
2009-12-06 19:56:06 -05:00
2011-10-06 12:28:14 -04:00
if ( messages . isEmpty ( ) ) {
2009-11-29 11:55:35 -05:00
return ;
}
2010-08-02 07:55:31 -04:00
remoteFolder . setFlags ( messages . toArray ( EMPTY_MESSAGE_ARRAY ) , new Flag [ ] { flag } , newState ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( remoteFolder ) ;
2009-12-06 19:56:06 -05:00
}
2009-12-05 09:17:32 -05:00
}
2009-12-06 19:56:06 -05:00
2009-12-05 09:17:32 -05:00
// TODO: This method is obsolete and is only for transition from K-9 2.0 to K-9 2.1
// Eventually, it should be removed
private void processPendingSetFlagOld ( PendingCommand command , Account account )
2011-02-06 17:09:48 -05:00
throws MessagingException {
2009-12-05 09:17:32 -05:00
String folder = command . arguments [ 0 ] ;
String uid = command . arguments [ 1 ] ;
2010-01-17 19:11:02 -05:00
2011-02-06 17:09:48 -05:00
if ( account . getErrorFolderName ( ) . equals ( folder ) ) {
2009-12-05 09:17:32 -05:00
return ;
2008-11-01 17:32:06 -04:00
}
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " processPendingSetFlagOld: folder = " + folder + " , uid = " + uid ) ;
2009-12-05 09:17:32 -05:00
boolean newState = Boolean . parseBoolean ( command . arguments [ 2 ] ) ;
Flag flag = Flag . valueOf ( command . arguments [ 3 ] ) ;
2010-01-16 11:22:20 -05:00
Folder remoteFolder = null ;
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
Store remoteStore = account . getRemoteStore ( ) ;
2010-01-16 11:22:20 -05:00
remoteFolder = remoteStore . getFolder ( folder ) ;
2011-02-06 17:09:48 -05:00
if ( ! remoteFolder . exists ( ) ) {
2010-01-16 11:22:20 -05:00
return ;
}
remoteFolder . open ( OpenMode . READ_WRITE ) ;
2011-02-06 17:09:48 -05:00
if ( remoteFolder . getMode ( ) ! = OpenMode . READ_WRITE ) {
2010-01-16 11:22:20 -05:00
return ;
}
Message remoteMessage = null ;
2011-02-06 17:09:48 -05:00
if ( ! uid . startsWith ( K9 . LOCAL_UID_PREFIX ) ) {
2010-01-16 11:22:20 -05:00
remoteMessage = remoteFolder . getMessage ( uid ) ;
}
2011-02-06 17:09:48 -05:00
if ( remoteMessage = = null ) {
2010-01-16 11:22:20 -05:00
return ;
}
remoteMessage . setFlag ( flag , newState ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( remoteFolder ) ;
2009-12-05 09:17:32 -05:00
}
}
2011-02-06 17:09:48 -05:00
private void queueExpunge ( final Account account , final String folderName ) {
putBackground ( " queueExpunge " + account . getDescription ( ) + " : " + folderName , null , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
PendingCommand command = new PendingCommand ( ) ;
command . command = PENDING_COMMAND_EXPUNGE ;
command . arguments = new String [ 1 ] ;
2009-12-27 12:22:51 -05:00
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
command . arguments [ 0 ] = folderName ;
queuePendingCommand ( account , command ) ;
processPendingCommands ( account ) ;
}
} ) ;
}
private void processPendingExpunge ( PendingCommand command , Account account )
2011-02-06 17:09:48 -05:00
throws MessagingException {
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
String folder = command . arguments [ 0 ] ;
2009-12-27 12:22:51 -05:00
2011-02-06 17:09:48 -05:00
if ( account . getErrorFolderName ( ) . equals ( folder ) ) {
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
return ;
}
if ( K9 . DEBUG )
2009-12-27 12:22:51 -05:00
Log . d ( K9 . LOG_TAG , " processPendingExpunge: folder = " + folder ) ;
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
2010-03-03 23:00:30 -05:00
Store remoteStore = account . getRemoteStore ( ) ;
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
Folder remoteFolder = remoteStore . getFolder ( folder ) ;
2011-02-06 17:09:48 -05:00
try {
if ( ! remoteFolder . exists ( ) ) {
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
return ;
}
remoteFolder . open ( OpenMode . READ_WRITE ) ;
2011-02-06 17:09:48 -05:00
if ( remoteFolder . getMode ( ) ! = OpenMode . READ_WRITE ) {
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
return ;
}
remoteFolder . expunge ( ) ;
if ( K9 . DEBUG )
2009-12-27 12:22:51 -05:00
Log . d ( K9 . LOG_TAG , " processPendingExpunge: complete for folder = " + folder ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( remoteFolder ) ;
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
}
}
2009-12-05 09:17:32 -05:00
2009-12-06 19:56:06 -05:00
2009-12-05 09:17:32 -05:00
// TODO: This method is obsolete and is only for transition from K-9 2.0 to K-9 2.1
// Eventually, it should be removed
private void processPendingMoveOrCopyOld ( PendingCommand command , Account account )
2011-02-06 17:09:48 -05:00
throws MessagingException {
2009-12-05 09:17:32 -05:00
String srcFolder = command . arguments [ 0 ] ;
String uid = command . arguments [ 1 ] ;
String destFolder = command . arguments [ 2 ] ;
String isCopyS = command . arguments [ 3 ] ;
boolean isCopy = false ;
2011-02-06 17:09:48 -05:00
if ( isCopyS ! = null ) {
2009-12-05 09:17:32 -05:00
isCopy = Boolean . parseBoolean ( isCopyS ) ;
}
2011-02-06 17:09:48 -05:00
if ( account . getErrorFolderName ( ) . equals ( srcFolder ) ) {
2009-12-05 09:17:32 -05:00
return ;
}
2010-03-03 23:00:30 -05:00
Store remoteStore = account . getRemoteStore ( ) ;
2009-12-05 09:17:32 -05:00
Folder remoteSrcFolder = remoteStore . getFolder ( srcFolder ) ;
Folder remoteDestFolder = remoteStore . getFolder ( destFolder ) ;
2011-02-06 17:09:48 -05:00
if ( ! remoteSrcFolder . exists ( ) ) {
2009-12-05 09:17:32 -05:00
throw new MessagingException ( " processPendingMoveOrCopyOld: remoteFolder " + srcFolder + " does not exist " , true ) ;
}
remoteSrcFolder . open ( OpenMode . READ_WRITE ) ;
2011-02-06 17:09:48 -05:00
if ( remoteSrcFolder . getMode ( ) ! = OpenMode . READ_WRITE ) {
2009-12-05 09:17:32 -05:00
throw new MessagingException ( " processPendingMoveOrCopyOld: could not open remoteSrcFolder " + srcFolder + " read/write " , true ) ;
}
Message remoteMessage = null ;
2011-02-06 17:09:48 -05:00
if ( ! uid . startsWith ( K9 . LOCAL_UID_PREFIX ) ) {
2009-12-05 09:17:32 -05:00
remoteMessage = remoteSrcFolder . getMessage ( uid ) ;
}
2011-02-06 17:09:48 -05:00
if ( remoteMessage = = null ) {
2009-12-05 09:17:32 -05:00
throw new MessagingException ( " processPendingMoveOrCopyOld: remoteMessage " + uid + " does not exist " , true ) ;
}
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " processPendingMoveOrCopyOld: source folder = " + srcFolder
2009-12-06 19:56:06 -05:00
+ " , uid = " + uid + " , destination folder = " + destFolder + " , isCopy = " + isCopy ) ;
2010-01-02 20:50:41 -05:00
2011-02-06 17:09:48 -05:00
if ( ! isCopy & & destFolder . equals ( account . getTrashFolderName ( ) ) ) {
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " processPendingMoveOrCopyOld doing special case for deleting message " ) ;
2010-01-02 20:50:41 -05:00
2009-12-05 09:17:32 -05:00
remoteMessage . delete ( account . getTrashFolderName ( ) ) ;
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
remoteSrcFolder . close ( ) ;
2009-12-05 09:17:32 -05:00
return ;
}
remoteDestFolder . open ( OpenMode . READ_WRITE ) ;
2011-02-06 17:09:48 -05:00
if ( remoteDestFolder . getMode ( ) ! = OpenMode . READ_WRITE ) {
2009-12-05 09:17:32 -05:00
throw new MessagingException ( " processPendingMoveOrCopyOld: could not open remoteDestFolder " + srcFolder + " read/write " , true ) ;
}
2011-02-06 17:09:48 -05:00
if ( isCopy ) {
2009-12-05 09:17:32 -05:00
remoteSrcFolder . copyMessages ( new Message [ ] { remoteMessage } , remoteDestFolder ) ;
2011-02-06 17:09:48 -05:00
} else {
2009-12-05 09:17:32 -05:00
remoteSrcFolder . moveMessages ( new Message [ ] { remoteMessage } , remoteDestFolder ) ;
}
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
remoteSrcFolder . close ( ) ;
remoteDestFolder . close ( ) ;
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
private void processPendingMarkAllAsRead ( PendingCommand command , Account account ) throws MessagingException {
2009-06-23 10:57:16 -04:00
String folder = command . arguments [ 0 ] ;
2010-01-16 11:22:20 -05:00
Folder remoteFolder = null ;
LocalFolder localFolder = null ;
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
Store localStore = account . getLocalStore ( ) ;
2010-01-16 11:22:20 -05:00
localFolder = ( LocalFolder ) localStore . getFolder ( folder ) ;
localFolder . open ( OpenMode . READ_WRITE ) ;
Message [ ] messages = localFolder . getMessages ( null , false ) ;
2011-02-06 17:09:48 -05:00
for ( Message message : messages ) {
if ( ! message . isSet ( Flag . SEEN ) ) {
2010-01-16 11:22:20 -05:00
message . setFlag ( Flag . SEEN , true ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2010-01-16 11:22:20 -05:00
l . listLocalMessagesUpdateMessage ( account , folder , message ) ;
}
2009-06-23 10:57:16 -04:00
}
}
2012-12-07 09:45:36 -05:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2010-01-16 11:22:20 -05:00
l . folderStatusChanged ( account , folder , 0 ) ;
}
2010-01-17 19:11:02 -05:00
2011-02-06 17:09:48 -05:00
if ( account . getErrorFolderName ( ) . equals ( folder ) ) {
2009-06-23 10:57:16 -04:00
return ;
}
2010-03-03 23:00:30 -05:00
Store remoteStore = account . getRemoteStore ( ) ;
2010-01-16 11:22:20 -05:00
remoteFolder = remoteStore . getFolder ( folder ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2011-05-14 17:30:47 -04:00
if ( ! remoteFolder . exists ( ) | | ! remoteFolder . isFlagSupported ( Flag . SEEN ) ) {
2009-06-23 10:57:16 -04:00
return ;
}
remoteFolder . open ( OpenMode . READ_WRITE ) ;
2011-02-06 17:09:48 -05:00
if ( remoteFolder . getMode ( ) ! = OpenMode . READ_WRITE ) {
2009-06-23 10:57:16 -04:00
return ;
}
2009-11-24 19:40:29 -05:00
remoteFolder . setFlags ( new Flag [ ] { Flag . SEEN } , true ) ;
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
remoteFolder . close ( ) ;
2011-02-06 17:09:48 -05:00
} catch ( UnsupportedOperationException uoe ) {
2009-12-14 21:50:53 -05:00
Log . w ( K9 . LOG_TAG , " Could not mark all server-side as read because store doesn't support operation " , uoe ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( localFolder ) ;
closeFolder ( remoteFolder ) ;
2009-06-23 10:57:16 -04:00
}
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
}
2013-01-17 09:24:22 -05:00
private void notifyUserIfCertificateProblem ( Context context , Exception e ,
Account account , boolean incoming ) {
if ( ! ( e instanceof CertificateValidationException ) ) {
return ;
}
CertificateValidationException cve = ( CertificateValidationException ) e ;
if ( ! cve . needsUserAttention ( ) ) {
return ;
}
final int id = incoming
? K9 . CERTIFICATE_EXCEPTION_NOTIFICATION_INCOMING + account . getAccountNumber ( )
: K9 . CERTIFICATE_EXCEPTION_NOTIFICATION_OUTGOING + account . getAccountNumber ( ) ;
final Intent i = incoming
? AccountSetupIncoming . intentActionEditIncomingSettings ( context , account )
: AccountSetupOutgoing . intentActionEditOutgoingSettings ( context , account ) ;
final PendingIntent pi = PendingIntent . getActivity ( context ,
account . getAccountNumber ( ) , i , PendingIntent . FLAG_UPDATE_CURRENT ) ;
final String title = context . getString (
2013-02-20 23:42:04 -05:00
R . string . notification_certificate_error_title , account . getName ( ) ) ;
2013-01-17 09:24:22 -05:00
2013-02-20 17:55:46 -05:00
final NotificationCompat . Builder builder = new NotificationBuilder ( context ) ;
2013-01-17 09:24:22 -05:00
builder . setSmallIcon ( R . drawable . stat_notify_email_generic ) ;
builder . setWhen ( System . currentTimeMillis ( ) ) ;
builder . setAutoCancel ( true ) ;
builder . setTicker ( title ) ;
builder . setContentTitle ( title ) ;
builder . setContentText ( context . getString ( R . string . notification_certificate_error_text ) ) ;
builder . setContentIntent ( pi ) ;
configureNotification ( builder , null , null ,
K9 . NOTIFICATION_LED_FAILURE_COLOR ,
K9 . NOTIFICATION_LED_BLINK_FAST , true ) ;
final NotificationManager nm = ( NotificationManager )
context . getSystemService ( Context . NOTIFICATION_SERVICE ) ;
nm . notify ( null , id , builder . build ( ) ) ;
}
public void clearCertificateErrorNotifications ( Context context ,
final Account account , boolean incoming , boolean outgoing ) {
final NotificationManager nm = ( NotificationManager )
context . getSystemService ( Context . NOTIFICATION_SERVICE ) ;
if ( incoming ) {
nm . cancel ( null , K9 . CERTIFICATE_EXCEPTION_NOTIFICATION_INCOMING + account . getAccountNumber ( ) ) ;
}
if ( outgoing ) {
nm . cancel ( null , K9 . CERTIFICATE_EXCEPTION_NOTIFICATION_OUTGOING + account . getAccountNumber ( ) ) ;
}
}
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
static long uidfill = 0 ;
static AtomicBoolean loopCatch = new AtomicBoolean ( ) ;
2011-02-06 17:09:48 -05:00
public void addErrorMessage ( Account account , String subject , Throwable t ) {
if ( ! loopCatch . compareAndSet ( false , true ) ) {
2009-11-24 19:40:29 -05:00
return ;
}
2011-02-06 17:09:48 -05:00
try {
if ( t = = null ) {
2009-11-24 19:40:29 -05:00
return ;
}
2010-09-11 07:20:50 -04:00
CharArrayWriter baos = new CharArrayWriter ( t . getStackTrace ( ) . length * 10 ) ;
PrintWriter ps = new PrintWriter ( baos ) ;
2009-11-24 19:40:29 -05:00
t . printStackTrace ( ps ) ;
ps . close ( ) ;
2011-02-06 17:09:48 -05:00
if ( subject = = null ) {
2010-07-10 12:41:07 -04:00
subject = getRootCauseMessage ( t ) ;
2009-10-21 20:41:06 -04:00
}
2009-11-24 19:40:29 -05:00
2010-07-10 12:41:07 -04:00
addErrorMessage ( account , subject , baos . toString ( ) ) ;
2011-02-06 17:09:48 -05:00
} catch ( Throwable it ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Could not save error message to " + account . getErrorFolderName ( ) , it ) ;
2011-02-06 17:09:48 -05:00
} finally {
2009-11-24 19:40:29 -05:00
loopCatch . set ( false ) ;
}
}
2011-02-06 17:09:48 -05:00
public void addErrorMessage ( Account account , String subject , String body ) {
if ( ! K9 . ENABLE_ERROR_FOLDER ) {
2009-11-24 19:40:29 -05:00
return ;
}
2011-02-06 17:09:48 -05:00
if ( ! loopCatch . compareAndSet ( false , true ) ) {
2009-11-24 19:40:29 -05:00
return ;
}
2011-02-06 17:09:48 -05:00
try {
if ( body = = null | | body . length ( ) < 1 ) {
2009-11-24 19:40:29 -05:00
return ;
}
2010-03-03 23:00:30 -05:00
Store localStore = account . getLocalStore ( ) ;
2009-11-24 19:40:29 -05:00
LocalFolder localFolder = ( LocalFolder ) localStore . getFolder ( account . getErrorFolderName ( ) ) ;
Message [ ] messages = new Message [ 1 ] ;
MimeMessage message = new MimeMessage ( ) ;
message . setBody ( new TextBody ( body ) ) ;
message . setFlag ( Flag . X_DOWNLOADED_FULL , true ) ;
message . setSubject ( subject ) ;
long nowTime = System . currentTimeMillis ( ) ;
Date nowDate = new Date ( nowTime ) ;
message . setInternalDate ( nowDate ) ;
message . addSentDate ( nowDate ) ;
message . setFrom ( new Address ( account . getEmail ( ) , " K9mail internal " ) ) ;
messages [ 0 ] = message ;
localFolder . appendMessages ( messages ) ;
2010-11-13 19:49:08 -05:00
localFolder . clearMessagesOlderThan ( nowTime - ( 15 * 60 * 1000 ) ) ;
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
} catch ( Throwable it ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Could not save error message to " + account . getErrorFolderName ( ) , it ) ;
2011-02-06 17:09:48 -05:00
} finally {
2009-11-24 19:40:29 -05:00
loopCatch . set ( false ) ;
}
}
2011-02-06 17:09:48 -05:00
public void markAllMessagesRead ( final Account account , final String folder ) {
2009-11-24 19:40:29 -05:00
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Marking all messages in " + account . getDescription ( ) + " : " + folder + " as read " ) ;
2009-11-24 19:40:29 -05:00
List < String > args = new ArrayList < String > ( ) ;
args . add ( folder ) ;
PendingCommand command = new PendingCommand ( ) ;
command . command = PENDING_COMMAND_MARK_ALL_AS_READ ;
2010-08-02 07:55:31 -04:00
command . arguments = args . toArray ( EMPTY_STRING_ARRAY ) ;
2009-11-24 19:40:29 -05:00
queuePendingCommand ( account , command ) ;
processPendingCommands ( account ) ;
}
2009-12-06 19:56:06 -05:00
2012-12-05 23:25:41 -05:00
public void setFlag ( final Account account , final List < Long > messageIds , final Flag flag ,
2013-01-11 20:28:12 -05:00
final boolean newState ) {
2012-11-03 00:56:12 -04:00
2013-02-18 22:45:14 -05:00
setFlagInCache ( account , messageIds , flag , newState ) ;
2012-12-05 23:25:41 -05:00
threadPool . execute ( new Runnable ( ) {
2010-03-03 23:00:30 -05:00
@Override
2012-12-05 23:25:41 -05:00
public void run ( ) {
2013-01-11 20:28:12 -05:00
setFlagSynchronous ( account , messageIds , flag , newState , false ) ;
2010-03-03 23:00:30 -05:00
}
} ) ;
2012-11-03 00:01:25 -04:00
}
2013-01-11 20:28:12 -05:00
public void setFlagForThreads ( final Account account , final List < Long > threadRootIds ,
final Flag flag , final boolean newState ) {
2013-02-18 22:45:14 -05:00
setFlagForThreadsInCache ( account , threadRootIds , flag , newState ) ;
2013-01-11 20:28:12 -05:00
threadPool . execute ( new Runnable ( ) {
@Override
public void run ( ) {
setFlagSynchronous ( account , threadRootIds , flag , newState , true ) ;
}
} ) ;
}
private void setFlagSynchronous ( final Account account , final List < Long > ids ,
2012-12-05 23:25:41 -05:00
final Flag flag , final boolean newState , final boolean threadedList ) {
2012-11-03 00:01:25 -04:00
2012-12-05 23:25:41 -05:00
LocalStore localStore ;
try {
localStore = account . getLocalStore ( ) ;
} catch ( MessagingException e ) {
Log . e ( K9 . LOG_TAG , " Couldn't get LocalStore instance " , e ) ;
return ;
}
2010-04-29 00:59:14 -04:00
2012-12-05 23:25:41 -05:00
// Update affected messages in the database. This should be as fast as possible so the UI
// can be updated with the new state.
try {
2013-01-11 20:28:12 -05:00
if ( threadedList ) {
localStore . setFlagForThreads ( ids , flag , newState ) ;
2013-02-18 22:45:14 -05:00
removeFlagFromCache ( account , ids , flag ) ;
2013-01-11 20:28:12 -05:00
} else {
localStore . setFlag ( ids , flag , newState ) ;
2013-02-18 22:45:14 -05:00
removeFlagForThreadsFromCache ( account , ids , flag ) ;
2013-01-11 20:28:12 -05:00
}
2012-12-05 23:25:41 -05:00
} catch ( MessagingException e ) {
Log . e ( K9 . LOG_TAG , " Couldn't set flags in local database " , e ) ;
}
2012-11-03 00:01:25 -04:00
2012-12-05 23:25:41 -05:00
// Read folder name and UID of messages from the database
Map < String , List < String > > folderMap ;
try {
2013-01-11 20:28:12 -05:00
folderMap = localStore . getFoldersAndUids ( ids , threadedList ) ;
2012-12-05 23:25:41 -05:00
} catch ( MessagingException e ) {
Log . e ( K9 . LOG_TAG , " Couldn't get folder name and UID of messages " , e ) ;
return ;
}
// Loop over all folders
for ( Entry < String , List < String > > entry : folderMap . entrySet ( ) ) {
String folderName = entry . getKey ( ) ;
2012-12-07 09:04:53 -05:00
// Notify listeners of changed folder status
LocalFolder localFolder = localStore . getFolder ( folderName ) ;
try {
int unreadMessageCount = localFolder . getUnreadMessageCount ( ) ;
for ( MessagingListener l : getListeners ( ) ) {
l . folderStatusChanged ( account , folderName , unreadMessageCount ) ;
}
} catch ( MessagingException e ) {
Log . w ( K9 . LOG_TAG , " Couldn't get unread count for folder: " + folderName , e ) ;
}
2012-12-05 23:25:41 -05:00
// The error folder is always a local folder
// TODO: Skip the remote part for all local-only folders
if ( account . getErrorFolderName ( ) . equals ( folderName ) ) {
continue ;
2012-11-03 00:01:25 -04:00
}
2012-12-05 23:25:41 -05:00
// Send flag change to server
String [ ] uids = entry . getValue ( ) . toArray ( EMPTY_STRING_ARRAY ) ;
queueSetFlag ( account , folderName , Boolean . toString ( newState ) , flag . toString ( ) , uids ) ;
processPendingCommands ( account ) ;
}
2009-11-26 00:30:13 -05:00
}
2009-12-06 19:56:06 -05:00
2012-02-04 08:52:45 -05:00
/ * *
* Set or remove a flag for a set of messages in a specific folder .
*
* < p >
* The { @link Message } objects passed in are updated to reflect the new flag state .
* < / p >
*
* @param account
* The account the folder containing the messages belongs to .
* @param folderName
* The name of the folder .
* @param messages
* The messages to change the flag for .
* @param flag
* The flag to change .
* @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 ,
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.
2009-11-29 11:55:35 -05:00
Folder localFolder = null ;
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
Store localStore = account . getLocalStore ( ) ;
2009-11-29 11:55:35 -05:00
localFolder = localStore . getFolder ( folderName ) ;
2008-11-01 17:32:06 -04:00
localFolder . open ( OpenMode . READ_WRITE ) ;
2012-02-04 08:52:45 -05:00
// Allows for re-allowing sending of messages that could not be sent
if ( flag = = Flag . FLAGGED & & ! newState & &
account . getOutboxFolderName ( ) . equals ( folderName ) ) {
for ( Message message : messages ) {
String uid = message . getUid ( ) ;
if ( uid ! = null ) {
sendCount . remove ( uid ) ;
}
2010-02-03 18:27:33 -05:00
}
2009-04-09 13:48:05 -04:00
}
2009-12-06 19:56:06 -05:00
2012-02-04 08:52:45 -05:00
// Update the messages in the local store
localFolder . setFlags ( messages , new Flag [ ] { flag } , newState ) ;
2009-05-11 00:39:03 -04:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
l . folderStatusChanged ( account , folderName , localFolder . getUnreadMessageCount ( ) ) ;
2009-11-24 19:40:29 -05:00
}
2009-05-11 00:39:03 -04:00
2012-02-04 08:52:45 -05:00
/ *
* Handle the remote side
* /
// The error folder is always a local folder
// TODO: Skip the remote part for all local-only folders
2011-02-06 17:09:48 -05:00
if ( account . getErrorFolderName ( ) . equals ( folderName ) ) {
2009-11-24 19:40:29 -05:00
return ;
}
2009-05-11 00:39:03 -04:00
2012-02-04 08:52:45 -05:00
String [ ] uids = new String [ messages . length ] ;
for ( int i = 0 , end = uids . length ; i < end ; i + + ) {
uids [ i ] = messages [ i ] . getUid ( ) ;
}
2009-11-29 11:55:35 -05:00
queueSetFlag ( account , folderName , Boolean . toString ( newState ) , flag . toString ( ) , uids ) ;
2008-11-01 17:32:06 -04:00
processPendingCommands ( account ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , me ) ;
2012-02-04 08:52:45 -05:00
throw new RuntimeException ( me ) ;
} finally {
closeFolder ( localFolder ) ;
}
}
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2012-02-04 08:52:45 -05:00
/ * *
* Set or remove a flag for a message referenced by message UID .
*
* @param account
* The account the folder containing the message belongs to .
* @param folderName
* The name of the folder .
2012-02-12 18:57:06 -05:00
* @param uid
* The UID of the message to change the flag for .
2012-02-04 08:52:45 -05:00
* @param flag
* The flag to change .
* @param newState
* { @code true } , if the flag should be set . { @code false } if it should be removed .
* /
public void setFlag ( Account account , String folderName , String uid , Flag flag ,
boolean newState ) {
Folder localFolder = null ;
try {
LocalStore localStore = account . getLocalStore ( ) ;
localFolder = localStore . getFolder ( folderName ) ;
localFolder . open ( OpenMode . READ_WRITE ) ;
Message message = localFolder . getMessage ( uid ) ;
2012-02-12 18:56:34 -05:00
if ( message ! = null ) {
setFlag ( account , folderName , new Message [ ] { message } , flag , newState ) ;
}
2012-02-04 08:52:45 -05:00
} catch ( MessagingException me ) {
addErrorMessage ( account , null , me ) ;
2008-11-01 17:32:06 -04:00
throw new RuntimeException ( me ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( localFolder ) ;
2009-11-29 11:55:35 -05:00
}
2012-02-04 08:52:45 -05:00
}
2009-05-11 00:39:03 -04:00
2011-02-06 17:09:48 -05:00
public void clearAllPending ( final Account account ) {
try {
2009-12-14 21:50:53 -05:00
Log . w ( K9 . LOG_TAG , " Clearing pending commands! " ) ;
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
2009-11-24 19:40:29 -05:00
localStore . removePendingCommands ( ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Unable to clear pending command " , me ) ;
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , me ) ;
2009-11-24 19:40:29 -05:00
}
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
}
2008-11-01 17:32:06 -04:00
2010-07-18 21:52:59 -04:00
public void loadMessageForViewRemote ( final Account account , final String folder ,
2011-02-06 17:09:48 -05:00
final String uid , final MessagingListener listener ) {
put ( " loadMessageForViewRemote " , listener , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2012-03-09 05:27:59 -05:00
loadMessageForViewRemoteSynchronous ( account , folder , uid , listener , false , false ) ;
}
} ) ;
}
2008-11-01 17:32:06 -04:00
2012-03-09 05:27:59 -05:00
public boolean loadMessageForViewRemoteSynchronous ( final Account account , final String folder ,
final String uid , final MessagingListener listener , final boolean force ,
final boolean loadPartialFromSearch ) {
Folder remoteFolder = null ;
LocalFolder localFolder = null ;
try {
LocalStore localStore = account . getLocalStore ( ) ;
localFolder = localStore . getFolder ( folder ) ;
localFolder . open ( OpenMode . READ_WRITE ) ;
2008-11-01 17:32:06 -04:00
2012-03-09 05:27:59 -05:00
Message message = localFolder . getMessage ( uid ) ;
2008-11-01 17:32:06 -04:00
2012-03-09 05:27:59 -05:00
if ( uid . startsWith ( K9 . LOCAL_UID_PREFIX ) ) {
Log . w ( K9 . LOG_TAG , " Message has local UID so cannot download fully. " ) ;
// ASH move toast
android . widget . Toast . makeText ( mApplication ,
" Message has local UID so cannot download fully " ,
android . widget . Toast . LENGTH_LONG ) . show ( ) ;
// TODO: Using X_DOWNLOADED_FULL is wrong because it's only a partial message. But
// one we can't download completely. Maybe add a new flag; X_PARTIAL_MESSAGE ?
message . setFlag ( Flag . X_DOWNLOADED_FULL , true ) ;
message . setFlag ( Flag . X_DOWNLOADED_PARTIAL , false ) ;
}
/ * commented out because this was pulled from another unmerged branch :
} else if ( localFolder . isLocalOnly ( ) & & ! force ) {
Log . w ( K9 . LOG_TAG , " Message in local-only folder so cannot download fully. " ) ;
// ASH move toast
android . widget . Toast . makeText ( mApplication ,
" Message in local-only folder so cannot download fully " ,
android . widget . Toast . LENGTH_LONG ) . show ( ) ;
message . setFlag ( Flag . X_DOWNLOADED_FULL , true ) ;
message . setFlag ( Flag . X_DOWNLOADED_PARTIAL , false ) ;
} * /
if ( message . isSet ( Flag . X_DOWNLOADED_FULL ) ) {
/ *
* If the message has been synchronized since we were called we ' ll
* just hand it back cause it ' s ready to go .
* /
FetchProfile fp = new FetchProfile ( ) ;
fp . add ( FetchProfile . Item . ENVELOPE ) ;
fp . add ( FetchProfile . Item . BODY ) ;
localFolder . fetch ( new Message [ ] { message } , fp , null ) ;
} else {
/ *
* At this point the message is not available , so we need to download it
* fully if possible .
* /
2008-11-01 17:32:06 -04:00
2012-03-09 05:27:59 -05:00
Store remoteStore = account . getRemoteStore ( ) ;
remoteFolder = remoteStore . getFolder ( folder ) ;
remoteFolder . open ( OpenMode . READ_WRITE ) ;
2010-07-18 21:52:59 -04:00
2012-03-09 05:27:59 -05:00
// Get the remote message and fully download it
Message remoteMessage = remoteFolder . getMessage ( uid ) ;
FetchProfile fp = new FetchProfile ( ) ;
fp . add ( FetchProfile . Item . BODY ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2012-03-09 05:27:59 -05:00
remoteFolder . fetch ( new Message [ ] { remoteMessage } , fp , null ) ;
// Store the message locally and load the stored message into memory
localFolder . appendMessages ( new Message [ ] { remoteMessage } ) ;
if ( loadPartialFromSearch ) {
fp . add ( FetchProfile . Item . BODY ) ;
2010-11-28 15:28:58 -05:00
}
2012-03-09 05:27:59 -05:00
fp . add ( FetchProfile . Item . ENVELOPE ) ;
message = localFolder . getMessage ( uid ) ;
localFolder . fetch ( new Message [ ] { message } , fp , null ) ;
// Mark that this message is now fully synched
if ( account . isMarkMessageAsReadOnView ( ) ) {
message . setFlag ( Flag . SEEN , true ) ;
}
message . setFlag ( Flag . X_DOWNLOADED_FULL , true ) ;
}
// now that we have the full message, refresh the headers
for ( MessagingListener l : getListeners ( listener ) ) {
l . loadMessageForViewHeadersAvailable ( account , folder , uid , message ) ;
}
for ( MessagingListener l : getListeners ( listener ) ) {
l . loadMessageForViewBodyAvailable ( account , folder , uid , message ) ;
}
for ( MessagingListener l : getListeners ( listener ) ) {
l . loadMessageForViewFinished ( account , folder , uid , message ) ;
}
return true ;
} catch ( Exception e ) {
for ( MessagingListener l : getListeners ( listener ) ) {
l . loadMessageForViewFailed ( account , folder , uid , e ) ;
}
2013-01-17 09:24:22 -05:00
notifyUserIfCertificateProblem ( mApplication , e , account , true ) ;
2012-03-09 05:27:59 -05:00
addErrorMessage ( account , null , e ) ;
return false ;
} finally {
closeFolder ( remoteFolder ) ;
closeFolder ( localFolder ) ;
}
2008-11-01 17:32:06 -04:00
}
public void loadMessageForView ( final Account account , final String folder , final String uid ,
2011-02-06 17:09:48 -05:00
final MessagingListener listener ) {
for ( MessagingListener l : getListeners ( listener ) ) {
2008-11-01 17:32:06 -04:00
l . loadMessageForViewStarted ( account , folder , uid ) ;
}
2011-02-06 17:09:48 -05:00
threadPool . execute ( new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
LocalFolder localFolder = localStore . getFolder ( folder ) ;
2009-10-19 15:35:31 -04:00
localFolder . open ( OpenMode . READ_WRITE ) ;
2009-11-24 19:40:29 -05:00
2012-03-05 15:04:34 -05:00
LocalMessage message = localFolder . getMessage ( uid ) ;
2011-02-06 17:09:48 -05:00
if ( message = = null
| | message . getId ( ) = = 0 ) {
2009-11-20 19:11:57 -05:00
throw new IllegalArgumentException ( " Message not found: folder= " + folder + " , uid= " + uid ) ;
}
2012-03-09 05:27:59 -05:00
// IMAP search results will usually need to be downloaded before viewing.
// TODO: limit by account.getMaximumAutoDownloadMessageSize().
if ( ! message . isSet ( Flag . X_DOWNLOADED_FULL ) & &
! message . isSet ( Flag . X_DOWNLOADED_PARTIAL ) ) {
if ( loadMessageForViewRemoteSynchronous ( account , folder , uid , listener ,
false , true ) ) {
2012-12-05 23:25:41 -05:00
2013-02-06 11:37:00 -05:00
markMessageAsReadOnView ( account , message ) ;
2012-03-09 05:27:59 -05:00
}
return ;
}
2013-02-06 11:37:00 -05:00
markMessageAsReadOnView ( account , message ) ;
2010-04-25 12:33:32 -04:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
2009-10-19 15:35:31 -04:00
l . loadMessageForViewHeadersAvailable ( account , folder , uid , message ) ;
}
2009-11-24 19:40:29 -05:00
2009-10-19 15:35:31 -04:00
FetchProfile fp = new FetchProfile ( ) ;
fp . add ( FetchProfile . Item . ENVELOPE ) ;
fp . add ( FetchProfile . Item . BODY ) ;
2011-02-06 17:09:48 -05:00
localFolder . fetch ( new Message [ ] {
2009-11-26 00:10:12 -05:00
message
} , fp , null ) ;
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
localFolder . close ( ) ;
2010-04-29 00:59:14 -04:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
2009-10-19 15:35:31 -04:00
l . loadMessageForViewBodyAvailable ( account , folder , uid , message ) ;
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( listener ) ) {
2009-10-19 15:35:31 -04:00
l . loadMessageForViewFinished ( account , folder , uid , message ) ;
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
for ( MessagingListener l : getListeners ( listener ) ) {
2009-10-19 15:35:31 -04:00
l . loadMessageForViewFailed ( account , folder , uid , e ) ;
}
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , e ) ;
2009-11-24 19:40:29 -05:00
2009-10-19 15:35:31 -04:00
}
}
2010-10-02 03:45:11 -04:00
} ) ;
2008-11-01 17:32:06 -04:00
}
2013-02-06 11:37:00 -05:00
/ * *
* Mark the provided message as read if not disabled by the account setting .
*
* @param account
* The account the message belongs to .
* @param message
* The message to mark as read . This { @link Message } instance will be modify by calling
* { @link Message # setFlag ( Flag , boolean ) } on it .
*
* @throws MessagingException
*
* @see Account # isMarkMessageAsReadOnView ( )
* /
private void markMessageAsReadOnView ( Account account , Message message )
throws MessagingException {
if ( account . isMarkMessageAsReadOnView ( ) & & ! message . isSet ( Flag . SEEN ) ) {
message . setFlag ( Flag . SEEN , true ) ;
setFlagSynchronous ( account , Collections . singletonList ( Long . valueOf ( message . getId ( ) ) ) ,
Flag . SEEN , true , false ) ;
}
}
2008-11-01 17:32:06 -04:00
/ * *
* Attempts to load the attachment specified by part from the given account and message .
* @param account
* @param message
* @param part
* @param listener
* /
public void loadAttachment (
2009-11-24 19:40:29 -05:00
final Account account ,
final Message message ,
final Part part ,
final Object tag ,
2011-02-06 17:09:48 -05:00
final MessagingListener listener ) {
2008-11-01 17:32:06 -04:00
/ *
* Check if the attachment has already been downloaded . If it has there ' s no reason to
* download it , so we just tell the listener that it ' s ready to go .
* /
2010-11-30 22:02:13 -05:00
2011-02-06 17:09:48 -05:00
if ( part . getBody ( ) ! = null ) {
2011-07-09 00:27:56 -04:00
for ( MessagingListener l : getListeners ( listener ) ) {
2010-12-01 01:32:29 -05:00
l . loadAttachmentStarted ( account , message , part , tag , false ) ;
}
2008-11-01 17:32:06 -04:00
2011-07-09 00:27:56 -04:00
for ( MessagingListener l : getListeners ( listener ) ) {
2010-12-01 01:32:29 -05:00
l . loadAttachmentFinished ( account , message , part , tag ) ;
}
return ;
}
2010-11-30 22:02:13 -05:00
2008-11-01 17:32:06 -04:00
2011-07-09 00:27:56 -04:00
for ( MessagingListener l : getListeners ( listener ) ) {
2008-11-01 17:32:06 -04:00
l . loadAttachmentStarted ( account , message , part , tag , true ) ;
}
2011-02-06 17:09:48 -05:00
put ( " loadAttachment " , listener , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2010-01-16 11:22:20 -05:00
Folder remoteFolder = null ;
LocalFolder localFolder = null ;
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
2012-02-13 17:11:59 -05:00
List < Part > attachments = MimeUtility . collectAttachments ( message ) ;
2011-02-06 17:09:48 -05:00
for ( Part attachment : attachments ) {
2008-11-01 17:32:06 -04:00
attachment . setBody ( null ) ;
}
2010-03-03 23:00:30 -05:00
Store remoteStore = account . getRemoteStore ( ) ;
localFolder = localStore . getFolder ( message . getFolder ( ) . getName ( ) ) ;
2010-01-16 11:22:20 -05:00
remoteFolder = remoteStore . getFolder ( message . getFolder ( ) . getName ( ) ) ;
2008-11-01 17:32:06 -04:00
remoteFolder . open ( OpenMode . READ_WRITE ) ;
2010-05-19 09:31:48 -04:00
//FIXME: This is an ugly hack that won't be needed once the Message objects have been united.
Message remoteMessage = remoteFolder . getMessage ( message . getUid ( ) ) ;
remoteMessage . setBody ( message . getBody ( ) ) ;
remoteFolder . fetchPart ( remoteMessage , part , null ) ;
2008-11-01 17:32:06 -04:00
localFolder . updateMessage ( ( LocalMessage ) message ) ;
2011-07-09 00:27:56 -04:00
for ( MessagingListener l : getListeners ( listener ) ) {
2008-11-01 17:32:06 -04:00
l . loadAttachmentFinished ( account , message , part , tag ) ;
}
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
2010-02-06 00:35:15 -05:00
Log . v ( K9 . LOG_TAG , " Exception loading attachment " , me ) ;
2010-01-02 20:50:41 -05:00
2011-07-09 00:27:56 -04:00
for ( MessagingListener l : getListeners ( listener ) ) {
2008-11-01 17:32:06 -04:00
l . loadAttachmentFailed ( account , message , part , tag , me . getMessage ( ) ) ;
}
2013-01-17 09:24:22 -05:00
notifyUserIfCertificateProblem ( mApplication , me , account , true ) ;
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , me ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( localFolder ) ;
closeFolder ( remoteFolder ) ;
2010-01-16 11:22:20 -05:00
}
2008-11-01 17:32:06 -04:00
}
} ) ;
}
/ * *
* Stores the given message in the Outbox and starts a sendPendingMessages command to
* attempt to send the message .
* @param account
* @param message
* @param listener
* /
public void sendMessage ( final Account account ,
2009-11-24 19:40:29 -05:00
final Message message ,
2011-02-06 17:09:48 -05:00
MessagingListener listener ) {
try {
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
LocalFolder localFolder = localStore . getFolder ( account . getOutboxFolderName ( ) ) ;
2008-11-01 17:32:06 -04:00
localFolder . open ( OpenMode . READ_WRITE ) ;
2010-11-28 15:29:02 -05:00
localFolder . appendMessages ( new Message [ ] { message } ) ;
2008-11-01 17:32:06 -04:00
Message localMessage = localFolder . getMessage ( message . getUid ( ) ) ;
localMessage . setFlag ( Flag . X_DOWNLOADED_FULL , true ) ;
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
localFolder . close ( ) ;
2010-09-20 07:47:02 -04:00
sendPendingMessages ( account , listener ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2010-04-16 08:20:10 -04:00
/ *
2009-11-24 19:40:29 -05:00
for ( MessagingListener l : getListeners ( ) )
{
2008-11-01 17:32:06 -04:00
// TODO general failed
}
2010-04-16 08:20:10 -04:00
* /
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , e ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2008-11-01 17:32:06 -04:00
}
}
2010-10-24 23:18:51 -04:00
2011-02-06 17:09:48 -05:00
public void sendPendingMessages ( MessagingListener listener ) {
2010-10-24 23:18:51 -04:00
final Preferences prefs = Preferences . getPreferences ( mApplication . getApplicationContext ( ) ) ;
2011-10-17 23:09:20 -04:00
for ( Account account : prefs . getAvailableAccounts ( ) ) {
2010-10-24 23:18:51 -04:00
sendPendingMessages ( account , listener ) ;
}
}
2008-11-01 17:32:06 -04:00
/ * *
* Attempt to send any messages that are sitting in the Outbox .
* @param account
* @param listener
* /
public void sendPendingMessages ( final Account account ,
2011-02-06 17:09:48 -05:00
MessagingListener listener ) {
putBackground ( " sendPendingMessages " , listener , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
if ( ! account . isAvailable ( mApplication ) ) {
2010-11-13 16:40:56 -05:00
throw new UnavailableAccountException ( ) ;
}
2011-02-06 17:09:48 -05:00
if ( messagesPendingSend ( account ) ) {
2010-10-24 23:19:19 -04:00
2010-11-28 15:29:02 -05:00
notifyWhileSending ( account ) ;
2011-02-06 17:09:48 -05:00
try {
2010-10-24 23:19:19 -04:00
sendPendingMessagesSynchronous ( account ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:29:02 -05:00
notifyWhileSendingDone ( account ) ;
2010-10-24 23:19:19 -04:00
}
}
2008-11-01 17:32:06 -04:00
}
} ) ;
}
2011-02-06 17:09:48 -05:00
private void cancelNotification ( int id ) {
2010-11-28 15:29:02 -05:00
NotificationManager notifMgr =
2012-05-04 16:03:35 -04:00
( NotificationManager ) mApplication . getSystemService ( Context . NOTIFICATION_SERVICE ) ;
2010-11-28 15:29:02 -05:00
notifMgr . cancel ( id ) ;
}
2011-02-06 17:09:48 -05:00
private void notifyWhileSendingDone ( Account account ) {
if ( account . isShowOngoing ( ) ) {
2010-11-28 15:29:02 -05:00
cancelNotification ( K9 . FETCHING_EMAIL_NOTIFICATION - account . getAccountNumber ( ) ) ;
}
}
2012-05-04 16:03:35 -04:00
/ * *
* Display an ongoing notification while a message is being sent .
*
* @param account
* The account the message is sent from . Never { @code null } .
* /
2011-02-06 17:09:48 -05:00
private void notifyWhileSending ( Account account ) {
if ( ! account . isShowOngoing ( ) ) {
2010-11-28 15:29:02 -05:00
return ;
}
2012-05-04 16:03:35 -04:00
2010-11-28 15:29:02 -05:00
NotificationManager notifMgr =
2012-05-04 16:03:35 -04:00
( NotificationManager ) mApplication . getSystemService ( Context . NOTIFICATION_SERVICE ) ;
2013-02-20 17:55:46 -05:00
NotificationCompat . Builder builder = new NotificationBuilder ( mApplication ) ;
2013-02-10 19:27:07 -05:00
builder . setSmallIcon ( R . drawable . ic_notify_check_mail ) ;
2012-05-04 16:03:35 -04:00
builder . setWhen ( System . currentTimeMillis ( ) ) ;
builder . setOngoing ( true ) ;
builder . setTicker ( mApplication . getString ( R . string . notification_bg_send_ticker ,
account . getDescription ( ) ) ) ;
builder . setContentTitle ( mApplication . getString ( R . string . notification_bg_send_title ) ) ;
builder . setContentText ( account . getDescription ( ) ) ;
2012-10-13 15:06:57 -04:00
LocalSearch search = new LocalSearch ( account . getInboxFolderName ( ) ) ;
search . addAllowedFolder ( account . getInboxFolderName ( ) ) ;
search . addAccountUuid ( account . getUuid ( ) ) ;
2012-10-23 23:28:38 -04:00
Intent intent = MessageList . intentDisplaySearch ( mApplication , search , false , true , true ) ;
2012-10-16 16:42:51 -04:00
2010-11-28 15:29:02 -05:00
PendingIntent pi = PendingIntent . getActivity ( mApplication , 0 , intent , 0 ) ;
2012-05-04 16:03:35 -04:00
builder . setContentIntent ( pi ) ;
2010-11-28 15:29:02 -05:00
2011-02-06 17:09:48 -05:00
if ( K9 . NOTIFICATION_LED_WHILE_SYNCING ) {
2012-05-04 16:03:35 -04:00
configureNotification ( builder , null , null ,
account . getNotificationSetting ( ) . getLedColor ( ) ,
K9 . NOTIFICATION_LED_BLINK_FAST , true ) ;
2010-11-28 15:29:02 -05:00
}
2012-05-04 16:03:35 -04:00
notifMgr . notify ( K9 . FETCHING_EMAIL_NOTIFICATION - account . getAccountNumber ( ) ,
2013-01-03 03:39:02 -05:00
builder . build ( ) ) ;
2010-11-28 15:29:02 -05:00
}
2009-11-17 22:06:23 -05:00
2011-03-09 22:41:09 -05:00
private void notifySendTempFailed ( Account account , Exception lastFailure ) {
notifySendFailed ( account , lastFailure , account . getOutboxFolderName ( ) ) ;
}
2012-05-04 16:03:35 -04:00
2011-03-09 22:41:09 -05:00
private void notifySendPermFailed ( Account account , Exception lastFailure ) {
notifySendFailed ( account , lastFailure , account . getDraftsFolderName ( ) ) ;
}
2012-05-04 16:03:35 -04:00
/ * *
* Display a notification when sending a message has failed .
*
* @param account
* The account that was used to sent the message .
* @param lastFailure
* The { @link Exception } instance that indicated sending the message has failed .
* @param openFolder
* The name of the folder to open when the notification is clicked .
* /
2011-03-09 22:41:09 -05:00
private void notifySendFailed ( Account account , Exception lastFailure , String openFolder ) {
2012-05-04 16:03:35 -04:00
NotificationManager notifMgr =
( NotificationManager ) mApplication . getSystemService ( Context . NOTIFICATION_SERVICE ) ;
2010-11-28 15:29:05 -05:00
2013-02-20 17:55:46 -05:00
NotificationCompat . Builder builder = new NotificationBuilder ( mApplication ) ;
2012-05-04 16:03:35 -04:00
builder . setSmallIcon ( R . drawable . stat_notify_email_generic ) ;
builder . setWhen ( System . currentTimeMillis ( ) ) ;
builder . setAutoCancel ( true ) ;
builder . setTicker ( mApplication . getString ( R . string . send_failure_subject ) ) ;
builder . setContentTitle ( mApplication . getString ( R . string . send_failure_subject ) ) ;
builder . setContentText ( getRootCauseMessage ( lastFailure ) ) ;
2010-11-28 15:29:05 -05:00
2012-05-04 16:03:35 -04:00
Intent i = FolderList . actionHandleNotification ( mApplication , account , openFolder ) ;
2010-11-28 15:29:05 -05:00
PendingIntent pi = PendingIntent . getActivity ( mApplication , 0 , i , 0 ) ;
2012-05-04 16:03:35 -04:00
builder . setContentIntent ( pi ) ;
2010-11-28 15:29:05 -05:00
2013-01-08 18:16:26 -05:00
configureNotification ( builder , null , null , K9 . NOTIFICATION_LED_FAILURE_COLOR ,
2012-05-04 16:03:35 -04:00
K9 . NOTIFICATION_LED_BLINK_FAST , true ) ;
2010-11-28 15:29:05 -05:00
2012-05-04 16:03:35 -04:00
notifMgr . notify ( K9 . SEND_FAILED_NOTIFICATION - account . getAccountNumber ( ) ,
2013-01-03 03:39:02 -05:00
builder . build ( ) ) ;
2010-11-28 15:29:05 -05:00
}
2012-05-04 16:03:35 -04:00
/ * *
* Display an ongoing notification while checking for new messages on the server .
*
* @param account
* The account that is checked for new messages . Never { @code null } .
* @param folder
* The folder that is being checked for new messages . Never { @code null } .
* /
2011-02-06 17:09:48 -05:00
private void notifyFetchingMail ( final Account account , final Folder folder ) {
2012-05-04 16:03:35 -04:00
if ( ! account . isShowOngoing ( ) ) {
return ;
}
final NotificationManager notifMgr =
( NotificationManager ) mApplication . getSystemService ( Context . NOTIFICATION_SERVICE ) ;
2013-02-20 17:55:46 -05:00
NotificationCompat . Builder builder = new NotificationBuilder ( mApplication ) ;
2013-02-10 19:27:07 -05:00
builder . setSmallIcon ( R . drawable . ic_notify_check_mail ) ;
2012-05-04 16:03:35 -04:00
builder . setWhen ( System . currentTimeMillis ( ) ) ;
builder . setOngoing ( true ) ;
builder . setTicker ( mApplication . getString (
R . string . notification_bg_sync_ticker , account . getDescription ( ) , folder . getName ( ) ) ) ;
builder . setContentTitle ( mApplication . getString ( R . string . notification_bg_sync_title ) ) ;
builder . setContentText ( account . getDescription ( ) +
mApplication . getString ( R . string . notification_bg_title_separator ) +
folder . getName ( ) ) ;
2012-10-13 15:06:57 -04:00
LocalSearch search = new LocalSearch ( account . getInboxFolderName ( ) ) ;
search . addAllowedFolder ( account . getInboxFolderName ( ) ) ;
search . addAccountUuid ( account . getUuid ( ) ) ;
2012-10-23 23:28:38 -04:00
Intent intent = MessageList . intentDisplaySearch ( mApplication , search , false , true , true ) ;
2012-10-16 16:42:51 -04:00
2012-05-04 16:03:35 -04:00
PendingIntent pi = PendingIntent . getActivity ( mApplication , 0 , intent , 0 ) ;
builder . setContentIntent ( pi ) ;
if ( K9 . NOTIFICATION_LED_WHILE_SYNCING ) {
configureNotification ( builder , null , null ,
account . getNotificationSetting ( ) . getLedColor ( ) ,
K9 . NOTIFICATION_LED_BLINK_FAST , true ) ;
2010-11-28 15:29:05 -05:00
}
2012-05-04 16:03:35 -04:00
notifMgr . notify ( K9 . FETCHING_EMAIL_NOTIFICATION - account . getAccountNumber ( ) ,
2013-01-03 03:39:02 -05:00
builder . build ( ) ) ;
2010-11-28 15:29:05 -05:00
}
2012-05-04 16:03:35 -04:00
2011-02-06 17:09:48 -05:00
private void notifyFetchingMailCancel ( final Account account ) {
if ( account . isShowOngoing ( ) ) {
2010-11-28 15:29:05 -05:00
cancelNotification ( K9 . FETCHING_EMAIL_NOTIFICATION - account . getAccountNumber ( ) ) ;
}
}
2011-02-06 17:09:48 -05:00
public boolean messagesPendingSend ( final Account account ) {
2010-01-16 11:22:20 -05:00
Folder localFolder = null ;
2011-02-06 17:09:48 -05:00
try {
2010-11-13 19:49:21 -05:00
localFolder = account . getLocalStore ( ) . getFolder (
2009-11-24 19:40:29 -05:00
account . getOutboxFolderName ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( ! localFolder . exists ( ) ) {
2009-11-17 22:06:23 -05:00
return false ;
}
localFolder . open ( OpenMode . READ_WRITE ) ;
2011-02-06 17:09:48 -05:00
if ( localFolder . getMessageCount ( ) > 0 ) {
2009-11-24 19:40:29 -05:00
return true ;
}
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Exception while checking for unsent messages " , e ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( localFolder ) ;
2010-01-16 11:22:20 -05:00
}
2009-11-24 19:40:29 -05:00
return false ;
}
2009-11-17 22:06:23 -05:00
2008-11-01 17:32:06 -04:00
/ * *
* Attempt to send any messages that are sitting in the Outbox .
* @param account
* /
2011-02-06 17:09:48 -05:00
public void sendPendingMessagesSynchronous ( final Account account ) {
2009-10-21 20:41:06 -04:00
Folder localFolder = null ;
2010-12-18 20:30:07 -05:00
Exception lastFailure = null ;
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
Store localStore = account . getLocalStore ( ) ;
2009-10-21 20:41:06 -04:00
localFolder = localStore . getFolder (
2009-11-24 19:40:29 -05:00
account . getOutboxFolderName ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( ! localFolder . exists ( ) ) {
2008-11-01 17:32:06 -04:00
return ;
}
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2009-11-24 19:40:29 -05:00
l . sendPendingMessagesStarted ( account ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
}
2008-11-01 17:32:06 -04:00
localFolder . open ( OpenMode . READ_WRITE ) ;
Message [ ] localMessages = localFolder . getMessages ( null ) ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
int progress = 0 ;
int todo = localMessages . length ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
l . synchronizeMailboxProgress ( account , account . getSentFolderName ( ) , progress , todo ) ;
}
2008-11-01 17:32:06 -04:00
/ *
* The profile we will use to pull all of the content
* for a given local message into memory for sending .
* /
FetchProfile fp = new FetchProfile ( ) ;
fp . add ( FetchProfile . Item . ENVELOPE ) ;
fp . add ( FetchProfile . Item . BODY ) ;
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Scanning folder ' " + account . getOutboxFolderName ( ) + " ' ( " + ( ( LocalFolder ) localFolder ) . getId ( ) + " ) for messages to send " ) ;
2010-03-03 23:00:30 -05:00
Transport transport = Transport . getInstance ( account ) ;
2011-02-06 17:09:48 -05:00
for ( Message message : localMessages ) {
if ( message . isSet ( Flag . DELETED ) ) {
2010-11-12 16:38:02 -05:00
message . destroy ( ) ;
2009-11-24 19:40:29 -05:00
continue ;
}
2011-02-06 17:09:48 -05:00
try {
2009-11-24 19:40:29 -05:00
AtomicInteger count = new AtomicInteger ( 0 ) ;
AtomicInteger oldCount = sendCount . putIfAbsent ( message . getUid ( ) , count ) ;
2011-02-06 17:09:48 -05:00
if ( oldCount ! = null ) {
2009-11-24 19:40:29 -05:00
count = oldCount ;
}
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Send count for message " + message . getUid ( ) + " is " + count . get ( ) ) ;
2009-11-24 19:40:29 -05:00
2011-03-09 22:42:54 -05:00
if ( count . incrementAndGet ( ) > K9 . MAX_SEND_ATTEMPTS ) {
2011-03-22 03:07:32 -04:00
Log . e ( K9 . LOG_TAG , " Send count for message " + message . getUid ( ) + " can't be delivered after " + K9 . MAX_SEND_ATTEMPTS + " attempts. Giving up until the user restarts the device " ) ;
2011-03-09 22:42:54 -05:00
notifySendTempFailed ( account , new MessagingException ( message . getSubject ( ) ) ) ;
continue ;
}
2008-11-01 17:32:06 -04:00
localFolder . fetch ( new Message [ ] { message } , fp , null ) ;
2011-02-06 17:09:48 -05:00
try {
2011-04-17 07:07:13 -04:00
if ( message . getHeader ( K9 . IDENTITY_HEADER ) ! = null ) {
Log . v ( K9 . LOG_TAG , " The user has set the Outbox and Drafts folder to the same thing. " +
" This message appears to be a draft, so K-9 will not send it " ) ;
continue ;
}
2008-11-01 17:32:06 -04:00
message . setFlag ( Flag . X_SEND_IN_PROGRESS , true ) ;
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Sending message with UID " + message . getUid ( ) ) ;
2008-11-01 17:32:06 -04:00
transport . sendMessage ( message ) ;
message . setFlag ( Flag . X_SEND_IN_PROGRESS , false ) ;
2009-01-24 13:52:58 -05:00
message . setFlag ( Flag . SEEN , true ) ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
progress + + ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
l . synchronizeMailboxProgress ( account , account . getSentFolderName ( ) , progress , todo ) ;
}
2012-04-11 03:19:18 -04:00
if ( ! account . hasSentFolder ( ) ) {
2010-02-08 22:03:40 -05:00
if ( K9 . DEBUG )
2012-04-11 03:19:18 -04:00
Log . i ( K9 . LOG_TAG , " Account does not have a sent mail folder; deleting sent message " ) ;
2010-02-08 22:03:40 -05:00
message . setFlag ( Flag . DELETED , true ) ;
2011-02-06 17:09:48 -05:00
} else {
LocalFolder localSentFolder = ( LocalFolder ) localStore . getFolder ( account . getSentFolderName ( ) ) ;
2010-02-08 22:03:40 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Moving sent message to folder ' " + account . getSentFolderName ( ) + " ' ( " + localSentFolder . getId ( ) + " ) " ) ;
2010-04-29 00:59:14 -04:00
2011-02-06 17:09:48 -05:00
localFolder . moveMessages ( new Message [ ] { message } , localSentFolder ) ;
2010-04-29 00:59:14 -04:00
2010-02-08 22:03:40 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Moved sent message to folder ' " + account . getSentFolderName ( ) + " ' ( " + localSentFolder . getId ( ) + " ) " ) ;
2010-04-29 00:59:14 -04:00
2010-02-08 22:03:40 -05:00
PendingCommand command = new PendingCommand ( ) ;
command . command = PENDING_COMMAND_APPEND ;
2010-11-12 20:47:02 -05:00
command . arguments = new String [ ] { localSentFolder . getName ( ) , message . getUid ( ) } ;
2010-02-08 22:03:40 -05:00
queuePendingCommand ( account , command ) ;
processPendingCommands ( account ) ;
}
2010-04-29 00:59:14 -04:00
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2011-03-09 22:41:44 -05:00
// 5.x.x errors from the SMTP server are "PERMFAIL"
// move the message over to drafts rather than leaving it in the outbox
// 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 ( ) ) ) ;
}
2013-01-17 09:24:22 -05:00
notifyUserIfCertificateProblem ( mApplication , e , account , false ) ;
2008-11-01 17:32:06 -04:00
message . setFlag ( Flag . X_SEND_FAILED , true ) ;
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Failed to send message " , e ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
l . synchronizeMailboxFailed ( account , localFolder . getName ( ) , getRootCauseMessage ( e ) ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
}
2010-11-12 20:47:02 -05:00
lastFailure = e ;
2008-11-01 17:32:06 -04:00
}
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Failed to fetch message for sending " , e ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
l . synchronizeMailboxFailed ( account , localFolder . getName ( ) , getRootCauseMessage ( e ) ) ;
2009-11-24 19:40:29 -05:00
}
2010-11-12 20:47:02 -05:00
lastFailure = e ;
2008-11-01 17:32:06 -04:00
}
}
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2008-11-01 17:32:06 -04:00
l . sendPendingMessagesCompleted ( account ) ;
}
2011-02-06 17:09:48 -05:00
if ( lastFailure ! = null ) {
2011-03-09 22:41:44 -05:00
if ( getRootCauseMessage ( lastFailure ) . startsWith ( " 5 " ) ) {
notifySendPermFailed ( account , lastFailure ) ;
} else {
notifySendTempFailed ( account , lastFailure ) ;
}
2009-11-24 19:40:29 -05:00
}
2011-02-06 17:09:48 -05:00
} catch ( UnavailableStorageException e ) {
2010-11-13 16:40:56 -05:00
Log . i ( K9 . LOG_TAG , " Failed to send pending messages because storage is not available - trying again later. " ) ;
throw new UnavailableAccountException ( e ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
for ( MessagingListener l : getListeners ( ) ) {
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
l . sendPendingMessagesFailed ( account ) ;
2008-11-01 17:32:06 -04:00
}
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , e ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2011-02-06 17:09:48 -05:00
} finally {
if ( lastFailure = = null ) {
2010-12-18 20:30:11 -05:00
cancelNotification ( K9 . SEND_FAILED_NOTIFICATION - account . getAccountNumber ( ) ) ;
}
2010-11-28 15:28:58 -05:00
closeFolder ( localFolder ) ;
2009-10-21 20:41:06 -04:00
}
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -05:00
2010-04-16 23:32:17 -04:00
public void getAccountStats ( final Context context , final Account account ,
2012-12-06 23:29:05 -05:00
final MessagingListener listener ) {
threadPool . execute ( new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
try {
2010-04-16 10:33:54 -04:00
AccountStats stats = account . getStats ( context ) ;
2012-12-06 23:29:05 -05:00
listener . accountStatusChanged ( account , stats ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2012-12-06 23:29:05 -05:00
Log . e ( K9 . LOG_TAG , " Count not get unread count for account " +
account . getDescription ( ) , me ) ;
2009-11-24 19:40:29 -05:00
}
2010-04-29 00:59:14 -04:00
2009-11-24 19:40:29 -05:00
}
2012-12-06 23:29:05 -05:00
} ) ;
}
public void getSearchAccountStats ( final SearchAccount searchAccount ,
final MessagingListener listener ) {
threadPool . execute ( new Runnable ( ) {
@Override
public void run ( ) {
2012-12-08 12:15:34 -05:00
getSearchAccountStatsSynchronous ( searchAccount , listener ) ;
}
} ) ;
}
2009-11-24 19:40:29 -05:00
2012-12-08 12:15:34 -05:00
public AccountStats getSearchAccountStatsSynchronous ( final SearchAccount searchAccount ,
final MessagingListener listener ) {
2012-12-06 23:29:05 -05:00
2012-12-08 12:15:34 -05:00
Preferences preferences = Preferences . getPreferences ( mApplication ) ;
LocalSearch search = searchAccount . getRelatedSearch ( ) ;
2012-12-06 23:29:05 -05:00
2012-12-08 12:15:34 -05:00
// Collect accounts that belong to the search
String [ ] accountUuids = search . getAccountUuids ( ) ;
Account [ ] accounts ;
if ( search . searchAllAccounts ( ) ) {
accounts = preferences . getAccounts ( ) ;
} else {
accounts = new Account [ accountUuids . length ] ;
for ( int i = 0 , len = accountUuids . length ; i < len ; i + + ) {
String accountUuid = accountUuids [ i ] ;
accounts [ i ] = preferences . getAccount ( accountUuid ) ;
}
}
2012-12-06 23:29:05 -05:00
2012-12-08 12:15:34 -05:00
ContentResolver cr = mApplication . getContentResolver ( ) ;
2012-12-06 23:29:05 -05:00
2012-12-08 12:15:34 -05:00
int unreadMessageCount = 0 ;
int flaggedMessageCount = 0 ;
2012-12-06 23:29:05 -05:00
2012-12-08 12:15:34 -05:00
String [ ] projection = {
StatsColumns . UNREAD_COUNT ,
StatsColumns . FLAGGED_COUNT
} ;
2012-12-06 23:29:05 -05:00
2012-12-08 12:15:34 -05:00
for ( Account account : accounts ) {
StringBuilder query = new StringBuilder ( ) ;
List < String > queryArgs = new ArrayList < String > ( ) ;
ConditionsTreeNode conditions = search . getConditions ( ) ;
SqlQueryBuilder . buildWhereClause ( account , conditions , query , queryArgs ) ;
String selection = query . toString ( ) ;
String [ ] selectionArgs = queryArgs . toArray ( EMPTY_STRING_ARRAY ) ;
2012-12-06 23:29:05 -05:00
2012-12-08 12:15:34 -05:00
Uri uri = Uri . withAppendedPath ( EmailProvider . CONTENT_URI ,
" account/ " + account . getUuid ( ) + " /stats " ) ;
2012-12-06 23:29:05 -05:00
2012-12-08 12:15:34 -05:00
// Query content provider to get the account stats
Cursor cursor = cr . query ( uri , projection , selection , selectionArgs , null ) ;
try {
if ( cursor . moveToFirst ( ) ) {
unreadMessageCount + = cursor . getInt ( 0 ) ;
flaggedMessageCount + = cursor . getInt ( 1 ) ;
}
} finally {
cursor . close ( ) ;
2012-12-06 23:29:05 -05:00
}
2012-12-08 12:15:34 -05:00
}
// Create AccountStats instance...
AccountStats stats = new AccountStats ( ) ;
stats . unreadMessageCount = unreadMessageCount ;
stats . flaggedMessageCount = flaggedMessageCount ;
// ...and notify the listener
if ( listener ! = null ) {
listener . accountStatusChanged ( searchAccount , stats ) ;
}
return stats ;
2009-02-05 23:28:29 -05:00
}
2010-04-29 00:59:14 -04:00
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
public void getFolderUnreadMessageCount ( final Account account , final String folderName ,
2011-02-06 17:09:48 -05:00
final MessagingListener l ) {
Runnable unreadRunnable = new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
int unreadMessageCount = 0 ;
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
Folder localFolder = account . getLocalStore ( ) . getFolder ( folderName ) ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
unreadMessageCount = localFolder . getUnreadMessageCount ( ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
Log . e ( K9 . LOG_TAG , " Count not get unread count for account " + account . getDescription ( ) , me ) ;
}
l . folderStatusChanged ( account , folderName , unreadMessageCount ) ;
}
} ;
put ( " getFolderUnread: " + account . getDescription ( ) + " : " + folderName , l , unreadRunnable ) ;
}
2009-12-06 19:56:06 -05:00
2010-04-29 00:59:14 -04:00
2011-02-06 17:09:48 -05:00
public boolean isMoveCapable ( Message message ) {
2010-08-29 19:40:14 -04:00
return ! message . getUid ( ) . startsWith ( K9 . LOCAL_UID_PREFIX ) ;
2009-03-05 02:32:45 -05:00
}
2011-02-06 17:09:48 -05:00
public boolean isCopyCapable ( Message message ) {
2009-11-24 19:40:29 -05:00
return isMoveCapable ( message ) ;
}
2011-02-06 17:09:48 -05:00
public boolean isMoveCapable ( final Account account ) {
try {
2010-03-03 23:00:30 -05:00
Store localStore = account . getLocalStore ( ) ;
Store remoteStore = account . getRemoteStore ( ) ;
2009-11-24 19:40:29 -05:00
return localStore . isMoveCapable ( ) & & remoteStore . isMoveCapable ( ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2009-03-05 02:32:45 -05:00
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Exception while ascertaining move capability " , me ) ;
2009-11-24 19:40:29 -05:00
return false ;
}
2009-03-05 02:32:45 -05:00
}
2011-02-06 17:09:48 -05:00
public boolean isCopyCapable ( final Account account ) {
try {
2010-03-03 23:00:30 -05:00
Store localStore = account . getLocalStore ( ) ;
Store remoteStore = account . getRemoteStore ( ) ;
2009-11-24 19:40:29 -05:00
return localStore . isCopyCapable ( ) & & remoteStore . isCopyCapable ( ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Exception while ascertaining copy capability " , me ) ;
2009-11-24 19:40:29 -05:00
return false ;
}
2009-03-05 02:32:45 -05:00
}
2012-11-03 00:56:12 -04:00
public void moveMessages ( final Account account , final String srcFolder ,
final List < Message > messages , final String destFolder ,
final MessagingListener listener ) {
2013-02-18 22:45:14 -05:00
suppressMessages ( account , messages ) ;
2012-11-03 00:56:12 -04:00
2011-02-06 17:09:48 -05:00
putBackground ( " moveMessages " , null , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2012-11-03 00:56:12 -04:00
moveOrCopyMessageSynchronous ( account , srcFolder , messages , destFolder , false ,
listener ) ;
2009-11-26 00:30:13 -05:00
}
2010-03-03 23:00:30 -05:00
} ) ;
2009-11-26 00:30:13 -05:00
}
2010-03-03 23:00:30 -05:00
2012-11-03 03:30:32 -04:00
public void moveMessagesInThread ( final Account account , final String srcFolder ,
final List < Message > messages , final String destFolder ) {
2013-02-18 22:45:14 -05:00
suppressMessages ( account , messages ) ;
2012-11-03 03:30:32 -04:00
putBackground ( " moveMessagesInThread " , null , new Runnable ( ) {
@Override
public void run ( ) {
try {
List < Message > messagesInThreads = collectMessagesInThreads ( account , messages ) ;
moveOrCopyMessageSynchronous ( account , srcFolder , messagesInThreads , destFolder ,
false , null ) ;
} catch ( MessagingException e ) {
addErrorMessage ( account , " Exception while moving messages " , e ) ;
}
}
} ) ;
}
2012-11-03 00:56:12 -04:00
public void moveMessage ( final Account account , final String srcFolder , final Message message ,
final String destFolder , final MessagingListener listener ) {
moveMessages ( account , srcFolder , Collections . singletonList ( message ) , destFolder , listener ) ;
2010-03-03 23:00:30 -05:00
}
2012-11-03 00:56:12 -04:00
public void copyMessages ( final Account account , final String srcFolder ,
final List < Message > messages , final String destFolder ,
final MessagingListener listener ) {
2011-02-06 17:09:48 -05:00
putBackground ( " copyMessages " , null , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2012-11-03 00:56:12 -04:00
moveOrCopyMessageSynchronous ( account , srcFolder , messages , destFolder , true ,
listener ) ;
2010-03-03 23:00:30 -05:00
}
} ) ;
}
2012-11-03 00:56:12 -04:00
2012-11-03 03:30:32 -04:00
public void copyMessagesInThread ( final Account account , final String srcFolder ,
final List < Message > messages , final String destFolder ) {
putBackground ( " copyMessagesInThread " , null , new Runnable ( ) {
@Override
public void run ( ) {
try {
List < Message > messagesInThreads = collectMessagesInThreads ( account , messages ) ;
moveOrCopyMessageSynchronous ( account , srcFolder , messagesInThreads , destFolder ,
true , null ) ;
} catch ( MessagingException e ) {
addErrorMessage ( account , " Exception while copying messages " , e ) ;
}
}
} ) ;
}
2012-11-03 00:56:12 -04:00
public void copyMessage ( final Account account , final String srcFolder , final Message message ,
final String destFolder , final MessagingListener listener ) {
copyMessages ( account , srcFolder , Collections . singletonList ( message ) , destFolder , listener ) ;
2009-03-05 02:32:45 -05:00
}
2009-11-24 19:40:29 -05:00
2012-11-03 00:56:12 -04:00
private void moveOrCopyMessageSynchronous ( final Account account , final String srcFolder ,
final List < Message > inMessages , final String destFolder , final boolean isCopy ,
MessagingListener listener ) {
2011-02-06 17:09:48 -05:00
try {
2011-06-28 07:20:48 -04:00
Map < String , String > uidMap = new HashMap < String , String > ( ) ;
2010-03-03 23:00:30 -05:00
Store localStore = account . getLocalStore ( ) ;
Store remoteStore = account . getRemoteStore ( ) ;
2011-02-06 17:09:48 -05:00
if ( ! isCopy & & ( ! remoteStore . isMoveCapable ( ) | | ! localStore . isMoveCapable ( ) ) ) {
2009-11-24 19:40:29 -05:00
return ;
}
2011-02-06 17:09:48 -05:00
if ( isCopy & & ( ! remoteStore . isCopyCapable ( ) | | ! localStore . isCopyCapable ( ) ) ) {
2009-11-24 19:40:29 -05:00
return ;
2009-03-05 02:32:45 -05:00
}
2009-11-24 19:40:29 -05:00
Folder localSrcFolder = localStore . getFolder ( srcFolder ) ;
Folder localDestFolder = localStore . getFolder ( destFolder ) ;
2010-04-29 00:59:14 -04:00
2012-02-07 10:30:38 -05:00
boolean unreadCountAffected = false ;
2010-03-03 23:00:30 -05:00
List < String > uids = new LinkedList < String > ( ) ;
2011-02-06 17:09:48 -05:00
for ( Message message : inMessages ) {
2010-03-03 23:00:30 -05:00
String uid = message . getUid ( ) ;
2011-02-06 17:09:48 -05:00
if ( ! uid . startsWith ( K9 . LOCAL_UID_PREFIX ) ) {
2010-03-03 23:00:30 -05:00
uids . add ( uid ) ;
}
2012-02-07 10:30:38 -05:00
if ( ! unreadCountAffected & & ! message . isSet ( Flag . SEEN ) ) {
unreadCountAffected = true ;
}
2010-03-03 23:00:30 -05:00
}
2010-04-29 00:59:14 -04:00
2010-08-02 07:55:31 -04:00
Message [ ] messages = localSrcFolder . getMessages ( uids . toArray ( EMPTY_STRING_ARRAY ) , null ) ;
2011-02-06 17:09:48 -05:00
if ( messages . length > 0 ) {
2010-03-03 23:00:30 -05:00
Map < String , Message > origUidMap = new HashMap < String , Message > ( ) ;
2010-04-29 00:59:14 -04:00
2011-02-06 17:09:48 -05:00
for ( Message message : messages ) {
2010-03-03 23:00:30 -05:00
origUidMap . put ( message . getUid ( ) , message ) ;
}
2010-04-29 00:59:14 -04:00
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " moveOrCopyMessageSynchronous: source folder = " + srcFolder
2010-03-03 23:00:30 -05:00
+ " , " + messages . length + " messages, " + " , destination folder = " + destFolder + " , isCopy = " + isCopy ) ;
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
if ( isCopy ) {
2009-11-24 19:40:29 -05:00
FetchProfile fp = new FetchProfile ( ) ;
fp . add ( FetchProfile . Item . ENVELOPE ) ;
fp . add ( FetchProfile . Item . BODY ) ;
2010-03-03 23:00:30 -05:00
localSrcFolder . fetch ( messages , fp , null ) ;
2011-06-28 07:20:48 -04:00
uidMap = localSrcFolder . copyMessages ( messages , localDestFolder ) ;
2012-02-07 10:30:38 -05:00
if ( unreadCountAffected ) {
// If this copy operation changes the unread count in the destination
// folder, notify the listeners.
int unreadMessageCount = localDestFolder . getUnreadMessageCount ( ) ;
for ( MessagingListener l : getListeners ( ) ) {
l . folderStatusChanged ( account , destFolder , unreadMessageCount ) ;
}
}
2011-02-06 17:09:48 -05:00
} else {
2011-06-28 07:20:48 -04:00
uidMap = localSrcFolder . moveMessages ( messages , localDestFolder ) ;
2011-11-01 00:42:12 -04:00
for ( Map . Entry < String , Message > entry : origUidMap . entrySet ( ) ) {
String origUid = entry . getKey ( ) ;
Message message = entry . getValue ( ) ;
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2011-11-01 00:42:12 -04:00
l . messageUidChanged ( account , srcFolder , origUid , message . getUid ( ) ) ;
2010-03-03 23:00:30 -05:00
}
2009-11-24 19:40:29 -05:00
}
2013-02-18 22:45:14 -05:00
unsuppressMessages ( account , messages ) ;
2012-02-07 10:30:38 -05:00
if ( unreadCountAffected ) {
// If this move operation changes the unread count, notify the listeners
// that the unread count changed in both the source and destination folder.
int unreadMessageCountSrc = localSrcFolder . getUnreadMessageCount ( ) ;
int unreadMessageCountDest = localDestFolder . getUnreadMessageCount ( ) ;
for ( MessagingListener l : getListeners ( ) ) {
l . folderStatusChanged ( account , srcFolder , unreadMessageCountSrc ) ;
l . folderStatusChanged ( account , destFolder , unreadMessageCountDest ) ;
}
}
2009-11-24 19:40:29 -05:00
}
2010-04-29 00:59:14 -04:00
2011-06-28 07:20:48 -04:00
queueMoveOrCopy ( account , srcFolder , destFolder , isCopy , origUidMap . keySet ( ) . toArray ( EMPTY_STRING_ARRAY ) , uidMap ) ;
2009-11-24 19:40:29 -05:00
}
2009-12-06 19:56:06 -05:00
2009-11-24 19:40:29 -05:00
processPendingCommands ( account ) ;
2011-02-06 17:09:48 -05:00
} catch ( UnavailableStorageException e ) {
2010-11-13 16:40:56 -05:00
Log . i ( K9 . LOG_TAG , " Failed to move/copy message because storage is not available - trying again later. " ) ;
throw new UnavailableAccountException ( e ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , me ) ;
2009-03-05 02:32:45 -05:00
2009-11-24 19:40:29 -05:00
throw new RuntimeException ( " Error moving message " , me ) ;
}
2009-03-05 02:32:45 -05:00
}
2009-12-27 12:22:51 -05:00
2011-02-06 17:09:48 -05:00
public void expunge ( final Account account , final String folder , final MessagingListener listener ) {
putBackground ( " expunge " , null , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
queueExpunge ( account , folder ) ;
}
} ) ;
}
2010-04-29 00:59:14 -04:00
2012-01-21 23:14:58 -05:00
public void deleteDraft ( final Account account , long id ) {
2010-03-03 23:00:30 -05:00
LocalFolder localFolder = null ;
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
localFolder = localStore . getFolder ( account . getDraftsFolderName ( ) ) ;
localFolder . open ( OpenMode . READ_WRITE ) ;
2012-01-21 23:14:58 -05:00
String uid = localFolder . getMessageUidById ( id ) ;
2012-01-25 18:37:25 -05:00
if ( uid ! = null ) {
Message message = localFolder . getMessage ( uid ) ;
if ( message ! = null ) {
2012-11-03 00:56:12 -04:00
deleteMessages ( Collections . singletonList ( message ) , null ) ;
2012-01-25 18:37:25 -05:00
}
2010-04-05 22:35:42 -04:00
}
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , me ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( localFolder ) ;
2010-03-03 23:00:30 -05:00
}
}
2009-12-06 19:56:06 -05:00
2012-11-03 00:56:12 -04:00
public void deleteThreads ( final List < Message > messages ) {
2012-11-02 20:52:45 -04:00
actOnMessages ( messages , new MessageActor ( ) {
@Override
public void act ( final Account account , final Folder folder ,
final List < Message > accountMessages ) {
2013-02-18 22:45:14 -05:00
suppressMessages ( account , messages ) ;
2012-11-02 20:52:45 -04:00
putBackground ( " deleteThreads " , null , new Runnable ( ) {
@Override
public void run ( ) {
deleteThreadsSynchronous ( account , folder . getName ( ) , accountMessages ) ;
}
} ) ;
}
} ) ;
}
public void deleteThreadsSynchronous ( Account account , String folderName ,
List < Message > messages ) {
try {
2012-11-03 00:01:25 -04:00
List < Message > messagesToDelete = collectMessagesInThreads ( account , messages ) ;
2012-11-02 20:52:45 -04:00
deleteMessagesSynchronous ( account , folderName ,
messagesToDelete . toArray ( EMPTY_MESSAGE_ARRAY ) , null ) ;
} catch ( MessagingException e ) {
Log . e ( K9 . LOG_TAG , " Something went wrong while deleting threads " , e ) ;
}
}
2012-11-03 00:01:25 -04:00
public List < Message > collectMessagesInThreads ( Account account , List < Message > messages )
throws MessagingException {
LocalStore localStore = account . getLocalStore ( ) ;
List < Message > messagesInThreads = new ArrayList < Message > ( ) ;
for ( Message message : messages ) {
2013-01-10 21:40:35 -05:00
LocalMessage localMessage = ( LocalMessage ) message ;
long rootId = localMessage . getRootId ( ) ;
long threadId = ( rootId = = - 1 ) ? localMessage . getThreadId ( ) : rootId ;
2012-11-03 00:01:25 -04:00
Message [ ] messagesInThread = localStore . getMessagesInThread ( threadId ) ;
Collections . addAll ( messagesInThreads , messagesInThread ) ;
}
return messagesInThreads ;
}
2012-11-03 00:56:12 -04:00
public void deleteMessages ( final List < Message > messages , final MessagingListener listener ) {
2011-02-06 17:09:48 -05:00
actOnMessages ( messages , new MessageActor ( ) {
2010-03-03 23:00:30 -05:00
@Override
public void act ( final Account account , final Folder folder ,
2012-11-03 00:56:12 -04:00
final List < Message > accountMessages ) {
2013-02-18 22:45:14 -05:00
suppressMessages ( account , messages ) ;
2010-03-03 23:00:30 -05:00
2011-02-06 17:09:48 -05:00
putBackground ( " deleteMessages " , null , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2012-11-03 00:56:12 -04:00
deleteMessagesSynchronous ( account , folder . getName ( ) ,
accountMessages . toArray ( EMPTY_MESSAGE_ARRAY ) , listener ) ;
2010-03-03 23:00:30 -05:00
}
} ) ;
2009-11-24 19:40:29 -05:00
}
2010-04-29 00:59:14 -04:00
2009-11-24 19:40:29 -05:00
} ) ;
2010-04-29 00:59:14 -04:00
2009-01-07 01:02:04 -05:00
}
2009-11-24 19:40:29 -05:00
2009-11-29 13:07:34 -05:00
private void deleteMessagesSynchronous ( final Account account , final String folder , final Message [ ] messages ,
2011-02-06 17:09:48 -05:00
MessagingListener listener ) {
2009-11-29 13:07:34 -05:00
Folder localFolder = null ;
Folder localTrashFolder = null ;
String [ ] uids = getUidsFromMessages ( messages ) ;
2011-02-06 17:09:48 -05:00
try {
2009-12-14 19:03:22 -05:00
//We need to make these callbacks before moving the messages to the trash
//as messages get a new UID after being moved
2011-02-06 17:09:48 -05:00
for ( Message message : messages ) {
2011-07-09 00:27:56 -04:00
for ( MessagingListener l : getListeners ( listener ) ) {
2009-12-14 19:03:22 -05:00
l . messageDeleted ( account , folder , message ) ;
}
}
2010-03-03 23:00:30 -05:00
Store localStore = account . getLocalStore ( ) ;
2009-11-29 13:07:34 -05:00
localFolder = localStore . getFolder ( folder ) ;
2012-02-16 18:43:35 -05:00
Map < String , String > uidMap = null ;
2012-04-11 03:19:18 -04:00
if ( folder . equals ( account . getTrashFolderName ( ) ) | | ! account . hasTrashFolder ( ) ) {
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
Log . d ( K9 . LOG_TAG , " Deleting messages in trash folder or trash set to -None-, not copying " ) ;
2010-01-02 20:50:41 -05:00
2009-11-29 13:07:34 -05:00
localFolder . setFlags ( messages , new Flag [ ] { Flag . DELETED } , true ) ;
2011-02-06 17:09:48 -05:00
} else {
2009-11-29 13:07:34 -05:00
localTrashFolder = localStore . getFolder ( account . getTrashFolderName ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( ! localTrashFolder . exists ( ) ) {
2009-11-29 13:07:34 -05:00
localTrashFolder . create ( Folder . FolderType . HOLDS_MESSAGES ) ;
}
2011-02-06 17:09:48 -05:00
if ( localTrashFolder . exists ( ) ) {
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Deleting messages in normal folder, moving " ) ;
2009-03-07 02:20:15 -05:00
2012-02-16 18:43:35 -05:00
uidMap = localFolder . moveMessages ( messages , localTrashFolder ) ;
2009-11-24 19:40:29 -05:00
2009-01-09 00:39:43 -05:00
}
2009-01-07 01:02:04 -05:00
}
2009-12-06 19:56:06 -05:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2010-01-03 19:41:26 -05:00
l . folderStatusChanged ( account , folder , localFolder . getUnreadMessageCount ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( localTrashFolder ! = null ) {
2010-01-03 19:41:26 -05:00
l . folderStatusChanged ( account , account . getTrashFolderName ( ) , localTrashFolder . getUnreadMessageCount ( ) ) ;
}
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
}
2009-11-24 19:40:29 -05:00
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Delete policy for account " + account . getDescription ( ) + " is " + account . getDeletePolicy ( ) ) ;
2010-01-02 20:50:41 -05:00
2011-02-06 17:09:48 -05:00
if ( folder . equals ( account . getOutboxFolderName ( ) ) ) {
for ( Message message : messages ) {
2009-11-29 13:07:34 -05:00
// If the message was in the Outbox, then it has been copied to local Trash, and has
// to be copied to remote trash
PendingCommand command = new PendingCommand ( ) ;
command . command = PENDING_COMMAND_APPEND ;
command . arguments =
2011-02-06 17:09:48 -05:00
new String [ ] {
2009-11-29 13:07:34 -05:00
account . getTrashFolderName ( ) ,
message . getUid ( )
} ;
queuePendingCommand ( account , command ) ;
}
2009-11-24 19:40:29 -05:00
processPendingCommands ( account ) ;
2011-02-06 17:09:48 -05:00
} else if ( account . getDeletePolicy ( ) = = Account . DELETE_POLICY_ON_DELETE ) {
if ( folder . equals ( account . getTrashFolderName ( ) ) ) {
2010-11-13 19:49:15 -05:00
queueSetFlag ( account , folder , Boolean . toString ( true ) , Flag . DELETED . toString ( ) , uids ) ;
2011-02-06 17:09:48 -05:00
} else {
2012-02-16 18:43:35 -05:00
queueMoveOrCopy ( account , folder , account . getTrashFolderName ( ) , false , uids , uidMap ) ;
2010-11-13 19:49:15 -05:00
}
2010-11-14 20:31:11 -05:00
processPendingCommands ( account ) ;
2011-02-06 17:09:48 -05:00
} else if ( account . getDeletePolicy ( ) = = Account . DELETE_POLICY_MARK_AS_READ ) {
2009-11-29 13:07:34 -05:00
queueSetFlag ( account , folder , Boolean . toString ( true ) , Flag . SEEN . toString ( ) , uids ) ;
2009-11-24 19:40:29 -05:00
processPendingCommands ( account ) ;
2011-02-06 17:09:48 -05:00
} else {
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Delete policy " + account . getDeletePolicy ( ) + " prevents delete from server " ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
}
2013-02-18 22:45:14 -05:00
unsuppressMessages ( account , messages ) ;
2011-02-06 17:09:48 -05:00
} catch ( UnavailableStorageException e ) {
2010-11-13 16:40:56 -05:00
Log . i ( K9 . LOG_TAG , " Failed to delete message because storage is not available - trying again later. " ) ;
throw new UnavailableAccountException ( e ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , me ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2008-11-01 17:32:06 -04:00
throw new RuntimeException ( " Error deleting message from local store. " , me ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( localFolder ) ;
closeFolder ( localTrashFolder ) ;
2009-11-29 13:07:34 -05:00
}
}
2009-12-06 19:56:06 -05:00
2011-02-06 17:09:48 -05:00
private String [ ] getUidsFromMessages ( Message [ ] messages ) {
2009-11-29 13:07:34 -05:00
String [ ] uids = new String [ messages . length ] ;
2011-02-06 17:09:48 -05:00
for ( int i = 0 ; i < messages . length ; i + + ) {
2009-11-29 13:07:34 -05:00
uids [ i ] = messages [ i ] . getUid ( ) ;
}
return uids ;
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
private void processPendingEmptyTrash ( PendingCommand command , Account account ) throws MessagingException {
2010-03-03 23:00:30 -05:00
Store remoteStore = account . getRemoteStore ( ) ;
2009-11-24 19:40:29 -05:00
Folder remoteFolder = remoteStore . getFolder ( account . getTrashFolderName ( ) ) ;
2011-02-06 17:09:48 -05:00
try {
if ( remoteFolder . exists ( ) ) {
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
remoteFolder . open ( OpenMode . READ_WRITE ) ;
remoteFolder . setFlags ( new Flag [ ] { Flag . DELETED } , true ) ;
2011-02-06 17:09:48 -05:00
if ( Account . EXPUNGE_IMMEDIATELY . equals ( account . getExpungePolicy ( ) ) ) {
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
remoteFolder . expunge ( ) ;
}
2010-12-01 01:04:22 -05:00
// When we empty trash, we need to actually synchronize the folder
// or local deletes will never get cleaned up
synchronizeFolder ( account , remoteFolder , true , 0 , null ) ;
compact ( account , null ) ;
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
}
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( remoteFolder ) ;
2009-11-24 19:40:29 -05:00
}
2009-01-24 13:52:58 -05:00
}
2008-11-01 17:32:06 -04:00
2011-02-06 17:09:48 -05:00
public void emptyTrash ( final Account account , MessagingListener listener ) {
putBackground ( " emptyTrash " , listener , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2012-01-26 18:51:18 -05:00
LocalFolder localFolder = null ;
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
Store localStore = account . getLocalStore ( ) ;
2012-01-26 18:51:18 -05:00
localFolder = ( LocalFolder ) localStore . getFolder ( account . getTrashFolderName ( ) ) ;
2008-11-01 17:32:06 -04:00
localFolder . open ( OpenMode . READ_WRITE ) ;
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
localFolder . setFlags ( new Flag [ ] { Flag . DELETED } , true ) ;
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2009-11-24 19:40:29 -05:00
l . emptyTrashCompleted ( account ) ;
2008-11-01 17:32:06 -04:00
}
2009-01-24 13:52:58 -05:00
List < String > args = new ArrayList < String > ( ) ;
PendingCommand command = new PendingCommand ( ) ;
command . command = PENDING_COMMAND_EMPTY_TRASH ;
2010-08-02 07:55:31 -04:00
command . arguments = args . toArray ( EMPTY_STRING_ARRAY ) ;
2009-01-24 13:52:58 -05:00
queuePendingCommand ( account , command ) ;
processPendingCommands ( account ) ;
2011-02-06 17:09:48 -05:00
} catch ( UnavailableStorageException e ) {
2010-11-13 16:40:56 -05:00
Log . i ( K9 . LOG_TAG , " Failed to empty trash because storage is not available - trying again later. " ) ;
throw new UnavailableAccountException ( e ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " emptyTrash failed " , e ) ;
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , e ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( localFolder ) ;
2010-01-16 11:22:20 -05:00
}
2008-11-01 17:32:06 -04:00
}
} ) ;
}
2011-02-06 17:09:48 -05:00
public void sendAlternate ( final Context context , Account account , Message message ) {
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " About to load message " + account . getDescription ( ) + " : " + message . getFolder ( ) . getName ( )
2009-11-24 19:40:29 -05:00
+ " : " + message . getUid ( ) + " for sendAlternate " ) ;
2010-01-02 20:50:41 -05:00
2009-11-24 19:40:29 -05:00
loadMessageForView ( account , message . getFolder ( ) . getName ( ) ,
2011-02-06 17:09:48 -05:00
message . getUid ( ) , new MessagingListener ( ) {
2009-11-24 19:40:29 -05:00
@Override
public void loadMessageForViewBodyAvailable ( Account account , String folder , String uid ,
2011-02-06 17:09:48 -05:00
Message message ) {
2009-12-14 21:50:53 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Got message " + account . getDescription ( ) + " : " + folder
2009-11-24 19:40:29 -05:00
+ " : " + message . getUid ( ) + " for sendAlternate " ) ;
2011-02-06 17:09:48 -05:00
try {
Intent msg = new Intent ( Intent . ACTION_SEND ) ;
2009-11-24 19:40:29 -05:00
String quotedText = null ;
Part part = MimeUtility . findFirstPartByMimeType ( message ,
" text/plain " ) ;
2011-02-06 17:09:48 -05:00
if ( part = = null ) {
2009-11-24 19:40:29 -05:00
part = MimeUtility . findFirstPartByMimeType ( message , " text/html " ) ;
}
2011-02-06 17:09:48 -05:00
if ( part ! = null ) {
2009-11-24 19:40:29 -05:00
quotedText = MimeUtility . getTextFromPart ( part ) ;
}
2011-02-06 17:09:48 -05:00
if ( quotedText ! = null ) {
2009-11-24 19:40:29 -05:00
msg . putExtra ( Intent . EXTRA_TEXT , quotedText ) ;
}
2011-02-09 01:08:10 -05:00
msg . putExtra ( Intent . EXTRA_SUBJECT , message . getSubject ( ) ) ;
2011-02-12 23:23:18 -05:00
Address [ ] from = message . getFrom ( ) ;
String [ ] senders = new String [ from . length ] ;
for ( int i = 0 ; i < from . length ; i + + ) {
senders [ i ] = from [ i ] . toString ( ) ;
}
msg . putExtra ( Intents . Share . EXTRA_FROM , senders ) ;
2011-02-09 01:08:10 -05:00
Address [ ] to = message . getRecipients ( RecipientType . TO ) ;
String [ ] recipientsTo = new String [ to . length ] ;
for ( int i = 0 ; i < to . length ; i + + ) {
recipientsTo [ i ] = to [ i ] . toString ( ) ;
}
msg . putExtra ( Intent . EXTRA_EMAIL , recipientsTo ) ;
Address [ ] cc = message . getRecipients ( RecipientType . CC ) ;
String [ ] recipientsCc = new String [ cc . length ] ;
for ( int i = 0 ; i < cc . length ; i + + ) {
recipientsCc [ i ] = cc [ i ] . toString ( ) ;
}
msg . putExtra ( Intent . EXTRA_CC , recipientsCc ) ;
2009-11-24 19:40:29 -05:00
msg . setType ( " text/plain " ) ;
context . startActivity ( Intent . createChooser ( msg , context . getString ( R . string . send_alternate_chooser_title ) ) ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Unable to send email through alternate program " , me ) ;
2009-11-24 19:40:29 -05:00
}
}
} ) ;
}
2008-11-01 17:32:06 -04:00
/ * *
* Checks mail for one or multiple accounts . If account is null all accounts
* are checked .
*
* @param context
* @param account
* @param listener
* /
2009-11-24 19:40:29 -05:00
public void checkMail ( final Context context , final Account account ,
final boolean ignoreLastCheckedTime ,
final boolean useManualWakeLock ,
2011-02-06 17:09:48 -05:00
final MessagingListener listener ) {
2009-11-24 19:40:29 -05:00
2010-05-16 20:30:32 -04:00
TracingWakeLock twakeLock = null ;
2011-02-06 17:09:48 -05:00
if ( useManualWakeLock ) {
2010-05-16 20:30:32 -04:00
TracingPowerManager pm = TracingPowerManager . getPowerManager ( context ) ;
2010-05-30 00:17:00 -04:00
2010-05-16 20:30:32 -04:00
twakeLock = pm . newWakeLock ( PowerManager . PARTIAL_WAKE_LOCK , " K9 MessagingController.checkMail " ) ;
2009-11-24 19:40:29 -05:00
twakeLock . setReferenceCounted ( false ) ;
2009-12-14 21:50:53 -05:00
twakeLock . acquire ( K9 . MANUAL_WAKE_LOCK_TIMEOUT ) ;
2009-11-24 19:40:29 -05:00
}
2010-05-16 20:30:32 -04:00
final TracingWakeLock wakeLock = twakeLock ;
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2008-11-01 17:32:06 -04:00
l . checkMailStarted ( context , account ) ;
}
2011-02-06 17:09:48 -05:00
putBackground ( " checkMail " , listener , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
2011-02-06 17:09:48 -05:00
try {
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Starting mail check " ) ;
2009-11-24 19:40:29 -05:00
Preferences prefs = Preferences . getPreferences ( context ) ;
2011-10-17 23:09:20 -04:00
Collection < Account > accounts ;
2011-02-06 17:09:48 -05:00
if ( account ! = null ) {
2011-10-17 23:09:20 -04:00
accounts = new ArrayList < Account > ( 1 ) ;
accounts . add ( account ) ;
2011-02-06 17:09:48 -05:00
} else {
2011-10-17 23:09:20 -04:00
accounts = prefs . getAvailableAccounts ( ) ;
2009-11-24 19:40:29 -05:00
}
2011-02-06 17:09:48 -05:00
for ( final Account account : accounts ) {
checkMailForAccount ( context , account , ignoreLastCheckedTime , prefs , listener ) ;
2010-11-28 15:28:42 -05:00
}
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2010-11-28 15:28:42 -05:00
Log . e ( K9 . LOG_TAG , " Unable to synchronize mail " , e ) ;
addErrorMessage ( account , null , e ) ;
}
2011-02-06 17:09:48 -05:00
putBackground ( " finalize sync " , null , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2010-11-28 15:28:42 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Finished mail sync " ) ;
2011-02-06 17:09:48 -05:00
if ( wakeLock ! = null ) {
2010-11-28 15:28:42 -05:00
wakeLock . release ( ) ;
2010-11-13 16:40:56 -05:00
}
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2010-11-28 15:28:42 -05:00
l . checkMailFinished ( context , account ) ;
2009-11-24 19:40:29 -05:00
}
2010-11-28 15:28:42 -05:00
}
}
) ;
}
} ) ;
}
2010-04-29 00:59:14 -04:00
2010-10-24 23:19:19 -04:00
2010-11-28 15:28:42 -05:00
private void checkMailForAccount ( final Context context , final Account account ,
final boolean ignoreLastCheckedTime ,
final Preferences prefs ,
2011-02-06 17:09:48 -05:00
final MessagingListener listener ) {
if ( ! account . isAvailable ( context ) ) {
if ( K9 . DEBUG ) {
2010-11-28 15:28:42 -05:00
Log . i ( K9 . LOG_TAG , " Skipping synchronizing unavailable account " + account . getDescription ( ) ) ;
}
return ;
}
final long accountInterval = account . getAutomaticCheckIntervalMinutes ( ) * 60 * 1000 ;
2011-02-06 17:09:48 -05:00
if ( ! ignoreLastCheckedTime & & accountInterval < = 0 ) {
2010-11-28 15:28:42 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Skipping synchronizing account " + account . getDescription ( ) ) ;
return ;
}
2009-11-24 19:40:29 -05:00
2010-11-28 15:28:42 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Synchronizing account " + account . getDescription ( ) ) ;
2009-11-24 19:40:29 -05:00
2010-11-28 15:28:42 -05:00
account . setRingNotified ( false ) ;
2009-11-24 19:40:29 -05:00
2010-11-28 15:28:42 -05:00
sendPendingMessages ( account , listener ) ;
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
try {
2010-11-28 15:28:42 -05:00
Account . FolderMode aDisplayMode = account . getFolderDisplayMode ( ) ;
Account . FolderMode aSyncMode = account . getFolderSyncMode ( ) ;
2009-11-24 19:40:29 -05:00
2010-11-28 15:28:42 -05:00
Store localStore = account . getLocalStore ( ) ;
2011-02-06 17:09:48 -05:00
for ( final Folder folder : localStore . getPersonalNamespaces ( false ) ) {
2010-11-28 15:28:42 -05:00
folder . open ( Folder . OpenMode . READ_WRITE ) ;
folder . refresh ( prefs ) ;
2009-11-24 19:40:29 -05:00
2010-11-28 15:28:42 -05:00
Folder . FolderClass fDisplayClass = folder . getDisplayClass ( ) ;
Folder . FolderClass fSyncClass = folder . getSyncClass ( ) ;
2011-02-06 17:09:48 -05:00
if ( modeMismatch ( aDisplayMode , fDisplayClass ) ) {
2010-11-28 15:28:42 -05:00
// Never sync a folder that isn't displayed
/ *
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " Not syncing folder " + folder . getName ( ) +
" which is in display mode " + fDisplayClass + " while account is in display mode " + aDisplayMode ) ;
* /
2009-11-24 19:40:29 -05:00
2010-11-28 15:28:46 -05:00
continue ;
2010-11-28 15:28:42 -05:00
}
2011-02-06 17:09:48 -05:00
if ( modeMismatch ( aSyncMode , fSyncClass ) ) {
2010-11-28 15:28:42 -05:00
// Do not sync folders in the wrong class
/ *
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " Not syncing folder " + folder . getName ( ) +
" which is in sync mode " + fSyncClass + " while account is in sync mode " + aSyncMode ) ;
* /
2010-11-28 15:28:46 -05:00
continue ;
2009-11-24 19:40:29 -05:00
}
2010-12-01 01:04:16 -05:00
synchronizeFolder ( account , folder , ignoreLastCheckedTime , accountInterval , listener ) ;
2010-11-28 15:28:42 -05:00
}
2011-02-06 17:09:48 -05:00
} catch ( MessagingException e ) {
2010-11-28 15:28:42 -05:00
Log . e ( K9 . LOG_TAG , " Unable to synchronize account " + account . getName ( ) , e ) ;
addErrorMessage ( account , null , e ) ;
2011-02-06 17:09:48 -05:00
} finally {
putBackground ( " clear notification flag for " + account . getDescription ( ) , null , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2010-11-28 15:28:42 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " Clearing notification flag for " + account . getDescription ( ) ) ;
account . setRingNotified ( false ) ;
2011-02-06 17:09:48 -05:00
try {
2010-11-28 15:28:42 -05:00
AccountStats stats = account . getStats ( context ) ;
2011-02-06 17:09:48 -05:00
if ( stats = = null | | stats . unreadMessageCount = = 0 ) {
2010-11-28 15:28:42 -05:00
notifyAccountCancel ( context , account ) ;
2009-11-17 22:06:23 -05:00
}
2011-02-06 17:09:48 -05:00
} catch ( MessagingException e ) {
2010-11-28 15:28:42 -05:00
Log . e ( K9 . LOG_TAG , " Unable to getUnreadMessageCount for account: " + account , e ) ;
2009-11-24 19:40:29 -05:00
}
}
2008-11-01 17:32:06 -04:00
}
2010-11-28 15:28:42 -05:00
) ;
}
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -05:00
2010-11-28 15:28:42 -05:00
2010-11-28 15:28:46 -05:00
private void synchronizeFolder (
2010-12-01 01:04:16 -05:00
final Account account ,
2010-11-28 15:28:46 -05:00
final Folder folder ,
final boolean ignoreLastCheckedTime ,
final long accountInterval ,
2011-02-06 17:09:48 -05:00
final MessagingListener listener ) {
2010-11-28 15:28:46 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " Folder " + folder . getName ( ) + " was last synced @ " +
new Date ( folder . getLastChecked ( ) ) ) ;
if ( ! ignoreLastCheckedTime & & folder . getLastChecked ( ) >
2011-02-06 17:09:48 -05:00
( System . currentTimeMillis ( ) - accountInterval ) ) {
2010-11-28 15:28:46 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " Not syncing folder " + folder . getName ( )
+ " , previously synced @ " + new Date ( folder . getLastChecked ( ) )
+ " which would be too recent for the account period " ) ;
return ;
}
2011-02-06 17:09:48 -05:00
putBackground ( " sync " + folder . getName ( ) , null , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2010-11-28 15:28:46 -05:00
LocalFolder tLocalFolder = null ;
2011-02-06 17:09:48 -05:00
try {
2010-11-28 15:28:46 -05:00
// In case multiple Commands get enqueued, don't run more than
// once
final LocalStore localStore = account . getLocalStore ( ) ;
tLocalFolder = localStore . getFolder ( folder . getName ( ) ) ;
tLocalFolder . open ( Folder . OpenMode . READ_WRITE ) ;
if ( ! ignoreLastCheckedTime & & tLocalFolder . getLastChecked ( ) >
2011-02-06 17:09:48 -05:00
( System . currentTimeMillis ( ) - accountInterval ) ) {
2010-11-28 15:28:46 -05:00
if ( K9 . DEBUG )
Log . v ( K9 . LOG_TAG , " Not running Command for folder " + folder . getName ( )
+ " , previously synced @ " + new Date ( folder . getLastChecked ( ) )
+ " which would be too recent for the account period " ) ;
return ;
}
2010-11-28 15:29:05 -05:00
notifyFetchingMail ( account , folder ) ;
2011-02-06 17:09:48 -05:00
try {
2010-11-28 15:28:46 -05:00
synchronizeMailboxSynchronous ( account , folder . getName ( ) , listener , null ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:29:05 -05:00
notifyFetchingMailCancel ( account ) ;
2010-11-28 15:28:46 -05:00
}
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2010-11-28 15:28:46 -05:00
Log . e ( K9 . LOG_TAG , " Exception while processing folder " +
account . getDescription ( ) + " : " + folder . getName ( ) , e ) ;
addErrorMessage ( account , null , e ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( tLocalFolder ) ;
2010-11-28 15:28:46 -05:00
}
}
}
) ;
}
2010-11-28 15:28:42 -05:00
2011-02-06 17:09:48 -05:00
public void compact ( final Account account , final MessagingListener ml ) {
putBackground ( " compact: " + account . getDescription ( ) , ml , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
try {
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
2009-11-24 19:40:29 -05:00
long oldSize = localStore . getSize ( ) ;
localStore . compact ( ) ;
long newSize = localStore . getSize ( ) ;
2011-07-09 00:27:56 -04:00
for ( MessagingListener l : getListeners ( ml ) ) {
2009-11-24 19:40:29 -05:00
l . accountSizeChanged ( account , oldSize , newSize ) ;
}
2011-02-06 17:09:48 -05:00
} catch ( UnavailableStorageException e ) {
2010-11-13 16:40:56 -05:00
Log . i ( K9 . LOG_TAG , " Failed to compact account because storage is not available - trying again later. " ) ;
throw new UnavailableAccountException ( e ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Failed to compact account " + account . getDescription ( ) , e ) ;
2009-11-24 19:40:29 -05:00
}
2009-02-09 22:18:42 -05:00
}
2009-11-24 19:40:29 -05:00
} ) ;
2009-02-09 22:18:42 -05:00
}
2008-11-01 17:32:06 -04:00
2011-02-06 17:09:48 -05:00
public void clear ( final Account account , final MessagingListener ml ) {
putBackground ( " clear: " + account . getDescription ( ) , ml , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
try {
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
2009-11-24 19:40:29 -05:00
long oldSize = localStore . getSize ( ) ;
localStore . clear ( ) ;
localStore . resetVisibleLimits ( account . getDisplayCount ( ) ) ;
long newSize = localStore . getSize ( ) ;
2010-05-02 01:37:48 -04:00
AccountStats stats = new AccountStats ( ) ;
stats . size = newSize ;
stats . unreadMessageCount = 0 ;
stats . flaggedMessageCount = 0 ;
2011-07-09 00:27:56 -04:00
for ( MessagingListener l : getListeners ( ml ) ) {
2009-11-24 19:40:29 -05:00
l . accountSizeChanged ( account , oldSize , newSize ) ;
2010-05-02 01:37:48 -04:00
l . accountStatusChanged ( account , stats ) ;
2009-11-24 19:40:29 -05:00
}
2011-02-06 17:09:48 -05:00
} catch ( UnavailableStorageException e ) {
2010-11-13 16:40:56 -05:00
Log . i ( K9 . LOG_TAG , " Failed to clear account because storage is not available - trying again later. " ) ;
throw new UnavailableAccountException ( e ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2010-05-12 00:17:52 -04:00
Log . e ( K9 . LOG_TAG , " Failed to clear account " + account . getDescription ( ) , e ) ;
}
}
} ) ;
}
2010-05-15 15:46:16 -04:00
2011-02-06 17:09:48 -05:00
public void recreate ( final Account account , final MessagingListener ml ) {
putBackground ( " recreate: " + account . getDescription ( ) , ml , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
try {
2010-05-12 00:17:52 -04:00
LocalStore localStore = account . getLocalStore ( ) ;
long oldSize = localStore . getSize ( ) ;
localStore . recreate ( ) ;
localStore . resetVisibleLimits ( account . getDisplayCount ( ) ) ;
long newSize = localStore . getSize ( ) ;
AccountStats stats = new AccountStats ( ) ;
stats . size = newSize ;
stats . unreadMessageCount = 0 ;
stats . flaggedMessageCount = 0 ;
2011-07-09 00:27:56 -04:00
for ( MessagingListener l : getListeners ( ml ) ) {
2010-05-12 00:17:52 -04:00
l . accountSizeChanged ( account , oldSize , newSize ) ;
l . accountStatusChanged ( account , stats ) ;
}
2011-02-06 17:09:48 -05:00
} catch ( UnavailableStorageException e ) {
2010-11-13 16:40:56 -05:00
Log . i ( K9 . LOG_TAG , " Failed to recreate an account because storage is not available - trying again later. " ) ;
throw new UnavailableAccountException ( e ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2010-05-12 00:17:52 -04:00
Log . e ( K9 . LOG_TAG , " Failed to recreate account " + account . getDescription ( ) , e ) ;
2009-11-24 19:40:29 -05:00
}
2009-02-09 22:18:42 -05:00
}
2009-11-24 19:40:29 -05:00
} ) ;
2009-02-09 22:18:42 -05:00
}
2009-11-24 19:40:29 -05:00
2010-08-08 14:50:31 -04:00
2011-02-06 17:09:48 -05:00
private boolean shouldNotifyForMessage ( Account account , LocalFolder localFolder , Message message ) {
2011-05-20 17:00:48 -04:00
// If we don't even have an account name, don't show the notification.
// (This happens during initial account setup)
if ( account . getName ( ) = = null ) {
return false ;
}
// Do not notify if the user does not have notifications enabled or if the message has
// been read.
if ( ! account . isNotifyNewMail ( ) | | message . isSet ( Flag . SEEN ) ) {
return false ;
}
// If the account is a POP3 account and the message is older than the oldest message we've
// previously seen, then don't notify about it.
if ( account . getStoreUri ( ) . startsWith ( " pop3 " ) & &
message . olderThan ( new Date ( account . getLatestOldMessageSeenTime ( ) ) ) ) {
2010-03-29 22:58:21 -04:00
return false ;
}
2010-05-15 15:46:16 -04:00
2011-05-20 17:00:48 -04:00
// No notification for new messages in Trash, Drafts, Spam or Sent folder.
// But do notify if it's the INBOX (see issue 1817).
2010-05-12 00:17:52 -04:00
Folder folder = message . getFolder ( ) ;
2011-02-06 17:09:48 -05:00
if ( folder ! = null ) {
2010-05-12 00:17:52 -04:00
String folderName = folder . getName ( ) ;
2011-04-05 05:23:57 -04:00
if ( ! account . getInboxFolderName ( ) . equals ( folderName ) & &
2010-06-17 08:42:22 -04:00
( account . getTrashFolderName ( ) . equals ( folderName )
2010-07-06 06:29:26 -04:00
| | account . getDraftsFolderName ( ) . equals ( folderName )
2011-01-16 16:33:54 -05:00
| | account . getSpamFolderName ( ) . equals ( folderName )
2011-02-06 17:09:48 -05:00
| | account . getSentFolderName ( ) . equals ( folderName ) ) ) {
2010-05-12 00:17:52 -04:00
return false ;
}
}
2010-01-21 13:49:11 -05:00
2011-02-06 17:09:48 -05:00
if ( message . getUid ( ) ! = null & & localFolder . getLastUid ( ) ! = null ) {
try {
2011-01-02 04:01:23 -05:00
Integer messageUid = Integer . parseInt ( message . getUid ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( messageUid < = localFolder . getLastUid ( ) ) {
if ( K9 . DEBUG )
2011-05-20 17:00:48 -04:00
Log . d ( K9 . LOG_TAG , " Message uid is " + messageUid + " , max message uid is " +
2011-06-01 16:03:56 -04:00
localFolder . getLastUid ( ) + " . Skipping notification. " ) ;
2011-01-02 04:01:23 -05:00
return false ;
}
2011-02-06 17:09:48 -05:00
} catch ( NumberFormatException e ) {
2011-01-02 04:01:23 -05:00
// Nothing to be done here.
}
}
2011-05-20 17:00:48 -04:00
// Don't notify if the sender address matches one of our identities and the user chose not
// to be notified for such messages.
if ( account . isAnIdentity ( message . getFrom ( ) ) & & ! account . isNotifySelfNewMail ( ) ) {
return false ;
}
2010-08-08 14:50:31 -04:00
2011-05-20 17:00:48 -04:00
return true ;
2010-08-08 14:50:31 -04:00
}
2013-01-08 06:52:56 -05:00
/ * *
* Get the pending notification data for an account .
* See { @link NotificationData } .
*
* @param account The account to retrieve the pending data for
* @param previousUnreadMessageCount The number of currently pending messages , which will be used
* if there ' s no pending data yet . If passed as null , a new instance
* won ' t be created if currently not existent .
* @return A pending data instance , or null if one doesn ' t exist and
* previousUnreadMessageCount was passed as null .
* /
private NotificationData getNotificationData ( Account account , Integer previousUnreadMessageCount ) {
2013-01-01 06:48:31 -05:00
NotificationData data ;
2010-08-08 14:50:31 -04:00
2013-01-01 06:48:31 -05:00
synchronized ( notificationData ) {
data = notificationData . get ( account . getAccountNumber ( ) ) ;
2013-01-08 06:52:56 -05:00
if ( data = = null & & previousUnreadMessageCount ! = null ) {
2013-01-01 06:48:31 -05:00
data = new NotificationData ( previousUnreadMessageCount ) ;
notificationData . put ( account . getAccountNumber ( ) , data ) ;
}
}
2010-08-08 14:50:31 -04:00
2013-01-01 06:48:31 -05:00
return data ;
}
2011-01-23 22:27:14 -05:00
2013-01-01 06:48:31 -05:00
private CharSequence getMessageSender ( Context context , Account account , Message message ) {
2011-02-06 17:09:48 -05:00
try {
2013-01-01 06:48:31 -05:00
boolean isSelf = false ;
2013-01-02 10:13:27 -05:00
final Contacts contacts = K9 . showContactName ( ) ? Contacts . getInstance ( context ) : null ;
final Address [ ] fromAddrs = message . getFrom ( ) ;
2013-01-01 06:48:31 -05:00
2013-01-02 10:13:27 -05:00
if ( fromAddrs ! = null ) {
2013-01-01 06:48:31 -05:00
isSelf = account . isAnIdentity ( fromAddrs ) ;
2013-01-02 10:13:27 -05:00
if ( ! isSelf & & fromAddrs . length > 0 ) {
return fromAddrs [ 0 ] . toFriendly ( contacts ) . toString ( ) ;
2010-09-01 18:37:11 -04:00
}
2013-01-01 06:48:31 -05:00
}
2010-10-05 02:04:28 -04:00
2013-01-02 10:13:27 -05:00
if ( isSelf ) {
2013-01-01 06:48:31 -05:00
// show To: if the message was sent from me
Address [ ] rcpts = message . getRecipients ( Message . RecipientType . TO ) ;
2013-01-02 10:13:27 -05:00
if ( rcpts ! = null & & rcpts . length > 0 ) {
return context . getString ( R . string . message_to_fmt ,
rcpts [ 0 ] . toFriendly ( contacts ) . toString ( ) ) ;
2010-01-21 13:49:11 -05:00
}
2010-10-05 02:04:28 -04:00
2013-01-01 06:48:31 -05:00
return context . getString ( R . string . general_no_sender ) ;
2010-01-21 13:49:11 -05:00
}
2011-02-06 17:09:48 -05:00
} catch ( MessagingException e ) {
2013-01-01 06:48:31 -05:00
Log . e ( K9 . LOG_TAG , " Unable to get sender information for notification. " , e ) ;
}
return null ;
}
private CharSequence getMessageSubject ( Context context , Message message ) {
String subject = message . getSubject ( ) ;
if ( ! TextUtils . isEmpty ( subject ) ) {
return subject ;
}
return context . getString ( R . string . general_no_subject ) ;
}
2013-01-02 11:02:57 -05:00
private static TextAppearanceSpan sEmphasizedSpan ;
2013-01-05 07:20:46 -05:00
private TextAppearanceSpan getEmphasizedSpan ( Context context ) {
2013-01-02 11:02:57 -05:00
if ( sEmphasizedSpan = = null ) {
sEmphasizedSpan = new TextAppearanceSpan ( context ,
R . style . TextAppearance_StatusBar_EventContent_Emphasized ) ;
}
2013-01-05 07:20:46 -05:00
return sEmphasizedSpan ;
2013-01-02 11:02:57 -05:00
}
private CharSequence getMessagePreview ( Context context , Message message ) {
2013-01-01 06:48:31 -05:00
CharSequence subject = getMessageSubject ( context , message ) ;
2013-01-05 07:20:46 -05:00
String snippet = message . getPreview ( ) ;
2013-01-01 06:48:31 -05:00
if ( TextUtils . isEmpty ( subject ) ) {
return snippet ;
} else if ( TextUtils . isEmpty ( snippet ) ) {
return subject ;
}
SpannableStringBuilder preview = new SpannableStringBuilder ( ) ;
preview . append ( subject ) ;
preview . append ( '\n' ) ;
preview . append ( snippet ) ;
2013-01-05 07:20:46 -05:00
preview . setSpan ( getEmphasizedSpan ( context ) , 0 , subject . length ( ) , 0 ) ;
2013-01-01 06:48:31 -05:00
return preview ;
}
2013-01-02 11:02:57 -05:00
private CharSequence buildMessageSummary ( Context context , CharSequence sender , CharSequence subject ) {
2013-01-01 06:48:31 -05:00
if ( sender = = null ) {
return subject ;
}
2013-01-02 11:02:57 -05:00
SpannableStringBuilder summary = new SpannableStringBuilder ( ) ;
summary . append ( sender ) ;
summary . append ( " " ) ;
summary . append ( subject ) ;
2013-01-05 07:20:46 -05:00
summary . setSpan ( getEmphasizedSpan ( context ) , 0 , sender . length ( ) , 0 ) ;
2013-01-02 11:02:57 -05:00
return summary ;
2013-01-01 06:48:31 -05:00
}
2013-01-04 02:24:03 -05:00
private static final boolean platformShowsNumberInNotification ( ) {
2013-01-01 06:48:31 -05:00
// Honeycomb and newer don't show the number as overlay on the notification icon.
// However, the number will appear in the detailed notification view.
return Build . VERSION . SDK_INT > = Build . VERSION_CODES . HONEYCOMB ;
}
2013-01-04 02:24:03 -05:00
public static final boolean platformSupportsExtendedNotifications ( ) {
2013-01-01 06:48:31 -05:00
// supported in Jellybean
// TODO: use constant once target SDK is set to >= 16
return Build . VERSION . SDK_INT > = 16 ;
}
2013-01-05 07:20:46 -05:00
private Message findNewestMessageForNotificationLocked ( Context context ,
Account account , NotificationData data ) {
if ( ! data . messages . isEmpty ( ) ) {
2013-01-08 03:27:28 -05:00
return data . messages . getFirst ( ) ;
2013-01-03 04:07:21 -05:00
}
2013-01-05 07:20:46 -05:00
if ( ! data . droppedMessages . isEmpty ( ) ) {
2013-01-08 03:27:28 -05:00
return data . droppedMessages . getFirst ( ) . restoreToLocalMessage ( context ) ;
2013-01-03 04:07:21 -05:00
}
return null ;
}
2013-01-01 06:48:31 -05:00
/ * *
* Creates a notification of a newly received message .
* /
2013-01-03 04:07:21 -05:00
private void notifyAccount ( Context context , Account account ,
Message message , int previousUnreadMessageCount ) {
final NotificationData data = getNotificationData ( account , previousUnreadMessageCount ) ;
synchronized ( data ) {
notifyAccountWithDataLocked ( context , account , message , data ) ;
}
}
private void notifyAccountWithDataLocked ( Context context , Account account ,
Message message , NotificationData data ) {
boolean updateSilently = false ;
if ( message = = null ) {
/* this can happen if a message we previously notified for is read or deleted remotely */
2013-01-05 07:20:46 -05:00
message = findNewestMessageForNotificationLocked ( context , account , data ) ;
2013-01-03 04:07:21 -05:00
updateSilently = true ;
if ( message = = null ) {
2013-01-08 04:06:01 -05:00
// seemingly both the message list as well as the overflow list is empty;
// it probably is a good idea to cancel the notification in that case
notifyAccountCancel ( context , account ) ;
2013-01-03 04:07:21 -05:00
return ;
}
} else {
2013-01-08 03:27:28 -05:00
data . addMessage ( message ) ;
2009-11-29 11:55:35 -05:00
}
2010-07-14 23:42:13 -04:00
2013-01-01 06:48:31 -05:00
final KeyguardManager keyguardService = ( KeyguardManager ) context . getSystemService ( Context . KEYGUARD_SERVICE ) ;
final CharSequence sender = getMessageSender ( context , account , message ) ;
final CharSequence subject = getMessageSubject ( context , message ) ;
2013-01-02 11:02:57 -05:00
CharSequence summary = buildMessageSummary ( context , sender , subject ) ;
2013-01-01 06:48:31 -05:00
2010-09-01 18:37:11 -04:00
// If privacy mode active and keyguard active
// OR
2012-08-01 19:41:40 -04:00
// GlobalPreference is ALWAYS hide subject
// OR
2010-01-21 13:49:11 -05:00
// If we could not set a per-message notification, revert to a default message
2012-08-01 20:31:54 -04:00
if ( ( K9 . getNotificationHideSubject ( ) = = NotificationHideSubject . WHEN_LOCKED & &
keyguardService . inKeyguardRestrictedInputMode ( ) ) | |
( K9 . getNotificationHideSubject ( ) = = NotificationHideSubject . ALWAYS ) | |
2013-01-01 06:48:31 -05:00
summary . length ( ) = = 0 ) {
2013-01-05 07:59:16 -05:00
summary = context . getString ( R . string . notification_new_title ) ;
2010-01-21 13:49:11 -05:00
}
2009-12-06 19:56:06 -05:00
2010-01-21 13:49:11 -05:00
NotificationManager notifMgr =
2012-05-04 16:03:35 -04:00
( NotificationManager ) context . getSystemService ( Context . NOTIFICATION_SERVICE ) ;
2013-02-20 17:55:46 -05:00
NotificationCompat . Builder builder = new NotificationBuilder ( context ) ;
2012-05-04 16:03:35 -04:00
builder . setSmallIcon ( R . drawable . stat_notify_email_generic ) ;
builder . setWhen ( System . currentTimeMillis ( ) ) ;
2013-01-03 04:07:21 -05:00
if ( ! updateSilently ) {
builder . setTicker ( summary ) ;
}
2012-05-04 16:03:35 -04:00
2013-01-03 04:07:21 -05:00
final int newMessages = data . getNewMessageCount ( ) ;
final int unreadCount = data . unreadBeforeNotification + newMessages ;
2013-01-01 06:48:31 -05:00
2013-01-03 04:07:21 -05:00
if ( account . isNotificationShowsUnreadCount ( ) | | platformShowsNumberInNotification ( ) ) {
2012-05-04 16:03:35 -04:00
builder . setNumber ( unreadCount ) ;
2011-01-11 20:23:17 -05:00
}
2009-11-24 19:40:29 -05:00
2012-05-04 16:03:35 -04:00
String accountDescr = ( account . getDescription ( ) ! = null ) ?
account . getDescription ( ) : account . getEmail ( ) ;
2013-01-04 10:11:39 -05:00
final ArrayList < MessageReference > allRefs = data . getAllMessageRefs ( ) ;
2009-11-24 19:40:29 -05:00
2013-01-03 04:07:21 -05:00
if ( platformSupportsExtendedNotifications ( ) ) {
if ( newMessages > 1 ) {
// multiple messages pending, show inbox style
NotificationCompat . InboxStyle style = new NotificationCompat . InboxStyle ( builder ) ;
for ( Message m : data . messages ) {
style . addLine ( buildMessageSummary ( context ,
getMessageSender ( context , account , m ) ,
getMessageSubject ( context , m ) ) ) ;
}
2013-01-05 07:20:46 -05:00
if ( ! data . droppedMessages . isEmpty ( ) ) {
2013-01-05 07:59:16 -05:00
style . setSummaryText ( context . getString ( R . string . notification_additional_messages ,
data . droppedMessages . size ( ) , accountDescr ) ) ;
2013-01-01 06:48:31 -05:00
}
2013-01-05 07:59:16 -05:00
String title = context . getString ( R . string . notification_new_messages_title , newMessages ) ;
2013-01-03 04:07:21 -05:00
style . setBigContentTitle ( title ) ;
builder . setContentTitle ( title ) ;
builder . setSubText ( accountDescr ) ;
builder . setStyle ( style ) ;
2013-01-01 06:48:31 -05:00
} else {
2013-01-03 04:07:21 -05:00
// single message pending, show big text
NotificationCompat . BigTextStyle style = new NotificationCompat . BigTextStyle ( builder ) ;
CharSequence preview = getMessagePreview ( context , message ) ;
if ( preview ! = null ) {
style . bigText ( preview ) ;
}
builder . setContentText ( subject ) ;
builder . setSubText ( accountDescr ) ;
builder . setContentTitle ( sender ) ;
builder . setStyle ( style ) ;
builder . addAction ( R . drawable . ic_action_single_message_options_dark ,
context . getString ( R . string . notification_action_reply ) ,
2013-01-04 02:24:03 -05:00
NotificationActionService . getReplyIntent ( context , account , message . makeMessageReference ( ) ) ) ;
2013-01-03 04:07:21 -05:00
}
2013-01-04 02:24:03 -05:00
2013-01-03 04:07:21 -05:00
builder . addAction ( R . drawable . ic_action_mark_as_read_dark ,
context . getString ( R . string . notification_action_read ) ,
2013-01-04 02:24:03 -05:00
NotificationActionService . getReadAllMessagesIntent ( context , account , allRefs ) ) ;
NotificationQuickDelete deleteOption = K9 . getNotificationQuickDeleteBehaviour ( ) ;
boolean showDeleteAction = deleteOption = = NotificationQuickDelete . ALWAYS | |
( deleteOption = = NotificationQuickDelete . FOR_SINGLE_MSG & & newMessages = = 1 ) ;
if ( showDeleteAction ) {
// we need to pass the action directly to the activity, otherwise the
// status bar won't be pulled up and we won't see the confirmation (if used)
builder . addAction ( R . drawable . ic_action_delete_dark ,
context . getString ( R . string . notification_action_delete ) ,
NotificationDeleteConfirmation . getIntent ( context , account , allRefs ) ) ;
}
2013-01-03 04:07:21 -05:00
} else {
String accountNotice = context . getString ( R . string . notification_new_one_account_fmt ,
unreadCount , accountDescr ) ;
builder . setContentTitle ( accountNotice ) ;
builder . setContentText ( summary ) ;
2013-01-01 06:48:31 -05:00
}
2009-11-24 19:40:29 -05:00
2013-01-04 10:11:39 -05:00
for ( Message m : data . messages ) {
if ( m . isSet ( Flag . FLAGGED ) ) {
builder . setPriority ( NotificationCompat . PRIORITY_HIGH ) ;
break ;
}
}
2013-01-05 08:10:07 -05:00
Intent targetIntent ;
2013-01-06 06:16:54 -05:00
boolean treatAsSingleMessageNotification ;
2013-01-05 08:10:07 -05:00
2013-01-06 06:16:54 -05:00
if ( platformSupportsExtendedNotifications ( ) ) {
// in the new-style notifications, we focus on the new messages, not the unread ones
treatAsSingleMessageNotification = newMessages = = 1 ;
} else {
// in the old-style notifications, we focus on unread messages, as we don't have a
// good way to express the new message count
treatAsSingleMessageNotification = unreadCount = = 1 ;
}
if ( treatAsSingleMessageNotification ) {
2013-01-30 22:34:23 -05:00
targetIntent = MessageList . actionHandleNotificationIntent (
2013-01-06 06:13:36 -05:00
context , message . makeMessageReference ( ) ) ;
2013-01-05 08:10:07 -05:00
} else {
String initialFolder = message . getFolder ( ) . getName ( ) ;
/* only go to folder if all messages are in the same folder, else go to folder list */
for ( MessageReference ref : allRefs ) {
if ( ! TextUtils . equals ( initialFolder , ref . folderName ) ) {
initialFolder = null ;
break ;
}
}
targetIntent = FolderList . actionHandleNotification ( context , account , initialFolder ) ;
}
2013-01-06 06:16:54 -05:00
2013-01-10 03:45:37 -05:00
builder . setContentIntent ( PendingIntent . getActivity ( context ,
account . getAccountNumber ( ) , targetIntent , PendingIntent . FLAG_UPDATE_CURRENT ) ) ;
2013-01-07 03:12:07 -05:00
builder . setDeleteIntent ( NotificationActionService . getAcknowledgeIntent ( context , account ) ) ;
2009-11-24 19:40:29 -05:00
2012-05-04 16:03:35 -04:00
// Only ring or vibrate if we have not done so already on this account and fetch
2010-09-19 16:54:43 -04:00
boolean ringAndVibrate = false ;
2013-01-03 04:07:21 -05:00
if ( ! updateSilently & & ! account . isRingNotified ( ) ) {
2010-03-29 22:58:21 -04:00
account . setRingNotified ( true ) ;
2010-09-19 16:54:43 -04:00
ringAndVibrate = true ;
}
2010-11-28 16:48:21 -05:00
NotificationSetting n = account . getNotificationSetting ( ) ;
2012-03-07 15:40:41 -05:00
configureNotification (
2012-05-04 16:03:35 -04:00
builder ,
2012-03-07 15:40:41 -05:00
( n . shouldRing ( ) ) ? n . getRingtone ( ) : null ,
( n . shouldVibrate ( ) ) ? n . getVibration ( ) : null ,
( n . isLed ( ) ) ? Integer . valueOf ( n . getLedColor ( ) ) : null ,
K9 . NOTIFICATION_LED_BLINK_SLOW ,
ringAndVibrate ) ;
2010-09-19 16:54:43 -04:00
2013-01-01 06:37:14 -05:00
notifMgr . notify ( account . getAccountNumber ( ) , builder . build ( ) ) ;
2010-09-19 16:54:43 -04:00
}
/ * *
2012-05-04 16:03:35 -04:00
* Configure the notification sound and LED
*
* @param builder
2013-01-07 23:51:37 -05:00
* { @link NotificationCompat . Builder } instance used to configure the notification .
2012-05-04 16:03:35 -04:00
* Never { @code null } .
2011-01-02 04:01:23 -05:00
* @param ringtone
2012-05-04 16:03:35 -04:00
* String name of ringtone . { @code null } , if no ringtone should be played .
2010-11-28 16:48:21 -05:00
* @param vibrationPattern
2012-05-04 16:03:35 -04:00
* { @code long [ ] } vibration pattern . { @code null } , if no vibration should be played .
2010-11-28 16:48:21 -05:00
* @param ledColor
2012-05-04 16:03:35 -04:00
* Color to flash LED . { @code null } , if no LED flash should happen .
2010-11-28 16:48:25 -05:00
* @param ledSpeed
2012-05-04 16:03:35 -04:00
* Either { @link K9 # NOTIFICATION_LED_BLINK_SLOW } or
* { @link K9 # NOTIFICATION_LED_BLINK_FAST } .
2010-09-19 16:54:43 -04:00
* @param ringAndVibrate
2012-05-04 16:03:35 -04:00
* { @code true } , if ringtone / vibration are allowed . { @code false } , otherwise .
2010-09-19 16:54:43 -04:00
* /
2013-01-01 06:37:14 -05:00
private void configureNotification ( NotificationCompat . Builder builder , String ringtone ,
2012-05-04 16:03:35 -04:00
long [ ] vibrationPattern , Integer ledColor , int ledSpeed , boolean ringAndVibrate ) {
2010-11-28 21:21:16 -05:00
// if it's quiet time, then we shouldn't be ringing, buzzing or flashing
2011-02-06 17:09:48 -05:00
if ( K9 . isQuietTime ( ) ) {
2010-11-28 21:21:16 -05:00
return ;
}
2011-02-06 17:09:48 -05:00
if ( ringAndVibrate ) {
2012-05-04 16:03:35 -04:00
if ( ringtone ! = null & & ! TextUtils . isEmpty ( ringtone ) ) {
builder . setSound ( Uri . parse ( ringtone ) ) ;
2010-03-29 22:58:21 -04:00
}
2012-05-04 16:03:35 -04:00
2011-02-06 17:09:48 -05:00
if ( vibrationPattern ! = null ) {
2012-05-04 16:03:35 -04:00
builder . setVibrate ( vibrationPattern ) ;
2010-03-29 22:58:21 -04:00
}
2010-01-21 13:49:11 -05:00
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
if ( ledColor ! = null ) {
2012-05-04 16:03:35 -04:00
int ledOnMS ;
int ledOffMS ;
2011-02-06 17:09:48 -05:00
if ( ledSpeed = = K9 . NOTIFICATION_LED_BLINK_SLOW ) {
2012-05-04 16:03:35 -04:00
ledOnMS = K9 . NOTIFICATION_LED_ON_TIME ;
ledOffMS = K9 . NOTIFICATION_LED_OFF_TIME ;
} else {
ledOnMS = K9 . NOTIFICATION_LED_FAST_ON_TIME ;
ledOffMS = K9 . NOTIFICATION_LED_FAST_OFF_TIME ;
2010-11-28 16:48:25 -05:00
}
2012-05-04 16:03:35 -04:00
builder . setLights ( ledColor , ledOnMS , ledOffMS ) ;
2010-09-19 16:54:43 -04:00
}
2010-01-21 13:49:11 -05:00
}
2009-11-24 19:40:29 -05:00
2010-01-21 13:49:11 -05:00
/** Cancel a notification of new email messages */
2011-02-06 17:09:48 -05:00
public void notifyAccountCancel ( Context context , Account account ) {
2010-01-21 13:49:11 -05:00
NotificationManager notifMgr =
( NotificationManager ) context . getSystemService ( Context . NOTIFICATION_SERVICE ) ;
notifMgr . cancel ( account . getAccountNumber ( ) ) ;
2010-05-16 20:30:32 -04:00
notifMgr . cancel ( - 1000 - account . getAccountNumber ( ) ) ;
2013-01-01 06:48:31 -05:00
notificationData . remove ( account . getAccountNumber ( ) ) ;
2009-10-21 20:41:06 -04:00
}
2011-01-02 04:01:23 -05:00
/ * *
* Save a draft message .
* @param account Account we are saving for .
* @param message Message to save .
* @return Message representing the entry in the local store .
* /
2012-01-21 23:14:58 -05:00
public Message saveDraft ( final Account account , final Message message , long existingDraftId ) {
2010-03-03 23:00:30 -05:00
Message localMessage = null ;
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
LocalFolder localFolder = localStore . getFolder ( account . getDraftsFolderName ( ) ) ;
2008-11-01 17:32:06 -04:00
localFolder . open ( OpenMode . READ_WRITE ) ;
2012-01-21 23:14:58 -05:00
if ( existingDraftId ! = INVALID_MESSAGE_ID ) {
String uid = localFolder . getMessageUidById ( existingDraftId ) ;
message . setUid ( uid ) ;
}
2011-01-02 04:01:23 -05:00
// Save the message to the store.
2011-02-06 17:09:48 -05:00
localFolder . appendMessages ( new Message [ ] {
2009-11-26 00:10:12 -05:00
message
} ) ;
2011-01-02 04:01:23 -05:00
// Fetch the message back from the store. This is the Message that's returned to the caller.
2010-03-03 23:00:30 -05:00
localMessage = localFolder . getMessage ( message . getUid ( ) ) ;
2008-11-01 17:32:06 -04:00
localMessage . setFlag ( Flag . X_DOWNLOADED_FULL , true ) ;
PendingCommand command = new PendingCommand ( ) ;
command . command = PENDING_COMMAND_APPEND ;
2011-02-06 17:09:48 -05:00
command . arguments = new String [ ] {
2009-11-24 19:40:29 -05:00
localFolder . getName ( ) ,
localMessage . getUid ( )
} ;
2008-11-01 17:32:06 -04:00
queuePendingCommand ( account , command ) ;
processPendingCommands ( account ) ;
2010-04-29 00:59:14 -04:00
2011-02-06 17:09:48 -05:00
} catch ( MessagingException e ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Unable to save message as draft. " , e ) ;
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , e ) ;
2008-11-01 17:32:06 -04:00
}
2010-03-03 23:00:30 -05:00
return localMessage ;
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -05:00
2012-01-21 23:14:58 -05:00
public long getId ( Message message ) {
long id ;
if ( message instanceof LocalMessage ) {
id = ( ( LocalMessage ) message ) . getId ( ) ;
} else {
Log . w ( K9 . LOG_TAG , " MessagingController.getId() called without a LocalMessage " ) ;
id = INVALID_MESSAGE_ID ;
}
return id ;
}
2011-02-06 17:09:48 -05:00
public boolean modeMismatch ( Account . FolderMode aMode , Folder . FolderClass fMode ) {
2009-10-21 20:41:06 -04:00
if ( aMode = = Account . FolderMode . NONE
2009-11-24 19:40:29 -05:00
| | ( aMode = = Account . FolderMode . FIRST_CLASS & &
fMode ! = Folder . FolderClass . FIRST_CLASS )
2009-10-21 20:41:06 -04:00
| | ( aMode = = Account . FolderMode . FIRST_AND_SECOND_CLASS & &
2009-11-24 19:40:29 -05:00
fMode ! = Folder . FolderClass . FIRST_CLASS & &
fMode ! = Folder . FolderClass . SECOND_CLASS )
| | ( aMode = = Account . FolderMode . NOT_SECOND_CLASS & &
2011-02-06 17:09:48 -05:00
fMode = = Folder . FolderClass . SECOND_CLASS ) ) {
2009-10-21 20:41:06 -04:00
return true ;
2011-02-06 17:09:48 -05:00
} else {
2009-10-21 20:41:06 -04:00
return false ;
}
}
2008-11-01 17:32:06 -04:00
2009-10-21 20:41:06 -04:00
static AtomicInteger sequencing = new AtomicInteger ( 0 ) ;
2011-02-06 17:09:48 -05:00
static class Command implements Comparable < Command > {
2008-11-01 17:32:06 -04:00
public Runnable runnable ;
public MessagingListener listener ;
public String description ;
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
boolean isForeground ;
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
int sequence = sequencing . getAndIncrement ( ) ;
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public int compareTo ( Command other ) {
if ( other . isForeground & & ! isForeground ) {
2010-04-16 08:20:10 -04:00
return 1 ;
2011-02-06 17:09:48 -05:00
} else if ( ! other . isForeground & & isForeground ) {
2010-04-16 08:20:10 -04:00
return - 1 ;
2011-02-06 17:09:48 -05:00
} else {
2010-04-16 08:20:10 -04:00
return ( sequence - other . sequence ) ;
2009-10-21 20:41:06 -04:00
}
}
2008-11-01 17:32:06 -04:00
}
2009-01-11 18:43:32 -05:00
2011-02-06 17:09:48 -05:00
public MessagingListener getCheckMailListener ( ) {
2009-11-24 19:40:29 -05:00
return checkMailListener ;
2009-01-11 18:43:32 -05:00
}
2011-02-06 17:09:48 -05:00
public void setCheckMailListener ( MessagingListener checkMailListener ) {
if ( this . checkMailListener ! = null ) {
2009-11-24 19:40:29 -05:00
removeListener ( this . checkMailListener ) ;
}
this . checkMailListener = checkMailListener ;
2011-02-06 17:09:48 -05:00
if ( this . checkMailListener ! = null ) {
2009-11-24 19:40:29 -05:00
addListener ( this . checkMailListener ) ;
}
2009-01-11 18:43:32 -05:00
}
2009-01-31 19:08:14 -05:00
2011-02-06 17:09:48 -05:00
public Collection < Pusher > getPushers ( ) {
2009-10-21 20:41:06 -04:00
return pushers . values ( ) ;
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
public boolean setupPushing ( final Account account ) {
try {
2009-11-28 09:51:44 -05:00
Pusher previousPusher = pushers . remove ( account ) ;
2011-02-06 17:09:48 -05:00
if ( previousPusher ! = null ) {
2009-11-28 09:51:44 -05:00
previousPusher . stop ( ) ;
2009-11-22 12:01:04 -05:00
}
2009-10-21 20:41:06 -04:00
Preferences prefs = Preferences . getPreferences ( mApplication ) ;
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
Account . FolderMode aDisplayMode = account . getFolderDisplayMode ( ) ;
Account . FolderMode aPushMode = account . getFolderPushMode ( ) ;
List < String > names = new ArrayList < String > ( ) ;
2009-11-24 19:40:29 -05:00
2010-03-03 23:00:30 -05:00
Store localStore = account . getLocalStore ( ) ;
2011-02-06 17:09:48 -05:00
for ( final Folder folder : localStore . getPersonalNamespaces ( false ) ) {
2010-02-06 00:35:15 -05:00
if ( folder . getName ( ) . equals ( account . getErrorFolderName ( ) )
2011-02-06 17:09:48 -05:00
| | folder . getName ( ) . equals ( account . getOutboxFolderName ( ) ) ) {
2010-11-03 23:11:34 -04:00
/ *
if ( K9 . DEBUG )
2010-02-06 00:35:15 -05:00
Log . v ( K9 . LOG_TAG , " Not pushing folder " + folder . getName ( ) +
" which should never be pushed " ) ;
2010-11-03 23:11:34 -04:00
* /
2010-02-06 00:35:15 -05:00
continue ;
}
2009-10-21 20:41:06 -04:00
folder . open ( Folder . OpenMode . READ_WRITE ) ;
folder . refresh ( prefs ) ;
Folder . FolderClass fDisplayClass = folder . getDisplayClass ( ) ;
Folder . FolderClass fPushClass = folder . getPushClass ( ) ;
2011-02-06 17:09:48 -05:00
if ( modeMismatch ( aDisplayMode , fDisplayClass ) ) {
2009-10-21 20:41:06 -04:00
// Never push a folder that isn't displayed
2010-11-03 23:11:34 -04:00
/ *
if ( K9 . DEBUG )
2009-12-14 21:50:53 -05:00
Log . v ( K9 . LOG_TAG , " Not pushing folder " + folder . getName ( ) +
2009-11-24 19:40:29 -05:00
" which is in display class " + fDisplayClass + " while account is in display mode " + aDisplayMode ) ;
2010-11-03 23:11:34 -04:00
* /
2009-10-21 20:41:06 -04:00
continue ;
}
2011-02-06 17:09:48 -05:00
if ( modeMismatch ( aPushMode , fPushClass ) ) {
2009-10-21 20:41:06 -04:00
// Do not push folders in the wrong class
2010-11-03 23:11:34 -04:00
/ *
if ( K9 . DEBUG )
2009-12-14 21:50:53 -05:00
Log . v ( K9 . LOG_TAG , " Not pushing folder " + folder . getName ( ) +
2009-11-24 19:40:29 -05:00
" which is in push mode " + fPushClass + " while account is in push mode " + aPushMode ) ;
2010-11-03 23:11:34 -04:00
* /
2009-10-21 20:41:06 -04:00
continue ;
}
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Starting pusher for " + account . getDescription ( ) + " : " + folder . getName ( ) ) ;
2009-10-21 20:41:06 -04:00
names . add ( folder . getName ( ) ) ;
}
2009-12-06 19:56:06 -05:00
2011-10-06 12:28:14 -04:00
if ( ! names . isEmpty ( ) ) {
2009-11-28 09:51:44 -05:00
PushReceiver receiver = new MessagingControllerPushReceiver ( mApplication , account , this ) ;
2009-12-24 13:08:23 -05:00
int maxPushFolders = account . getMaxPushFolders ( ) ;
2010-01-02 20:50:41 -05:00
2011-02-06 17:09:48 -05:00
if ( names . size ( ) > maxPushFolders ) {
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Count of folders to push for account " + account . getDescription ( ) + " is " + names . size ( )
+ " , greater than limit of " + maxPushFolders + " , truncating " ) ;
2009-12-24 13:08:23 -05:00
names = names . subList ( 0 , maxPushFolders ) ;
}
2009-12-06 19:56:06 -05:00
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
Store store = account . getRemoteStore ( ) ;
2011-02-06 17:09:48 -05:00
if ( ! store . isPushCapable ( ) ) {
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Account " + account . getDescription ( ) + " is not push capable, skipping " ) ;
2009-11-28 09:51:44 -05:00
return false ;
}
Pusher pusher = store . getPusher ( receiver ) ;
2011-02-06 17:09:48 -05:00
if ( pusher ! = null ) {
2010-05-06 09:27:42 -04:00
Pusher oldPusher = pushers . putIfAbsent ( account , pusher ) ;
2011-02-06 17:09:48 -05:00
if ( oldPusher = = null ) {
2010-05-06 09:27:42 -04:00
pusher . start ( names ) ;
}
}
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Could not get remote store " , e ) ;
2009-11-28 09:51:44 -05:00
return false ;
2009-10-21 20:41:06 -04:00
}
2009-12-06 19:56:06 -05:00
2009-11-28 09:51:44 -05:00
return true ;
2011-02-06 17:09:48 -05:00
} else {
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " No folders are configured for pushing in account " + account . getDescription ( ) ) ;
2009-11-28 09:51:44 -05:00
return false ;
2009-10-21 20:41:06 -04:00
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Got exception while setting up pushing " , e ) ;
2009-10-21 20:41:06 -04:00
}
2009-11-28 09:51:44 -05:00
return false ;
2009-10-21 20:41:06 -04:00
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
public void stopAllPushing ( ) {
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Stopping all pushers " ) ;
2009-10-21 20:41:06 -04:00
Iterator < Pusher > iter = pushers . values ( ) . iterator ( ) ;
2011-02-06 17:09:48 -05:00
while ( iter . hasNext ( ) ) {
2009-10-21 20:41:06 -04:00
Pusher pusher = iter . next ( ) ;
iter . remove ( ) ;
pusher . stop ( ) ;
}
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
public void messagesArrived ( final Account account , final Folder remoteFolder , final List < Message > messages , final boolean flagSyncOnly ) {
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " Got new pushed email messages for account " + account . getDescription ( )
+ " , folder " + remoteFolder . getName ( ) ) ;
2009-10-21 20:41:06 -04:00
final CountDownLatch latch = new CountDownLatch ( 1 ) ;
2009-11-24 19:40:29 -05:00
putBackground ( " Push messageArrived of account " + account . getDescription ( )
2011-02-06 17:09:48 -05:00
+ " , folder " + remoteFolder . getName ( ) , null , new Runnable ( ) {
2010-12-20 16:34:01 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2009-10-21 20:41:06 -04:00
LocalFolder localFolder = null ;
2011-02-06 17:09:48 -05:00
try {
2010-03-03 23:00:30 -05:00
LocalStore localStore = account . getLocalStore ( ) ;
2011-01-18 19:57:12 -05:00
localFolder = localStore . getFolder ( remoteFolder . getName ( ) ) ;
2009-10-21 20:41:06 -04:00
localFolder . open ( OpenMode . READ_WRITE ) ;
2010-03-29 22:58:21 -04:00
account . setRingNotified ( false ) ;
2009-11-26 00:10:12 -05:00
int newCount = downloadMessages ( account , remoteFolder , localFolder , messages , flagSyncOnly ) ;
2012-12-07 09:45:36 -05:00
int unreadMessageCount = localFolder . getUnreadMessageCount ( ) ;
2010-04-16 10:33:54 -04:00
2009-10-21 20:41:06 -04:00
localFolder . setLastPush ( System . currentTimeMillis ( ) ) ;
localFolder . setStatus ( null ) ;
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
2010-01-21 13:49:11 -05:00
Log . i ( K9 . LOG_TAG , " messagesArrived newCount = " + newCount + " , unread count = " + unreadMessageCount ) ;
2010-01-02 20:50:41 -05:00
2011-02-06 17:09:48 -05:00
if ( unreadMessageCount = = 0 ) {
2010-01-21 13:49:11 -05:00
notifyAccountCancel ( mApplication , account ) ;
}
2009-10-21 20:41:06 -04:00
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
l . folderStatusChanged ( account , remoteFolder . getName ( ) , unreadMessageCount ) ;
2009-10-21 20:41:06 -04:00
}
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2009-10-21 20:41:06 -04:00
String rootMessage = getRootCauseMessage ( e ) ;
String errorMessage = " Push failed: " + rootMessage ;
2011-02-06 17:09:48 -05:00
try {
2011-01-18 19:57:12 -05:00
// Oddly enough, using a local variable gets rid of a
// potential null pointer access warning with Eclipse.
LocalFolder folder = localFolder ;
folder . setStatus ( errorMessage ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception se ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Unable to set failed status on localFolder " , se ) ;
2009-10-21 20:41:06 -04:00
}
2011-02-06 17:09:48 -05:00
for ( MessagingListener l : getListeners ( ) ) {
2009-11-26 00:10:12 -05:00
l . synchronizeMailboxFailed ( account , remoteFolder . getName ( ) , errorMessage ) ;
2009-10-21 20:41:06 -04:00
}
2010-04-14 23:17:25 -04:00
addErrorMessage ( account , null , e ) ;
2011-02-06 17:09:48 -05:00
} finally {
2010-11-28 15:28:58 -05:00
closeFolder ( localFolder ) ;
2009-10-21 20:41:06 -04:00
latch . countDown ( ) ;
}
}
} ) ;
2011-02-06 17:09:48 -05:00
try {
2009-10-21 20:41:06 -04:00
latch . await ( ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2009-12-14 21:50:53 -05:00
Log . e ( K9 . LOG_TAG , " Interrupted while awaiting latch release " , e ) ;
2009-10-21 20:41:06 -04:00
}
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . i ( K9 . LOG_TAG , " MessagingController.messagesArrivedLatch released " ) ;
2009-10-21 20:41:06 -04:00
}
2011-02-04 18:18:08 -05:00
2011-02-06 17:09:48 -05:00
public void systemStatusChanged ( ) {
for ( MessagingListener l : getListeners ( ) ) {
2011-02-04 18:18:08 -05:00
l . systemStatusChanged ( ) ;
}
}
2010-11-30 22:07:28 -05:00
enum MemorizingState { STARTED , FINISHED , FAILED }
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
static class Memory {
2009-10-21 20:41:06 -04:00
Account account ;
String folderName ;
MemorizingState syncingState = null ;
MemorizingState sendingState = null ;
MemorizingState pushingState = null ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
MemorizingState processingState = null ;
2009-10-21 20:41:06 -04:00
String failureMessage = null ;
int syncingTotalMessagesInMailbox ;
int syncingNumNewMessages ;
2009-12-20 00:41:43 -05:00
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
int folderCompleted = 0 ;
int folderTotal = 0 ;
String processingCommandTitle = null ;
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
Memory ( Account nAccount , String nFolderName ) {
2009-10-21 20:41:06 -04:00
account = nAccount ;
folderName = nFolderName ;
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
String getKey ( ) {
2009-10-21 20:41:06 -04:00
return getMemoryKey ( account , folderName ) ;
}
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
}
2011-02-06 17:09:48 -05:00
static String getMemoryKey ( Account taccount , String tfolderName ) {
2009-10-21 20:41:06 -04:00
return taccount . getDescription ( ) + " : " + tfolderName ;
}
2011-02-06 17:09:48 -05:00
static class MemorizingListener extends MessagingListener {
2009-10-21 20:41:06 -04:00
HashMap < String , Memory > memories = new HashMap < String , Memory > ( 31 ) ;
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
Memory getMemory ( Account account , String folderName ) {
2009-10-21 20:41:06 -04:00
Memory memory = memories . get ( getMemoryKey ( account , folderName ) ) ;
2011-02-06 17:09:48 -05:00
if ( memory = = null ) {
2009-10-21 20:41:06 -04:00
memory = new Memory ( account , folderName ) ;
memories . put ( memory . getKey ( ) , memory ) ;
}
return memory ;
}
2009-11-24 19:40:29 -05:00
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public synchronized void synchronizeMailboxStarted ( Account account , String folder ) {
2009-10-21 20:41:06 -04:00
Memory memory = getMemory ( account , folder ) ;
memory . syncingState = MemorizingState . STARTED ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
memory . folderCompleted = 0 ;
memory . folderTotal = 0 ;
2009-10-21 20:41:06 -04:00
}
2010-04-16 08:20:10 -04:00
@Override
2009-10-21 20:41:06 -04:00
public synchronized void synchronizeMailboxFinished ( Account account , String folder ,
2011-02-06 17:09:48 -05:00
int totalMessagesInMailbox , int numNewMessages ) {
2009-10-21 20:41:06 -04:00
Memory memory = getMemory ( account , folder ) ;
2009-11-24 19:40:29 -05:00
memory . syncingState = MemorizingState . FINISHED ;
2009-10-21 20:41:06 -04:00
memory . syncingTotalMessagesInMailbox = totalMessagesInMailbox ;
memory . syncingNumNewMessages = numNewMessages ;
}
2010-04-16 08:20:10 -04:00
@Override
2009-10-21 20:41:06 -04:00
public synchronized void synchronizeMailboxFailed ( Account account , String folder ,
2011-02-06 17:09:48 -05:00
String message ) {
2009-10-21 20:41:06 -04:00
Memory memory = getMemory ( account , folder ) ;
memory . syncingState = MemorizingState . FAILED ;
memory . failureMessage = message ;
}
2011-02-06 17:09:48 -05:00
synchronized void refreshOther ( MessagingListener other ) {
if ( other ! = null ) {
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
Memory syncStarted = null ;
Memory sendStarted = null ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
Memory processingStarted = null ;
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
for ( Memory memory : memories . values ( ) ) {
if ( memory . syncingState ! = null ) {
switch ( memory . syncingState ) {
case STARTED :
syncStarted = memory ;
break ;
case FINISHED :
other . synchronizeMailboxFinished ( memory . account , memory . folderName ,
memory . syncingTotalMessagesInMailbox , memory . syncingNumNewMessages ) ;
break ;
case FAILED :
other . synchronizeMailboxFailed ( memory . account , memory . folderName ,
memory . failureMessage ) ;
break ;
2009-10-21 20:41:06 -04:00
}
}
2009-11-24 19:40:29 -05:00
2011-02-06 17:09:48 -05:00
if ( memory . sendingState ! = null ) {
switch ( memory . sendingState ) {
case STARTED :
sendStarted = memory ;
break ;
case FINISHED :
other . sendPendingMessagesCompleted ( memory . account ) ;
break ;
case FAILED :
other . sendPendingMessagesFailed ( memory . account ) ;
break ;
2009-10-21 20:41:06 -04:00
}
}
2011-02-06 17:09:48 -05:00
if ( memory . pushingState ! = null ) {
switch ( memory . pushingState ) {
case STARTED :
other . setPushActive ( memory . account , memory . folderName , true ) ;
break ;
case FINISHED :
other . setPushActive ( memory . account , memory . folderName , false ) ;
break ;
2013-02-04 05:18:49 -05:00
case FAILED :
break ;
2009-10-21 20:41:06 -04:00
}
}
2011-02-06 17:09:48 -05:00
if ( memory . processingState ! = null ) {
switch ( memory . processingState ) {
case STARTED :
processingStarted = memory ;
break ;
case FINISHED :
case FAILED :
other . pendingCommandsFinished ( memory . account ) ;
break ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
}
}
2009-10-21 20:41:06 -04:00
}
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
Memory somethingStarted = null ;
2011-02-06 17:09:48 -05:00
if ( syncStarted ! = null ) {
2009-10-21 20:41:06 -04:00
other . synchronizeMailboxStarted ( syncStarted . account , syncStarted . folderName ) ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
somethingStarted = syncStarted ;
2009-10-21 20:41:06 -04:00
}
2011-02-06 17:09:48 -05:00
if ( sendStarted ! = null ) {
2009-10-21 20:41:06 -04:00
other . sendPendingMessagesStarted ( sendStarted . account ) ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
somethingStarted = sendStarted ;
}
2011-02-06 17:09:48 -05:00
if ( processingStarted ! = null ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
other . pendingCommandsProcessing ( processingStarted . account ) ;
2011-02-06 17:09:48 -05:00
if ( processingStarted . processingCommandTitle ! = null ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
other . pendingCommandStarted ( processingStarted . account , processingStarted . processingCommandTitle ) ;
2009-12-20 00:41:43 -05:00
2011-02-06 17:09:48 -05:00
} else {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
other . pendingCommandCompleted ( processingStarted . account , processingStarted . processingCommandTitle ) ;
}
somethingStarted = processingStarted ;
}
2011-02-06 17:09:48 -05:00
if ( somethingStarted ! = null & & somethingStarted . folderTotal > 0 ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
other . synchronizeMailboxProgress ( somethingStarted . account , somethingStarted . folderName , somethingStarted . folderCompleted , somethingStarted . folderTotal ) ;
2009-10-21 20:41:06 -04:00
}
2009-11-24 19:40:29 -05:00
2009-10-21 20:41:06 -04:00
}
}
@Override
2011-02-06 17:09:48 -05:00
public synchronized void setPushActive ( Account account , String folderName , boolean active ) {
2009-10-21 20:41:06 -04:00
Memory memory = getMemory ( account , folderName ) ;
memory . pushingState = ( active ? MemorizingState . STARTED : MemorizingState . FINISHED ) ;
}
2009-11-24 19:40:29 -05:00
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public synchronized void sendPendingMessagesStarted ( Account account ) {
2009-10-21 20:41:06 -04:00
Memory memory = getMemory ( account , null ) ;
memory . sendingState = MemorizingState . STARTED ;
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
memory . folderCompleted = 0 ;
memory . folderTotal = 0 ;
2009-10-21 20:41:06 -04:00
}
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public synchronized void sendPendingMessagesCompleted ( Account account ) {
2009-10-21 20:41:06 -04:00
Memory memory = getMemory ( account , null ) ;
memory . sendingState = MemorizingState . FINISHED ;
}
2009-11-24 19:40:29 -05:00
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public synchronized void sendPendingMessagesFailed ( Account account ) {
2009-10-21 20:41:06 -04:00
Memory memory = getMemory ( account , null ) ;
memory . sendingState = MemorizingState . FAILED ;
}
2009-12-20 00:41:43 -05:00
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public synchronized void synchronizeMailboxProgress ( Account account , String folderName , int completed , int total ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
Memory memory = getMemory ( account , folderName ) ;
memory . folderCompleted = completed ;
memory . folderTotal = total ;
}
2009-12-20 00:41:43 -05:00
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public synchronized void pendingCommandsProcessing ( Account account ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
Memory memory = getMemory ( account , null ) ;
memory . processingState = MemorizingState . STARTED ;
memory . folderCompleted = 0 ;
memory . folderTotal = 0 ;
}
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public synchronized void pendingCommandsFinished ( Account account ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
Memory memory = getMemory ( account , null ) ;
memory . processingState = MemorizingState . FINISHED ;
}
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public synchronized void pendingCommandStarted ( Account account , String commandTitle ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
Memory memory = getMemory ( account , null ) ;
memory . processingCommandTitle = commandTitle ;
}
2009-12-20 00:41:43 -05:00
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public synchronized void pendingCommandCompleted ( Account account , String commandTitle ) {
Enhanced header in Accounts, MessageList and Folder to show the unread
count, scoped for the Activity, the in-progress operation, the account
on which the operation is in progress, the folder for the operation,
when appropriate, and the progress of the operation, when it applies
to multiple items. For the MessageList, also use the determinate
progress bar to show progress for synchronization of the folder being
displayed.
Fixes Issue 924.
Also, a minor change that might help with Issue 913, by putting the
insertion of the pending command into a background thread.
2009-12-19 19:02:46 -05:00
Memory memory = getMemory ( account , null ) ;
memory . processingCommandTitle = null ;
}
2009-10-21 20:41:06 -04:00
}
2010-01-13 20:07:28 -05:00
2012-11-03 00:56:12 -04:00
private void actOnMessages ( List < Message > messages , MessageActor actor ) {
2010-03-03 23:00:30 -05:00
Map < Account , Map < Folder , List < Message > > > accountMap = new HashMap < Account , Map < Folder , List < Message > > > ( ) ;
2010-04-29 00:59:14 -04:00
2011-02-06 17:09:48 -05:00
for ( Message message : messages ) {
2010-03-03 23:00:30 -05:00
Folder folder = message . getFolder ( ) ;
Account account = folder . getAccount ( ) ;
2010-04-29 00:59:14 -04:00
2010-03-03 23:00:30 -05:00
Map < Folder , List < Message > > folderMap = accountMap . get ( account ) ;
2011-02-06 17:09:48 -05:00
if ( folderMap = = null ) {
2010-03-03 23:00:30 -05:00
folderMap = new HashMap < Folder , List < Message > > ( ) ;
accountMap . put ( account , folderMap ) ;
}
List < Message > messageList = folderMap . get ( folder ) ;
2011-02-06 17:09:48 -05:00
if ( messageList = = null ) {
2010-03-03 23:00:30 -05:00
messageList = new LinkedList < Message > ( ) ;
folderMap . put ( folder , messageList ) ;
2010-01-06 00:41:19 -05:00
}
2010-04-29 00:59:14 -04:00
2010-03-03 23:00:30 -05:00
messageList . add ( message ) ;
2010-01-06 00:41:19 -05:00
}
2011-02-06 17:09:48 -05:00
for ( Map . Entry < Account , Map < Folder , List < Message > > > entry : accountMap . entrySet ( ) ) {
2010-03-03 23:00:30 -05:00
Account account = entry . getKey ( ) ;
2009-11-24 19:40:29 -05:00
2010-03-03 23:00:30 -05:00
//account.refresh(Preferences.getPreferences(K9.app));
Map < Folder , List < Message > > folderMap = entry . getValue ( ) ;
2011-02-06 17:09:48 -05:00
for ( Map . Entry < Folder , List < Message > > folderEntry : folderMap . entrySet ( ) ) {
2010-03-03 23:00:30 -05:00
Folder folder = folderEntry . getKey ( ) ;
List < Message > messageList = folderEntry . getValue ( ) ;
actor . act ( account , folder , messageList ) ;
}
}
}
2010-04-29 00:59:14 -04:00
2011-02-06 17:09:48 -05:00
interface MessageActor {
2010-03-03 23:00:30 -05:00
public void act ( final Account account , final Folder folder , final List < Message > messages ) ;
}
2008-11-01 17:32:06 -04:00
}