use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class MessageTest method testMessage.
@Test
public void testMessage() throws MessagingException, IOException {
MimeMessage message;
ByteArrayOutputStream out;
BinaryTempFileBody.setTempDirectory(context.getCacheDir());
mMimeBoundary = 101;
message = nestedMessage(nestedMessage(sampleMessage()));
out = new ByteArrayOutputStream();
message.writeTo(out);
assertEquals(SEVEN_BIT_RESULT, out.toString());
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class ImapConnectionTest method open_authPlainWithLoginDisabled_shouldThrow.
@Test
public void open_authPlainWithLoginDisabled_shouldThrow() throws Exception {
settings.setAuthType(AuthType.PLAIN);
MockImapServer server = new MockImapServer();
preAuthenticationDialog(server, "LOGINDISABLED");
ImapConnection imapConnection = startServerAndCreateImapConnection(server);
try {
imapConnection.open();
fail("Expected exception");
} catch (MessagingException e) {
assertEquals("Server doesn't support unencrypted passwords using AUTH=PLAIN and LOGIN is disabled.", e.getMessage());
}
server.verifyConnectionClosed();
server.verifyInteractionCompleted();
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class ImapConnectionTest method open_authCramMd5WithoutAuthCramMd5Capability_shouldThrow.
@Test
public void open_authCramMd5WithoutAuthCramMd5Capability_shouldThrow() throws Exception {
settings.setAuthType(AuthType.CRAM_MD5);
MockImapServer server = new MockImapServer();
preAuthenticationDialog(server, "AUTH=PLAIN");
ImapConnection imapConnection = startServerAndCreateImapConnection(server);
try {
imapConnection.open();
fail("Expected exception");
} catch (MessagingException e) {
assertEquals("Server doesn't support encrypted passwords using CRAM-MD5.", e.getMessage());
}
server.verifyConnectionClosed();
server.verifyInteractionCompleted();
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class MessageTest method testToBodyPart.
@Test
public void testToBodyPart() throws MessagingException, IOException {
MimeMessage message;
ByteArrayOutputStream out;
BinaryTempFileBody.setTempDirectory(context.getCacheDir());
mMimeBoundary = 101;
message = nestedMessage(nestedMessage(sampleMessage()));
out = new ByteArrayOutputStream();
MimeBodyPart bodyPart = message.toBodyPart();
bodyPart.writeTo(out);
assertEquals(TO_BODY_PART_RESULT, out.toString());
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class EmailProvider method getAccountStats.
private Cursor getAccountStats(String accountUuid, String[] columns, final String selection, final String[] selectionArgs) {
Account account = getAccount(accountUuid);
LockableDatabase database = getDatabase(account);
// Use default projection if none was given
String[] sourceProjection = (columns == null) ? STATS_DEFAULT_PROJECTION : columns;
// Create SQL query string
final StringBuilder sql = new StringBuilder();
sql.append("SELECT ");
// Append projection for the database query
// e.g. "SUM(read=0) AS unread_count, SUM(flagged) AS flagged_count"
boolean first = true;
for (String columnName : sourceProjection) {
if (!first) {
sql.append(',');
} else {
first = false;
}
if (StatsColumns.UNREAD_COUNT.equals(columnName)) {
sql.append("SUM(" + MessageColumns.READ + "=0) AS " + StatsColumns.UNREAD_COUNT);
} else if (StatsColumns.FLAGGED_COUNT.equals(columnName)) {
sql.append("SUM(" + MessageColumns.FLAGGED + ") AS " + StatsColumns.FLAGGED_COUNT);
} else {
throw new IllegalArgumentException("Column name not allowed: " + columnName);
}
}
// Table selection
sql.append(" FROM messages");
if (containsAny(selection, FOLDERS_COLUMNS)) {
sql.append(" JOIN folders ON (folders.id = messages.folder_id)");
}
// WHERE clause
sql.append(" WHERE (deleted = 0 AND empty = 0)");
if (!TextUtils.isEmpty(selection)) {
sql.append(" AND (");
sql.append(selection);
sql.append(")");
}
// Query the database and return the result cursor
try {
return database.execute(false, new DbCallback<Cursor>() {
@Override
public Cursor doDbWork(SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
return db.rawQuery(sql.toString(), selectionArgs);
}
});
} catch (UnavailableStorageException e) {
throw new RuntimeException("Storage not available", e);
} catch (MessagingException e) {
throw new RuntimeException("messaging exception", e);
}
}
Aggregations