Search in sources :

Example 51 with K9

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

the class MessagingController method fetchUnsyncedMessages.

private <T extends Message> void fetchUnsyncedMessages(final Account account, final Folder<T> remoteFolder, List<T> unsyncedMessages, final List<Message> smallMessages, final List<Message> largeMessages, final AtomicInteger progress, final int todo, FetchProfile fp) throws MessagingException {
    final String folder = remoteFolder.getName();
    final Date earliestDate = account.getEarliestPollDate();
    remoteFolder.fetch(unsyncedMessages, fp, new MessageRetrievalListener<T>() {

        @Override
        public void messageFinished(T message, int number, int ofTotal) {
            try {
                if (message.isSet(Flag.DELETED) || message.olderThan(earliestDate)) {
                    if (K9.isDebug()) {
                        if (message.isSet(Flag.DELETED)) {
                            Timber.v("Newly downloaded message %s:%s:%s was marked deleted on server, " + "skipping", account, folder, message.getUid());
                        } else {
                            Timber.d("Newly downloaded message %s is older than %s, skipping", message.getUid(), earliestDate);
                        }
                    }
                    progress.incrementAndGet();
                    for (MessagingListener l : getListeners()) {
                        //TODO: This might be the source of poll count errors in the UI. Is todo always the same as ofTotal
                        l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
                    }
                    return;
                }
                if (account.getMaximumAutoDownloadMessageSize() > 0 && message.getSize() > account.getMaximumAutoDownloadMessageSize()) {
                    largeMessages.add(message);
                } else {
                    smallMessages.add(message);
                }
            } catch (Exception e) {
                Timber.e(e, "Error while storing downloaded message.");
                addErrorMessage(account, null, e);
            }
        }

        @Override
        public void messageStarted(String uid, int number, int ofTotal) {
        }

        @Override
        public void messagesFinished(int total) {
        // FIXME this method is almost never invoked by various Stores! Don't rely on it unless fixed!!
        }
    });
}
Also used : Date(java.util.Date) SuppressLint(android.annotation.SuppressLint) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) UnavailableStorageException(com.fsck.k9.mailstore.UnavailableStorageException) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Example 52 with K9

use of com.fsck.k9.K9 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);
    if (K9.getK9ComposerThemeSetting() != K9.Theme.USE_GLOBAL) {
        // theme the whole content according to the theme (except the action bar)
        ContextThemeWrapper themeContext = new ContextThemeWrapper(this, K9.getK9ThemeResourceId(K9.getK9ComposerTheme()));
        // this is the top level activity element, it has no root
        @SuppressLint("InflateParams") View v = LayoutInflater.from(themeContext).inflate(R.layout.message_compose, null);
        TypedValue outValue = new TypedValue();
        // background color needs to be forced
        themeContext.getTheme().resolveAttribute(R.attr.messageViewBackgroundColor, outValue, true);
        v.setBackgroundColor(outValue.data);
        setContentView(v);
    } else {
        setContentView(R.layout.message_compose);
    }
    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);
    account = Preferences.getPreferences(this).getAccount(accountUuid);
    if (account == null) {
        account = Preferences.getPreferences(this).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.
             */
        startActivity(new Intent(this, Accounts.class));
        changesMadeSinceLastSave = false;
        finish();
        return;
    }
    contacts = Contacts.getInstance(MessageCompose.this);
    chooseIdentityButton = (TextView) findViewById(R.id.identity);
    chooseIdentityButton.setOnClickListener(this);
    RecipientMvpView recipientMvpView = new RecipientMvpView(this);
    ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
    recipientPresenter = new RecipientPresenter(getApplicationContext(), getLoaderManager(), recipientMvpView, account, composePgpInlineDecider, new ReplyToParser(), this);
    recipientPresenter.updateCryptoStatus();
    subjectView = (EditText) findViewById(R.id.subject);
    subjectView.getInputExtras(true).putBoolean("allowEmoji", true);
    EolConvertingEditText upperSignature = (EolConvertingEditText) findViewById(R.id.upper_signature);
    EolConvertingEditText lowerSignature = (EolConvertingEditText) findViewById(R.id.lower_signature);
    QuotedMessageMvpView quotedMessageMvpView = new QuotedMessageMvpView(this);
    quotedMessagePresenter = new QuotedMessagePresenter(this, quotedMessageMvpView, account);
    attachmentPresenter = new AttachmentPresenter(getApplicationContext(), attachmentMvpView, getLoaderManager(), this);
    messageContentView = (EolConvertingEditText) findViewById(R.id.message_content);
    messageContentView.getInputExtras(true).putBoolean("allowEmoji", true);
    attachmentsView = (LinearLayout) 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;
        }
    };
    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_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.isMessageReadReceiptAlways();
    updateFrom();
    if (!relatedMessageProcessed) {
        if (action == Action.REPLY || action == Action.REPLY_ALL || action == Action.FORWARD || action == Action.EDIT_DRAFT) {
            messageLoaderHelper = new MessageLoaderHelper(this, getLoaderManager(), getFragmentManager(), messageLoaderCallbacks);
            internalMessageHandler.sendEmptyMessage(MSG_PROGRESS_ON);
            Parcelable cachedDecryptionResult = intent.getParcelableExtra(EXTRA_MESSAGE_DECRYPTION_RESULT);
            messageLoaderHelper.asyncStartOrResumeLoadingMessage(relatedMessageReference, cachedDecryptionResult);
        }
        if (action != Action.EDIT_DRAFT) {
            String alwaysBccString = account.getAlwaysBcc();
            if (!TextUtils.isEmpty(alwaysBccString)) {
                recipientPresenter.addBccAddresses(Address.parse(alwaysBccString));
            }
        }
    }
    if (action == Action.REPLY || action == Action.REPLY_ALL) {
        relatedMessageReference = relatedMessageReference.withModifiedFlag(Flag.ANSWERED);
    }
    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();
    }
    if (action == Action.FORWARD) {
        relatedMessageReference = relatedMessageReference.withModifiedFlag(Flag.FORWARDED);
    }
    updateMessageFormat();
    // Set font size of input controls
    int fontSize = K9.getFontSizes().getMessageComposeInput();
    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) getLastNonConfigurationInstance();
    if (currentMessageBuilder != null) {
        setProgressBarIndeterminateVisibility(true);
        currentMessageBuilder.reattachCallback(this);
    }
}
Also used : ComposePgpInlineDecider(com.fsck.k9.message.ComposePgpInlineDecider) RecipientPresenter(com.fsck.k9.activity.compose.RecipientPresenter) EolConvertingEditText(com.fsck.k9.ui.EolConvertingEditText) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Parcelable(android.os.Parcelable) QuotedMessageMvpView(com.fsck.k9.ui.compose.QuotedMessageMvpView) View(android.view.View) QuotedMessageMvpView(com.fsck.k9.ui.compose.QuotedMessageMvpView) TextView(android.widget.TextView) AttachmentMvpView(com.fsck.k9.activity.compose.AttachmentPresenter.AttachmentMvpView) RecipientMvpView(com.fsck.k9.activity.compose.RecipientMvpView) SuppressLint(android.annotation.SuppressLint) QuotedMessagePresenter(com.fsck.k9.ui.compose.QuotedMessagePresenter) ReplyToParser(com.fsck.k9.helper.ReplyToParser) SimpleTextWatcher(com.fsck.k9.helper.SimpleTextWatcher) ContextThemeWrapper(android.view.ContextThemeWrapper) SuppressLint(android.annotation.SuppressLint) RecipientMvpView(com.fsck.k9.activity.compose.RecipientMvpView) SimpleTextWatcher(com.fsck.k9.helper.SimpleTextWatcher) TextWatcher(android.text.TextWatcher) AttachmentPresenter(com.fsck.k9.activity.compose.AttachmentPresenter) TypedValue(android.util.TypedValue)

Example 53 with K9

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

the class MessageCompose method createMessageBuilder.

@Nullable
private MessageBuilder createMessageBuilder(boolean isDraft) {
    MessageBuilder builder;
    recipientPresenter.updateCryptoStatus();
    ComposeCryptoStatus cryptoStatus = recipientPresenter.getCurrentCryptoStatus();
    // TODO encrypt drafts for storage
    if (!isDraft && cryptoStatus.shouldUsePgpMessageBuilder()) {
        SendErrorState maybeSendErrorState = cryptoStatus.getSendErrorStateOrNull();
        if (maybeSendErrorState != null) {
            recipientPresenter.showPgpSendError(maybeSendErrorState);
            return null;
        }
        PgpMessageBuilder pgpBuilder = PgpMessageBuilder.newInstance();
        recipientPresenter.builderSetProperties(pgpBuilder);
        builder = pgpBuilder;
    } else {
        builder = SimpleMessageBuilder.newInstance();
    }
    builder.setSubject(Utility.stripNewLines(subjectView.getText().toString())).setSentDate(new Date()).setHideTimeZone(K9.hideTimeZone()).setTo(recipientPresenter.getToAddresses()).setCc(recipientPresenter.getCcAddresses()).setBcc(recipientPresenter.getBccAddresses()).setInReplyTo(repliedToMessageId).setReferences(referencedMessageIds).setRequestReadReceipt(requestReadReceipt).setIdentity(identity).setMessageFormat(currentMessageFormat).setText(messageContentView.getCharacters()).setAttachments(attachmentPresenter.createAttachmentList()).setSignature(signatureView.getCharacters()).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(android.support.annotation.Nullable)

Example 54 with K9

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

the class MessageCompose method onCreateDialog.

@Override
public Dialog onCreateDialog(int id) {
    switch(id) {
        case DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE:
            return new AlertDialog.Builder(this).setTitle(R.string.save_or_discard_draft_message_dlg_title).setMessage(R.string.save_or_discard_draft_message_instructions_fmt).setPositiveButton(R.string.save_draft_action, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE);
                    checkToSaveDraftAndSave();
                }
            }).setNegativeButton(R.string.discard_action, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE);
                    onDiscard();
                }
            }).create();
        case DIALOG_CONFIRM_DISCARD_ON_BACK:
            return new AlertDialog.Builder(this).setTitle(R.string.confirm_discard_draft_message_title).setMessage(R.string.confirm_discard_draft_message).setPositiveButton(R.string.cancel_action, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    dismissDialog(DIALOG_CONFIRM_DISCARD_ON_BACK);
                }
            }).setNegativeButton(R.string.discard_action, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    dismissDialog(DIALOG_CONFIRM_DISCARD_ON_BACK);
                    Toast.makeText(MessageCompose.this, getString(R.string.message_discarded_toast), Toast.LENGTH_LONG).show();
                    onDiscard();
                }
            }).create();
        case DIALOG_CHOOSE_IDENTITY:
            Context context = new ContextThemeWrapper(this, (K9.getK9Theme() == K9.Theme.LIGHT) ? R.style.Theme_K9_Dialog_Light : R.style.Theme_K9_Dialog_Dark);
            Builder builder = new AlertDialog.Builder(context);
            builder.setTitle(R.string.send_as);
            final IdentityAdapter adapter = new IdentityAdapter(context);
            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    IdentityContainer container = (IdentityContainer) adapter.getItem(which);
                    onAccountChosen(container.account, container.identity);
                }
            });
            return builder.create();
        case DIALOG_CONFIRM_DISCARD:
            {
                return new AlertDialog.Builder(this).setTitle(R.string.dialog_confirm_delete_title).setMessage(R.string.dialog_confirm_delete_message).setPositiveButton(R.string.dialog_confirm_delete_confirm_button, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        onDiscard();
                    }
                }).setNegativeButton(R.string.dialog_confirm_delete_cancel_button, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).create();
            }
    }
    return super.onCreateDialog(id);
}
Also used : AlertDialog(android.app.AlertDialog) Context(android.content.Context) IdentityAdapter(com.fsck.k9.activity.compose.IdentityAdapter) ContextThemeWrapper(android.view.ContextThemeWrapper) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) PgpMessageBuilder(com.fsck.k9.message.PgpMessageBuilder) SimpleMessageBuilder(com.fsck.k9.message.SimpleMessageBuilder) MessageBuilder(com.fsck.k9.message.MessageBuilder) Builder(android.app.AlertDialog.Builder) OnClickListener(android.view.View.OnClickListener) IdentityContainer(com.fsck.k9.activity.compose.IdentityAdapter.IdentityContainer) SuppressLint(android.annotation.SuppressLint)

Example 55 with K9

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

the class MessageCompose method processDraftMessage.

private void processDraftMessage(MessageViewInfo messageViewInfo) {
    Message message = messageViewInfo.message;
    draftId = MessagingController.getInstance(getApplication()).getId(message);
    subjectView.setText(message.getSubject());
    recipientPresenter.initFromDraftMessage(message);
    // Read In-Reply-To header from draft
    final String[] inReplyTo = message.getHeader("In-Reply-To");
    if (inReplyTo.length >= 1) {
        repliedToMessageId = inReplyTo[0];
    }
    // Read References header from draft
    final String[] references = message.getHeader("References");
    if (references.length >= 1) {
        referencedMessageIds = references[0];
    }
    if (!relatedMessageProcessed) {
        attachmentPresenter.loadNonInlineAttachments(messageViewInfo);
    }
    // Decode the identity header when loading a draft.
    // See buildIdentityHeader(TextBody) for a detailed description of the composition of this blob.
    Map<IdentityField, String> k9identity = new HashMap<>();
    String[] identityHeaders = message.getHeader(K9.IDENTITY_HEADER);
    if (identityHeaders.length > 0 && identityHeaders[0] != null) {
        k9identity = IdentityHeaderParser.parse(identityHeaders[0]);
    }
    Identity newIdentity = new Identity();
    if (k9identity.containsKey(IdentityField.SIGNATURE)) {
        newIdentity.setSignatureUse(true);
        newIdentity.setSignature(k9identity.get(IdentityField.SIGNATURE));
        signatureChanged = true;
    } else {
        if (message instanceof LocalMessage) {
            newIdentity.setSignatureUse(((LocalMessage) message).getFolder().getSignatureUse());
        }
        newIdentity.setSignature(identity.getSignature());
    }
    if (k9identity.containsKey(IdentityField.NAME)) {
        newIdentity.setName(k9identity.get(IdentityField.NAME));
        identityChanged = true;
    } else {
        newIdentity.setName(identity.getName());
    }
    if (k9identity.containsKey(IdentityField.EMAIL)) {
        newIdentity.setEmail(k9identity.get(IdentityField.EMAIL));
        identityChanged = true;
    } else {
        newIdentity.setEmail(identity.getEmail());
    }
    if (k9identity.containsKey(IdentityField.ORIGINAL_MESSAGE)) {
        relatedMessageReference = null;
        String originalMessage = k9identity.get(IdentityField.ORIGINAL_MESSAGE);
        MessageReference messageReference = MessageReference.parse(originalMessage);
        if (messageReference != null) {
            // Check if this is a valid account in our database
            Preferences prefs = Preferences.getPreferences(getApplicationContext());
            Account account = prefs.getAccount(messageReference.getAccountUuid());
            if (account != null) {
                relatedMessageReference = messageReference;
            }
        }
    }
    identity = newIdentity;
    updateSignature();
    updateFrom();
    quotedMessagePresenter.processDraftMessage(messageViewInfo, k9identity);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) Account(com.fsck.k9.Account) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) HashMap(java.util.HashMap) Identity(com.fsck.k9.Identity) Preferences(com.fsck.k9.Preferences) IdentityField(com.fsck.k9.message.IdentityField)

Aggregations

Account (com.fsck.k9.Account)20 MessagingException (com.fsck.k9.mail.MessagingException)13 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)10 LocalStore (com.fsck.k9.mailstore.LocalStore)10 Message (com.fsck.k9.mail.Message)9 Store (com.fsck.k9.mail.Store)9 LocalFolder (com.fsck.k9.mailstore.LocalFolder)9 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)9 Intent (android.content.Intent)8 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)8 LocalMessage (com.fsck.k9.mailstore.LocalMessage)8 SuppressLint (android.annotation.SuppressLint)7 BaseAccount (com.fsck.k9.BaseAccount)7 Preferences (com.fsck.k9.Preferences)7 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)7 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)7 Folder (com.fsck.k9.mail.Folder)7 SearchAccount (com.fsck.k9.search.SearchAccount)7