Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1eb0ef4a authored by cketti's avatar cketti
Browse files

Merge pull request #1390

Fix reply to all, and some refactorings for initFromReplyTo
parents 4795c26e 3762e156
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ public abstract class Message implements Part, CompositeBody {

    public abstract void setSentDate(Date sentDate, boolean hideTimeZone) throws MessagingException;

    public abstract Address[] getRecipients(RecipientType type) throws MessagingException;
    public abstract Address[] getRecipients(RecipientType type);

    public abstract void setRecipients(RecipientType type, Address[] addresses)
    throws MessagingException;
+19 −15
Original line number Diff line number Diff line
@@ -197,27 +197,31 @@ public class MimeMessage extends Message {
     * found the method returns an empty array.
     */
    @Override
    public Address[] getRecipients(RecipientType type) throws MessagingException {
        if (type == RecipientType.TO) {
    public Address[] getRecipients(RecipientType type) {
        switch (type) {
            case TO: {
                if (mTo == null) {
                    mTo = Address.parse(MimeUtility.unfold(getFirstHeader("To")));
                }
                return mTo;
        } else if (type == RecipientType.CC) {
            }
            case CC: {
                if (mCc == null) {
                    mCc = Address.parse(MimeUtility.unfold(getFirstHeader("CC")));
                }
                return mCc;
        } else if (type == RecipientType.BCC) {
            }
            case BCC: {
                if (mBcc == null) {
                    mBcc = Address.parse(MimeUtility.unfold(getFirstHeader("BCC")));
                }
                return mBcc;
        } else {
            throw new MessagingException("Unrecognized recipient type.");
            }
        }

        throw new IllegalArgumentException("Unrecognized recipient type.");
    }

    @Override
    public void setRecipients(RecipientType type, Address[] addresses) throws MessagingException {
        if (type == RecipientType.TO) {
+14 −23
Original line number Diff line number Diff line
@@ -538,7 +538,6 @@ public class K9 extends Application {

        MessagingController.getInstance(this).addListener(new MessagingListener() {
            private void broadcastIntent(String action, Account account, String folder, Message message) {
                try {
                Uri uri = Uri.parse("email://messages/" + account.getAccountNumber() + "/" + Uri.encode(folder) + "/" + Uri.encode(message.getUid()));
                Intent intent = new Intent(action, uri);
                intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
@@ -557,14 +556,6 @@ public class K9 extends Application {
                          + " folder=" + folder
                          + " message uid=" + message.getUid()
                         );

                } catch (MessagingException e) {
                    Log.w(K9.LOG_TAG, "Error: action=" + action
                          + " account=" + account.getDescription()
                          + " folder=" + folder
                          + " message uid=" + message.getUid()
                         );
                }
            }

            private void updateUnreadWidget() {
+5 −2
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import com.fsck.k9.fragment.ProgressDialogFragment.CancelListener;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.helper.IdentityHelper;
import com.fsck.k9.helper.MailTo;
import com.fsck.k9.helper.ReplyToParser;
import com.fsck.k9.helper.SimpleTextWatcher;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Flag;
@@ -400,7 +401,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,

        RecipientMvpView recipientMvpView = new RecipientMvpView(this);
        ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
        recipientPresenter = new RecipientPresenter(this, recipientMvpView, mAccount, composePgpInlineDecider);
        recipientPresenter = new RecipientPresenter(this, recipientMvpView, mAccount,
                composePgpInlineDecider, new ReplyToParser());

        mSubjectView = (EditText) findViewById(R.id.subject);
        mSubjectView.getInputExtras(true).putBoolean("allowEmoji", true);
@@ -1598,7 +1600,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
         * If a reply-to was included with the message use that, otherwise use the from
         * or sender address.
         */
        recipientPresenter.initFromReplyToMessage(message);
        boolean isReplyAll = mAction == Action.REPLY_ALL;
        recipientPresenter.initFromReplyToMessage(message, isReplyAll);

        if (message.getMessageId() != null && message.getMessageId().length() > 0) {
            mInReplyTo = message.getMessageId();
+19 −56
Original line number Diff line number Diff line
@@ -27,15 +27,14 @@ import com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.helper.MailTo;
import com.fsck.k9.helper.ReplyToParser;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.helper.ReplyToParser.ReplyToAddresses;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.message.PgpMessageBuilder;
import com.fsck.k9.message.ComposePgpInlineDecider;
import com.fsck.k9.message.PgpMessageBuilder;
import com.fsck.k9.view.RecipientSelectView.Recipient;
import org.openintents.openpgp.IOpenPgpService2;
import org.openintents.openpgp.util.OpenPgpApi;
@@ -61,6 +60,7 @@ public class RecipientPresenter implements PermissionPingCallback {
    private final Context context;
    private final RecipientMvpView recipientMvpView;
    private final ComposePgpInlineDecider composePgpInlineDecider;
    private ReplyToParser replyToParser;
    private Account account;
    private String cryptoProvider;
    private Boolean hasContactPicker;
@@ -78,10 +78,11 @@ public class RecipientPresenter implements PermissionPingCallback {


    public RecipientPresenter(Context context, RecipientMvpView recipientMvpView, Account account,
            ComposePgpInlineDecider composePgpInlineDecider) {
            ComposePgpInlineDecider composePgpInlineDecider, ReplyToParser replyToParser) {
        this.recipientMvpView = recipientMvpView;
        this.context = context;
        this.composePgpInlineDecider = composePgpInlineDecider;
        this.replyToParser = replyToParser;

        recipientMvpView.setPresenter(this);
        onSwitchAccount(account);
@@ -134,51 +135,18 @@ public class RecipientPresenter implements PermissionPingCallback {
        return false;
    }

    public void initFromReplyToMessage(Message message) {
        Address[] replyToAddresses = ReplyToParser.getRecipientsToReplyTo(message);
        
        try {
            // if we're replying to a message we sent, we probably meant
            // to reply to the recipient of that message
            if (account.isAnIdentity(replyToAddresses)) {
                replyToAddresses = message.getRecipients(RecipientType.TO);
            }

            addRecipientsFromAddresses(RecipientType.TO, replyToAddresses);

            if (message.getReplyTo().length > 0) {
                for (Address address : message.getFrom()) {
                    if (!account.isAnIdentity(address) && !Utility.arrayContains(replyToAddresses, address)) {
                        addRecipientsFromAddresses(RecipientType.TO, address);
                    }
                }
            }

            for (Address address : message.getRecipients(RecipientType.TO)) {
                if (!account.isAnIdentity(address) && !Utility.arrayContains(replyToAddresses, address)) {
                    addToAddresses(address);
                }

            }

            if (message.getRecipients(RecipientType.CC).length > 0) {
                for (Address address : message.getRecipients(RecipientType.CC)) {
                    if (!account.isAnIdentity(address) && !Utility.arrayContains(replyToAddresses, address)) {
                        addCcAddresses(address);
                    }
    public void initFromReplyToMessage(Message message, boolean isReplyAll) {
        ReplyToAddresses replyToAddresses = isReplyAll ?
                replyToParser.getRecipientsToReplyAllTo(message, account) :
                replyToParser.getRecipientsToReplyTo(message, account);

                }
            }
        addToAddresses(replyToAddresses.to);
        addCcAddresses(replyToAddresses.cc);

        boolean shouldSendAsPgpInline = composePgpInlineDecider.shouldReplyInline(message);
        if (shouldSendAsPgpInline) {
            cryptoEnablePgpInline = true;
        }

        } catch (MessagingException e) {
            // can't happen, we know the recipient types exist
            throw new AssertionError(e);
        }
    }

    public void initFromMailto(MailTo mailTo) {
@@ -228,7 +196,6 @@ public class RecipientPresenter implements PermissionPingCallback {
    }

    private void initRecipientsFromDraftMessage(LocalMessage message) {
        try {
        addToAddresses(message.getRecipients(RecipientType.TO));

        Address[] ccRecipients = message.getRecipients(RecipientType.CC);
@@ -236,10 +203,6 @@ public class RecipientPresenter implements PermissionPingCallback {

        Address[] bccRecipients = message.getRecipients(RecipientType.BCC);
        addBccAddresses(bccRecipients);
        } catch (MessagingException e) {
            // can't happen, we know the recipient types exist
            throw new AssertionError(e);
        }
    }

    private void initPgpInlineFromDraftMessage(LocalMessage message) {
Loading