Search in sources :

Example 96 with Message

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

the class EmailProviderTest method query_forThreadedMessages_showsThreadOfEmailWithSameSendTimeOnce.

@Test
public void query_forThreadedMessages_showsThreadOfEmailWithSameSendTimeOnce() throws MessagingException {
    Account account = Preferences.getPreferences(getContext()).newAccount();
    account.getUuid();
    account.getLocalStore().getFolder("Inbox").appendMessages(Collections.singletonList(message));
    account.getLocalStore().getFolder("Inbox").appendMessages(Collections.singletonList(replyAtSameTime));
    Cursor cursor = getProvider().query(Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages/threaded"), new String[] { EmailProvider.MessageColumns.ID, EmailProvider.MessageColumns.FOLDER_ID, EmailProvider.ThreadColumns.ROOT, EmailProvider.MessageColumns.SUBJECT, EmailProvider.MessageColumns.DATE, EmailProvider.SpecialColumns.THREAD_COUNT }, "", new String[] {}, EmailProvider.MessageColumns.DATE + " DESC");
    assertNotNull(cursor);
    assertTrue(cursor.moveToFirst());
    assertEquals(2, cursor.getInt(5));
    assertFalse(cursor.moveToNext());
}
Also used : Account(com.fsck.k9.Account) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 97 with Message

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

the class EmailProviderTest method buildMessages.

private void buildMessages() throws MessagingException {
    message = new MimeMessage();
    message.setSubject("Test Subject");
    message.setSentDate(new GregorianCalendar(2016, 1, 2).getTime(), false);
    message.setMessageId("<uid001@email.com>");
    laterMessage = new MimeMessage();
    laterMessage.setSubject("Test Subject2");
    laterMessage.setSentDate(new GregorianCalendar(2016, 1, 3).getTime(), false);
    reply = new MimeMessage();
    reply.setSubject("Re: Test Subject");
    reply.setSentDate(new GregorianCalendar(2016, 1, 3).getTime(), false);
    reply.setMessageId("<uid002@email.com>");
    reply.setInReplyTo("<uid001@email.com>");
    replyAtSameTime = new MimeMessage();
    replyAtSameTime.setSubject("Re: Test Subject");
    replyAtSameTime.setSentDate(new GregorianCalendar(2016, 1, 2).getTime(), false);
    replyAtSameTime.setMessageId("<uid002@email.com>");
    replyAtSameTime.setInReplyTo("<uid001@email.com>");
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) GregorianCalendar(java.util.GregorianCalendar)

Example 98 with Message

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

the class EmailProviderTest method query_forThreadedMessages_sortsCorrectly.

@Test
public void query_forThreadedMessages_sortsCorrectly() throws MessagingException {
    Account account = Preferences.getPreferences(getContext()).newAccount();
    account.getUuid();
    account.getLocalStore().getFolder("Inbox").appendMessages(Arrays.asList(message, laterMessage));
    Cursor cursor = getProvider().query(Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages/threaded"), new String[] { EmailProvider.MessageColumns.ID, EmailProvider.MessageColumns.FOLDER_ID, EmailProvider.ThreadColumns.ROOT, EmailProvider.MessageColumns.SUBJECT, EmailProvider.MessageColumns.DATE }, "", new String[] {}, EmailProvider.MessageColumns.DATE + " DESC");
    assertNotNull(cursor);
    assertTrue(cursor.moveToFirst());
    assertEquals(laterMessage.getSubject(), cursor.getString(3));
    cursor.moveToNext();
    assertEquals(message.getSubject(), cursor.getString(3));
}
Also used : Account(com.fsck.k9.Account) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 99 with Message

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

the class EmailProviderTest method query_forThreadedMessages_showsThreadOfEmailOnce.

@Test
public void query_forThreadedMessages_showsThreadOfEmailOnce() throws MessagingException {
    Account account = Preferences.getPreferences(getContext()).newAccount();
    account.getUuid();
    account.getLocalStore().getFolder("Inbox").appendMessages(Collections.singletonList(message));
    account.getLocalStore().getFolder("Inbox").appendMessages(Collections.singletonList(reply));
    Cursor cursor = getProvider().query(Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages/threaded"), new String[] { EmailProvider.MessageColumns.ID, EmailProvider.MessageColumns.FOLDER_ID, EmailProvider.ThreadColumns.ROOT, EmailProvider.MessageColumns.SUBJECT, EmailProvider.MessageColumns.DATE, EmailProvider.SpecialColumns.THREAD_COUNT }, "", new String[] {}, EmailProvider.MessageColumns.DATE + " DESC");
    assertNotNull(cursor);
    assertTrue(cursor.moveToFirst());
    assertEquals(2, cursor.getInt(5));
    assertFalse(cursor.moveToNext());
}
Also used : Account(com.fsck.k9.Account) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 100 with Message

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

the class K9 method onCreate.

@Override
public void onCreate() {
    if (K9.DEVELOPER_MODE) {
        StrictMode.enableDefaults();
    }
    PRNGFixes.apply();
    super.onCreate();
    app = this;
    Globals.setContext(this);
    K9MailLib.setDebugStatus(new K9MailLib.DebugStatus() {

        @Override
        public boolean enabled() {
            return DEBUG;
        }

        @Override
        public boolean debugSensitive() {
            return DEBUG_SENSITIVE;
        }
    });
    checkCachedDatabaseVersion();
    Preferences prefs = Preferences.getPreferences(this);
    loadPrefs(prefs);
    /*
         * We have to give MimeMessage a temp directory because File.createTempFile(String, String)
         * doesn't work in Android and MimeMessage does not have access to a Context.
         */
    BinaryTempFileBody.setTempDirectory(getCacheDir());
    LocalKeyStore.setKeyStoreLocation(getDir("KeyStore", MODE_PRIVATE).toString());
    /*
         * Enable background sync of messages
         */
    setServicesEnabled(this);
    registerReceivers();
    MessagingController.getInstance(this).addListener(new SimpleMessagingListener() {

        private void broadcastIntent(String action, Account account, String folder, Message message) {
            Uri uri = Uri.parse("email://messages/" + account.getAccountNumber() + "/" + Uri.encode(folder) + "/" + Uri.encode(message.getUid()));
            Intent intent = new Intent(action, uri);
            intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
            intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folder);
            intent.putExtra(K9.Intents.EmailReceived.EXTRA_SENT_DATE, message.getSentDate());
            intent.putExtra(K9.Intents.EmailReceived.EXTRA_FROM, Address.toString(message.getFrom()));
            intent.putExtra(K9.Intents.EmailReceived.EXTRA_TO, Address.toString(message.getRecipients(Message.RecipientType.TO)));
            intent.putExtra(K9.Intents.EmailReceived.EXTRA_CC, Address.toString(message.getRecipients(Message.RecipientType.CC)));
            intent.putExtra(K9.Intents.EmailReceived.EXTRA_BCC, Address.toString(message.getRecipients(Message.RecipientType.BCC)));
            intent.putExtra(K9.Intents.EmailReceived.EXTRA_SUBJECT, message.getSubject());
            intent.putExtra(K9.Intents.EmailReceived.EXTRA_FROM_SELF, account.isAnIdentity(message.getFrom()));
            K9.this.sendBroadcast(intent);
            Timber.d("Broadcasted: action=%s account=%s folder=%s message uid=%s", action, account.getDescription(), folder, message.getUid());
        }

        private void updateUnreadWidget() {
            try {
                UnreadWidgetProvider.updateUnreadCount(K9.this);
            } catch (Exception e) {
                Timber.e(e, "Error while updating unread widget(s)");
            }
        }

        private void updateMailListWidget() {
            try {
                MessageListWidgetProvider.triggerMessageListWidgetUpdate(K9.this);
            } catch (RuntimeException e) {
                if (BuildConfig.DEBUG) {
                    throw e;
                } else {
                    Timber.e(e, "Error while updating message list widget");
                }
            }
        }

        @Override
        public void synchronizeMailboxRemovedMessage(Account account, String folder, Message message) {
            broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
            updateUnreadWidget();
            updateMailListWidget();
        }

        @Override
        public void messageDeleted(Account account, String folder, Message message) {
            broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
            updateUnreadWidget();
            updateMailListWidget();
        }

        @Override
        public void synchronizeMailboxNewMessage(Account account, String folder, Message message) {
            broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, account, folder, message);
            updateUnreadWidget();
            updateMailListWidget();
        }

        @Override
        public void folderStatusChanged(Account account, String folderName, int unreadMessageCount) {
            updateUnreadWidget();
            updateMailListWidget();
            // let observers know a change occurred
            Intent intent = new Intent(K9.Intents.EmailReceived.ACTION_REFRESH_OBSERVER, null);
            intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
            intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folderName);
            K9.this.sendBroadcast(intent);
        }
    });
    notifyObservers();
}
Also used : Message(com.fsck.k9.mail.Message) Intent(android.content.Intent) Uri(android.net.Uri) K9MailLib(com.fsck.k9.mail.K9MailLib) SimpleMessagingListener(com.fsck.k9.controller.SimpleMessagingListener) SharedPreferences(android.content.SharedPreferences)

Aggregations

Test (org.junit.Test)127 Message (com.fsck.k9.mail.Message)111 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)102 Part (com.fsck.k9.mail.Part)47 LocalMessage (com.fsck.k9.mailstore.LocalMessage)46 MessagingException (com.fsck.k9.mail.MessagingException)41 ArrayList (java.util.ArrayList)41 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)33 BodyPart (com.fsck.k9.mail.BodyPart)32 Account (com.fsck.k9.Account)27 LocalFolder (com.fsck.k9.mailstore.LocalFolder)24 TextBody (com.fsck.k9.mail.internet.TextBody)23 IOException (java.io.IOException)22 Address (com.fsck.k9.mail.Address)21 LocalStore (com.fsck.k9.mailstore.LocalStore)21 Date (java.util.Date)20 MessageReference (com.fsck.k9.activity.MessageReference)16 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)16 Folder (com.fsck.k9.mail.Folder)14 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)13