Search in sources :

Example 26 with Folder

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

the class MessagingController method refreshRemoteSynchronous.

@VisibleForTesting
void refreshRemoteSynchronous(final Account account, final MessagingListener listener) {
    List<LocalFolder> localFolders = null;
    try {
        Store store = account.getRemoteStore();
        List<? extends Folder> remoteFolders = store.getPersonalNamespaces(false);
        LocalStore localStore = account.getLocalStore();
        Set<String> remoteFolderNames = new HashSet<>();
        List<LocalFolder> foldersToCreate = new LinkedList<>();
        localFolders = localStore.getPersonalNamespaces(false);
        Set<String> localFolderNames = new HashSet<>();
        for (Folder localFolder : localFolders) {
            localFolderNames.add(localFolder.getName());
        }
        for (Folder remoteFolder : remoteFolders) {
            if (!localFolderNames.contains(remoteFolder.getName())) {
                LocalFolder localFolder = localStore.getFolder(remoteFolder.getName());
                foldersToCreate.add(localFolder);
            }
            remoteFolderNames.add(remoteFolder.getName());
        }
        localStore.createFolders(foldersToCreate, account.getDisplayCount());
        localFolders = localStore.getPersonalNamespaces(false);
        /*
             * Clear out any folders that are no longer on the remote store.
             */
        for (Folder localFolder : localFolders) {
            String localFolderName = localFolder.getName();
            //        special placeholder folder "-NONE-".
            if (K9.FOLDER_NONE.equals(localFolderName)) {
                localFolder.delete(false);
            }
            if (!account.isSpecialFolder(localFolderName) && !remoteFolderNames.contains(localFolderName)) {
                localFolder.delete(false);
            }
        }
        localFolders = localStore.getPersonalNamespaces(false);
        for (MessagingListener l : getListeners(listener)) {
            l.listFolders(account, localFolders);
        }
        for (MessagingListener l : getListeners(listener)) {
            l.listFoldersFinished(account);
        }
    } catch (Exception e) {
        for (MessagingListener l : getListeners(listener)) {
            l.listFoldersFailed(account, "");
        }
        addErrorMessage(account, null, e);
    } finally {
        if (localFolders != null) {
            for (Folder localFolder : localFolders) {
                closeFolder(localFolder);
            }
        }
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalStore(com.fsck.k9.mailstore.LocalStore) Store(com.fsck.k9.mail.Store) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) LocalStore(com.fsck.k9.mailstore.LocalStore) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) LinkedList(java.util.LinkedList) 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) HashSet(java.util.HashSet) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 27 with Folder

use of com.fsck.k9.mail.Folder 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 28 with Folder

use of com.fsck.k9.mail.Folder 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)

Example 29 with Folder

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

the class SyncNotificationsTest method createFakeFolder.

private Folder createFakeFolder() {
    Folder folder = mock(Folder.class);
    when(folder.getName()).thenReturn(FOLDER_NAME);
    return folder;
}
Also used : Folder(com.fsck.k9.mail.Folder)

Example 30 with Folder

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

the class SyncNotificationsTest method testGetFetchingMailNotificationId.

@Test
public void testGetFetchingMailNotificationId() throws Exception {
    Folder folder = createFakeFolder();
    int notificationId = NotificationIds.getFetchingMailNotificationId(account);
    syncNotifications.showFetchingMailNotification(account, folder);
    verify(notificationManager).notify(eq(notificationId), any(Notification.class));
    verify(builder).setSmallIcon(R.drawable.ic_notify_check_mail);
    verify(builder).setTicker("Checking mail: " + ACCOUNT_NAME + ":" + FOLDER_NAME);
    verify(builder).setContentTitle("Checking mail");
    verify(builder).setContentText(ACCOUNT_NAME + ":" + FOLDER_NAME);
    verify(builder).setContentIntent(contentIntent);
    verify(builder).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
}
Also used : Folder(com.fsck.k9.mail.Folder) Notification(android.app.Notification) Test(org.junit.Test)

Aggregations

Folder (com.fsck.k9.mail.Folder)45 LocalFolder (com.fsck.k9.mailstore.LocalFolder)40 Test (org.junit.Test)36 MessagingException (com.fsck.k9.mail.MessagingException)34 LocalStore (com.fsck.k9.mailstore.LocalStore)29 LocalMessage (com.fsck.k9.mailstore.LocalMessage)22 FetchProfile (com.fsck.k9.mail.FetchProfile)21 Message (com.fsck.k9.mail.Message)20 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)20 Store (com.fsck.k9.mail.Store)17 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)16 Account (com.fsck.k9.Account)15 IOException (java.io.IOException)14 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)13 SuppressLint (android.annotation.SuppressLint)12 ArrayList (java.util.ArrayList)12 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)11 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)11 Date (java.util.Date)9 HashMap (java.util.HashMap)8