2008-11-01 17:32:06 -04:00
|
|
|
|
2008-12-16 18:34:01 -05:00
|
|
|
package com.android.email;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.util.Config;
|
|
|
|
import android.util.Log;
|
|
|
|
|
2008-12-16 18:34:01 -05:00
|
|
|
import com.android.email.activity.MessageCompose;
|
|
|
|
import com.android.email.mail.internet.BinaryTempFileBody;
|
|
|
|
import com.android.email.mail.internet.MimeMessage;
|
|
|
|
import com.android.email.service.BootReceiver;
|
|
|
|
import com.android.email.service.MailService;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2008-12-16 18:34:01 -05:00
|
|
|
public class Email extends Application {
|
2008-12-02 23:10:59 -05:00
|
|
|
public static Application app = null;
|
2008-11-01 17:32:06 -04:00
|
|
|
public static File tempDirectory;
|
2008-12-02 23:10:59 -05:00
|
|
|
public static final String LOG_TAG = "k9";
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Some log messages can be sent to a file, so that the logs
|
|
|
|
* can be read using unprivileged access (eg. Terminal Emulator)
|
|
|
|
* on the phone, without adb. Set to null to disable
|
|
|
|
*/
|
|
|
|
public static final String logFile = null;
|
|
|
|
//public static final String logFile = "/sdcard/k9mail/debug.log";
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If this is enabled there will be additional logging information sent to
|
|
|
|
* Log.d, including protocol dumps.
|
|
|
|
*/
|
|
|
|
public static boolean DEBUG = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If this is enabled than logging that normally hides sensitive information
|
|
|
|
* like passwords will show that information.
|
|
|
|
*/
|
|
|
|
public static boolean DEBUG_SENSITIVE = false;
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Can create messages containing stack traces that can be forwarded
|
|
|
|
* to the development team.
|
|
|
|
*/
|
|
|
|
public static boolean ENABLE_ERROR_FOLDER = true;
|
|
|
|
public static String ERROR_FOLDER_NAME = "K9mail-errors";
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're willing to send. At the moment it is not possible
|
|
|
|
* to open a chooser with a list of filter types, so the chooser is only opened with the first
|
|
|
|
* item in the list. The entire list will be used to filter down attachments that are added
|
|
|
|
* with Intent.ACTION_SEND.
|
|
|
|
*/
|
|
|
|
public static final String[] ACCEPTABLE_ATTACHMENT_SEND_TYPES = new String[] {
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're willing to view.
|
|
|
|
*/
|
|
|
|
public static final String[] ACCEPTABLE_ATTACHMENT_VIEW_TYPES = new String[] {
|
|
|
|
"image/*",
|
|
|
|
"audio/*",
|
|
|
|
"text/*",
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're not willing to view.
|
|
|
|
*/
|
|
|
|
public static final String[] UNACCEPTABLE_ATTACHMENT_VIEW_TYPES = new String[] {
|
|
|
|
"image/gif",
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're willing to download to SD.
|
|
|
|
*/
|
|
|
|
public static final String[] ACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] {
|
2008-12-15 20:42:17 -05:00
|
|
|
"*/*",
|
2008-11-01 17:32:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're not willing to download to SD.
|
|
|
|
*/
|
|
|
|
public static final String[] UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] {
|
2008-12-06 19:29:11 -05:00
|
|
|
"image/gif",
|
2008-11-01 17:32:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The special name "INBOX" is used throughout the application to mean "Whatever folder
|
|
|
|
* the server refers to as the user's Inbox. Placed here to ease use.
|
|
|
|
*/
|
|
|
|
public static final String INBOX = "INBOX";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies how many messages will be shown in a folder by default. This number is set
|
|
|
|
* on each new folder and can be incremented with "Load more messages..." by the
|
|
|
|
* VISIBLE_LIMIT_INCREMENT
|
|
|
|
*/
|
2008-12-11 00:25:59 -05:00
|
|
|
public static int DEFAULT_VISIBLE_LIMIT = 25;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
/**
|
2008-12-06 19:29:11 -05:00
|
|
|
* Number of additioanl messages to load when a user selectes "Load more messages..."
|
2008-11-01 17:32:06 -04:00
|
|
|
*/
|
2008-12-11 00:25:59 -05:00
|
|
|
public static int VISIBLE_LIMIT_INCREMENT = 25;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The maximum size of an attachment we're willing to download (either View or Save)
|
|
|
|
* Attachments that are base64 encoded (most) will be about 1.375x their actual size
|
|
|
|
* so we should probably factor that in. A 5MB attachment will generally be around
|
|
|
|
* 6.8MB downloaded but only 5MB saved.
|
|
|
|
*/
|
|
|
|
public static final int MAX_ATTACHMENT_DOWNLOAD_SIZE = (5 * 1024 * 1024);
|
2008-12-19 14:32:27 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Max time (in millis) the wake lock will be held for when background sync is happening
|
|
|
|
*/
|
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
|
|
|
public static final int WAKE_LOCK_TIMEOUT = 600000;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2008-12-19 14:46:47 -05:00
|
|
|
/**
|
|
|
|
* LED color used for the new email notitication
|
|
|
|
*/
|
|
|
|
public static final int NOTIFICATION_LED_COLOR = 0xffff00ff;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Time the LED is on when blicking on new email notification
|
|
|
|
*/
|
|
|
|
public static final int NOTIFICATION_LED_ON_TIME = 500;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Time the LED is off when blicking on new email notification
|
|
|
|
*/
|
2009-01-11 18:43:32 -05:00
|
|
|
public static final int NOTIFICATION_LED_OFF_TIME = 2000;
|
|
|
|
|
|
|
|
public static final boolean NOTIFICATION_LED_WHILE_SYNCING = false;
|
|
|
|
public static final int NOTIFICATION_LED_DIM_COLOR = 0x77770077;
|
|
|
|
public static final int NOTIFICATION_LED_FAST_ON_TIME = 100;
|
|
|
|
public static final int NOTIFICATION_LED_FAST_OFF_TIME = 100;
|
2008-12-19 14:46:47 -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
|
|
|
// Must not conflict with an account number
|
|
|
|
public static final int FETCHING_EMAIL_NOTIFICATION_ID = -4;
|
|
|
|
public static final int FETCHING_EMAIL_NOTIFICATION_MULTI_ACCOUNT_ID = -1;
|
|
|
|
public static final int FETCHING_EMAIL_NOTIFICATION_NO_ACCOUNT = -2;
|
2008-12-19 14:59:49 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
/**
|
|
|
|
* Called throughout the application when the number of accounts has changed. This method
|
|
|
|
* enables or disables the Compose activity, the boot receiver and the service based on
|
|
|
|
* whether any accounts are configured.
|
|
|
|
*/
|
|
|
|
public static void setServicesEnabled(Context context) {
|
|
|
|
setServicesEnabled(context, Preferences.getPreferences(context).getAccounts().length > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setServicesEnabled(Context context, boolean enabled) {
|
|
|
|
PackageManager pm = context.getPackageManager();
|
|
|
|
if (!enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
|
|
|
|
/*
|
|
|
|
* If no accounts now exist but the service is still enabled we're about to disable it
|
|
|
|
* so we'll reschedule to kill off any existing alarms.
|
|
|
|
*/
|
|
|
|
MailService.actionReschedule(context);
|
|
|
|
}
|
|
|
|
pm.setComponentEnabledSetting(
|
|
|
|
new ComponentName(context, MessageCompose.class),
|
|
|
|
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
|
|
PackageManager.DONT_KILL_APP);
|
|
|
|
pm.setComponentEnabledSetting(
|
|
|
|
new ComponentName(context, BootReceiver.class),
|
|
|
|
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
|
|
PackageManager.DONT_KILL_APP);
|
|
|
|
pm.setComponentEnabledSetting(
|
|
|
|
new ComponentName(context, MailService.class),
|
|
|
|
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
|
|
PackageManager.DONT_KILL_APP);
|
|
|
|
if (enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
|
|
|
|
/*
|
|
|
|
* And now if accounts do exist then we've just enabled the service and we want to
|
|
|
|
* schedule alarms for the new accounts.
|
|
|
|
*/
|
|
|
|
MailService.actionReschedule(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
2008-12-02 23:10:59 -05:00
|
|
|
app = this;
|
2008-11-01 17:32:06 -04:00
|
|
|
Preferences prefs = Preferences.getPreferences(this);
|
|
|
|
DEBUG = prefs.geteEnableDebugLogging();
|
|
|
|
DEBUG_SENSITIVE = prefs.getEnableSensitiveLogging();
|
|
|
|
MessagingController.getInstance(this).resetVisibleLimits(prefs.getAccounts());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to give MimeMessage a temp directory because File.createTempFile(String, String)
|
|
|
|
* doesn't work in Android and MimeMessage does not have access to a Context.
|
|
|
|
*/
|
|
|
|
BinaryTempFileBody.setTempDirectory(getCacheDir());
|
2008-12-13 22:21:39 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable background sync of messages
|
|
|
|
*/
|
|
|
|
|
|
|
|
setServicesEnabled(this);
|
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|