Search in sources :

Example 1 with MessagingController

use of com.fsck.k9.controller.MessagingController in project k-9 by k9mail.

the class NotificationActionService method markMessageAsSpam.

private void markMessageAsSpam(Intent intent, Account account, MessagingController controller) {
    Timber.i("NotificationActionService moving messages to spam");
    String messageReferenceString = intent.getStringExtra(EXTRA_MESSAGE_REFERENCE);
    MessageReference messageReference = MessageReference.parse(messageReferenceString);
    if (messageReference == null) {
        Timber.w("Invalid message reference: %s", messageReferenceString);
        return;
    }
    String spamFolderName = account.getSpamFolderName();
    if (spamFolderName != null && !K9.confirmSpam() && isMovePossible(controller, account, spamFolderName)) {
        String sourceFolderName = messageReference.getFolderName();
        controller.moveMessage(account, sourceFolderName, messageReference, spamFolderName);
    }
}
Also used : MessageReference(com.fsck.k9.activity.MessageReference)

Example 2 with MessagingController

use of com.fsck.k9.controller.MessagingController in project k-9 by k9mail.

the class UnreadWidgetProvider method updateWidget.

public static void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, String accountUuid) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.unread_widget_layout);
    int unreadCount = 0;
    String accountName = context.getString(R.string.app_name);
    Intent clickIntent = null;
    try {
        BaseAccount account = null;
        AccountStats stats = null;
        SearchAccount searchAccount = null;
        if (SearchAccount.UNIFIED_INBOX.equals(accountUuid)) {
            searchAccount = SearchAccount.createUnifiedInboxAccount(context);
        } else if (SearchAccount.ALL_MESSAGES.equals(accountUuid)) {
            searchAccount = SearchAccount.createAllMessagesAccount(context);
        }
        if (searchAccount != null) {
            account = searchAccount;
            MessagingController controller = MessagingController.getInstance(context);
            stats = controller.getSearchAccountStatsSynchronous(searchAccount, null);
            clickIntent = MessageList.intentDisplaySearch(context, searchAccount.getRelatedSearch(), false, true, true);
        } else {
            Account realAccount = Preferences.getPreferences(context).getAccount(accountUuid);
            if (realAccount != null) {
                account = realAccount;
                stats = realAccount.getStats(context);
                if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName())) {
                    clickIntent = FolderList.actionHandleAccountIntent(context, realAccount, false);
                } else {
                    LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolderName());
                    search.addAllowedFolder(realAccount.getAutoExpandFolderName());
                    search.addAccountUuid(account.getUuid());
                    clickIntent = MessageList.intentDisplaySearch(context, search, false, true, true);
                }
                clickIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            }
        }
        if (account != null) {
            accountName = account.getDescription();
        }
        if (stats != null) {
            unreadCount = stats.unreadMessageCount;
        }
    } catch (Exception e) {
        Timber.e(e, "Error getting widget configuration");
    }
    if (unreadCount <= 0) {
        // Hide TextView for unread count if there are no unread messages.
        remoteViews.setViewVisibility(R.id.unread_count, View.GONE);
    } else {
        remoteViews.setViewVisibility(R.id.unread_count, View.VISIBLE);
        String displayCount = (unreadCount <= MAX_COUNT) ? String.valueOf(unreadCount) : String.valueOf(MAX_COUNT) + "+";
        remoteViews.setTextViewText(R.id.unread_count, displayCount);
    }
    remoteViews.setTextViewText(R.id.account_name, accountName);
    if (clickIntent == null) {
        // If the widget configuration couldn't be loaded we open the configuration
        // activity when the user clicks the widget.
        clickIntent = new Intent(context, UnreadWidgetConfiguration.class);
        clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    }
    clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.unread_widget_layout, pendingIntent);
    appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) BaseAccount(com.fsck.k9.BaseAccount) UnreadWidgetConfiguration(com.fsck.k9.activity.UnreadWidgetConfiguration) MessagingController(com.fsck.k9.controller.MessagingController) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SearchAccount(com.fsck.k9.search.SearchAccount) RemoteViews(android.widget.RemoteViews) LocalSearch(com.fsck.k9.search.LocalSearch) BaseAccount(com.fsck.k9.BaseAccount) PendingIntent(android.app.PendingIntent) AccountStats(com.fsck.k9.AccountStats)

Example 3 with MessagingController

use of com.fsck.k9.controller.MessagingController in project k-9 by k9mail.

the class PollService method startService.

@Override
public int startService(Intent intent, int startId) {
    if (START_SERVICE.equals(intent.getAction())) {
        Timber.i("PollService started with startId = %d", startId);
        MessagingController controller = MessagingController.getInstance(getApplication());
        Listener listener = (Listener) controller.getCheckMailListener();
        if (listener == null) {
            Timber.i("***** PollService *****: starting new check");
            mListener.setStartId(startId);
            mListener.wakeLockAcquire();
            controller.setCheckMailListener(mListener);
            controller.checkMail(this, null, false, false, mListener);
        } else {
            Timber.i("***** PollService *****: renewing WakeLock");
            listener.setStartId(startId);
            listener.wakeLockAcquire();
        }
    } else if (STOP_SERVICE.equals(intent.getAction())) {
        Timber.i("PollService stopping");
        stopSelf();
    }
    return START_NOT_STICKY;
}
Also used : SimpleMessagingListener(com.fsck.k9.controller.SimpleMessagingListener) MessagingController(com.fsck.k9.controller.MessagingController)

Example 4 with MessagingController

use of com.fsck.k9.controller.MessagingController in project k-9 by k9mail.

the class NotificationActionService method cancelNotifications.

private void cancelNotifications(Intent intent, Account account, MessagingController controller) {
    if (intent.hasExtra(EXTRA_MESSAGE_REFERENCE)) {
        String messageReferenceString = intent.getStringExtra(EXTRA_MESSAGE_REFERENCE);
        MessageReference messageReference = MessageReference.parse(messageReferenceString);
        if (messageReference != null) {
            controller.cancelNotificationForMessage(account, messageReference);
        } else {
            Timber.w("Invalid message reference: %s", messageReferenceString);
        }
    } else if (intent.hasExtra(EXTRA_MESSAGE_REFERENCES)) {
        List<String> messageReferenceStrings = intent.getStringArrayListExtra(EXTRA_MESSAGE_REFERENCES);
        List<MessageReference> messageReferences = toMessageReferenceList(messageReferenceStrings);
        for (MessageReference messageReference : messageReferences) {
            controller.cancelNotificationForMessage(account, messageReference);
        }
    } else {
        controller.cancelNotificationsForAccount(account);
    }
}
Also used : ArrayList(java.util.ArrayList) MessageReferenceHelper.toMessageReferenceStringList(com.fsck.k9.activity.MessageReferenceHelper.toMessageReferenceStringList) MessageReferenceHelper.toMessageReferenceList(com.fsck.k9.activity.MessageReferenceHelper.toMessageReferenceList) List(java.util.List) MessageReference(com.fsck.k9.activity.MessageReference)

Example 5 with MessagingController

use of com.fsck.k9.controller.MessagingController in project k-9 by k9mail.

the class MessageCompose method onMessageBuildSuccess.

@Override
public void onMessageBuildSuccess(MimeMessage message, boolean isDraft) {
    String plaintextSubject = (currentMessageBuilder instanceof PgpMessageBuilder) ? currentMessageBuilder.getSubject() : null;
    if (isDraft) {
        changesMadeSinceLastSave = false;
        currentMessageBuilder = null;
        new SaveMessageTask(messagingController, account, internalMessageHandler, message, draftMessageId, plaintextSubject).execute();
        if (finishAfterDraftSaved) {
            finish();
        } else {
            setProgressBarIndeterminateVisibility(false);
        }
    } else {
        currentMessageBuilder = null;
        new SendMessageTask(messagingController, preferences, account, contacts, message, draftMessageId, plaintextSubject, relatedMessageReference, relatedFlag).execute();
        finish();
    }
}
Also used : SaveMessageTask(com.fsck.k9.activity.compose.SaveMessageTask) PgpMessageBuilder(com.fsck.k9.message.PgpMessageBuilder)

Aggregations

MessagingController (com.fsck.k9.controller.MessagingController)10 Account (com.fsck.k9.Account)6 MessageReference (com.fsck.k9.activity.MessageReference)5 SearchAccount (com.fsck.k9.search.SearchAccount)5 SimpleMessagingListener (com.fsck.k9.controller.SimpleMessagingListener)3 Context (android.content.Context)2 BaseAccount (com.fsck.k9.BaseAccount)2 PendingIntent (android.app.PendingIntent)1 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 RemoteViews (android.widget.RemoteViews)1 AccountStats (com.fsck.k9.AccountStats)1 Preferences (com.fsck.k9.Preferences)1 MessageReferenceHelper.toMessageReferenceList (com.fsck.k9.activity.MessageReferenceHelper.toMessageReferenceList)1 MessageReferenceHelper.toMessageReferenceStringList (com.fsck.k9.activity.MessageReferenceHelper.toMessageReferenceStringList)1 UnreadWidgetConfiguration (com.fsck.k9.activity.UnreadWidgetConfiguration)1 SaveMessageTask (com.fsck.k9.activity.compose.SaveMessageTask)1 MessageReference (com.fsck.k9.controller.MessageReference)1 Contacts (com.fsck.k9.helper.Contacts)1