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);
}
}
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);
}
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;
}
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);
}
}
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();
}
}
Aggregations