1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-11 20:15:03 -05:00

Minor cleanup so that we only broadcast the message received intent once

This commit is contained in:
Bao-Long Nguyen-Trong 2009-10-20 04:59:02 +00:00
parent d3803e5e0f
commit 7323fe67fd
3 changed files with 37 additions and 22 deletions

View File

@ -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

View File

@ -227,6 +227,8 @@ 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) {

View File

@ -3,12 +3,8 @@ package com.android.email;
import android.content.Context; 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.Folder;
import com.android.email.mail.Message; import com.android.email.mail.Message;
import com.android.email.mail.MessagingException;
import com.android.email.mail.Part; import com.android.email.mail.Part;
/** /**
@ -67,24 +63,7 @@ public class MessagingListener {
public void synchronizeMailboxStarted(Account account, String folder) { public void synchronizeMailboxStarted(Account account, String folder) {
} }
public final void synchronizeMailboxNewMessage(Context context, Account account, String folder, Message message) { 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);
}
} }
public void synchronizeMailboxAddOrUpdateMessage(Account account, String folder, Message message) { public void synchronizeMailboxAddOrUpdateMessage(Account account, String folder, Message message) {