diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4b46f753c..dc056f3a6 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -119,20 +119,40 @@
+
+
+
+
+
+
+
Loading\u2026
Loading messages\u2026
Connection error
+ Message not found
Error
Sending\u2026
Retry loading more messages
diff --git a/src/com/android/email/Email.java b/src/com/android/email/Email.java
index 1e62b5dd4..ec28dc483 100644
--- a/src/com/android/email/Email.java
+++ b/src/com/android/email/Email.java
@@ -166,10 +166,6 @@ public class Email extends Application {
public static final int FLAGGED_COLOR = 0xff4444;
- public static final String INTENT_DATA_URI_SCHEMA = "content";
- public static final String INTENT_DATA_UR_PATH_PREFIX = "email";
- public static final String INTENT_DATA_URI_PREFIX = INTENT_DATA_URI_SCHEMA + "://" + INTENT_DATA_UR_PATH_PREFIX;
-
/**
* 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
diff --git a/src/com/android/email/Intent.java b/src/com/android/email/Intent.java
new file mode 100644
index 000000000..307d227b9
--- /dev/null
+++ b/src/com/android/email/Intent.java
@@ -0,0 +1,14 @@
+package com.android.email;
+
+public class Intent {
+
+ public static final String ACTION_EMAIL_RECEIVED = "com.android.email.intent.action.EMAIL_RECEIVED";
+ public static final String EXTRA_ACCOUNT = "com.android.email.intent.extra.ACCOUNT";
+ public static final String EXTRA_FOLDER = "com.android.email.intent.extra.FOLDER";
+ public static final String EXTRA_SENT_DATE = "com.android.email.intent.extra.SENT_DATE";
+ public static final String EXTRA_FROM = "com.android.email.intent.extra.FROM";
+ public static final String EXTRA_TO = "com.android.email.intent.extra.TO";
+ public static final String EXTRA_CC = "com.android.email.intent.extra.CC";
+ public static final String EXTRA_BCC = "com.android.email.intent.extra.BCC";
+ public static final String EXTRA_SUBJECT = "com.android.email.intent.extra.SUBJECT";
+}
diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java
index 83579d108..c64ce753c 100644
--- a/src/com/android/email/MessagingController.java
+++ b/src/com/android/email/MessagingController.java
@@ -511,12 +511,12 @@ public class MessagingController implements Runnable {
}
}
- public void loadMoreMessages(Account account, String folder, MessagingListener listener) {
+ public void loadMoreMessages(Context context, Account account, String folder, MessagingListener listener) {
try {
LocalStore localStore = (LocalStore) Store.getInstance( account.getLocalStoreUri(), mApplication);
LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder);
localFolder.setVisibleLimit(localFolder.getVisibleLimit() + account.getDisplayCount());
- synchronizeMailbox(account, folder, listener);
+ synchronizeMailbox(context, account, folder, listener);
}
catch (MessagingException me) {
addErrorMessage(account, me);
@@ -546,10 +546,10 @@ public class MessagingController implements Runnable {
* @param folder
* @param listener
*/
- public void synchronizeMailbox(final Account account, final String folder, MessagingListener listener) {
+ public void synchronizeMailbox(final Context context, final Account account, final String folder, MessagingListener listener) {
put("synchronizeMailbox", listener, new Runnable() {
public void run() {
- synchronizeMailboxSynchronous(account, folder);
+ synchronizeMailboxSynchronous(context, account, folder);
}
});
}
@@ -562,7 +562,7 @@ public class MessagingController implements Runnable {
*
* TODO Break this method up into smaller chunks.
*/
- public void synchronizeMailboxSynchronous(final Account account, final String folder) {
+ public void synchronizeMailboxSynchronous(final Context context, final Account account, final String folder) {
/*
* We don't ever sync the Outbox.
*/
@@ -740,7 +740,7 @@ public class MessagingController implements Runnable {
* This will serve to indicate the true "new" message count that will be reported to
* the user via notification.
*/
- final ArrayList newMessages = new ArrayList();
+ final ArrayList newMessageUidList = new ArrayList();
/*
* Fetch the flags and envelope only of the new messages. This is intended to get us
@@ -769,7 +769,7 @@ public class MessagingController implements Runnable {
public void messageFinished(Message message, int number, int ofTotal) {
try {
if (!message.isSet(Flag.SEEN)) {
- newMessages.add(message);
+ newMessageUidList.add(message.getUid());
}
// Store the new message locally
@@ -787,9 +787,9 @@ public class MessagingController implements Runnable {
* ENVELOPE, only size.
*/
if (isMessageSuppressed(account, folder, message) == false) {
- Log.i(Email.LOG_TAG, "place 2 About to notify listeners that we got a new message "+ account + folder + message.getUid());
+ Log.i(Email.LOG_TAG, "place 2 About to notify listeners that we got a new message "+ account + folder + message.getUid());
for (MessagingListener l : getListeners()) {
- l.synchronizeMailboxNewMessage(account, folder, localFolder.getMessage(message.getUid()));
+ l.synchronizeMailboxAddOrUpdateMessage(account, folder, localFolder.getMessage(message.getUid()));
}
}
}
@@ -838,7 +838,7 @@ public class MessagingController implements Runnable {
}
if (messageChanged && isMessageSuppressed(account, folder, localMessage) == false) {
for (MessagingListener l : getListeners()) {
- l.synchronizeMailboxNewMessage(account, folder, localMessage);
+ l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage);
}
}
}
@@ -853,7 +853,7 @@ public class MessagingController implements Runnable {
*/
int remoteUnreadMessageCount = remoteFolder.getUnreadMessageCount();
if (remoteUnreadMessageCount == -1) {
- localFolder.setUnreadMessageCount(localFolder.getUnreadMessageCount() + newMessages.size());
+ localFolder.setUnreadMessageCount(localFolder.getUnreadMessageCount() + newMessageUidList.size());
}
else {
localFolder.setUnreadMessageCount(remoteUnreadMessageCount);
@@ -922,7 +922,12 @@ public class MessagingController implements Runnable {
{
// Update the listener with what we've found
for (MessagingListener l : getListeners()) {
- l.synchronizeMailboxNewMessage( account, folder, localMessage);
+ l.synchronizeMailboxAddOrUpdateMessage( account, folder, localMessage);
+ }
+ }
+ if (newMessageUidList.contains(message.getUid())) {
+ for (MessagingListener l : getListeners()) {
+ l.synchronizeMailboxNewMessage(context, account, folder, localMessage);
}
}
}
@@ -952,6 +957,7 @@ public class MessagingController implements Runnable {
remoteFolder.fetch(largeMessages.toArray(new Message[largeMessages.size()]), fp, null);
for (Message message : largeMessages) {
+ Message localMessage = null;
if (message.getBody() == null) {
/*
* The provider was unable to get the structure of the message, so
@@ -971,7 +977,7 @@ public class MessagingController implements Runnable {
// Store the updated message locally
localFolder.appendMessages(new Message[] { message });
- Message localMessage = localFolder.getMessage(message.getUid());
+ localMessage = localFolder.getMessage(message.getUid());
/*
* Mark the message as fully downloaded if the message size is smaller than
@@ -1011,7 +1017,7 @@ public class MessagingController implements Runnable {
// Store the updated message locally
localFolder.appendMessages(new Message[] { message });
- Message localMessage = localFolder.getMessage(message.getUid());
+ localMessage = localFolder.getMessage(message.getUid());
// Set a flag indicating this message has been fully downloaded and can be
// viewed.
@@ -1022,7 +1028,12 @@ public class MessagingController implements Runnable {
Log.i(Email.LOG_TAG, "About to notify listeners that we got a new message "+ account + folder + message.getUid());
// Update the listener with what we've found
for (MessagingListener l : getListeners()) {
- l.synchronizeMailboxNewMessage( account, folder, localFolder.getMessage(message.getUid()));
+ l.synchronizeMailboxAddOrUpdateMessage( account, folder, localMessage);
+ }
+ }
+ if (newMessageUidList.contains(message.getUid())) {
+ for (MessagingListener l : getListeners()) {
+ l.synchronizeMailboxNewMessage(context, account, folder, localMessage);
}
}
}//for large messsages
@@ -1044,11 +1055,11 @@ public class MessagingController implements Runnable {
if (Config.LOGD) {
log( "Done synchronizing folder " +
account.getDescription() + ":" + folder + " @ " + new Date() +
- " with " + newMessages.size() + " new messages");
+ " with " + newMessageUidList.size() + " new messages");
}
for (MessagingListener l : getListeners()) {
- l.synchronizeMailboxFinished( account, folder, remoteMessageCount, newMessages.size());
+ l.synchronizeMailboxFinished( account, folder, remoteMessageCount, newMessageUidList.size());
}
if (commandException != null) {
@@ -1523,6 +1534,7 @@ public class MessagingController implements Runnable {
}
String rootCauseMessage = getRootCauseMessage(t);
+ Log.e(Email.LOG_TAG, rootCauseMessage, t);
log("Error" + "'" + rootCauseMessage + "'");
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
@@ -1811,11 +1823,11 @@ public class MessagingController implements Runnable {
}
catch (Exception e) {
for (MessagingListener l : getListeners()) {
- l.loadMessageForViewFailed(account, folder, uid, e.getMessage());
+ l.loadMessageForViewFailed(account, folder, uid, e);
}
if (listener != null && !getListeners().contains(listener))
{
- listener.loadMessageForViewFailed(account, folder, uid, e.getMessage());
+ listener.loadMessageForViewFailed(account, folder, uid, e);
}
addErrorMessage(account, e);
@@ -1848,75 +1860,80 @@ public class MessagingController implements Runnable {
for (MessagingListener l : getListeners()) {
l.loadMessageForViewStarted(account, folder, uid);
}
- if (listener != null && !getListeners().contains(listener))
- {
- listener.loadMessageForViewStarted(account, folder, uid);
- }
+ if (listener != null && !getListeners().contains(listener))
+ {
+ listener.loadMessageForViewStarted(account, folder, uid);
+ }
threadPool.execute(new Runnable() {
public void run() {
-
- try {
- Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
- LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder);
- localFolder.open(OpenMode.READ_WRITE);
+ try {
+ Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
+ LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder);
+ localFolder.open(OpenMode.READ_WRITE);
- Message message = localFolder.getMessage(uid);
-
- for (MessagingListener l : getListeners()) {
- l.loadMessageForViewHeadersAvailable(account, folder, uid, message);
- }
- if (listener != null && !getListeners().contains(listener))
- {
- listener.loadMessageForViewHeadersAvailable(account, folder, uid, message);
- }
-
- if (!message.isSet(Flag.X_DOWNLOADED_FULL)) {
- loadMessageForViewRemote(account, folder, uid, listener);
- localFolder.close(false);
- return;
- }
-
- FetchProfile fp = new FetchProfile();
- fp.add(FetchProfile.Item.ENVELOPE);
- fp.add(FetchProfile.Item.BODY);
- localFolder.fetch(new Message[] {
- message
- }, fp, null);
- localFolder.close(false);
- if (!message.isSet(Flag.SEEN)) {
- markMessageRead(account, localFolder, message, true);
- }
-
- for (MessagingListener l : getListeners()) {
- l.loadMessageForViewBodyAvailable(account, folder, uid, message);
- }
- if (listener != null && !getListeners().contains(listener))
- {
- listener.loadMessageForViewBodyAvailable(account, folder, uid, message);
- }
-
- for (MessagingListener l : getListeners()) {
- l.loadMessageForViewFinished(account, folder, uid, message);
- }
- if (listener != null && !getListeners().contains(listener))
- {
- listener.loadMessageForViewFinished(account, folder, uid, message);
- }
-
- }
- catch (Exception e) {
- for (MessagingListener l : getListeners()) {
- l.loadMessageForViewFailed(account, folder, uid, e.getMessage());
- }
+ LocalMessage message = (LocalMessage)localFolder.getMessage(uid);
+ if (message==null
+ || message.getId()==0) {
+ throw new IllegalArgumentException("Message not found: folder=" + folder + ", uid=" + uid);
+ }
+
+ for (MessagingListener l : getListeners()) {
+ l.loadMessageForViewHeadersAvailable(account, folder, uid, message);
+ }
if (listener != null && !getListeners().contains(listener))
{
- listener.loadMessageForViewFailed(account, folder, uid, e.getMessage());
+ listener.loadMessageForViewHeadersAvailable(account, folder, uid, message);
+ }
+
+ if (!message.isSet(Flag.X_DOWNLOADED_FULL)) {
+ Log.v(Email.LOG_TAG, "Message not fully downloaded --> starting bg remote download");
+ loadMessageForViewRemote(account, folder, uid, listener);
+ localFolder.close(false);
+ return;
}
- addErrorMessage(account, e);
- }
- }
+ FetchProfile fp = new FetchProfile();
+ fp.add(FetchProfile.Item.ENVELOPE);
+ fp.add(FetchProfile.Item.BODY);
+ localFolder.fetch(new Message[] {
+ message
+ }, fp, null);
+ localFolder.close(false);
+ if (!message.isSet(Flag.SEEN)) {
+ markMessageRead(account, localFolder, message, true);
+ }
+
+ for (MessagingListener l : getListeners()) {
+ l.loadMessageForViewBodyAvailable(account, folder, uid, message);
+ }
+ if (listener != null && !getListeners().contains(listener))
+ {
+ listener.loadMessageForViewBodyAvailable(account, folder, uid, message);
+ }
+
+ for (MessagingListener l : getListeners()) {
+ l.loadMessageForViewFinished(account, folder, uid, message);
+ }
+ if (listener != null && !getListeners().contains(listener))
+ {
+ listener.loadMessageForViewFinished(account, folder, uid, message);
+ }
+
+ }
+ catch (Exception e) {
+ for (MessagingListener l : getListeners()) {
+ l.loadMessageForViewFailed(account, folder, uid, e);
+ }
+ if (listener != null && !getListeners().contains(listener))
+ {
+ listener.loadMessageForViewFailed(account, folder, uid, e);
+ }
+ addErrorMessage(account, e);
+
+ }
+ }
});
+ Log.v(Email.LOG_TAG, "loadMessageForView started in bg thread");
}
// public void loadMessageForViewSynchronous(final Account account, final String folder, final String uid,
@@ -2877,7 +2894,7 @@ public class MessagingController implements Runnable {
}
try
{
- synchronizeMailboxSynchronous(account, folder.getName());
+ synchronizeMailboxSynchronous(context, account, folder.getName());
}
finally {
diff --git a/src/com/android/email/MessagingListener.java b/src/com/android/email/MessagingListener.java
index a30e26c08..13a0b78dc 100644
--- a/src/com/android/email/MessagingListener.java
+++ b/src/com/android/email/MessagingListener.java
@@ -3,8 +3,12 @@ package com.android.email;
import android.content.Context;
+import android.net.Uri;
+import android.util.Log;
+import com.android.email.mail.Address;
import com.android.email.mail.Folder;
import com.android.email.mail.Message;
+import com.android.email.mail.MessagingException;
import com.android.email.mail.Part;
/**
@@ -15,7 +19,7 @@ import com.android.email.mail.Part;
* changes in this class.
*/
public class MessagingListener {
-
+
public void accountStatusChanged(Account account, int unreadMessageCount) {
}
@@ -63,7 +67,27 @@ public class MessagingListener {
public void synchronizeMailboxStarted(Account account, String folder) {
}
- public void synchronizeMailboxNewMessage(Account account, String folder, Message message) {
+ public final void synchronizeMailboxNewMessage(Context context, Account account, String folder, Message message) {
+ try {
+ Uri uri = Uri.parse("email://messages/" + account.getAccountNumber() + "/" + Uri.encode(folder) + "/" + Uri.encode(message.getUid()));
+ android.content.Intent intent = new android.content.Intent(Intent.ACTION_EMAIL_RECEIVED, uri);
+ intent.putExtra(Intent.EXTRA_ACCOUNT, account.getDescription());
+ intent.putExtra(Intent.EXTRA_FOLDER, folder);
+ intent.putExtra(Intent.EXTRA_SENT_DATE, message.getSentDate());
+ intent.putExtra(Intent.EXTRA_FROM, Address.toString(message.getFrom()));
+ intent.putExtra(Intent.EXTRA_TO, Address.toString(message.getRecipients(Message.RecipientType.TO)));
+ intent.putExtra(Intent.EXTRA_CC, Address.toString(message.getRecipients(Message.RecipientType.CC)));
+ intent.putExtra(Intent.EXTRA_BCC, Address.toString(message.getRecipients(Message.RecipientType.BCC)));
+ intent.putExtra(Intent.EXTRA_SUBJECT, message.getSubject());
+ context.sendBroadcast(intent);
+ Log.d(Email.LOG_TAG, "Broadcasted intent: " + message.getSubject());
+ }
+ catch (MessagingException e) {
+ Log.w(Email.LOG_TAG, "Account=" + account.getName() + " folder=" + folder + "message uid=" + message.getUid(), e);
+ }
+ }
+
+ public void synchronizeMailboxAddOrUpdateMessage(Account account, String folder, Message message) {
}
public void synchronizeMailboxRemovedMessage(Account account, String folder,Message message) {
@@ -92,7 +116,7 @@ public class MessagingListener {
Message message) {
}
- public void loadMessageForViewFailed(Account account, String folder, String uid, String message) {
+ public void loadMessageForViewFailed(Account account, String folder, String uid, Throwable t) {
}
public void checkMailStarted(Context context, Account account) {
diff --git a/src/com/android/email/activity/FolderList.java b/src/com/android/email/activity/FolderList.java
index 170a131f7..1517a3d17 100644
--- a/src/com/android/email/activity/FolderList.java
+++ b/src/com/android/email/activity/FolderList.java
@@ -66,8 +66,6 @@ import java.util.concurrent.TimeUnit;
public class FolderList extends K9ListActivity {
- private static final String INTENT_DATA_PATH_SUFFIX = "/accounts";
-
private static final int DIALOG_MARK_ALL_AS_READ = 1;
private static final String EXTRA_ACCOUNT = "account";
@@ -329,7 +327,7 @@ public class FolderList extends K9ListActivity {
if (mSynchronizeRemote) {
// Tell the MessagingController to run a remote update of this folder
// at it's leisure
- MessagingController.getInstance(getApplication()).synchronizeMailbox(mAccount, mFolder, mAdapter.mListener);
+ MessagingController.getInstance(getApplication()).synchronizeMailbox(FolderList.this, mAccount, mFolder, mAdapter.mListener);
}
} finally {
wakeLock.release();
@@ -359,7 +357,11 @@ public class FolderList extends K9ListActivity {
}
public static Intent actionHandleAccountIntent(Context context, Account account, String initialFolder) {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Email.INTENT_DATA_URI_PREFIX + INTENT_DATA_PATH_SUFFIX + "/" + account.getAccountNumber()), context, FolderList.class);
+ Intent intent = new Intent(
+ Intent.ACTION_VIEW,
+ Uri.parse("email://accounts/" + account.getAccountNumber()),
+ context,
+ FolderList.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(EXTRA_ACCOUNT, account);
intent.putExtra(EXTRA_CLEAR_NOTIFICATION, true);
@@ -582,10 +584,6 @@ public class FolderList extends K9ListActivity {
MessagingController.getInstance(getApplication()).checkMail(this, account, true, true, mAdapter.mListener);
}
- private void checkMail(Account account, String folderName) {
- MessagingController.getInstance(getApplication()).synchronizeMailbox(account, folderName, mAdapter.mListener);
- }
-
@Override public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.compose:
diff --git a/src/com/android/email/activity/MessageCompose.java b/src/com/android/email/activity/MessageCompose.java
index ff741ff5c..abd21632b 100644
--- a/src/com/android/email/activity/MessageCompose.java
+++ b/src/com/android/email/activity/MessageCompose.java
@@ -1340,7 +1340,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
@Override
- public void loadMessageForViewFailed(Account account, String folder, String uid, final String message) {
+ public void loadMessageForViewFailed(Account account, String folder, String uid, Throwable t) {
if (mSourceMessageUid==null
|| !mSourceMessageUid.equals(uid)) {
return;
diff --git a/src/com/android/email/activity/MessageList.java b/src/com/android/email/activity/MessageList.java
index dcfaca113..1f702685b 100644
--- a/src/com/android/email/activity/MessageList.java
+++ b/src/com/android/email/activity/MessageList.java
@@ -89,6 +89,7 @@ public class MessageList extends K9ListActivity {
private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1;
private static final int ACTIVITY_CHOOSE_FOLDER_COPY = 2;
+
private static final boolean FORCE_REMOTE_SYNC = true;
private static final String EXTRA_ACCOUNT = "account";
@@ -409,6 +410,7 @@ public class MessageList extends K9ListActivity {
if ((itemPosition+1) == (mAdapter.getCount() )) {
MessagingController.getInstance(getApplication()).loadMoreMessages(
+ MessageList.this,
mAccount,
mFolderName,
mAdapter.mListener);
@@ -572,7 +574,7 @@ public class MessageList extends K9ListActivity {
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
if (forceRemote) {
- MessagingController.getInstance(getApplication()).synchronizeMailbox( mAccount, mFolderName, mAdapter.mListener);
+ MessagingController.getInstance(getApplication()).synchronizeMailbox(MessageList.this, mAccount, mFolderName, mAdapter.mListener);
MessagingController.getInstance(getApplication()).sendPendingMessages(mAccount, null);
}
MessagingController.getInstance(getApplication()).listLocalMessages(mAccount, mFolderName, mAdapter.mListener);
@@ -920,7 +922,7 @@ public class MessageList extends K9ListActivity {
// }
private void checkMail(Account account, String folderName) {
- MessagingController.getInstance(getApplication()).synchronizeMailbox( account, folderName, mAdapter.mListener);
+ MessagingController.getInstance(getApplication()).synchronizeMailbox(this, account, folderName, mAdapter.mListener);
}
@Override
@@ -1164,7 +1166,7 @@ public class MessageList extends K9ListActivity {
}
@Override
- public void synchronizeMailboxNewMessage(Account account, String folder, Message message) {
+ public void synchronizeMailboxAddOrUpdateMessage(Account account, String folder, Message message) {
if (!account.equals(mAccount) || !folder.equals(mFolderName)) {
return;
}
@@ -1192,7 +1194,7 @@ public class MessageList extends K9ListActivity {
return;
}
- mHandler.sortMessages();
+ mHandler.sortMessages();
mHandler.progress(false);
mHandler.folderLoading(folder, false);
}
@@ -1203,7 +1205,7 @@ public class MessageList extends K9ListActivity {
return;
}
- mHandler.sortMessages();
+ mHandler.sortMessages();
mHandler.progress(false);
mHandler.folderLoading(folder, false);
}
diff --git a/src/com/android/email/activity/MessageView.java b/src/com/android/email/activity/MessageView.java
index 6c6c70f76..536616093 100644
--- a/src/com/android/email/activity/MessageView.java
+++ b/src/com/android/email/activity/MessageView.java
@@ -27,7 +27,6 @@ import android.os.Environment;
import android.os.Handler;
import android.provider.Contacts;
import android.provider.Contacts.Intents;
-import android.text.Spannable;
import android.util.Config;
import android.util.Log;
import android.view.KeyEvent;
@@ -52,6 +51,7 @@ import com.android.email.Account;
import com.android.email.Email;
import com.android.email.MessagingController;
import com.android.email.MessagingListener;
+import com.android.email.Preferences;
import com.android.email.R;
import com.android.email.Utility;
import com.android.email.mail.Address;
@@ -68,8 +68,7 @@ import com.android.email.mail.store.LocalStore.LocalTextBody;
import com.android.email.provider.AttachmentProvider;
import java.net.HttpURLConnection;
import java.util.HashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.List;
public class MessageView extends K9Activity
implements UrlInterceptHandler, OnClickListener {
@@ -206,6 +205,8 @@ public class MessageView extends K9Activity
private static final int MSG_ATTACHMENT_NOT_SAVED = 8;
private static final int MSG_SHOW_SHOW_PICTURES = 9;
private static final int MSG_FETCHING_ATTACHMENT = 10;
+ private static final int MSG_INVALID_ID_ERROR = 11;
+
private static final int FLAG_FLAGGED = 1;
private static final int FLAG_ANSWERED = 2;
@@ -263,6 +264,10 @@ public class MessageView extends K9Activity
Toast.makeText(MessageView.this,
R.string.status_network_error, Toast.LENGTH_LONG).show();
break;
+ case MSG_INVALID_ID_ERROR:
+ Toast.makeText(MessageView.this,
+ R.string.status_invalid_id_error, Toast.LENGTH_LONG).show();
+ break;
case MSG_ATTACHMENT_SAVED:
Toast.makeText(MessageView.this, String.format(
getString(R.string.message_view_status_attachment_saved), msg.obj),
@@ -331,6 +336,10 @@ public class MessageView extends K9Activity
sendEmptyMessage(MSG_NETWORK_ERROR);
}
+ public void invalidIdError() {
+ sendEmptyMessage(MSG_INVALID_ID_ERROR);
+ }
+
public void attachmentSaved(String filename) {
android.os.Message msg = new android.os.Message();
msg.what = MSG_ATTACHMENT_SAVED;
@@ -436,21 +445,61 @@ public class MessageView extends K9Activity
setTitle("");
Intent intent = getIntent();
- mAccount = (Account) intent.getSerializableExtra(EXTRA_ACCOUNT);
- mFolder = intent.getStringExtra(EXTRA_FOLDER);
- mMessageUid = intent.getStringExtra(EXTRA_MESSAGE);
- mFolderUids = intent.getStringArrayListExtra(EXTRA_FOLDER_UIDS);
+ Uri uri = intent.getData();
+
+ if (uri==null) {
+ mAccount = (Account) intent.getSerializableExtra(EXTRA_ACCOUNT);
+ mFolder = intent.getStringExtra(EXTRA_FOLDER);
+ mMessageUid = intent.getStringExtra(EXTRA_MESSAGE);
+ mFolderUids = intent.getStringArrayListExtra(EXTRA_FOLDER_UIDS);
+
+ Log.v(Email.LOG_TAG, "mAccount number: " + mAccount.getAccountNumber());
+ Log.v(Email.LOG_TAG, "mFolder: " + mFolder);
+ Log.v(Email.LOG_TAG, "mMessageUid: " + mMessageUid);
+ }
+ else {
+ Log.v(Email.LOG_TAG, "uri: " + uri.toString());
+ List segmentList = uri.getPathSegments();
+ Log.v(Email.LOG_TAG, "segmentList size: " + segmentList.size());
+ if (segmentList.size()==3) {
+ String accountId = segmentList.get(0);
+ Account[] accounts = Preferences.getPreferences(this).getAccounts();
+ Log.v(Email.LOG_TAG, "account.length: " + accounts.length);
+ boolean found = false;
+ for (Account account : accounts) {
+ Log.v(Email.LOG_TAG, "account: name=" + account.getDescription() + " number=" + account.getAccountNumber());
+ if (String.valueOf(account.getAccountNumber()).equals(accountId)) {
+ mAccount = account;
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ //TODO: Use ressource to externalize message
+ Toast.makeText(this, "Invalid account id: " + accountId, Toast.LENGTH_LONG).show();
+ return;
+ }
+ mFolder = segmentList.get(1);
+ mMessageUid = segmentList.get(2);
+ mFolderUids = new ArrayList();
+ }
+ else {
+ for (String segment : segmentList) {
+ Log.v(Email.LOG_TAG, "segment: " + segment);
+ }
+ //TODO: Use ressource to externalize message
+ Toast.makeText(this, "Invalid intent uri: " + uri.toString(), Toast.LENGTH_LONG).show();
+ return;
+ }
+ }
next = findViewById(R.id.next);
previous = findViewById(R.id.previous);
-
setOnClickListener(R.id.next);
setOnClickListener(R.id.previous);
next_scrolling = findViewById(R.id.next_scrolling);
-
-
previous_scrolling = findViewById(R.id.previous_scrolling);
boolean goNext = intent.getBooleanExtra(EXTRA_NEXT, false);
@@ -460,7 +509,7 @@ public class MessageView extends K9Activity
Account.HideButtons hideButtons = mAccount.getHideMessageViewButtons();
- // MessagingController.getInstance(getApplication()).addListener(mListener);
+ //MessagingController.getInstance(getApplication()).addListener(mListener);
if (Account.HideButtons.ALWAYS == hideButtons)
{
hideButtons();
@@ -1200,7 +1249,7 @@ public class MessageView extends K9Activity
@Override
public void loadMessageForViewFailed(Account account, String folder, String uid,
- final String message) {
+ final Throwable t) {
if (!mMessageUid.equals(uid)) {
return;
}
@@ -1208,7 +1257,12 @@ public class MessageView extends K9Activity
mHandler.post(new Runnable() {
public void run() {
setProgressBarIndeterminateVisibility(false);
- mHandler.networkError();
+ if (t instanceof IllegalArgumentException) {
+ mHandler.invalidIdError();
+ }
+ else {
+ mHandler.networkError();
+ }
mMessageContentView.loadUrl("file:///android_asset/empty.html");
}
});
diff --git a/src/com/android/email/activity/setup/AccountSetupCheckSettings.java b/src/com/android/email/activity/setup/AccountSetupCheckSettings.java
index d2a12446f..41d678f59 100644
--- a/src/com/android/email/activity/setup/AccountSetupCheckSettings.java
+++ b/src/com/android/email/activity/setup/AccountSetupCheckSettings.java
@@ -109,7 +109,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
MessagingController.getInstance(getApplication()).listFolders(mAccount, true, null);
- MessagingController.getInstance(getApplication()).synchronizeMailbox( mAccount, Email.INBOX , null);
+ MessagingController.getInstance(getApplication()).synchronizeMailbox(AccountSetupCheckSettings.this, mAccount, Email.INBOX , null);
}
}.start();