Search in sources :

Example 1 with LocalStore

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

the class MigrationTo55 method createFtsSearchTable.

static void createFtsSearchTable(SQLiteDatabase db, MigrationsHelper migrationsHelper) {
    db.execSQL("CREATE VIRTUAL TABLE messages_fulltext USING fts4 (fulltext)");
    LocalStore localStore = migrationsHelper.getLocalStore();
    MessageFulltextCreator fulltextCreator = localStore.getMessageFulltextCreator();
    try {
        List<LocalFolder> folders = localStore.getPersonalNamespaces(true);
        ContentValues cv = new ContentValues();
        FetchProfile fp = new FetchProfile();
        fp.add(FetchProfile.Item.BODY);
        for (LocalFolder folder : folders) {
            List<String> messageUids = folder.getAllMessageUids();
            for (String messageUid : messageUids) {
                LocalMessage localMessage = folder.getMessage(messageUid);
                folder.fetch(Collections.singletonList(localMessage), fp, null);
                String fulltext = fulltextCreator.createFulltext(localMessage);
                if (!TextUtils.isEmpty(fulltext)) {
                    Timber.d("fulltext for msg id %d is %d chars long", localMessage.getId(), fulltext.length());
                    cv.clear();
                    cv.put("docid", localMessage.getId());
                    cv.put("fulltext", fulltext);
                    db.insert("messages_fulltext", null, cv);
                } else {
                    Timber.d("no fulltext for msg id %d :(", localMessage.getId());
                }
            }
        }
    } catch (MessagingException e) {
        Timber.e(e, "error indexing fulltext - skipping rest, fts index is incomplete!");
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) ContentValues(android.content.ContentValues) LocalMessage(com.fsck.k9.mailstore.LocalMessage) FetchProfile(com.fsck.k9.mail.FetchProfile) MessageFulltextCreator(com.fsck.k9.message.extractors.MessageFulltextCreator) MessagingException(com.fsck.k9.mail.MessagingException) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 2 with LocalStore

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

the class MigrationTo42 method from41MoveFolderPreferences.

public static void from41MoveFolderPreferences(MigrationsHelper migrationsHelper) {
    try {
        LocalStore localStore = migrationsHelper.getLocalStore();
        Storage storage = migrationsHelper.getStorage();
        long startTime = System.currentTimeMillis();
        StorageEditor editor = storage.edit();
        List<? extends Folder> folders = localStore.getPersonalNamespaces(true);
        for (Folder folder : folders) {
            if (folder instanceof LocalFolder) {
                LocalFolder lFolder = (LocalFolder) folder;
                lFolder.save(editor);
            }
        }
        editor.commit();
        long endTime = System.currentTimeMillis();
        Timber.i("Putting folder preferences for %d folders back into Preferences took %d ms", folders.size(), endTime - startTime);
    } catch (Exception e) {
        Timber.e(e, "Could not replace Preferences in upgrade from DB_VERSION 41");
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) Storage(com.fsck.k9.preferences.Storage) LocalStore(com.fsck.k9.mailstore.LocalStore) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 3 with LocalStore

use of com.fsck.k9.mailstore.LocalStore 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 4 with LocalStore

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

the class MessagingController method addErrorMessage.

private void addErrorMessage(Account account, String subject, String body) {
    if (!K9.isDebug()) {
        return;
    }
    if (!loopCatch.compareAndSet(false, true)) {
        return;
    }
    try {
        if (body == null || body.length() < 1) {
            return;
        }
        Store localStore = account.getLocalStore();
        LocalFolder localFolder = (LocalFolder) localStore.getFolder(account.getErrorFolderName());
        MimeMessage message = new MimeMessage();
        MimeMessageHelper.setBody(message, new TextBody(body));
        message.setFlag(Flag.X_DOWNLOADED_FULL, true);
        message.setSubject(subject);
        long nowTime = System.currentTimeMillis();
        Date nowDate = new Date(nowTime);
        message.setInternalDate(nowDate);
        message.addSentDate(nowDate, K9.hideTimeZone());
        message.setFrom(new Address(account.getEmail(), "K9mail internal"));
        localFolder.appendMessages(Collections.singletonList(message));
        localFolder.clearMessagesOlderThan(nowTime - (15 * 60 * 1000));
    } catch (Throwable it) {
        Timber.e(it, "Could not save error message to %s", account.getErrorFolderName());
    } finally {
        loopCatch.set(false);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) TextBody(com.fsck.k9.mail.internet.TextBody) Address(com.fsck.k9.mail.Address) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) LocalStore(com.fsck.k9.mailstore.LocalStore) Store(com.fsck.k9.mail.Store) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) Date(java.util.Date)

Example 5 with LocalStore

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

the class MessagingController method moveMessageToDraftsFolder.

private void moveMessageToDraftsFolder(Account account, Folder localFolder, Store localStore, Message message) throws MessagingException {
    LocalFolder draftsFolder = (LocalFolder) localStore.getFolder(account.getDraftsFolderName());
    localFolder.moveMessages(Collections.singletonList(message), draftsFolder);
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder)

Aggregations

LocalStore (com.fsck.k9.mailstore.LocalStore)63 LocalFolder (com.fsck.k9.mailstore.LocalFolder)53 MessagingException (com.fsck.k9.mail.MessagingException)46 LocalMessage (com.fsck.k9.mailstore.LocalMessage)27 FetchProfile (com.fsck.k9.mail.FetchProfile)17 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)16 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)16 Store (com.fsck.k9.mail.Store)16 Folder (com.fsck.k9.mail.Folder)15 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)15 Account (com.fsck.k9.Account)13 Message (com.fsck.k9.mail.Message)13 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)13 ArrayList (java.util.ArrayList)13 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)10 Test (org.junit.Test)10 Backend (com.fsck.k9.backend.api.Backend)9 IOException (java.io.IOException)9 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)8 SuppressLint (android.annotation.SuppressLint)7