diff --git a/res/menu/message_list_option.xml b/res/menu/message_list_option.xml
index df7999d58..e8e80a1b4 100644
--- a/res/menu/message_list_option.xml
+++ b/res/menu/message_list_option.xml
@@ -143,11 +143,9 @@
-
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0a7cb50b2..991e15afe 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -735,6 +735,8 @@ Please submit bug reports, contribute new features and ask questions at
Latest messages first
Subject alphabetical
Subject reverse alphabetical
+ Sender alphabetical
+ Sender reverse alphabetical
Starred messages first
Unstarred messages first
Unread messages first
@@ -746,6 +748,7 @@ Please submit bug reports, contribute new features and ask questions at
Date
Arrival
Subject
+ Sender
Star
Read/unread
Attachments
diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java
index 11c2df5ba..f6f347596 100644
--- a/src/com/fsck/k9/Account.java
+++ b/src/com/fsck/k9/Account.java
@@ -106,7 +106,7 @@ public class Account implements BaseAccount {
SORT_DATE(R.string.sort_earliest_first, R.string.sort_latest_first, false),
SORT_ARRIVAL(R.string.sort_earliest_first, R.string.sort_latest_first, false),
SORT_SUBJECT(R.string.sort_subject_alpha, R.string.sort_subject_re_alpha, true),
-// SORT_SENDER(R.string.sort_sender_alpha, R.string.sort_sender_re_alpha, true),
+ SORT_SENDER(R.string.sort_sender_alpha, R.string.sort_sender_re_alpha, true),
SORT_UNREAD(R.string.sort_unread_first, R.string.sort_unread_last, true),
SORT_FLAGGED(R.string.sort_flagged_first, R.string.sort_flagged_last, true),
SORT_ATTACHMENT(R.string.sort_attach_first, R.string.sort_unattached_first, true);
diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java
index 3adc8e40d..4e4b5480d 100644
--- a/src/com/fsck/k9/activity/MessageList.java
+++ b/src/com/fsck/k9/activity/MessageList.java
@@ -757,10 +757,10 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
mMessageListFragment.changeSort(SortType.SORT_SUBJECT);
return true;
}
-// case R.id.set_sort_sender: {
-// mMessageListFragment.changeSort(SortType.SORT_SENDER);
-// return true;
-// }
+ case R.id.set_sort_sender: {
+ mMessageListFragment.changeSort(SortType.SORT_SENDER);
+ return true;
+ }
case R.id.set_sort_flag: {
mMessageListFragment.changeSort(SortType.SORT_FLAGGED);
return true;
diff --git a/src/com/fsck/k9/fragment/MessageListFragment.java b/src/com/fsck/k9/fragment/MessageListFragment.java
index 2d8563354..f28622fdd 100644
--- a/src/com/fsck/k9/fragment/MessageListFragment.java
+++ b/src/com/fsck/k9/fragment/MessageListFragment.java
@@ -307,6 +307,25 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
}
}
+ public static class SenderComparator implements Comparator {
+
+ @Override
+ public int compare(Cursor cursor1, Cursor cursor2) {
+ String sender1 = getSenderAddressFromCursor(cursor1);
+ String sender2 = getSenderAddressFromCursor(cursor2);
+
+ if (sender1 == null && sender2 == null) {
+ return 0;
+ } else if (sender1 == null) {
+ return 1;
+ } else if (sender2 == null) {
+ return -1;
+ } else {
+ return sender1.compareToIgnoreCase(sender2);
+ }
+ }
+ }
+
private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1;
private static final int ACTIVITY_CHOOSE_FOLDER_COPY = 2;
@@ -335,6 +354,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
map.put(SortType.SORT_ARRIVAL, new ArrivalComparator());
map.put(SortType.SORT_FLAGGED, new FlaggedComparator());
map.put(SortType.SORT_SUBJECT, new SubjectComparator());
+ map.put(SortType.SORT_SENDER, new SenderComparator());
map.put(SortType.SORT_UNREAD, new UnreadComparator());
// make it immutable to prevent accidental alteration (content is immutable already)
@@ -1360,10 +1380,10 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
changeSort(SortType.SORT_SUBJECT);
return true;
}
-// case R.id.set_sort_sender: {
-// changeSort(SortType.SORT_SENDER);
-// return true;
-// }
+ case R.id.set_sort_sender: {
+ changeSort(SortType.SORT_SENDER);
+ return true;
+ }
case R.id.set_sort_flag: {
changeSort(SortType.SORT_FLAGGED);
return true;
@@ -1493,7 +1513,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
}
- private String getSenderAddressFromCursor(Cursor cursor) {
+ private static String getSenderAddressFromCursor(Cursor cursor) {
String fromList = cursor.getString(SENDER_LIST_COLUMN);
Address[] fromAddrs = Address.unpack(fromList);
return (fromAddrs.length > 0) ? fromAddrs[0].getAddress() : null;
@@ -3224,11 +3244,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
sortColumn = "(" + MessageColumns.FLAGGED + " != 1)";
break;
}
-// case SORT_SENDER: {
-// //FIXME
-// sortColumn = MessageColumns.SENDER_LIST;
-// break;
-// }
+ case SORT_SENDER: {
+ //FIXME
+ sortColumn = MessageColumns.SENDER_LIST;
+ break;
+ }
case SORT_SUBJECT: {
sortColumn = MessageColumns.SUBJECT + " COLLATE NOCASE";
break;