Search in sources :

Example 1 with PgpMessageBuilder

use of com.fsck.k9.message.PgpMessageBuilder in project k-9 by k9mail.

the class PgpMessageBuilderTest method createDefaultPgpMessageBuilder.

private static PgpMessageBuilder createDefaultPgpMessageBuilder(OpenPgpApi openPgpApi) {
    PgpMessageBuilder builder = new PgpMessageBuilder(RuntimeEnvironment.application, MessageIdGenerator.getInstance(), BoundaryGenerator.getInstance());
    builder.setOpenPgpApi(openPgpApi);
    Identity identity = new Identity();
    identity.setName("tester");
    identity.setEmail("test@example.org");
    identity.setDescription("test identity");
    identity.setSignatureUse(false);
    builder.setSubject("subject").setSentDate(new Date()).setHideTimeZone(false).setTo(new ArrayList<Address>()).setCc(new ArrayList<Address>()).setBcc(new ArrayList<Address>()).setInReplyTo("inreplyto").setReferences("references").setRequestReadReceipt(false).setIdentity(identity).setMessageFormat(SimpleMessageFormat.TEXT).setText(TEST_MESSAGE_TEXT).setAttachments(new ArrayList<Attachment>()).setSignature("signature").setQuoteStyle(QuoteStyle.PREFIX).setQuotedTextMode(QuotedTextMode.NONE).setQuotedText("quoted text").setQuotedHtmlContent(new InsertableHtmlContent()).setReplyAfterQuote(false).setSignatureBeforeQuotedText(false).setIdentityChanged(false).setSignatureChanged(false).setCursorPosition(0).setMessageReference(null).setDraft(false);
    return builder;
}
Also used : Address(com.fsck.k9.mail.Address) ArrayList(java.util.ArrayList) Attachment(com.fsck.k9.activity.misc.Attachment) InsertableHtmlContent(com.fsck.k9.message.quote.InsertableHtmlContent) Identity(com.fsck.k9.Identity) Date(java.util.Date)

Example 2 with PgpMessageBuilder

use of com.fsck.k9.message.PgpMessageBuilder in project k-9 by k9mail.

the class MessageCompose method onMessageBuildSuccess.

@Override
public void onMessageBuildSuccess(MimeMessage message, boolean isDraft) {
    String plaintextSubject = (currentMessageBuilder instanceof PgpMessageBuilder) ? currentMessageBuilder.getSubject() : null;
    if (isDraft) {
        changesMadeSinceLastSave = false;
        currentMessageBuilder = null;
        new SaveMessageTask(messagingController, account, internalMessageHandler, message, draftMessageId, plaintextSubject).execute();
        if (finishAfterDraftSaved) {
            finish();
        } else {
            setProgressBarIndeterminateVisibility(false);
        }
    } else {
        currentMessageBuilder = null;
        new SendMessageTask(messagingController, preferences, account, contacts, message, draftMessageId, plaintextSubject, relatedMessageReference, relatedFlag).execute();
        finish();
    }
}
Also used : SaveMessageTask(com.fsck.k9.activity.compose.SaveMessageTask) PgpMessageBuilder(com.fsck.k9.message.PgpMessageBuilder)

Example 3 with PgpMessageBuilder

use of com.fsck.k9.message.PgpMessageBuilder in project k-9 by k9mail.

the class PgpMessageBuilder method buildMessageInternal.

@Override
protected void buildMessageInternal() {
    if (currentProcessedMimeMessage != null) {
        throw new IllegalStateException("message can only be built once!");
    }
    if (cryptoStatus == null) {
        throw new IllegalStateException("PgpMessageBuilder must have cryptoStatus set before building!");
    }
    Long openPgpKeyId = cryptoStatus.getOpenPgpKeyId();
    try {
        currentProcessedMimeMessage = build();
    } catch (MessagingException me) {
        queueMessageBuildException(me);
        return;
    }
    if (openPgpKeyId == null) {
        queueMessageBuildSuccess(currentProcessedMimeMessage);
        return;
    }
    if (!cryptoStatus.isProviderStateOk()) {
        queueMessageBuildException(new MessagingException("OpenPGP Provider is not ready!"));
        return;
    }
    addAutocryptHeaderIfAvailable(openPgpKeyId);
    if (isDraft()) {
        addDraftStateHeader();
    }
    startOrContinueBuildMessage(null);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException)

Example 4 with PgpMessageBuilder

use of com.fsck.k9.message.PgpMessageBuilder in project k-9 by k9mail.

the class PgpMessageBuilder method newInstance.

public static PgpMessageBuilder newInstance() {
    MessageIdGenerator messageIdGenerator = MessageIdGenerator.getInstance();
    BoundaryGenerator boundaryGenerator = BoundaryGenerator.getInstance();
    AutocryptOperations autocryptOperations = AutocryptOperations.getInstance();
    AutocryptOpenPgpApiInteractor autocryptOpenPgpApiInteractor = AutocryptOpenPgpApiInteractor.getInstance();
    CoreResourceProvider resourceProvider = DI.get(CoreResourceProvider.class);
    return new PgpMessageBuilder(messageIdGenerator, boundaryGenerator, autocryptOperations, autocryptOpenPgpApiInteractor, resourceProvider);
}
Also used : CoreResourceProvider(com.fsck.k9.CoreResourceProvider) AutocryptOperations(com.fsck.k9.autocrypt.AutocryptOperations) AutocryptOpenPgpApiInteractor(com.fsck.k9.autocrypt.AutocryptOpenPgpApiInteractor) MessageIdGenerator(com.fsck.k9.mail.internet.MessageIdGenerator) BoundaryGenerator(com.fsck.k9.mail.BoundaryGenerator)

Example 5 with PgpMessageBuilder

use of com.fsck.k9.message.PgpMessageBuilder in project k-9 by k9mail.

the class MessageCompose method createMessageBuilder.

@Nullable
private MessageBuilder createMessageBuilder(boolean isDraft) {
    MessageBuilder builder;
    ComposeCryptoStatus cryptoStatus = recipientPresenter.getCurrentCachedCryptoStatus();
    if (cryptoStatus == null) {
        return null;
    }
    boolean shouldUsePgpMessageBuilder = cryptoStatus.isOpenPgpConfigured();
    if (shouldUsePgpMessageBuilder) {
        SendErrorState maybeSendErrorState = cryptoStatus.getSendErrorStateOrNull();
        if (maybeSendErrorState != null) {
            recipientPresenter.showPgpSendError(maybeSendErrorState);
            return null;
        }
        PgpMessageBuilder pgpBuilder = PgpMessageBuilder.newInstance();
        recipientPresenter.builderSetProperties(pgpBuilder, cryptoStatus);
        builder = pgpBuilder;
    } else {
        builder = SimpleMessageBuilder.newInstance();
        recipientPresenter.builderSetProperties(builder);
    }
    builder.setSubject(Utility.stripNewLines(subjectView.getText().toString())).setSentDate(new Date()).setHideTimeZone(K9.isHideTimeZone()).setInReplyTo(repliedToMessageId).setReferences(referencedMessageIds).setRequestReadReceipt(requestReadReceipt).setIdentity(identity).setReplyTo(replyToPresenter.getAddresses()).setMessageFormat(currentMessageFormat).setText(CrLfConverter.toCrLf(messageContentView.getText())).setAttachments(attachmentPresenter.getAttachments()).setInlineAttachments(attachmentPresenter.getInlineAttachments()).setSignature(CrLfConverter.toCrLf(signatureView.getText())).setSignatureBeforeQuotedText(account.isSignatureBeforeQuotedText()).setIdentityChanged(identityChanged).setSignatureChanged(signatureChanged).setCursorPosition(messageContentView.getSelectionStart()).setMessageReference(relatedMessageReference).setDraft(isDraft).setIsPgpInlineEnabled(cryptoStatus.isPgpInlineModeEnabled());
    quotedMessagePresenter.builderSetProperties(builder);
    return builder;
}
Also used : SendErrorState(com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState) PgpMessageBuilder(com.fsck.k9.message.PgpMessageBuilder) SimpleMessageBuilder(com.fsck.k9.message.SimpleMessageBuilder) MessageBuilder(com.fsck.k9.message.MessageBuilder) PgpMessageBuilder(com.fsck.k9.message.PgpMessageBuilder) ComposeCryptoStatus(com.fsck.k9.activity.compose.ComposeCryptoStatus) Date(java.util.Date) Nullable(androidx.annotation.Nullable)

Aggregations

PgpMessageBuilder (com.fsck.k9.message.PgpMessageBuilder)2 Date (java.util.Date)2 Nullable (androidx.annotation.Nullable)1 CoreResourceProvider (com.fsck.k9.CoreResourceProvider)1 Identity (com.fsck.k9.Identity)1 ComposeCryptoStatus (com.fsck.k9.activity.compose.ComposeCryptoStatus)1 SendErrorState (com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState)1 SaveMessageTask (com.fsck.k9.activity.compose.SaveMessageTask)1 Attachment (com.fsck.k9.activity.misc.Attachment)1 AutocryptOpenPgpApiInteractor (com.fsck.k9.autocrypt.AutocryptOpenPgpApiInteractor)1 AutocryptOperations (com.fsck.k9.autocrypt.AutocryptOperations)1 Address (com.fsck.k9.mail.Address)1 BoundaryGenerator (com.fsck.k9.mail.BoundaryGenerator)1 MessagingException (com.fsck.k9.mail.MessagingException)1 MessageIdGenerator (com.fsck.k9.mail.internet.MessageIdGenerator)1 MessageBuilder (com.fsck.k9.message.MessageBuilder)1 SimpleMessageBuilder (com.fsck.k9.message.SimpleMessageBuilder)1 InsertableHtmlContent (com.fsck.k9.message.quote.InsertableHtmlContent)1 ArrayList (java.util.ArrayList)1