use of com.fsck.k9.mail.MessagingException 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());
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class Account method getStats.
/**
* @return <code>null</code> if not available
* @throws MessagingException
* @see {@link #isAvailable(Context)}
*/
public AccountStats getStats(Context context) throws MessagingException {
if (!isAvailable(context)) {
return null;
}
AccountStats stats = new AccountStats();
ContentResolver cr = context.getContentResolver();
Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + getUuid() + "/stats");
String[] projection = { StatsColumns.UNREAD_COUNT, StatsColumns.FLAGGED_COUNT };
// Create LocalSearch instance to exclude special folders (Trash, Drafts, Spam, Outbox,
// Sent) and limit the search to displayable folders.
LocalSearch search = new LocalSearch();
excludeSpecialFolders(search);
limitToDisplayableFolders(search);
// Use the LocalSearch instance to create a WHERE clause to query the content provider
StringBuilder query = new StringBuilder();
List<String> queryArgs = new ArrayList<>();
ConditionsTreeNode conditions = search.getConditions();
SqlQueryBuilder.buildWhereClause(this, conditions, query, queryArgs);
String selection = query.toString();
String[] selectionArgs = queryArgs.toArray(new String[0]);
Cursor cursor = cr.query(uri, projection, selection, selectionArgs, null);
try {
if (cursor != null && cursor.moveToFirst()) {
stats.unreadMessageCount = cursor.getInt(0);
stats.flaggedMessageCount = cursor.getInt(1);
}
} finally {
Utility.closeQuietly(cursor);
}
LocalStore localStore = getLocalStore();
if (K9.measureAccounts()) {
stats.size = localStore.getSize();
}
return stats;
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class MessageCompose method processMessageToForward.
private void processMessageToForward(MessageViewInfo messageViewInfo) throws MessagingException {
Message message = messageViewInfo.message;
String subject = message.getSubject();
if (subject != null && !subject.toLowerCase(Locale.US).startsWith("fwd:")) {
subjectView.setText("Fwd: " + subject);
} else {
subjectView.setText(subject);
}
// even if there are multiple references.
if (!TextUtils.isEmpty(message.getMessageId())) {
repliedToMessageId = message.getMessageId();
referencedMessageIds = repliedToMessageId;
} else {
Timber.d("could not get Message-ID.");
}
// Quote the message and setup the UI.
quotedMessagePresenter.processMessageToForward(messageViewInfo);
attachmentPresenter.processMessageToForward(messageViewInfo);
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class ReconstructMessageFromDatabaseTest method testThatByteIdenticalCopyOfMessageIsReconstructed.
public void testThatByteIdenticalCopyOfMessageIsReconstructed() throws IOException, MessagingException {
LocalFolder folder = createFolderInDatabase();
MimeMessage message = parseMessage();
saveMessageToDatabase(folder, message);
LocalMessage localMessage = readMessageFromDatabase(folder, message);
String reconstructedMessage = writeMessageToString(localMessage);
assertEquals(MESSAGE_SOURCE, reconstructedMessage);
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class MessagingControllerTest method localMessageWithCopyOnServer.
private LocalMessage localMessageWithCopyOnServer() throws MessagingException {
String messageUid = "UID";
Message remoteMessage = mock(Message.class);
LocalMessage localMessage = mock(LocalMessage.class);
when(remoteMessage.getUid()).thenReturn(messageUid);
when(localMessage.getUid()).thenReturn(messageUid);
when(remoteFolder.getMessages(anyInt(), anyInt(), any(Date.class), any(MessageRetrievalListener.class))).thenReturn(Collections.singletonList(remoteMessage));
return localMessage;
}
Aggregations