Search in sources :

Example 16 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class MessageHelperTest method toFriendly_nameStartingWithAtShouldNotTriggerSpoofPrevention.

@Test
public void toFriendly_nameStartingWithAtShouldNotTriggerSpoofPrevention() {
    Address address = new Address("address@domain.example", "@username");
    CharSequence friendly = MessageHelper.toFriendly(address, contacts);
    assertEquals("@username", friendly.toString());
}
Also used : Address(com.fsck.k9.mail.Address) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 17 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class MessageHelperTest method testToFriendlyArray.

@Test
public void testToFriendlyArray() throws Exception {
    Address address1 = new Address("test@testor.com", "Tim Testor");
    Address address2 = new Address("foo@bar.com", "Foo Bar");
    Address[] addresses = new Address[] { address1, address2 };
    assertEquals("Tim Testor,Foo Bar", MessageHelper.toFriendly(addresses, contacts).toString());
}
Also used : Address(com.fsck.k9.mail.Address) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 18 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class MessageHelperTest method toFriendly_spoofPreventionOverridesPersonal.

@Test
public void toFriendly_spoofPreventionOverridesPersonal() {
    Address address = new Address("test@testor.com", "potus@whitehouse.gov");
    CharSequence friendly = MessageHelper.toFriendly(address, contacts);
    assertEquals("test@testor.com", friendly.toString());
}
Also used : Address(com.fsck.k9.mail.Address) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 19 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class MessageCompose method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (UpgradeDatabases.actionUpgradeDatabases(this, getIntent())) {
        finish();
        return;
    }
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setLayout(R.layout.message_compose);
    ViewStub contentContainer = findViewById(R.id.message_compose_content);
    sizeFormatter = new SizeFormatter(getResources());
    ThemeManager themeManager = getThemeManager();
    int messageComposeThemeResourceId = themeManager.getMessageComposeThemeResourceId();
    ContextThemeWrapper themeContext = new ContextThemeWrapper(this, messageComposeThemeResourceId);
    LayoutInflater themedLayoutInflater = LayoutInflater.from(themeContext);
    contentContainer.setLayoutInflater(themedLayoutInflater);
    View contentView = contentContainer.inflate();
    // background color needs to be forced
    // TODO: Change themes to use appropriate background colors that don't need overriding.
    TypedValue outValue = new TypedValue();
    themeContext.getTheme().resolveAttribute(R.attr.messageViewBackgroundColor, outValue, true);
    contentView.setBackgroundColor(outValue.data);
    initializeActionBar();
    // on api level 15, setContentView() shows the progress bar for some reason...
    setProgressBarIndeterminateVisibility(false);
    final Intent intent = getIntent();
    String messageReferenceString = intent.getStringExtra(EXTRA_MESSAGE_REFERENCE);
    relatedMessageReference = MessageReference.parse(messageReferenceString);
    final String accountUuid = (relatedMessageReference != null) ? relatedMessageReference.getAccountUuid() : intent.getStringExtra(EXTRA_ACCOUNT);
    if (accountUuid != null) {
        account = preferences.getAccount(accountUuid);
    }
    if (account == null) {
        account = preferences.getDefaultAccount();
    }
    if (account == null) {
        /*
             * There are no accounts set up. This should not have happened. Prompt the
             * user to set up an account as an acceptable bailout.
             */
        MessageList.launch(this);
        changesMadeSinceLastSave = false;
        finish();
        return;
    }
    contacts = Contacts.getInstance(MessageCompose.this);
    chooseIdentityButton = findViewById(R.id.identity);
    chooseIdentityButton.setOnClickListener(this);
    ReplyToView replyToView = new ReplyToView(this);
    replyToPresenter = new ReplyToPresenter(replyToView);
    RecipientMvpView recipientMvpView = new RecipientMvpView(this);
    ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
    ComposePgpEnableByDefaultDecider composePgpEnableByDefaultDecider = new ComposePgpEnableByDefaultDecider();
    OpenPgpApiManager openPgpApiManager = new OpenPgpApiManager(getApplicationContext(), this);
    recipientPresenter = new RecipientPresenter(getApplicationContext(), getSupportLoaderManager(), openPgpApiManager, recipientMvpView, account, composePgpInlineDecider, composePgpEnableByDefaultDecider, AutocryptStatusInteractor.getInstance(), new ReplyToParser(), DI.get(AutocryptDraftStateHeaderParser.class));
    recipientPresenter.asyncUpdateCryptoStatus();
    subjectView = findViewById(R.id.subject);
    subjectView.getInputExtras(true).putBoolean("allowEmoji", true);
    EditText upperSignature = findViewById(R.id.upper_signature);
    EditText lowerSignature = findViewById(R.id.lower_signature);
    QuotedMessageMvpView quotedMessageMvpView = new QuotedMessageMvpView(this);
    quotedMessagePresenter = new QuotedMessagePresenter(this, quotedMessageMvpView, account);
    attachmentPresenter = new AttachmentPresenter(getApplicationContext(), attachmentMvpView, getSupportLoaderManager(), this);
    messageContentView = findViewById(R.id.message_content);
    messageContentView.getInputExtras(true).putBoolean("allowEmoji", true);
    attachmentsView = findViewById(R.id.attachments);
    TextWatcher draftNeedsChangingTextWatcher = new SimpleTextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            changesMadeSinceLastSave = true;
        }
    };
    TextWatcher signTextWatcher = new SimpleTextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            changesMadeSinceLastSave = true;
            signatureChanged = true;
        }
    };
    replyToView.addTextChangedListener(draftNeedsChangingTextWatcher);
    recipientMvpView.addTextChangedListener(draftNeedsChangingTextWatcher);
    quotedMessageMvpView.addTextChangedListener(draftNeedsChangingTextWatcher);
    subjectView.addTextChangedListener(draftNeedsChangingTextWatcher);
    messageContentView.addTextChangedListener(draftNeedsChangingTextWatcher);
    /*
         * We set this to invisible by default. Other methods will turn it back on if it's
         * needed.
         */
    quotedMessagePresenter.showOrHideQuotedText(QuotedTextMode.NONE);
    subjectView.setOnFocusChangeListener(this);
    messageContentView.setOnFocusChangeListener(this);
    if (savedInstanceState != null) {
        /*
             * This data gets used in onCreate, so grab it here instead of onRestoreInstanceState
             */
        relatedMessageProcessed = savedInstanceState.getBoolean(STATE_KEY_SOURCE_MESSAGE_PROCED, false);
    }
    if (initFromIntent(intent)) {
        action = Action.COMPOSE;
        changesMadeSinceLastSave = true;
    } else {
        String action = intent.getAction();
        if (ACTION_COMPOSE.equals(action)) {
            this.action = Action.COMPOSE;
        } else if (ACTION_REPLY.equals(action)) {
            this.action = Action.REPLY;
        } else if (ACTION_REPLY_ALL.equals(action)) {
            this.action = Action.REPLY_ALL;
        } else if (ACTION_FORWARD.equals(action)) {
            this.action = Action.FORWARD;
        } else if (ACTION_FORWARD_AS_ATTACHMENT.equals(action)) {
            this.action = Action.FORWARD_AS_ATTACHMENT;
        } else if (ACTION_EDIT_DRAFT.equals(action)) {
            this.action = Action.EDIT_DRAFT;
        } else {
            // This shouldn't happen
            Timber.w("MessageCompose was started with an unsupported action");
            this.action = Action.COMPOSE;
        }
    }
    if (identity == null) {
        identity = account.getIdentity(0);
    }
    if (account.isSignatureBeforeQuotedText()) {
        signatureView = upperSignature;
        lowerSignature.setVisibility(View.GONE);
    } else {
        signatureView = lowerSignature;
        upperSignature.setVisibility(View.GONE);
    }
    updateSignature();
    signatureView.addTextChangedListener(signTextWatcher);
    if (!identity.getSignatureUse()) {
        signatureView.setVisibility(View.GONE);
    }
    requestReadReceipt = account.isMessageReadReceipt();
    updateFrom();
    replyToPresenter.setIdentity(identity);
    if (!relatedMessageProcessed) {
        if (action == Action.REPLY || action == Action.REPLY_ALL || action == Action.FORWARD || action == Action.FORWARD_AS_ATTACHMENT || action == Action.EDIT_DRAFT) {
            messageLoaderHelper = messageLoaderHelperFactory.createForMessageCompose(this, getSupportLoaderManager(), getSupportFragmentManager(), messageLoaderCallbacks);
            internalMessageHandler.sendEmptyMessage(MSG_PROGRESS_ON);
            if (action == Action.FORWARD_AS_ATTACHMENT) {
                messageLoaderHelper.asyncStartOrResumeLoadingMessageMetadata(relatedMessageReference);
            } else {
                Parcelable cachedDecryptionResult = intent.getParcelableExtra(EXTRA_MESSAGE_DECRYPTION_RESULT);
                messageLoaderHelper.asyncStartOrResumeLoadingMessage(relatedMessageReference, cachedDecryptionResult);
            }
        }
    }
    if (action == Action.REPLY || action == Action.REPLY_ALL) {
        relatedFlag = Flag.ANSWERED;
    } else if (action == Action.FORWARD || action == Action.FORWARD_AS_ATTACHMENT) {
        relatedFlag = Flag.FORWARDED;
    }
    if (action == Action.REPLY || action == Action.REPLY_ALL || action == Action.EDIT_DRAFT) {
        // change focus to message body.
        messageContentView.requestFocus();
    } else {
        // Explicitly set focus to "To:" input field (see issue 2998)
        recipientMvpView.requestFocusOnToField();
    }
    updateMessageFormat();
    // Set font size of input controls
    int fontSize = K9.getFontSizes().getMessageComposeInput();
    replyToView.setFontSizes(K9.getFontSizes(), fontSize);
    recipientMvpView.setFontSizes(K9.getFontSizes(), fontSize);
    quotedMessageMvpView.setFontSizes(K9.getFontSizes(), fontSize);
    K9.getFontSizes().setViewTextSize(subjectView, fontSize);
    K9.getFontSizes().setViewTextSize(messageContentView, fontSize);
    K9.getFontSizes().setViewTextSize(signatureView, fontSize);
    updateMessageFormat();
    setTitle();
    currentMessageBuilder = (MessageBuilder) getLastCustomNonConfigurationInstance();
    if (currentMessageBuilder != null) {
        setProgressBarIndeterminateVisibility(true);
        currentMessageBuilder.reattachCallback(this);
    }
    if (savedInstanceState == null) {
        checkAndRequestPermissions();
    }
}
Also used : ComposePgpInlineDecider(com.fsck.k9.message.ComposePgpInlineDecider) SizeFormatter(com.fsck.k9.ui.helper.SizeFormatter) ReplyToParser(com.fsck.k9.helper.ReplyToParser) RecipientMvpView(com.fsck.k9.activity.compose.RecipientMvpView) TextWatcher(android.text.TextWatcher) SimpleTextWatcher(com.fsck.k9.helper.SimpleTextWatcher) AttachmentPresenter(com.fsck.k9.activity.compose.AttachmentPresenter) ComposePgpEnableByDefaultDecider(com.fsck.k9.message.ComposePgpEnableByDefaultDecider) TypedValue(android.util.TypedValue) EditText(android.widget.EditText) RecipientPresenter(com.fsck.k9.activity.compose.RecipientPresenter) OpenPgpApiManager(org.openintents.openpgp.OpenPgpApiManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Parcelable(android.os.Parcelable) ThemeManager(com.fsck.k9.ui.base.ThemeManager) QuotedMessageMvpView(com.fsck.k9.ui.compose.QuotedMessageMvpView) ImageView(android.widget.ImageView) RecipientMvpView(com.fsck.k9.activity.compose.RecipientMvpView) View(android.view.View) QuotedMessageMvpView(com.fsck.k9.ui.compose.QuotedMessageMvpView) TextView(android.widget.TextView) ReplyToView(com.fsck.k9.activity.compose.ReplyToView) AttachmentMvpView(com.fsck.k9.activity.compose.AttachmentPresenter.AttachmentMvpView) SuppressLint(android.annotation.SuppressLint) ViewStub(android.view.ViewStub) ReplyToView(com.fsck.k9.activity.compose.ReplyToView) ReplyToPresenter(com.fsck.k9.activity.compose.ReplyToPresenter) QuotedMessagePresenter(com.fsck.k9.ui.compose.QuotedMessagePresenter) SimpleTextWatcher(com.fsck.k9.helper.SimpleTextWatcher) ContextThemeWrapper(android.view.ContextThemeWrapper) LayoutInflater(android.view.LayoutInflater)

Example 20 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class RecipientLoader method fillContactDataFromCursor.

private void fillContactDataFromCursor(Cursor cursor, List<Recipient> recipients, Map<String, Recipient> recipientMap, @Nullable String prefilledName, @Nullable Integer maxRecipients) {
    while (cursor.moveToNext() && (maxRecipients == null || recipients.size() < maxRecipients)) {
        String name = prefilledName != null ? prefilledName : cursor.getString(INDEX_NAME);
        String email = cursor.getString(INDEX_EMAIL);
        // already exists? just skip then
        if (email == null || !isSupportedEmailAddress(email) || recipientMap.containsKey(email)) {
            // TODO We should probably merging contacts with the same email address
            continue;
        }
        long contactId = cursor.getLong(INDEX_CONTACT_ID);
        String lookupKey = cursor.getString(INDEX_LOOKUP_KEY);
        int timesContacted = cursor.getInt(INDEX_TIMES_CONTACTED);
        String sortKey = cursor.getString(INDEX_KEY_PRIMARY);
        boolean starred = cursor.getInt(INDEX_STARRED) == 1;
        int addressType = cursor.getInt(INDEX_EMAIL_TYPE);
        String addressLabel = null;
        switch(addressType) {
            case ContactsContract.CommonDataKinds.Email.TYPE_HOME:
                {
                    addressLabel = getContext().getString(R.string.address_type_home);
                    break;
                }
            case ContactsContract.CommonDataKinds.Email.TYPE_WORK:
                {
                    addressLabel = getContext().getString(R.string.address_type_work);
                    break;
                }
            case ContactsContract.CommonDataKinds.Email.TYPE_OTHER:
                {
                    addressLabel = getContext().getString(R.string.address_type_other);
                    break;
                }
            case ContactsContract.CommonDataKinds.Email.TYPE_MOBILE:
                {
                    // mobile isn't listed as an option contacts app, but it has a constant so we better support it
                    addressLabel = getContext().getString(R.string.address_type_mobile);
                    break;
                }
            case ContactsContract.CommonDataKinds.Email.TYPE_CUSTOM:
                {
                    addressLabel = cursor.getString(INDEX_EMAIL_CUSTOM_LABEL);
                    break;
                }
        }
        Recipient recipient = new Recipient(name, email, addressLabel, contactId, lookupKey, timesContacted, sortKey, starred);
        if (recipient.isValidEmailAddress()) {
            recipient.photoThumbnailUri = cursor.isNull(INDEX_PHOTO_URI) ? null : Uri.parse(cursor.getString(INDEX_PHOTO_URI));
            recipientMap.put(email, recipient);
            recipients.add(recipient);
        }
    }
    cursor.close();
}
Also used : Recipient(com.fsck.k9.view.RecipientSelectView.Recipient)

Aggregations

Address (com.fsck.k9.mail.Address)13 Contacts (com.fsck.k9.helper.Contacts)8 RobolectricTest (com.fsck.k9.RobolectricTest)6 Test (org.junit.Test)6 Uri (android.net.Uri)3 Recipient (com.fsck.k9.view.RecipientSelectView.Recipient)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Cursor (android.database.Cursor)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Message (android.os.Message)1 Parcelable (android.os.Parcelable)1 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextWatcher (android.text.TextWatcher)1 TypedValue (android.util.TypedValue)1 ContextThemeWrapper (android.view.ContextThemeWrapper)1