Search in sources :

Example 1 with Account

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

the class MigrationTo43 method fixOutboxFolders.

public static void fixOutboxFolders(SQLiteDatabase db, MigrationsHelper migrationsHelper) {
    try {
        LocalStore localStore = migrationsHelper.getLocalStore();
        Account account = migrationsHelper.getAccount();
        Context context = migrationsHelper.getContext();
        // If folder "OUTBOX" (old, v3.800 - v3.802) exists, rename it to
        // "K9MAIL_INTERNAL_OUTBOX" (new)
        LocalFolder oldOutbox = new LocalFolder(localStore, "OUTBOX");
        if (oldOutbox.exists()) {
            ContentValues cv = new ContentValues();
            cv.put("name", Account.OUTBOX);
            db.update("folders", cv, "name = ?", new String[] { "OUTBOX" });
            Timber.i("Renamed folder OUTBOX to %s", OUTBOX);
        }
        // Check if old (pre v3.800) localized outbox folder exists
        String localizedOutbox = context.getString(R.string.special_mailbox_name_outbox);
        LocalFolder obsoleteOutbox = new LocalFolder(localStore, localizedOutbox);
        if (obsoleteOutbox.exists()) {
            // Get all messages from the localized outbox ...
            List<? extends Message> messages = obsoleteOutbox.getMessages(null, false);
            if (messages.size() > 0) {
                // ... and move them to the drafts folder (we don't want to
                // surprise the user by sending potentially very old messages)
                LocalFolder drafts = new LocalFolder(localStore, account.getDraftsFolderName());
                obsoleteOutbox.moveMessages(messages, drafts);
            }
            // Now get rid of the localized outbox
            obsoleteOutbox.delete();
            obsoleteOutbox.delete(true);
        }
    } catch (Exception e) {
        Timber.e(e, "Error trying to fix the outbox folders");
    }
}
Also used : Context(android.content.Context) LocalFolder(com.fsck.k9.mailstore.LocalFolder) ContentValues(android.content.ContentValues) Account(com.fsck.k9.Account) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 2 with Account

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

the class DeviceNotifications method createInboxStyleSummaryNotification.

private NotificationCompat.Builder createInboxStyleSummaryNotification(Account account, NotificationData notificationData, int unreadMessageCount) {
    NotificationHolder latestNotification = notificationData.getHolderForLatestNotification();
    int newMessagesCount = notificationData.getNewMessagesCount();
    String accountName = controller.getAccountName(account);
    String title = context.getResources().getQuantityString(R.plurals.notification_new_messages_title, newMessagesCount, newMessagesCount);
    String summary = (notificationData.hasSummaryOverflowMessages()) ? context.getString(R.string.notification_additional_messages, notificationData.getSummaryOverflowMessagesCount(), accountName) : accountName;
    String groupKey = NotificationGroupKeys.getGroupKey(account);
    NotificationCompat.Builder builder = createAndInitializeNotificationBuilder(account).setNumber(unreadMessageCount).setTicker(latestNotification.content.summary).setGroup(groupKey).setGroupSummary(true).setContentTitle(title).setSubText(accountName);
    NotificationCompat.InboxStyle style = createInboxStyle(builder).setBigContentTitle(title).setSummaryText(summary);
    for (NotificationContent content : notificationData.getContentForSummaryNotification()) {
        style.addLine(content.summary);
    }
    builder.setStyle(style);
    addMarkAllAsReadAction(builder, notificationData);
    addDeleteAllAction(builder, notificationData);
    wearNotifications.addSummaryActions(builder, notificationData);
    int notificationId = NotificationIds.getNewMailSummaryNotificationId(account);
    List<MessageReference> messageReferences = notificationData.getAllMessageReferences();
    PendingIntent contentIntent = actionCreator.createViewMessagesPendingIntent(account, messageReferences, notificationId);
    builder.setContentIntent(contentIntent);
    return builder;
}
Also used : Builder(android.support.v4.app.NotificationCompat.Builder) NotificationCompat(android.support.v4.app.NotificationCompat) InboxStyle(android.support.v4.app.NotificationCompat.InboxStyle) PendingIntent(android.app.PendingIntent) MessageReference(com.fsck.k9.activity.MessageReference)

Example 3 with Account

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

the class DeviceNotifications method addDeleteAllAction.

private void addDeleteAllAction(Builder builder, NotificationData notificationData) {
    if (K9.getNotificationQuickDeleteBehaviour() != NotificationQuickDelete.ALWAYS) {
        return;
    }
    int icon = getDeleteActionIcon();
    String title = context.getString(R.string.notification_action_delete);
    Account account = notificationData.getAccount();
    int notificationId = NotificationIds.getNewMailSummaryNotificationId(account);
    ArrayList<MessageReference> messageReferences = notificationData.getAllMessageReferences();
    PendingIntent action = actionCreator.createDeleteAllPendingIntent(account, messageReferences, notificationId);
    builder.addAction(icon, title, action);
}
Also used : Account(com.fsck.k9.Account) PendingIntent(android.app.PendingIntent) MessageReference(com.fsck.k9.activity.MessageReference)

Example 4 with Account

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

the class DeviceNotifications method addMarkAllAsReadAction.

private void addMarkAllAsReadAction(Builder builder, NotificationData notificationData) {
    int icon = getMarkAsReadActionIcon();
    String title = context.getString(R.string.notification_action_mark_as_read);
    Account account = notificationData.getAccount();
    ArrayList<MessageReference> messageReferences = notificationData.getAllMessageReferences();
    int notificationId = NotificationIds.getNewMailSummaryNotificationId(account);
    PendingIntent markAllAsReadPendingIntent = actionCreator.createMarkAllAsReadPendingIntent(account, messageReferences, notificationId);
    builder.addAction(icon, title, markAllAsReadPendingIntent);
}
Also used : Account(com.fsck.k9.Account) PendingIntent(android.app.PendingIntent) MessageReference(com.fsck.k9.activity.MessageReference)

Example 5 with Account

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

the class NotificationActionCreator method buildMessageViewBackStack.

private TaskStackBuilder buildMessageViewBackStack(MessageReference message) {
    Account account = Preferences.getPreferences(context).getAccount(message.getAccountUuid());
    String folderName = message.getFolderName();
    TaskStackBuilder stack = buildMessageListBackStack(account, folderName);
    Intent intent = MessageList.actionDisplayMessageIntent(context, message);
    stack.addNextIntent(intent);
    return stack;
}
Also used : Account(com.fsck.k9.Account) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder)

Aggregations

Account (com.fsck.k9.Account)136 Test (org.junit.Test)89 MessagingException (com.fsck.k9.mail.MessagingException)74 LocalFolder (com.fsck.k9.mailstore.LocalFolder)62 LocalStore (com.fsck.k9.mailstore.LocalStore)61 LocalMessage (com.fsck.k9.mailstore.LocalMessage)53 ArrayList (java.util.ArrayList)43 MessageReference (com.fsck.k9.activity.MessageReference)29 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)29 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)28 Message (com.fsck.k9.mail.Message)28 SearchAccount (com.fsck.k9.search.SearchAccount)26 Folder (com.fsck.k9.mail.Folder)21 Cursor (android.database.Cursor)20 PendingIntent (android.app.PendingIntent)19 FetchProfile (com.fsck.k9.mail.FetchProfile)19 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)18 IOException (java.io.IOException)17 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)16 Intent (android.content.Intent)15