Search in sources :

Example 26 with MessagingException

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

the class MessagingController method saveDraft.

/**
     * Save a draft message.
     *
     * @param account
     *         Account we are saving for.
     * @param message
     *         Message to save.
     *
     * @return Message representing the entry in the local store.
     */
public Message saveDraft(final Account account, final Message message, long existingDraftId, boolean saveRemotely) {
    Message localMessage = null;
    try {
        LocalStore localStore = account.getLocalStore();
        LocalFolder localFolder = localStore.getFolder(account.getDraftsFolderName());
        localFolder.open(Folder.OPEN_MODE_RW);
        if (existingDraftId != INVALID_MESSAGE_ID) {
            String uid = localFolder.getMessageUidById(existingDraftId);
            message.setUid(uid);
        }
        // Save the message to the store.
        localFolder.appendMessages(Collections.singletonList(message));
        // Fetch the message back from the store.  This is the Message that's returned to the caller.
        localMessage = localFolder.getMessage(message.getUid());
        localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
        if (saveRemotely) {
            PendingCommand command = PendingAppend.create(localFolder.getName(), localMessage.getUid());
            queuePendingCommand(account, command);
            processPendingCommands(account);
        }
    } catch (MessagingException e) {
        Timber.e(e, "Unable to save message as draft.");
        addErrorMessage(account, null, e);
    }
    return localMessage;
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MessagingException(com.fsck.k9.mail.MessagingException) LocalStore(com.fsck.k9.mailstore.LocalStore) PendingCommand(com.fsck.k9.controller.MessagingControllerCommands.PendingCommand)

Example 27 with MessagingException

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

the class MessagingController method updateMoreMessages.

private void updateMoreMessages(Folder remoteFolder, LocalFolder localFolder, Date earliestDate, int remoteStart) throws MessagingException, IOException {
    if (remoteStart == 1) {
        localFolder.setMoreMessages(MoreMessages.FALSE);
    } else {
        boolean moreMessagesAvailable = remoteFolder.areMoreMessagesAvailable(remoteStart, earliestDate);
        MoreMessages newMoreMessages = (moreMessagesAvailable) ? MoreMessages.TRUE : MoreMessages.FALSE;
        localFolder.setMoreMessages(newMoreMessages);
    }
}
Also used : MoreMessages(com.fsck.k9.mailstore.LocalFolder.MoreMessages)

Example 28 with MessagingException

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

the class MessagingController method downloadPartial.

private void downloadPartial(Folder remoteFolder, LocalFolder localFolder, Message message) throws MessagingException {
    /*
         * We have a structure to deal with, from which
         * we can pull down the parts we want to actually store.
         * Build a list of parts we are interested in. Text parts will be downloaded
         * right now, attachments will be left for later.
         */
    Set<Part> viewables = MessageExtractor.collectTextParts(message);
    /*
         * Now download the parts we're interested in storing.
         */
    for (Part part : viewables) {
        remoteFolder.fetchPart(message, part, null);
    }
    // Store the updated message locally
    localFolder.appendMessages(Collections.singletonList(message));
    Message localMessage = localFolder.getMessage(message.getUid());
    // Set a flag indicating this message has been fully downloaded and can be
    // viewed.
    localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, true);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) Part(com.fsck.k9.mail.Part)

Example 29 with MessagingException

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

the class FolderSettings method saveSettings.

private void saveSettings() throws MessagingException {
    mFolder.setInTopGroup(mInTopGroup.isChecked());
    mFolder.setIntegrate(mIntegrate.isChecked());
    // We call getPushClass() because display class changes can affect push class when push class is set to inherit
    FolderClass oldPushClass = mFolder.getPushClass();
    FolderClass oldDisplayClass = mFolder.getDisplayClass();
    mFolder.setDisplayClass(FolderClass.valueOf(mDisplayClass.getValue()));
    mFolder.setSyncClass(FolderClass.valueOf(mSyncClass.getValue()));
    mFolder.setPushClass(FolderClass.valueOf(mPushClass.getValue()));
    mFolder.setNotifyClass(FolderClass.valueOf(mNotifyClass.getValue()));
    mFolder.save();
    FolderClass newPushClass = mFolder.getPushClass();
    FolderClass newDisplayClass = mFolder.getDisplayClass();
    if (oldPushClass != newPushClass || (newPushClass != FolderClass.NO_CLASS && oldDisplayClass != newDisplayClass)) {
        MailService.actionRestartPushers(getApplication(), null);
    }
}
Also used : FolderClass(com.fsck.k9.mail.Folder.FolderClass)

Example 30 with MessagingException

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

the class FolderSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String folderName = (String) getIntent().getSerializableExtra(EXTRA_FOLDER_NAME);
    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    Account mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    try {
        LocalStore localStore = mAccount.getLocalStore();
        mFolder = localStore.getFolder(folderName);
        mFolder.open(Folder.OPEN_MODE_RW);
    } catch (MessagingException me) {
        Timber.e(me, "Unable to edit folder %s preferences", folderName);
        return;
    }
    boolean isPushCapable = false;
    try {
        Store store = mAccount.getRemoteStore();
        isPushCapable = store.isPushCapable();
    } catch (Exception e) {
        Timber.e(e, "Could not get remote store");
    }
    addPreferencesFromResource(R.xml.folder_settings_preferences);
    String displayName = FolderInfoHolder.getDisplayName(this, mAccount, mFolder.getName());
    Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
    category.setTitle(displayName);
    mInTopGroup = (CheckBoxPreference) findPreference(PREFERENCE_IN_TOP_GROUP);
    mInTopGroup.setChecked(mFolder.isInTopGroup());
    mIntegrate = (CheckBoxPreference) findPreference(PREFERENCE_INTEGRATE);
    mIntegrate.setChecked(mFolder.isIntegrate());
    mDisplayClass = (ListPreference) findPreference(PREFERENCE_DISPLAY_CLASS);
    mDisplayClass.setValue(mFolder.getDisplayClass().name());
    mDisplayClass.setSummary(mDisplayClass.getEntry());
    mDisplayClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mDisplayClass.findIndexOfValue(summary);
            mDisplayClass.setSummary(mDisplayClass.getEntries()[index]);
            mDisplayClass.setValue(summary);
            return false;
        }
    });
    mSyncClass = (ListPreference) findPreference(PREFERENCE_SYNC_CLASS);
    mSyncClass.setValue(mFolder.getRawSyncClass().name());
    mSyncClass.setSummary(mSyncClass.getEntry());
    mSyncClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mSyncClass.findIndexOfValue(summary);
            mSyncClass.setSummary(mSyncClass.getEntries()[index]);
            mSyncClass.setValue(summary);
            return false;
        }
    });
    mPushClass = (ListPreference) findPreference(PREFERENCE_PUSH_CLASS);
    mPushClass.setEnabled(isPushCapable);
    mPushClass.setValue(mFolder.getRawPushClass().name());
    mPushClass.setSummary(mPushClass.getEntry());
    mPushClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mPushClass.findIndexOfValue(summary);
            mPushClass.setSummary(mPushClass.getEntries()[index]);
            mPushClass.setValue(summary);
            return false;
        }
    });
    mNotifyClass = (ListPreference) findPreference(PREFERENCE_NOTIFY_CLASS);
    mNotifyClass.setValue(mFolder.getRawNotifyClass().name());
    mNotifyClass.setSummary(mNotifyClass.getEntry());
    mNotifyClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mNotifyClass.findIndexOfValue(summary);
            mNotifyClass.setSummary(mNotifyClass.getEntries()[index]);
            mNotifyClass.setValue(summary);
            return false;
        }
    });
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) Store(com.fsck.k9.mail.Store) LocalStore(com.fsck.k9.mailstore.LocalStore) LocalStore(com.fsck.k9.mailstore.LocalStore) MessagingException(com.fsck.k9.mail.MessagingException)

Aggregations

MessagingException (com.fsck.k9.mail.MessagingException)159 Test (org.junit.Test)73 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)52 LocalFolder (com.fsck.k9.mailstore.LocalFolder)49 LocalStore (com.fsck.k9.mailstore.LocalStore)49 ArrayList (java.util.ArrayList)49 Message (com.fsck.k9.mail.Message)44 LocalMessage (com.fsck.k9.mailstore.LocalMessage)42 IOException (java.io.IOException)42 FetchProfile (com.fsck.k9.mail.FetchProfile)30 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)28 ByteArrayOutputStream (java.io.ByteArrayOutputStream)27 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)26 BodyPart (com.fsck.k9.mail.BodyPart)23 Part (com.fsck.k9.mail.Part)22 Account (com.fsck.k9.Account)21 Body (com.fsck.k9.mail.Body)21 TextBody (com.fsck.k9.mail.internet.TextBody)21 Date (java.util.Date)20 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)18