use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.
the class MessageCryptoHelper method extractClearsignedTextReplacementPart.
private static MimeBodyPart extractClearsignedTextReplacementPart(Part part) {
try {
String clearsignedText = MessageExtractor.getTextFromPart(part);
String replacementText = OpenPgpUtils.extractClearsignedMessage(clearsignedText);
if (replacementText == null) {
Timber.e("failed to extract clearsigned text for replacement part");
return NO_REPLACEMENT_PART;
}
return new MimeBodyPart(new TextBody(replacementText), "text/plain");
} catch (MessagingException e) {
Timber.e(e, "failed to create clearsigned text replacement part");
return NO_REPLACEMENT_PART;
}
}
use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.
the class ImapFolderTest method fetchPart_withTextSection_shouldProcessImapResponses.
@Test
public void fetchPart_withTextSection_shouldProcessImapResponses() throws Exception {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
ImapMessage message = createImapMessage("1");
Part part = createPlainTextPart("1.1");
setupSingleFetchResponseToCallback();
folder.fetchPart(message, part, null);
ArgumentCaptor<Body> bodyArgumentCaptor = ArgumentCaptor.forClass(Body.class);
verify(part).setBody(bodyArgumentCaptor.capture());
Body body = bodyArgumentCaptor.getValue();
Buffer buffer = new Buffer();
body.writeTo(buffer.outputStream());
assertEquals("text", buffer.readUtf8());
}
use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.
the class ImapFolderTest method fetchPart_withTextSection_shouldIssueRespectiveCommand.
@Test
public void fetchPart_withTextSection_shouldIssueRespectiveCommand() throws Exception {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
when(storeConfig.getMaximumAutoDownloadMessageSize()).thenReturn(4096);
folder.open(OPEN_MODE_RO);
ImapMessage message = createImapMessage("1");
Part part = createPart("TEXT");
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
folder.fetchPart(message, part, null);
verify(imapConnection).sendCommand("UID FETCH 1 (UID BODY.PEEK[TEXT]<0.4096>)", false);
}
use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.
the class MessageBuilder method buildText.
/**
* Build the {@link Body} that will contain the text of the message.
*
* <p>
* Draft messages are treated somewhat differently in that signatures are not appended and HTML
* separators between composed text and quoted text are not added.
* </p>
*
* @param isDraft
* If {@code true} we build a message that will be saved as a draft (as opposed to
* sent).
* @param simpleMessageFormat
* Specifies what type of message to build ({@code text/plain} vs. {@code text/html}).
*
* @return {@link TextBody} instance that contains the entered text and possibly the quoted
* original message.
*/
private TextBody buildText(boolean isDraft, SimpleMessageFormat simpleMessageFormat) {
String messageText = text;
TextBodyBuilder textBodyBuilder = new TextBodyBuilder(messageText);
/*
* Find out if we need to include the original message as quoted text.
*
* We include the quoted text in the body if the user didn't choose to
* hide it. We always include the quoted text when we're saving a draft.
* That's so the user is able to "un-hide" the quoted text if (s)he
* opens a saved draft.
*/
boolean includeQuotedText = (isDraft || quotedTextMode == QuotedTextMode.SHOW);
boolean isReplyAfterQuote = (quoteStyle == QuoteStyle.PREFIX && this.isReplyAfterQuote);
textBodyBuilder.setIncludeQuotedText(false);
if (includeQuotedText) {
if (simpleMessageFormat == SimpleMessageFormat.HTML && quotedHtmlContent != null) {
textBodyBuilder.setIncludeQuotedText(true);
textBodyBuilder.setQuotedTextHtml(quotedHtmlContent);
textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote);
}
if (simpleMessageFormat == SimpleMessageFormat.TEXT && quotedText.length() > 0) {
textBodyBuilder.setIncludeQuotedText(true);
textBodyBuilder.setQuotedText(quotedText);
textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote);
}
}
textBodyBuilder.setInsertSeparator(!isDraft);
boolean useSignature = (!isDraft && identity.getSignatureUse());
if (useSignature) {
textBodyBuilder.setAppendSignature(true);
textBodyBuilder.setSignature(signature);
textBodyBuilder.setSignatureBeforeQuotedText(isSignatureBeforeQuotedText);
} else {
textBodyBuilder.setAppendSignature(false);
}
TextBody body;
if (simpleMessageFormat == SimpleMessageFormat.HTML) {
body = textBodyBuilder.buildTextHtml();
} else {
body = textBodyBuilder.buildTextPlain();
}
return body;
}
use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.
the class PgpMessageBuilder method startOrContinueBuildMessage.
private void startOrContinueBuildMessage(@Nullable Intent pgpApiIntent) {
try {
boolean shouldSign = cryptoStatus.isSigningEnabled();
boolean shouldEncrypt = cryptoStatus.isEncryptionEnabled();
boolean isPgpInlineMode = cryptoStatus.isPgpInlineModeEnabled();
if (!shouldSign && !shouldEncrypt) {
return;
}
boolean isSimpleTextMessage = MimeUtility.isSameMimeType("text/plain", currentProcessedMimeMessage.getMimeType());
if (isPgpInlineMode && !isSimpleTextMessage) {
throw new MessagingException("Attachments are not supported in PGP/INLINE format!");
}
if (pgpApiIntent == null) {
pgpApiIntent = buildOpenPgpApiIntent(shouldSign, shouldEncrypt, isPgpInlineMode);
}
PendingIntent returnedPendingIntent = launchOpenPgpApiIntent(pgpApiIntent, shouldEncrypt || isPgpInlineMode, shouldEncrypt || !isPgpInlineMode, isPgpInlineMode);
if (returnedPendingIntent != null) {
queueMessageBuildPendingIntent(returnedPendingIntent, REQUEST_USER_INTERACTION);
return;
}
queueMessageBuildSuccess(currentProcessedMimeMessage);
} catch (MessagingException me) {
queueMessageBuildException(me);
}
}
Aggregations