Search in sources :

Example 1 with FetchProfile

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

the class ImapFolderTest method createFetchProfile.

private FetchProfile createFetchProfile(Item... items) {
    FetchProfile fetchProfile = new FetchProfile();
    Collections.addAll(fetchProfile, items);
    return fetchProfile;
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile)

Example 2 with FetchProfile

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

the class ImapFolderTest method fetch_withFlagsFetchProfile_shouldIssueRespectiveCommand.

@Test
public void fetch_withFlagsFetchProfile_shouldIssueRespectiveCommand() throws Exception {
    ImapFolder folder = createFolder("Folder");
    prepareImapFolderForOpen(OPEN_MODE_RO);
    folder.open(OPEN_MODE_RO);
    when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
    List<ImapMessage> messages = createImapMessages("1");
    FetchProfile fetchProfile = createFetchProfile(Item.FLAGS);
    folder.fetch(messages, fetchProfile, null);
    verify(imapConnection).sendCommand("UID FETCH 1 (UID FLAGS)", false);
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) Test(org.junit.Test)

Example 3 with FetchProfile

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

the class ImapFolderTest method fetch_withEmptyMessageListArgument_shouldDoNothing.

@Test
public void fetch_withEmptyMessageListArgument_shouldDoNothing() throws Exception {
    ImapFolder folder = createFolder("Folder");
    FetchProfile fetchProfile = createFetchProfile();
    folder.fetch(Collections.<ImapMessage>emptyList(), fetchProfile, null);
    verifyNoMoreInteractions(imapStore);
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) Test(org.junit.Test)

Example 4 with FetchProfile

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

the class ImapFolderTest method fetch_withBodySaneFetchProfileAndNoMaximumDownloadSize_shouldIssueRespectiveCommand.

@Test
public void fetch_withBodySaneFetchProfileAndNoMaximumDownloadSize_shouldIssueRespectiveCommand() throws Exception {
    ImapFolder folder = createFolder("Folder");
    prepareImapFolderForOpen(OPEN_MODE_RO);
    folder.open(OPEN_MODE_RO);
    when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
    List<ImapMessage> messages = createImapMessages("1");
    FetchProfile fetchProfile = createFetchProfile(Item.BODY_SANE);
    when(storeConfig.getMaximumAutoDownloadMessageSize()).thenReturn(0);
    folder.fetch(messages, fetchProfile, null);
    verify(imapConnection).sendCommand("UID FETCH 1 (UID BODY.PEEK[])", false);
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) Test(org.junit.Test)

Example 5 with FetchProfile

use of com.fsck.k9.mail.FetchProfile 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)

Aggregations

FetchProfile (com.fsck.k9.mail.FetchProfile)49 Test (org.junit.Test)27 LocalMessage (com.fsck.k9.mailstore.LocalMessage)15 MessagingException (com.fsck.k9.mail.MessagingException)12 ArrayList (java.util.ArrayList)10 LocalFolder (com.fsck.k9.mailstore.LocalFolder)9 LocalStore (com.fsck.k9.mailstore.LocalStore)9 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)8 Date (java.util.Date)8 Message (com.fsck.k9.mail.Message)7 SuppressLint (android.annotation.SuppressLint)6 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)6 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)5 Multipart (com.fsck.k9.mail.Multipart)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 WebDavMessage (com.fsck.k9.mail.store.webdav.WebDavMessage)4 LinkedList (java.util.LinkedList)4 HttpResponse (org.apache.http.HttpResponse)4 StatusLine (org.apache.http.StatusLine)4