Search in sources :

Example 6 with MessageFormat

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

the class MessageBuilder method buildBody.

private void buildBody(MimeMessage message) throws MessagingException {
    // Build the body.
    // TODO FIXME - body can be either an HTML or Text part, depending on whether we're in
    // HTML mode or not.  Should probably fix this so we don't mix up html and text parts.
    TextBody body = buildText(isDraft);
    // text/plain part when messageFormat == MessageFormat.HTML
    TextBody bodyPlain = null;
    final boolean hasAttachments = !attachments.isEmpty();
    if (messageFormat == SimpleMessageFormat.HTML) {
        // HTML message (with alternative text part)
        // This is the compiled MIME part for an HTML message.
        MimeMultipart composedMimeMessage = createMimeMultipart();
        composedMimeMessage.setSubType("alternative");
        // Let the receiver select either the text or the HTML part.
        bodyPlain = buildText(isDraft, SimpleMessageFormat.TEXT);
        composedMimeMessage.addBodyPart(new MimeBodyPart(bodyPlain, "text/plain"));
        composedMimeMessage.addBodyPart(new MimeBodyPart(body, "text/html"));
        if (hasAttachments) {
            // If we're HTML and have attachments, we have a MimeMultipart container to hold the
            // whole message (mp here), of which one part is a MimeMultipart container
            // (composedMimeMessage) with the user's composed messages, and subsequent parts for
            // the attachments.
            MimeMultipart mp = createMimeMultipart();
            mp.addBodyPart(new MimeBodyPart(composedMimeMessage));
            addAttachmentsToMessage(mp);
            MimeMessageHelper.setBody(message, mp);
        } else {
            // If no attachments, our multipart/alternative part is the only one we need.
            MimeMessageHelper.setBody(message, composedMimeMessage);
        }
    } else if (messageFormat == SimpleMessageFormat.TEXT) {
        // Text-only message.
        if (hasAttachments) {
            MimeMultipart mp = createMimeMultipart();
            mp.addBodyPart(new MimeBodyPart(body, "text/plain"));
            addAttachmentsToMessage(mp);
            MimeMessageHelper.setBody(message, mp);
        } else {
            // No attachments to include, just stick the text body in the message and call it good.
            MimeMessageHelper.setBody(message, body);
        }
    }
    // If this is a draft, add metadata for thawing.
    if (isDraft) {
        // Add the identity to the message.
        message.addHeader(K9.IDENTITY_HEADER, buildIdentityHeader(body, bodyPlain));
    }
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 7 with MessageFormat

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

the class Account method loadAccount.

/**
     * Load stored settings for this account.
     */
private synchronized void loadAccount(Preferences preferences) {
    Storage storage = preferences.getStorage();
    mStoreUri = Base64.decode(storage.getString(mUuid + ".storeUri", null));
    mLocalStorageProviderId = storage.getString(mUuid + ".localStorageProvider", StorageManager.getInstance(K9.app).getDefaultProviderId());
    mTransportUri = Base64.decode(storage.getString(mUuid + ".transportUri", null));
    mDescription = storage.getString(mUuid + ".description", null);
    mAlwaysBcc = storage.getString(mUuid + ".alwaysBcc", mAlwaysBcc);
    mAutomaticCheckIntervalMinutes = storage.getInt(mUuid + ".automaticCheckIntervalMinutes", -1);
    mIdleRefreshMinutes = storage.getInt(mUuid + ".idleRefreshMinutes", 24);
    mPushPollOnConnect = storage.getBoolean(mUuid + ".pushPollOnConnect", true);
    mDisplayCount = storage.getInt(mUuid + ".displayCount", K9.DEFAULT_VISIBLE_LIMIT);
    if (mDisplayCount < 0) {
        mDisplayCount = K9.DEFAULT_VISIBLE_LIMIT;
    }
    mLatestOldMessageSeenTime = storage.getLong(mUuid + ".latestOldMessageSeenTime", 0);
    mNotifyNewMail = storage.getBoolean(mUuid + ".notifyNewMail", false);
    mFolderNotifyNewMailMode = getEnumStringPref(storage, mUuid + ".folderNotifyNewMailMode", FolderMode.ALL);
    mNotifySelfNewMail = storage.getBoolean(mUuid + ".notifySelfNewMail", true);
    mNotifyContactsMailOnly = storage.getBoolean(mUuid + ".notifyContactsMailOnly", false);
    mNotifySync = storage.getBoolean(mUuid + ".notifyMailCheck", false);
    mDeletePolicy = DeletePolicy.fromInt(storage.getInt(mUuid + ".deletePolicy", DeletePolicy.NEVER.setting));
    mInboxFolderName = storage.getString(mUuid + ".inboxFolderName", INBOX);
    mDraftsFolderName = storage.getString(mUuid + ".draftsFolderName", "Drafts");
    mSentFolderName = storage.getString(mUuid + ".sentFolderName", "Sent");
    mTrashFolderName = storage.getString(mUuid + ".trashFolderName", "Trash");
    mArchiveFolderName = storage.getString(mUuid + ".archiveFolderName", "Archive");
    mSpamFolderName = storage.getString(mUuid + ".spamFolderName", "Spam");
    mExpungePolicy = getEnumStringPref(storage, mUuid + ".expungePolicy", Expunge.EXPUNGE_IMMEDIATELY);
    mSyncRemoteDeletions = storage.getBoolean(mUuid + ".syncRemoteDeletions", true);
    mMaxPushFolders = storage.getInt(mUuid + ".maxPushFolders", 10);
    goToUnreadMessageSearch = storage.getBoolean(mUuid + ".goToUnreadMessageSearch", false);
    subscribedFoldersOnly = storage.getBoolean(mUuid + ".subscribedFoldersOnly", false);
    maximumPolledMessageAge = storage.getInt(mUuid + ".maximumPolledMessageAge", -1);
    maximumAutoDownloadMessageSize = storage.getInt(mUuid + ".maximumAutoDownloadMessageSize", 32768);
    mMessageFormat = getEnumStringPref(storage, mUuid + ".messageFormat", DEFAULT_MESSAGE_FORMAT);
    mMessageFormatAuto = storage.getBoolean(mUuid + ".messageFormatAuto", DEFAULT_MESSAGE_FORMAT_AUTO);
    if (mMessageFormatAuto && mMessageFormat == MessageFormat.TEXT) {
        mMessageFormat = MessageFormat.AUTO;
    }
    mMessageReadReceipt = storage.getBoolean(mUuid + ".messageReadReceipt", DEFAULT_MESSAGE_READ_RECEIPT);
    mQuoteStyle = getEnumStringPref(storage, mUuid + ".quoteStyle", DEFAULT_QUOTE_STYLE);
    mQuotePrefix = storage.getString(mUuid + ".quotePrefix", DEFAULT_QUOTE_PREFIX);
    mDefaultQuotedTextShown = storage.getBoolean(mUuid + ".defaultQuotedTextShown", DEFAULT_QUOTED_TEXT_SHOWN);
    mReplyAfterQuote = storage.getBoolean(mUuid + ".replyAfterQuote", DEFAULT_REPLY_AFTER_QUOTE);
    mStripSignature = storage.getBoolean(mUuid + ".stripSignature", DEFAULT_STRIP_SIGNATURE);
    for (NetworkType type : NetworkType.values()) {
        Boolean useCompression = storage.getBoolean(mUuid + ".useCompression." + type, true);
        compressionMap.put(type, useCompression);
    }
    mAutoExpandFolderName = storage.getString(mUuid + ".autoExpandFolderName", INBOX);
    mAccountNumber = storage.getInt(mUuid + ".accountNumber", 0);
    mChipColor = storage.getInt(mUuid + ".chipColor", ColorPicker.getRandomColor());
    mSortType = getEnumStringPref(storage, mUuid + ".sortTypeEnum", SortType.SORT_DATE);
    mSortAscending.put(mSortType, storage.getBoolean(mUuid + ".sortAscending", false));
    mShowPictures = getEnumStringPref(storage, mUuid + ".showPicturesEnum", ShowPictures.NEVER);
    mNotificationSetting.setVibrate(storage.getBoolean(mUuid + ".vibrate", false));
    mNotificationSetting.setVibratePattern(storage.getInt(mUuid + ".vibratePattern", 0));
    mNotificationSetting.setVibrateTimes(storage.getInt(mUuid + ".vibrateTimes", 5));
    mNotificationSetting.setRing(storage.getBoolean(mUuid + ".ring", true));
    mNotificationSetting.setRingtone(storage.getString(mUuid + ".ringtone", "content://settings/system/notification_sound"));
    mNotificationSetting.setLed(storage.getBoolean(mUuid + ".led", true));
    mNotificationSetting.setLedColor(storage.getInt(mUuid + ".ledColor", mChipColor));
    mFolderDisplayMode = getEnumStringPref(storage, mUuid + ".folderDisplayMode", FolderMode.NOT_SECOND_CLASS);
    mFolderSyncMode = getEnumStringPref(storage, mUuid + ".folderSyncMode", FolderMode.FIRST_CLASS);
    mFolderPushMode = getEnumStringPref(storage, mUuid + ".folderPushMode", FolderMode.FIRST_CLASS);
    mFolderTargetMode = getEnumStringPref(storage, mUuid + ".folderTargetMode", FolderMode.NOT_SECOND_CLASS);
    searchableFolders = getEnumStringPref(storage, mUuid + ".searchableFolders", Searchable.ALL);
    mIsSignatureBeforeQuotedText = storage.getBoolean(mUuid + ".signatureBeforeQuotedText", false);
    identities = loadIdentities(storage);
    mCryptoKey = storage.getLong(mUuid + ".cryptoKey", NO_OPENPGP_KEY);
    mAllowRemoteSearch = storage.getBoolean(mUuid + ".allowRemoteSearch", false);
    mRemoteSearchFullText = storage.getBoolean(mUuid + ".remoteSearchFullText", false);
    mRemoteSearchNumResults = storage.getInt(mUuid + ".remoteSearchNumResults", DEFAULT_REMOTE_SEARCH_NUM_RESULTS);
    mEnabled = storage.getBoolean(mUuid + ".enabled", true);
    mMarkMessageAsReadOnView = storage.getBoolean(mUuid + ".markMessageAsReadOnView", true);
    mAlwaysShowCcBcc = storage.getBoolean(mUuid + ".alwaysShowCcBcc", false);
    cacheChips();
    // Use email address as account description if necessary
    if (mDescription == null) {
        mDescription = getEmail();
    }
}
Also used : Storage(com.fsck.k9.preferences.Storage) NetworkType(com.fsck.k9.mail.NetworkType)

Aggregations

MessageFormat (com.fsck.k9.Account.MessageFormat)3 NetworkType (com.fsck.k9.mail.NetworkType)3 SimpleMessageFormat (com.fsck.k9.message.SimpleMessageFormat)3 StorageEditor (com.fsck.k9.preferences.StorageEditor)2 MessagingException (com.fsck.k9.mail.MessagingException)1 Part (com.fsck.k9.mail.Part)1 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)1 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)1 TextBody (com.fsck.k9.mail.internet.TextBody)1 QuotedTextMode (com.fsck.k9.message.QuotedTextMode)1 InsertableHtmlContent (com.fsck.k9.message.quote.InsertableHtmlContent)1 Storage (com.fsck.k9.preferences.Storage)1 ArrayList (java.util.ArrayList)1