diff --git a/src/com/android/email/IntentBroadcastingMessagingListener.java b/src/com/android/email/IntentBroadcastingMessagingListener.java new file mode 100644 index 000000000..97966043a --- /dev/null +++ b/src/com/android/email/IntentBroadcastingMessagingListener.java @@ -0,0 +1,34 @@ +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.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())); + 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); + } + } + +}//IntentBroadcastingMessagingListener diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index c64ce753c..12cf676b3 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -227,6 +227,8 @@ public class MessagingController implements Runnable { mApplication = application; mThread = new Thread(this); mThread.start(); + + addListener(new IntentBroadcastingMessagingListener()); } public void log(String logmess) { diff --git a/src/com/android/email/MessagingListener.java b/src/com/android/email/MessagingListener.java index 13a0b78dc..c86002fb7 100644 --- a/src/com/android/email/MessagingListener.java +++ b/src/com/android/email/MessagingListener.java @@ -3,12 +3,8 @@ 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; /** @@ -67,24 +63,7 @@ public class MessagingListener { public void synchronizeMailboxStarted(Account account, String folder) { } - 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 synchronizeMailboxNewMessage(Context context, Account account, String folder, Message message) { } public void synchronizeMailboxAddOrUpdateMessage(Account account, String folder, Message message) {