mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-25 15:11:52 -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.app.Application;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.util.Config;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.email.activity.MessageCompose;
|
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.BinaryTempFileBody;
|
||||||
import com.android.email.mail.internet.MimeMessage;
|
|
||||||
import com.android.email.service.BootReceiver;
|
import com.android.email.service.BootReceiver;
|
||||||
import com.android.email.service.MailService;
|
import com.android.email.service.MailService;
|
||||||
|
|
||||||
@ -234,7 +237,6 @@ public class Email extends Application {
|
|||||||
DEBUG = prefs.getEnableDebugLogging();
|
DEBUG = prefs.getEnableDebugLogging();
|
||||||
DEBUG_SENSITIVE = prefs.getEnableSensitiveLogging();
|
DEBUG_SENSITIVE = prefs.getEnableSensitiveLogging();
|
||||||
MessagingController.getInstance(this).resetVisibleLimits(prefs.getAccounts());
|
MessagingController.getInstance(this).resetVisibleLimits(prefs.getAccounts());
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We have to give MimeMessage a temp directory because File.createTempFile(String, String)
|
* We have to give MimeMessage a temp directory because File.createTempFile(String, String)
|
||||||
@ -248,6 +250,28 @@ public class Email extends Application {
|
|||||||
|
|
||||||
setServicesEnabled(this);
|
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;
|
mApplication = application;
|
||||||
mThread = new Thread(this);
|
mThread = new Thread(this);
|
||||||
mThread.start();
|
mThread.start();
|
||||||
|
|
||||||
addListener(new IntentBroadcastingMessagingListener());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(String logmess) {
|
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 {
|
try {
|
||||||
LocalStore localStore = (LocalStore) Store.getInstance( account.getLocalStoreUri(), mApplication);
|
LocalStore localStore = (LocalStore) Store.getInstance( account.getLocalStoreUri(), mApplication);
|
||||||
LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder);
|
LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder);
|
||||||
localFolder.setVisibleLimit(localFolder.getVisibleLimit() + account.getDisplayCount());
|
localFolder.setVisibleLimit(localFolder.getVisibleLimit() + account.getDisplayCount());
|
||||||
synchronizeMailbox(context, account, folder, listener);
|
synchronizeMailbox(account, folder, listener);
|
||||||
}
|
}
|
||||||
catch (MessagingException me) {
|
catch (MessagingException me) {
|
||||||
addErrorMessage(account, me);
|
addErrorMessage(account, me);
|
||||||
@ -548,10 +546,10 @@ public class MessagingController implements Runnable {
|
|||||||
* @param folder
|
* @param folder
|
||||||
* @param listener
|
* @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() {
|
put("synchronizeMailbox", listener, new Runnable() {
|
||||||
public void run() {
|
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.
|
* 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.
|
* We don't ever sync the Outbox.
|
||||||
*/
|
*/
|
||||||
@ -929,7 +927,7 @@ public class MessagingController implements Runnable {
|
|||||||
}
|
}
|
||||||
if (newMessageUidList.contains(message.getUid())) {
|
if (newMessageUidList.contains(message.getUid())) {
|
||||||
for (MessagingListener l : getListeners()) {
|
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())) {
|
if (newMessageUidList.contains(message.getUid())) {
|
||||||
for (MessagingListener l : getListeners()) {
|
for (MessagingListener l : getListeners()) {
|
||||||
l.synchronizeMailboxNewMessage(context, account, folder, localMessage);
|
l.synchronizeMailboxNewMessage(account, folder, localMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}//for large messsages
|
}//for large messsages
|
||||||
@ -2896,7 +2894,7 @@ public class MessagingController implements Runnable {
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
synchronizeMailboxSynchronous(context, account, folder.getName());
|
synchronizeMailboxSynchronous(account, folder.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
finally {
|
finally {
|
||||||
|
@ -63,7 +63,7 @@ public class MessagingListener {
|
|||||||
public void synchronizeMailboxStarted(Account account, String folder) {
|
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) {
|
public void synchronizeMailboxAddOrUpdateMessage(Account account, String folder, Message message) {
|
||||||
|
@ -327,7 +327,7 @@ public class FolderList extends K9ListActivity {
|
|||||||
if (mSynchronizeRemote) {
|
if (mSynchronizeRemote) {
|
||||||
// Tell the MessagingController to run a remote update of this folder
|
// Tell the MessagingController to run a remote update of this folder
|
||||||
// at it's leisure
|
// at it's leisure
|
||||||
MessagingController.getInstance(getApplication()).synchronizeMailbox(FolderList.this, mAccount, mFolder, mAdapter.mListener);
|
MessagingController.getInstance(getApplication()).synchronizeMailbox(mAccount, mFolder, mAdapter.mListener);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
wakeLock.release();
|
wakeLock.release();
|
||||||
|
@ -410,7 +410,6 @@ public class MessageList extends K9ListActivity {
|
|||||||
if ((itemPosition+1) == (mAdapter.getCount() )) {
|
if ((itemPosition+1) == (mAdapter.getCount() )) {
|
||||||
|
|
||||||
MessagingController.getInstance(getApplication()).loadMoreMessages(
|
MessagingController.getInstance(getApplication()).loadMoreMessages(
|
||||||
MessageList.this,
|
|
||||||
mAccount,
|
mAccount,
|
||||||
mFolderName,
|
mFolderName,
|
||||||
mAdapter.mListener);
|
mAdapter.mListener);
|
||||||
@ -574,7 +573,7 @@ public class MessageList extends K9ListActivity {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
if (forceRemote) {
|
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()).sendPendingMessages(mAccount, null);
|
||||||
}
|
}
|
||||||
MessagingController.getInstance(getApplication()).listLocalMessages(mAccount, mFolderName, mAdapter.mListener);
|
MessagingController.getInstance(getApplication()).listLocalMessages(mAccount, mFolderName, mAdapter.mListener);
|
||||||
@ -922,7 +921,7 @@ public class MessageList extends K9ListActivity {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
private void checkMail(Account account, String folderName) {
|
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
|
@Override
|
||||||
|
@ -109,7 +109,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
|
|||||||
public void run() {
|
public void run() {
|
||||||
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
MessagingController.getInstance(getApplication()).listFolders(mAccount, true, null);
|
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();
|
}.start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user