diff options
Diffstat (limited to 'src/com/android/email/service/ImapService.java')
-rw-r--r-- | src/com/android/email/service/ImapService.java | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/com/android/email/service/ImapService.java b/src/com/android/email/service/ImapService.java index 5abd05d91..38109e430 100644 --- a/src/com/android/email/service/ImapService.java +++ b/src/com/android/email/service/ImapService.java @@ -75,6 +75,7 @@ public class ImapService extends Service { private static final long QUICK_SYNC_WINDOW_MILLIS = DateUtils.DAY_IN_MILLIS; private static final long FULL_SYNC_WINDOW_MILLIS = 7 * DateUtils.DAY_IN_MILLIS; private static final long FULL_SYNC_INTERVAL_MILLIS = 4 * DateUtils.HOUR_IN_MILLIS; + private static final String TAG = "ImapService"; // The maximum number of messages to fetch in a single command. private static final int MAX_MESSAGES_TO_FETCH = 500; @@ -107,6 +108,19 @@ public class ImapService extends Service { * We write this into the serverId field of messages that will never be upsynced. */ private static final String LOCAL_SERVERID_PREFIX = "Local-"; + private static final String ACTION_CHECK_MAIL = + "com.android.email.intent.action.MAIL_SERVICE_WAKEUP"; + private static final String EXTRA_ACCOUNT = "com.android.email.intent.extra.ACCOUNT"; + private static final String ACTION_DELETE_MESSAGE = + "com.android.email.intent.action.MAIL_SERVICE_DELETE_MESSAGE"; + private static final String ACTION_MOVE_MESSAGE = + "com.android.email.intent.action.MAIL_SERVICE_MOVE_MESSAGE"; + private static final String ACTION_MESSAGE_READ = + "com.android.email.intent.action.MAIL_SERVICE_MESSAGE_READ"; + private static final String ACTION_SEND_PENDING_MAIL = + "com.android.email.intent.action.MAIL_SERVICE_SEND_PENDING"; + private static final String EXTRA_MESSAGE_ID = "com.android.email.intent.extra.MESSAGE_ID"; + private static final String EXTRA_MESSAGE_INFO = "com.android.email.intent.extra.MESSAGE_INFO"; private static String sMessageDecodeErrorString; @@ -128,6 +142,104 @@ public class ImapService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { + + final String action = intent.getAction(); + if (Logging.LOGD) { + LogUtils.d(Logging.LOG_TAG, "Action: ", action); + } + final long accountId = intent.getLongExtra(EXTRA_ACCOUNT, -1); + Context context = getApplicationContext(); + if (ACTION_CHECK_MAIL.equals(action)) { + final long inboxId = Mailbox.findMailboxOfType(context, accountId, + Mailbox.TYPE_INBOX); + if (Logging.LOGD) { + LogUtils.d(Logging.LOG_TAG,"accountId is " + accountId); + LogUtils.d(Logging.LOG_TAG,"inboxId is " + inboxId); + } + if (accountId <= -1 || inboxId <= -1 ){ + return START_NOT_STICKY; + } + mBinder.init(context); + mBinder.requestSync(inboxId,true,0); + } else if (ACTION_DELETE_MESSAGE.equals(action)) { + final long messageId = intent.getLongExtra(EXTRA_MESSAGE_ID, -1); + if (Logging.LOGD) { + LogUtils.d(Logging.LOG_TAG, "action: Delete Message mail"); + LogUtils.d(Logging.LOG_TAG, "action: delmsg "+messageId); + } + if (accountId <= -1 || messageId <= -1 ){ + return START_NOT_STICKY; + } + Store remoteStore = null; + try { + remoteStore = Store.getInstance(Account.getAccountForMessageId(context, messageId), + context); + mBinder.init(context); + mBinder.deleteMessage(messageId); + processPendingActionsSynchronous(context, + Account.getAccountForMessageId(context, messageId),remoteStore,true); + } catch (Exception e){ + LogUtils.d(Logging.LOG_TAG,"RemoteException " +e); + } + } else if (ACTION_MESSAGE_READ.equals(action)) { + final long messageId = intent.getLongExtra(EXTRA_MESSAGE_ID, -1); + final int flagRead = intent.getIntExtra(EXTRA_MESSAGE_INFO, 0); + if (Logging.LOGD) { + LogUtils.d(Logging.LOG_TAG, "action: Message Mark Read or UnRead "); + LogUtils.d(Logging.LOG_TAG, "action: delmsg "+messageId); + } + if (accountId <= -1 || messageId <= -1 ) { + return START_NOT_STICKY; + } + Store remoteStore = null; + try { + mBinder.init(context); + mBinder.setMessageRead(messageId, (flagRead == 1)? true:false); + remoteStore = Store.getInstance(Account.getAccountForMessageId(context, messageId), + context); + processPendingActionsSynchronous(context, + Account.getAccountForMessageId(context, messageId),remoteStore,true); + } catch (Exception e){ + LogUtils.d(Logging.LOG_TAG,"RemoteException " +e); + } + } else if (ACTION_MOVE_MESSAGE.equals(action)) { + final long messageId = intent.getLongExtra(EXTRA_MESSAGE_ID, -1); + final int mailboxType = intent.getIntExtra(EXTRA_MESSAGE_INFO, Mailbox.TYPE_INBOX); + final long mailboxId = Mailbox.findMailboxOfType(context, accountId, mailboxType); + if (Logging.LOGD) { + LogUtils.d(Logging.LOG_TAG, "action: Move Message mail"); + LogUtils.d(Logging.LOG_TAG, "action: movemsg "+ messageId + + "mailbox: " +mailboxType + "accountId: "+accountId + "mailboxId: " + mailboxId); + } + if (accountId <= -1 || messageId <= -1 || mailboxId <= -1){ + return START_NOT_STICKY; + } + Store remoteStore = null; + try { + mBinder.init(context); + mBinder.MoveMessages(messageId, mailboxId); + remoteStore = Store.getInstance(Account.getAccountForMessageId(context, messageId), + context); + processPendingActionsSynchronous(context, + Account.getAccountForMessageId(context, messageId),remoteStore, true); + } catch (Exception e){ + LogUtils.d(Logging.LOG_TAG,"RemoteException " +e); + } + } else if (ACTION_SEND_PENDING_MAIL.equals(action)) { + if (Logging.LOGD) { + LogUtils.d(Logging.LOG_TAG, "action: Send Pending Mail "+accountId); + } + if (accountId <= -1 ) { + return START_NOT_STICKY; + } + try { + mBinder.init(context); + mBinder.sendMail(accountId); + } catch (Exception e) { + LogUtils.e(Logging.LOG_TAG,"RemoteException " +e); + } + } + return Service.START_STICKY; } |