Skip to content

Commit

Permalink
Merge pull request #3219 from k9mail/GH-632_case_sensitive_folder_nam…
Browse files Browse the repository at this point in the history
…e_comparisons

Case sensitive folder name comparisons
  • Loading branch information
cketti authored Feb 27, 2018
2 parents fdce9af + 95b046b commit 49257b0
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@


class ImapFolder extends Folder<ImapMessage> {
static final String INBOX = "INBOX";
private static final ThreadLocal<SimpleDateFormat> RFC3501_DATE = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
Expand Down Expand Up @@ -78,7 +79,7 @@ public ImapFolder(ImapStore store, String name) {
private String getPrefixedName() throws MessagingException {
String prefixedName = "";

if (!store.getStoreConfig().getInboxFolderName().equalsIgnoreCase(name)) {
if (!INBOX.equalsIgnoreCase(name)) {
ImapConnection connection;
synchronized (this) {
if (this.connection == null) {
Expand Down Expand Up @@ -391,7 +392,7 @@ public void delete(List<? extends Message> messages, String trashFolderName) thr
return;
}

if (trashFolderName == null || getName().equalsIgnoreCase(trashFolderName)) {
if (trashFolderName == null || getName().equals(trashFolderName)) {
setFlags(messages, Collections.singleton(Flag.DELETED), true);
} else {
ImapFolder remoteTrashFolder = getStore().getFolder(trashFolderName);
Expand Down Expand Up @@ -1369,7 +1370,7 @@ private MessagingException ioExceptionHandler(ImapConnection connection, IOExcep
public boolean equals(Object other) {
if (other instanceof ImapFolder) {
ImapFolder otherFolder = (ImapFolder) other;
return otherFolder.getName().equalsIgnoreCase(getName());
return otherFolder.getName().equals(getName());
}

return super.equals(other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private Set<String> listFolders(ImapConnection connection, boolean subscribedOnl
combinedPrefix = null;
}

if (folder.equalsIgnoreCase(mStoreConfig.getInboxFolderName())) {
if (ImapFolder.INBOX.equalsIgnoreCase(folder)) {
continue;
} else if (folder.equals(mStoreConfig.getOutboxFolderName())) {
/*
Expand All @@ -216,12 +216,14 @@ private Set<String> listFolders(ImapConnection connection, boolean subscribedOnl
}
}

folderNames.add(mStoreConfig.getInboxFolderName());
folderNames.add(ImapFolder.INBOX);

return folderNames;
}

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

if (!connection.hasCapability(Capabilities.SPECIAL_USE)) {
if (K9MailLib.isDebug()) {
Timber.d("No detected folder auto-configuration methods.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
* POP3 only supports one folder, "Inbox". So the folder name is the ID here.
*/
class Pop3Folder extends Folder<Pop3Message> {
static final String INBOX = "INBOX";


private Pop3Store pop3Store;
private Map<String, Pop3Message> uidToMsgMap = new HashMap<>();
@SuppressLint("UseSparseArrays")
Expand All @@ -44,10 +47,6 @@ class Pop3Folder extends Folder<Pop3Message> {
super();
this.pop3Store = pop3Store;
this.name = name;

if (this.name.equalsIgnoreCase(pop3Store.getConfig().getInboxFolderName())) {
this.name = pop3Store.getConfig().getInboxFolderName();
}
}

@Override
Expand All @@ -56,7 +55,7 @@ public synchronized void open(int mode) throws MessagingException {
return;
}

if (!name.equalsIgnoreCase(pop3Store.getConfig().getInboxFolderName())) {
if (!INBOX.equals(name)) {
throw new MessagingException("Folder does not exist");
}

Expand Down Expand Up @@ -113,7 +112,7 @@ public boolean create(FolderType type) throws MessagingException {

@Override
public boolean exists() throws MessagingException {
return name.equalsIgnoreCase(pop3Store.getConfig().getInboxFolderName());
return INBOX.equals(name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,15 @@ public Pop3Folder getFolder(String name) {
@Override
public List<Pop3Folder> getPersonalNamespaces(boolean forceListAll) throws MessagingException {
List<Pop3Folder> folders = new LinkedList<>();
folders.add(getFolder(mStoreConfig.getInboxFolderName()));
folders.add(getFolder(Pop3Folder.INBOX));
return folders;
}

@Override
public void checkSettings() throws MessagingException {
Pop3Folder folder = new Pop3Folder(this, mStoreConfig.getInboxFolderName());
mStoreConfig.setInboxFolderName(Pop3Folder.INBOX);

Pop3Folder folder = new Pop3Folder(this, Pop3Folder.INBOX);
try {
folder.open(Folder.OPEN_MODE_RW);
folder.requestUidl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import com.fsck.k9.mail.FetchProfile;
Expand Down Expand Up @@ -49,10 +47,10 @@ public void before() throws MessagingException {
mockStoreConfig = mock(StoreConfig.class);
mockListener = mock(MessageRetrievalListener.class);
when(mockStore.getConfig()).thenReturn(mockStoreConfig);
when(mockStoreConfig.getInboxFolderName()).thenReturn("Inbox");
when(mockStoreConfig.getInboxFolderName()).thenReturn(Pop3Folder.INBOX);
when(mockStore.createConnection()).thenReturn(mockConnection);
when(mockConnection.executeSimpleCommand(Pop3Commands.STAT_COMMAND)).thenReturn("+OK 10 0");
folder = new Pop3Folder(mockStore, "Inbox");
folder = new Pop3Folder(mockStore, Pop3Folder.INBOX);
BinaryTempFileBody.setTempDirectory(new File(System.getProperty("java.io.tmpdir")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class Pop3StoreTest {
public void setUp() throws Exception {
//Using a SSL socket allows us to mock it
when(mockStoreConfig.getStoreUri()).thenReturn("pop3+ssl+://PLAIN:user:password@server:12345");
when(mockStoreConfig.getInboxFolderName()).thenReturn("Inbox");
when(mockStoreConfig.getInboxFolderName()).thenReturn(Pop3Folder.INBOX);
when(mockTrustedSocketFactory.createSocket(null, "server", 12345, null)).thenReturn(mockSocket);
when(mockSocket.isConnected()).thenReturn(true);
when(mockSocket.isClosed()).thenReturn(false);
Expand Down Expand Up @@ -187,7 +187,7 @@ public void getPersonalNamespace_shouldReturnListConsistingOfInbox() throws Exce
List<Pop3Folder> folders = store.getPersonalNamespaces(true);

assertEquals(1, folders.size());
assertEquals("Inbox", folders.get(0).getName());
assertEquals("INBOX", folders.get(0).getName());
}

@Test
Expand Down Expand Up @@ -247,7 +247,7 @@ public void open_withAuthResponseUsingAuthPlain_shouldRetrieveMessageCountOnAuth
when(mockSocket.getInputStream()).thenReturn(new ByteArrayInputStream(response.getBytes("UTF-8")));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
when(mockSocket.getOutputStream()).thenReturn(byteArrayOutputStream);
Pop3Folder folder = store.getFolder("Inbox");
Pop3Folder folder = store.getFolder(Pop3Folder.INBOX);

folder.open(Folder.OPEN_MODE_RW);

Expand All @@ -262,7 +262,7 @@ public void open_withFailedAuth_shouldThrow() throws Exception {
CAPA_RESPONSE +
AUTH_PLAIN_FAILED_RESPONSE;
when(mockSocket.getInputStream()).thenReturn(new ByteArrayInputStream(response.getBytes("UTF-8")));
Pop3Folder folder = store.getFolder("Inbox");
Pop3Folder folder = store.getFolder(Pop3Folder.INBOX);

folder.open(Folder.OPEN_MODE_RW);
}
Expand Down
12 changes: 6 additions & 6 deletions k9mail/src/main/java/com/fsck/k9/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ public synchronized void setDeletePolicy(DeletePolicy deletePolicy) {
}

public boolean isSpecialFolder(String folderName) {
return (folderName != null && (folderName.equalsIgnoreCase(getInboxFolderName()) ||
return (folderName != null && (folderName.equals(getInboxFolderName()) ||
folderName.equals(getTrashFolderName()) ||
folderName.equals(getDraftsFolderName()) ||
folderName.equals(getArchiveFolderName()) ||
Expand All @@ -1096,7 +1096,7 @@ public synchronized void setDraftsFolderName(String name) {
* @return true if account has a drafts folder set.
*/
public synchronized boolean hasDraftsFolder() {
return !K9.FOLDER_NONE.equalsIgnoreCase(draftsFolderName);
return !K9.FOLDER_NONE.equals(draftsFolderName);
}

public synchronized String getSentFolderName() {
Expand All @@ -1112,7 +1112,7 @@ public synchronized void setSentFolderName(String name) {
* @return true if account has a sent folder set.
*/
public synchronized boolean hasSentFolder() {
return !K9.FOLDER_NONE.equalsIgnoreCase(sentFolderName);
return !K9.FOLDER_NONE.equals(sentFolderName);
}


Expand All @@ -1129,7 +1129,7 @@ public synchronized void setTrashFolderName(String name) {
* @return true if account has a trash folder set.
*/
public synchronized boolean hasTrashFolder() {
return !K9.FOLDER_NONE.equalsIgnoreCase(trashFolderName);
return !K9.FOLDER_NONE.equals(trashFolderName);
}

public synchronized String getArchiveFolderName() {
Expand All @@ -1145,7 +1145,7 @@ public synchronized void setArchiveFolderName(String archiveFolderName) {
* @return true if account has an archive folder set.
*/
public synchronized boolean hasArchiveFolder() {
return !K9.FOLDER_NONE.equalsIgnoreCase(archiveFolderName);
return !K9.FOLDER_NONE.equals(archiveFolderName);
}

public synchronized String getSpamFolderName() {
Expand All @@ -1161,7 +1161,7 @@ public synchronized void setSpamFolderName(String name) {
* @return true if account has a spam folder set.
*/
public synchronized boolean hasSpamFolder() {
return !K9.FOLDER_NONE.equalsIgnoreCase(spamFolderName);
return !K9.FOLDER_NONE.equals(spamFolderName);
}

public synchronized String getOutboxFolderName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ private String getActionInProgressOperation(Context context) {
}

if (account != null) {
if (displayName.equalsIgnoreCase(account.getInboxFolderName())) {
if (displayName.equals(account.getInboxFolderName())) {
displayName = context.getString(R.string.special_mailbox_name_inbox);
} else if (displayName.equalsIgnoreCase(account.getOutboxFolderName())) {
} else if (displayName.equals(account.getOutboxFolderName())) {
displayName = context.getString(R.string.special_mailbox_name_outbox);
}
}
Expand Down
11 changes: 3 additions & 8 deletions k9mail/src/main/java/com/fsck/k9/activity/ChooseFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,7 @@ public void listFolders(Account account, List<LocalFolder> folders) {
for (Folder folder : folders) {
String name = folder.getName();

// Inbox needs to be compared case-insensitively
if (mHideCurrentFolder && (name.equals(mFolder) || (
mAccount.getInboxFolderName().equalsIgnoreCase(mFolder) &&
mAccount.getInboxFolderName().equalsIgnoreCase(name)))) {
if (mHideCurrentFolder && name.equals(mFolder)) {
continue;
}
Folder.FolderClass fMode = folder.getDisplayClass();
Expand Down Expand Up @@ -335,7 +332,7 @@ public int compare(String s1, String s2) {
try {
int position = 0;
for (String name : localFolders) {
if (mAccount.getInboxFolderName().equalsIgnoreCase(name)) {
if (mAccount.getInboxFolderName().equals(name)) {
folderList.add(getString(R.string.special_mailbox_name_inbox));
mHeldInbox = name;
} else if (!account.getOutboxFolderName().equals(name)) {
Expand All @@ -351,9 +348,7 @@ public int compare(String s1, String s2) {
if (name.equals(mSelectFolder)) {
selectedFolder = position;
}
} else if (name.equals(mFolder) || (
mAccount.getInboxFolderName().equalsIgnoreCase(mFolder) &&
mAccount.getInboxFolderName().equalsIgnoreCase(name))) {
} else if (name.equals(mFolder)) {
selectedFolder = position;
}
position++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ public static String getDisplayName(Context context, Account account, String nam
context.getString(R.string.special_mailbox_name_drafts_fmt), name);
} else if (name.equals(account.getOutboxFolderName())) {
displayName = context.getString(R.string.special_mailbox_name_outbox);
// FIXME: We really shouldn't do a case-insensitive comparison here
} else if (name.equalsIgnoreCase(account.getInboxFolderName())) {
} else if (name.equals(account.getInboxFolderName())) {
displayName = context.getString(R.string.special_mailbox_name_inbox);
} else {
displayName = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ public void onChooseAutoExpandFolder() {
}

private String translateFolder(String in) {
if (account.getInboxFolderName().equalsIgnoreCase(in)) {
if (account.getInboxFolderName().equals(in)) {
return getString(R.string.special_mailbox_name_inbox);
} else {
return in;
Expand Down
5 changes: 2 additions & 3 deletions k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -918,16 +918,15 @@ public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
if (account.isSpecialFolder(name)) {
prefHolder.inTopGroup = true;
prefHolder.displayClass = LocalFolder.FolderClass.FIRST_CLASS;
if (name.equalsIgnoreCase(account.getInboxFolderName())) {
if (name.equals(account.getInboxFolderName())) {
prefHolder.integrate = true;
prefHolder.notifyClass = LocalFolder.FolderClass.FIRST_CLASS;
prefHolder.pushClass = LocalFolder.FolderClass.FIRST_CLASS;
} else {
prefHolder.pushClass = LocalFolder.FolderClass.INHERITED;

}
if (name.equalsIgnoreCase(account.getInboxFolderName()) ||
name.equalsIgnoreCase(account.getDraftsFolderName())) {
if (name.equals(account.getInboxFolderName()) || name.equals(account.getDraftsFolderName())) {
prefHolder.syncClass = LocalFolder.FolderClass.FIRST_CLASS;
} else {
prefHolder.syncClass = LocalFolder.FolderClass.NO_CLASS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private void cancelNotifications(Intent intent, Account account, MessagingContro

private boolean isMovePossible(MessagingController controller, Account account,
String destinationFolderName) {
boolean isSpecialFolderConfigured = !K9.FOLDER_NONE.equalsIgnoreCase(destinationFolderName);
boolean isSpecialFolderConfigured = !K9.FOLDER_NONE.equals(destinationFolderName);

return isSpecialFolderConfigured && controller.isMoveCapable(account);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private boolean isSpamActionAvailableForWear(Account account) {
}

private boolean isMovePossible(Account account, String destinationFolderName) {
if (K9.FOLDER_NONE.equalsIgnoreCase(destinationFolderName)) {
if (K9.FOLDER_NONE.equals(destinationFolderName)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void onRefile(String dstFolder) {
return;
}

if (K9.FOLDER_NONE.equalsIgnoreCase(dstFolder)) {
if (K9.FOLDER_NONE.equals(dstFolder)) {
return;
}

Expand Down

0 comments on commit 49257b0

Please sign in to comment.