use of com.fsck.k9.message.MessageBuilder.Callback in project k-9 by k9mail.
the class PgpMessageBuilderTest method build__withCryptoProviderNotOk__shouldThrow.
@Test
public void build__withCryptoProviderNotOk__shouldThrow() throws MessagingException {
cryptoStatusBuilder.setCryptoMode(CryptoMode.SIGN_ONLY);
CryptoProviderState[] cryptoProviderStates = { CryptoProviderState.LOST_CONNECTION, CryptoProviderState.UNCONFIGURED, CryptoProviderState.UNINITIALIZED, CryptoProviderState.ERROR };
for (CryptoProviderState state : cryptoProviderStates) {
cryptoStatusBuilder.setCryptoProviderState(state);
pgpMessageBuilder.setCryptoStatus(cryptoStatusBuilder.build());
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);
verify(mockCallback).onMessageBuildException(any(MessagingException.class));
verifyNoMoreInteractions(mockCallback);
}
}
use of com.fsck.k9.message.MessageBuilder.Callback in project k-9 by k9mail.
the class MessageBuilderTest method build_withMessageAttachment_shouldAttachAsApplicationOctetStream.
@Test
public void build_withMessageAttachment_shouldAttachAsApplicationOctetStream() throws Exception {
MessageBuilder messageBuilder = createSimpleMessageBuilder();
Attachment attachment = createAttachmentWithContent("message/rfc822", "attach.txt", TEST_ATTACHMENT_TEXT);
messageBuilder.setAttachments(Collections.singletonList(attachment));
messageBuilder.buildAsync(callback);
MimeMessage message = getMessageFromCallback();
assertEquals(MESSAGE_HEADERS + MESSAGE_CONTENT_WITH_MESSAGE_ATTACH, getMessageContents(message));
}
use of com.fsck.k9.message.MessageBuilder.Callback in project k-9 by k9mail.
the class ImapFolder method fetchPart.
@Override
public void fetchPart(Message message, Part part, MessageRetrievalListener<Message> listener) throws MessagingException {
checkOpen();
String partId = part.getServerExtra();
String fetch;
if ("TEXT".equalsIgnoreCase(partId)) {
int maximumAutoDownloadMessageSize = store.getStoreConfig().getMaximumAutoDownloadMessageSize();
fetch = String.format(Locale.US, "BODY.PEEK[TEXT]<0.%d>", maximumAutoDownloadMessageSize);
} else {
fetch = String.format("BODY.PEEK[%s]", partId);
}
try {
String command = String.format("UID FETCH %s (UID %s)", message.getUid(), fetch);
connection.sendCommand(command, false);
ImapResponse response;
int messageNumber = 0;
ImapResponseCallback callback = new FetchPartCallback(part);
do {
response = connection.readResponse(callback);
if (response.getTag() == null && ImapResponseParser.equalsIgnoreCase(response.get(1), "FETCH")) {
ImapList fetchList = (ImapList) response.getKeyedValue("FETCH");
String uid = fetchList.getKeyedString("UID");
if (!message.getUid().equals(uid)) {
if (K9MailLib.isDebug()) {
Log.d(LOG_TAG, "Did not ask for UID " + uid + " for " + getLogId());
}
handleUntaggedResponse(response);
continue;
}
if (listener != null) {
listener.messageStarted(uid, messageNumber++, 1);
}
ImapMessage imapMessage = (ImapMessage) message;
Object literal = handleFetchResponse(imapMessage, fetchList);
if (literal != null) {
if (literal instanceof Body) {
// Most of the work was done in FetchAttchmentCallback.foundLiteral()
MimeMessageHelper.setBody(part, (Body) literal);
} else if (literal instanceof String) {
String bodyString = (String) literal;
InputStream bodyStream = new ByteArrayInputStream(bodyString.getBytes());
String contentTransferEncoding = part.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING)[0];
String contentType = part.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0];
MimeMessageHelper.setBody(part, MimeUtility.createBody(bodyStream, contentTransferEncoding, contentType));
} else {
// This shouldn't happen
throw new MessagingException("Got FETCH response with bogus parameters");
}
}
if (listener != null) {
listener.messageFinished(message, messageNumber, 1);
}
} else {
handleUntaggedResponse(response);
}
} while (response.getTag() == null);
} catch (IOException ioe) {
throw ioExceptionHandler(connection, ioe);
}
}
use of com.fsck.k9.message.MessageBuilder.Callback in project k-9 by k9mail.
the class MessageLoaderHelper method onLoadMessageFromDatabaseFinished.
@UiThread
private void onLoadMessageFromDatabaseFinished() {
if (callback == null) {
throw new IllegalStateException("unexpected call when callback is already detached");
}
callback.onMessageDataLoadFinished(localMessage);
boolean downloadedCompletely = localMessage.isSet(Flag.X_DOWNLOADED_FULL);
boolean downloadedPartially = localMessage.isSet(Flag.X_DOWNLOADED_PARTIAL);
boolean messageIncomplete = !downloadedCompletely && !downloadedPartially;
if (messageIncomplete) {
startDownloadingMessageBody(false);
return;
}
if (onlyLoadMetadata) {
MessageViewInfo messageViewInfo = MessageViewInfo.createForMetadataOnly(localMessage, !downloadedCompletely);
onDecodeMessageFinished(messageViewInfo);
return;
}
String openPgpProvider = account.getOpenPgpProvider();
if (openPgpProvider != null) {
startOrResumeCryptoOperation(openPgpProvider);
return;
}
startOrResumeDecodeMessage();
}
use of com.fsck.k9.message.MessageBuilder.Callback in project k-9 by k9mail.
the class RealImapConnectionTest method createOAuth2TokenProvider.
private OAuth2TokenProvider createOAuth2TokenProvider() {
return new OAuth2TokenProvider() {
private int invalidationCount = 0;
@Override
public String getToken(String username, long timeoutMillis) throws AuthenticationFailedException {
assertEquals(USERNAME, username);
assertEquals(OAUTH2_TIMEOUT, timeoutMillis);
switch(invalidationCount) {
case 0:
{
return XOAUTH_TOKEN;
}
case 1:
{
return XOAUTH_ANOTHER_TOKEN;
}
default:
{
throw new AuthenticationFailedException("Ran out of auth tokens. invalidateToken() called too often?");
}
}
}
@Override
public void invalidateToken(String username) {
assertEquals(USERNAME, username);
invalidationCount++;
}
@Override
public List<String> getAccounts() {
throw new UnsupportedOperationException();
}
@Override
public void authorizeApi(String username, Activity activity, OAuth2TokenProviderAuthCallback callback) {
throw new UnsupportedOperationException();
}
};
}
Aggregations