mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
. MessageListener.synchronizeMailboxNewMessage() does not requires a context to be passed anymore.
. We use the application as context when broadcasting message received intents
This commit is contained in:
parent
4ffe75fa85
commit
78da963031
@ -6,13 +6,16 @@ import java.io.File;
|
||||
import android.app.Application;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Config;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.email.activity.MessageCompose;
|
||||
import com.android.email.mail.Address;
|
||||
import com.android.email.mail.Message;
|
||||
import com.android.email.mail.MessagingException;
|
||||
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;
|
||||
|
||||
@ -235,7 +238,6 @@ public class Email extends Application {
|
||||
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.
|
||||
@ -248,6 +250,28 @@ public class Email extends Application {
|
||||
|
||||
setServicesEnabled(this);
|
||||
|
||||
MessagingController.getInstance(this).addListener(new MessagingListener() {
|
||||
@Override
|
||||
public void synchronizeMailboxNewMessage(Account account, String folder, Message message) {
|
||||
try {
|
||||
Uri uri = Uri.parse("email://messages/" + account.getAccountNumber() + "/" + Uri.encode(folder) + "/" + Uri.encode(message.getUid()));
|
||||
Intent intent = new Intent(Email.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, uri);
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_FOLDER, folder);
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_SENT_DATE, message.getSentDate());
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_FROM, Address.toString(message.getFrom()));
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_TO, Address.toString(message.getRecipients(Message.RecipientType.TO)));
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_CC, Address.toString(message.getRecipients(Message.RecipientType.CC)));
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_BCC, Address.toString(message.getRecipients(Message.RecipientType.BCC)));
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_SUBJECT, message.getSubject());
|
||||
Email.this.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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
package com.android.email;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import com.android.email.mail.Address;
|
||||
import com.android.email.mail.Message;
|
||||
import com.android.email.mail.MessagingException;
|
||||
|
||||
public class IntentBroadcastingMessagingListener
|
||||
extends MessagingListener {
|
||||
|
||||
@Override
|
||||
public 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()));
|
||||
Intent intent = new Intent(Email.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, uri);
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_FOLDER, folder);
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_SENT_DATE, message.getSentDate());
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_FROM, Address.toString(message.getFrom()));
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_TO, Address.toString(message.getRecipients(Message.RecipientType.TO)));
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_CC, Address.toString(message.getRecipients(Message.RecipientType.CC)));
|
||||
intent.putExtra(Email.Intents.EmailReceived.EXTRA_BCC, Address.toString(message.getRecipients(Message.RecipientType.BCC)));
|
||||
intent.putExtra(Email.Intents.EmailReceived.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);
|
||||
}
|
||||
}
|
||||
|
||||
}//IntentBroadcastingMessagingListener
|
@ -227,8 +227,6 @@ public class MessagingController implements Runnable {
|
||||
mApplication = application;
|
||||
mThread = new Thread(this);
|
||||
mThread.start();
|
||||
|
||||
addListener(new IntentBroadcastingMessagingListener());
|
||||
}
|
||||
|
||||
public void log(String logmess) {
|
||||
@ -513,12 +511,12 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public void loadMoreMessages(Context context, Account account, String folder, MessagingListener listener) {
|
||||
public void loadMoreMessages(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(context, account, folder, listener);
|
||||
synchronizeMailbox(account, folder, listener);
|
||||
}
|
||||
catch (MessagingException me) {
|
||||
addErrorMessage(account, me);
|
||||
@ -548,10 +546,10 @@ public class MessagingController implements Runnable {
|
||||
* @param folder
|
||||
* @param listener
|
||||
*/
|
||||
public void synchronizeMailbox(final Context context, final Account account, final String folder, MessagingListener listener) {
|
||||
public void synchronizeMailbox(final Account account, final String folder, MessagingListener listener) {
|
||||
put("synchronizeMailbox", listener, new Runnable() {
|
||||
public void run() {
|
||||
synchronizeMailboxSynchronous(context, account, folder);
|
||||
synchronizeMailboxSynchronous(account, folder);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -564,7 +562,7 @@ public class MessagingController implements Runnable {
|
||||
*
|
||||
* TODO Break this method up into smaller chunks.
|
||||
*/
|
||||
public void synchronizeMailboxSynchronous(final Context context, final Account account, final String folder) {
|
||||
public void synchronizeMailboxSynchronous(final Account account, final String folder) {
|
||||
/*
|
||||
* We don't ever sync the Outbox.
|
||||
*/
|
||||
@ -929,7 +927,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
if (newMessageUidList.contains(message.getUid())) {
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.synchronizeMailboxNewMessage(context, account, folder, localMessage);
|
||||
l.synchronizeMailboxNewMessage(account, folder, localMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1035,7 +1033,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
if (newMessageUidList.contains(message.getUid())) {
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.synchronizeMailboxNewMessage(context, account, folder, localMessage);
|
||||
l.synchronizeMailboxNewMessage(account, folder, localMessage);
|
||||
}
|
||||
}
|
||||
}//for large messsages
|
||||
@ -2896,7 +2894,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
try
|
||||
{
|
||||
synchronizeMailboxSynchronous(context, account, folder.getName());
|
||||
synchronizeMailboxSynchronous(account, folder.getName());
|
||||
}
|
||||
|
||||
finally {
|
||||
|
@ -63,7 +63,7 @@ public class MessagingListener {
|
||||
public void synchronizeMailboxStarted(Account account, String folder) {
|
||||
}
|
||||
|
||||
public void synchronizeMailboxNewMessage(Context context, Account account, String folder, Message message) {
|
||||
public void synchronizeMailboxNewMessage(Account account, String folder, Message message) {
|
||||
}
|
||||
|
||||
public void synchronizeMailboxAddOrUpdateMessage(Account account, String folder, Message message) {
|
||||
|
@ -327,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(FolderList.this, mAccount, mFolder, mAdapter.mListener);
|
||||
MessagingController.getInstance(getApplication()).synchronizeMailbox(mAccount, mFolder, mAdapter.mListener);
|
||||
}
|
||||
} finally {
|
||||
wakeLock.release();
|
||||
|
@ -410,7 +410,6 @@ public class MessageList extends K9ListActivity {
|
||||
if ((itemPosition+1) == (mAdapter.getCount() )) {
|
||||
|
||||
MessagingController.getInstance(getApplication()).loadMoreMessages(
|
||||
MessageList.this,
|
||||
mAccount,
|
||||
mFolderName,
|
||||
mAdapter.mListener);
|
||||
@ -574,7 +573,7 @@ public class MessageList extends K9ListActivity {
|
||||
public void run() {
|
||||
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||
if (forceRemote) {
|
||||
MessagingController.getInstance(getApplication()).synchronizeMailbox(MessageList.this, mAccount, mFolderName, mAdapter.mListener);
|
||||
MessagingController.getInstance(getApplication()).synchronizeMailbox(mAccount, mFolderName, mAdapter.mListener);
|
||||
MessagingController.getInstance(getApplication()).sendPendingMessages(mAccount, null);
|
||||
}
|
||||
MessagingController.getInstance(getApplication()).listLocalMessages(mAccount, mFolderName, mAdapter.mListener);
|
||||
@ -922,7 +921,7 @@ public class MessageList extends K9ListActivity {
|
||||
// }
|
||||
|
||||
private void checkMail(Account account, String folderName) {
|
||||
MessagingController.getInstance(getApplication()).synchronizeMailbox(this, account, folderName, mAdapter.mListener);
|
||||
MessagingController.getInstance(getApplication()).synchronizeMailbox(account, folderName, mAdapter.mListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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(AccountSetupCheckSettings.this, mAccount, Email.INBOX , null);
|
||||
MessagingController.getInstance(getApplication()).synchronizeMailbox(mAccount, Email.INBOX , null);
|
||||
|
||||
}
|
||||
}.start();
|
||||
|
Loading…
Reference in New Issue
Block a user