Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 72a66445 authored by cketti's avatar cketti
Browse files

Remove StoreConfig.set*Folder()

parent 5cd28280
Loading
Loading
Loading
Loading
+0 −25
Original line number Diff line number Diff line
@@ -1851,29 +1851,4 @@ public class Account implements BaseAccount, StoreConfig {
            localKeyStore.deleteCertificate(uri.getHost(), uri.getPort());
        }
    }

    @Override
    public void setArchiveFolder(String name) {
        setArchiveFolder(name, SpecialFolderSelection.AUTOMATIC);
    }

    @Override
    public void setDraftsFolder(String name) {
        setDraftsFolder(name, SpecialFolderSelection.AUTOMATIC);
    }

    @Override
    public void setTrashFolder(String name) {
        setTrashFolder(name, SpecialFolderSelection.AUTOMATIC);
    }

    @Override
    public void setSpamFolder(String name) {
        setSpamFolder(name, SpecialFolderSelection.AUTOMATIC);
    }

    @Override
    public void setSentFolder(String name) {
        setSentFolder(name, SpecialFolderSelection.AUTOMATIC);
    }
}
+0 −8
Original line number Diff line number Diff line
@@ -11,14 +11,6 @@ public interface StoreConfig {
    String getOutboxFolder();
    String getDraftsFolder();

    void setArchiveFolder(String name);
    void setDraftsFolder(String name);
    void setTrashFolder(String name);
    void setSpamFolder(String name);
    void setSentFolder(String name);
    void setAutoExpandFolder(String name);
    void setInboxFolder(String name);

    int getMaximumAutoDownloadMessageSize();

    boolean allowRemoteSearch();
+0 −71
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Folder.FolderType;
import com.fsck.k9.mail.K9MailLib;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.NetworkType;
import com.fsck.k9.mail.oauth.OAuth2TokenProvider;
@@ -244,75 +243,6 @@ public class ImapStore extends RemoteStore {
        return folders;
    }

    void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException {
        mStoreConfig.setInboxFolder(ImapFolder.INBOX);

        if (!connection.hasCapability(Capabilities.SPECIAL_USE)) {
            if (K9MailLib.isDebug()) {
                Timber.d("No detected folder auto-configuration methods.");
            }
            return;
        }

        if (K9MailLib.isDebug()) {
            Timber.d("Folder auto-configuration: Using RFC6154/SPECIAL-USE.");
        }

        String command = String.format("LIST (SPECIAL-USE) \"\" %s", ImapUtility.encodeString(getCombinedPrefix() + "*"));
        List<ImapResponse> responses = connection.executeSimpleCommand(command);

        List<ListResponse> listResponses = ListResponse.parseList(responses);

        for (ListResponse listResponse : listResponses) {
            String decodedFolderName;
            try {
                decodedFolderName = folderNameCodec.decode(listResponse.getName());
            } catch (CharacterCodingException e) {
                Timber.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s",
                        listResponse.getName());
                // We currently just skip folders with malformed names.
                continue;
            }

            if (pathDelimiter == null) {
                pathDelimiter = listResponse.getHierarchyDelimiter();
                combinedPrefix = null;
            }

            decodedFolderName = removePrefixFromFolderName(decodedFolderName);
            if (decodedFolderName == null) {
                continue;
            }

            if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) {
                mStoreConfig.setArchiveFolder(decodedFolderName);
                if (K9MailLib.isDebug()) {
                    Timber.d("Folder auto-configuration detected Archive folder: %s", decodedFolderName);
                }
            } else if (listResponse.hasAttribute("\\Drafts")) {
                mStoreConfig.setDraftsFolder(decodedFolderName);
                if (K9MailLib.isDebug()) {
                    Timber.d("Folder auto-configuration detected Drafts folder: %s", decodedFolderName);
                }
            } else if (listResponse.hasAttribute("\\Sent")) {
                mStoreConfig.setSentFolder(decodedFolderName);
                if (K9MailLib.isDebug()) {
                    Timber.d("Folder auto-configuration detected Sent folder: %s", decodedFolderName);
                }
            } else if (listResponse.hasAttribute("\\Junk")) {
                mStoreConfig.setSpamFolder(decodedFolderName);
                if (K9MailLib.isDebug()) {
                    Timber.d("Folder auto-configuration detected Spam folder: %s", decodedFolderName);
                }
            } else if (listResponse.hasAttribute("\\Trash")) {
                mStoreConfig.setTrashFolder(decodedFolderName);
                if (K9MailLib.isDebug()) {
                    Timber.d("Folder auto-configuration detected Trash folder: %s", decodedFolderName);
                }
            }
        }
    }

    @Nullable
    private String removePrefixFromFolderName(String folderName) {
        String prefix = getCombinedPrefix();
@@ -336,7 +266,6 @@ public class ImapStore extends RemoteStore {
            ImapConnection connection = createImapConnection();

            connection.open();
            autoconfigureFolders(connection);
            connection.close();
        } catch (IOException ioe) {
            throw new MessagingException("Unable to connect", ioe);
+27 −38
Original line number Diff line number Diff line
@@ -6,8 +6,10 @@ import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import android.net.ConnectivityManager;
@@ -15,6 +17,7 @@ import android.net.ConnectivityManager;
import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Folder.FolderType;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.oauth.OAuth2TokenProvider;
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
@@ -29,12 +32,10 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;


@@ -98,7 +99,7 @@ public class ImapStoreTest {
    }

    @Test
    public void autoconfigureFolders_withSpecialUseCapability_shouldSetSpecialFolders() throws Exception {
    public void getPersonalNamespaces_withSpecialUseCapability_shouldReturnSpecialFolderInfo() throws Exception {
        ImapConnection imapConnection = mock(ImapConnection.class);
        when(imapConnection.hasCapability(Capabilities.SPECIAL_USE)).thenReturn(true);
        List<ImapResponse> imapResponses = Arrays.asList(
@@ -114,50 +115,29 @@ public class ImapStoreTest {
                createImapResponse("5 OK Success")
        );
        when(imapConnection.executeSimpleCommand("LIST (SPECIAL-USE) \"\" \"*\"")).thenReturn(imapResponses);
        imapStore.enqueueImapConnection(imapConnection);

        imapStore.autoconfigureFolders(imapConnection);
        List<ImapFolder> folders = imapStore.getPersonalNamespaces();

        verify(storeConfig).setDraftsFolder("[Gmail]/Drafts");
        verify(storeConfig).setSentFolder("[Gmail]/Sent Mail");
        verify(storeConfig).setSpamFolder("[Gmail]/Spam");
        verify(storeConfig).setTrashFolder("[Gmail]/Trash");
        verify(storeConfig).setArchiveFolder("[Gmail]/All Mail");
        Map<String, ImapFolder> folderMap = toFolderMap(folders);
        assertEquals(FolderType.INBOX, folderMap.get("INBOX").getType());
        assertEquals(FolderType.DRAFTS, folderMap.get("[Gmail]/Drafts").getType());
        assertEquals(FolderType.SENT, folderMap.get("[Gmail]/Sent Mail").getType());
        assertEquals(FolderType.SPAM, folderMap.get("[Gmail]/Spam").getType());
        assertEquals(FolderType.TRASH, folderMap.get("[Gmail]/Trash").getType());
        assertEquals(FolderType.ARCHIVE, folderMap.get("[Gmail]/All Mail").getType());
    }

    @Test
    public void autoconfigureFolders_withoutSpecialUseCapability_shouldNotIssueImapCommand() throws Exception {
    public void getPersonalNamespaces_withoutSpecialUseCapability_shouldUseSimpleListCommand() throws Exception {
        ImapConnection imapConnection = mock(ImapConnection.class);
        when(imapConnection.hasCapability(Capabilities.SPECIAL_USE)).thenReturn(false);
        imapStore.enqueueImapConnection(imapConnection);

        imapStore.autoconfigureFolders(imapConnection);

        verify(imapConnection, atLeastOnce()).hasCapability(anyString());
        verifyNoMoreInteractions(imapConnection);
    }

    @Test
    public void autoconfigureFolders_removeNamespacePrefix() throws Exception {
        ImapConnection imapConnection = mock(ImapConnection.class);
        when(imapConnection.hasCapability(Capabilities.SPECIAL_USE)).thenReturn(true);
        List<ImapResponse> imapResponses = Arrays.asList(
                createImapResponse("* LIST (\\Drafts) \".\" \"INBOX.Drafts\""),
                createImapResponse("* LIST (\\Sent) \".\" \"INBOX.Sent\""),
                createImapResponse("* LIST (\\Junk) \".\" \"INBOX.Spam\""),
                createImapResponse("* LIST (\\Trash) \".\" \"INBOX.Trash\""),
                createImapResponse("* LIST (\\Archive) \".\" \"INBOX.Archive\""),
                createImapResponse("5 OK Success")
        );
        when(imapConnection.executeSimpleCommand("LIST (SPECIAL-USE) \"\" \"INBOX.*\"")).thenReturn(imapResponses);

        imapStore.setTestCombinedPrefix("INBOX.");
        imapStore.autoconfigureFolders(imapConnection);
        imapStore.getPersonalNamespaces();

        assertEquals("INBOX.", imapStore.getCombinedPrefix());
        verify(storeConfig).setDraftsFolder("Drafts");
        verify(storeConfig).setSentFolder("Sent");
        verify(storeConfig).setSpamFolder("Spam");
        verify(storeConfig).setTrashFolder("Trash");
        verify(storeConfig).setArchiveFolder("Archive");
        verify(imapConnection, never()).executeSimpleCommand("LIST (SPECIAL-USE) \"\" \"*\"");
        verify(imapConnection).executeSimpleCommand("LIST \"\" \"*\"");
    }

    @Test
@@ -372,6 +352,15 @@ public class ImapStoreTest {
        return folderNames;
    }

    private Map<String, ImapFolder> toFolderMap(List<ImapFolder> folders) {
        Map<String, ImapFolder> folderMap = new HashMap<>();
        for (ImapFolder folder : folders) {
            folderMap.put(folder.getServerId(), folder);
        }

        return folderMap;
    }


    static class TestImapStore extends ImapStore {
        private Deque<ImapConnection> imapConnections = new ArrayDeque<>();
+0 −2
Original line number Diff line number Diff line
@@ -61,8 +61,6 @@ public class Pop3Store extends RemoteStore {

    @Override
    public void checkSettings() throws MessagingException {
        mStoreConfig.setInboxFolder(Pop3Folder.INBOX);

        Pop3Folder folder = new Pop3Folder(this, Pop3Folder.INBOX);
        try {
            folder.open(Folder.OPEN_MODE_RW);