NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Sorting API

Prototype for generic comparison function, compatible with qsort_r() More...

Functions

static int alias_sort_name (const void *a, const void *b, void *sdata)
 Compare two Aliases by their short names - Implements sort_t -.
 
static int alias_sort_address (const void *a, const void *b, void *sdata)
 Compare two Aliases by their Addresses - Implements sort_t -.
 
static int alias_sort_unsort (const void *a, const void *b, void *sdata)
 Compare two Aliases by their original configuration position - Implements sort_t -.
 
static int browser_sort_subject (const void *a, const void *b, void *sdata)
 Compare two browser entries by their subject - Implements sort_t -.
 
static int browser_sort_order (const void *a, const void *b, void *sdata)
 Compare two browser entries by their order - Implements sort_t -.
 
static int browser_sort_desc (const void *a, const void *b, void *sdata)
 Compare two browser entries by their descriptions - Implements sort_t -.
 
static int browser_sort_date (const void *a, const void *b, void *sdata)
 Compare two browser entries by their date - Implements sort_t -.
 
static int browser_sort_size (const void *a, const void *b, void *sdata)
 Compare two browser entries by their size - Implements sort_t -.
 
static int browser_sort_count (const void *a, const void *b, void *sdata)
 Compare two browser entries by their message count - Implements sort_t -.
 
static int browser_sort_count_new (const void *a, const void *b, void *sdata)
 Compare two browser entries by their new count - Implements sort_t -.
 
static int browser_sort_helper (const void *a, const void *b, void *sdata)
 Helper to sort the items in the browser - Implements sort_t -.
 
static int envlist_sort (const void *a, const void *b, void *sdata)
 Compare two environment strings - Implements sort_t -.
 
static int label_sort (const void *a, const void *b, void *sdata)
 Compare two label strings - Implements sort_t -.
 
int elem_list_sort (const void *a, const void *b, void *sdata)
 Compare two HashElem pointers to config - Implements sort_t -.
 
static int commands_sort (const void *a, const void *b, void *sdata)
 Compare two commands by name - Implements sort_t -.
 
static int imap_sort_email_uid (const void *a, const void *b, void *sdata)
 Compare two Emails by UID - Implements sort_t -.
 
int imap_sort_uid (const void *a, const void *b, void *sdata)
 Compare two UIDs - Implements sort_t -.
 
static int maildir_sort_inode (const void *a, const void *b, void *sdata)
 Compare two Maildirs by inode number - Implements sort_t -.
 
static int maildir_sort_flags (const void *a, const void *b, void *sdata)
 Compare two flag characters - Implements sort_t -.
 
static int mh_sort_path (const void *a, const void *b, void *sdata)
 Compare two Mh Mailboxes by path - Implements sort_t -.
 
int mutt_str_inbox_cmp (const char *a, const char *b)
 Do two folders share the same path and one is an inbox -.
 
static int compare_threads (const void *a, const void *b, void *sdata)
 Helper to sort email threads - Implements sort_t -.
 
static int crypt_sort_address (const void *a, const void *b, void *sdata)
 Compare two keys by their addresses - Implements sort_t -.
 
static int crypt_sort_keyid (const void *a, const void *b, void *sdata)
 Compare two keys by their IDs - Implements sort_t -.
 
static int crypt_sort_date (const void *a, const void *b, void *sdata)
 Compare two keys by their dates - Implements sort_t -.
 
static int crypt_sort_trust (const void *a, const void *b, void *sdata)
 Compare two keys by their trust levels - Implements sort_t -.
 
static int pgp_sort_address (const void *a, const void *b, void *sdata)
 Compare two keys by their addresses - Implements sort_t -.
 
static int pgp_sort_date (const void *a, const void *b, void *sdata)
 Compare two keys by their dates - Implements sort_t -.
 
static int pgp_sort_keyid (const void *a, const void *b, void *sdata)
 Compare two keys by their IDs - Implements sort_t -.
 
static int pgp_sort_trust (const void *a, const void *b, void *sdata)
 Compare two keys by their trust levels - Implements sort_t -.
 
static int sb_sort_count (const void *a, const void *b, void *sdata)
 Compare two Sidebar entries by count - Implements sort_t -.
 
static int sb_sort_desc (const void *a, const void *b, void *sdata)
 Compare two Sidebar entries by description - Implements sort_t -.
 
static int sb_sort_flagged (const void *a, const void *b, void *sdata)
 Compare two Sidebar entries by flagged - Implements sort_t -.
 
static int sb_sort_path (const void *a, const void *b, void *sdata)
 Compare two Sidebar entries by path - Implements sort_t -.
 
static int sb_sort_unread (const void *a, const void *b, void *sdata)
 Compare two Sidebar entries by unread - Implements sort_t -.
 
static int sb_sort_order (const void *a, const void *b, void *sdata)
 Compare two Sidebar entries by order of creation - Implements sort_t -.
 
static int sb_sort_unsorted (const void *a, const void *b, void *sdata)
 Compare two Sidebar entries into their original order - Implements sort_t -.
 
static int compare_email_shim (const void *a, const void *b, void *sdata)
 Helper to sort emails - Implements sort_t -.
 
int mutt_compare_emails (const struct Email *a, const struct Email *b, enum MailboxType type, short sort, short sort_aux)
 Compare two emails using up to two sort methods -.
 

Detailed Description

Prototype for generic comparison function, compatible with qsort_r()

Parameters
aFirst item
bSecond item
sdataPrivate data
Return values
<0a precedes b
0a and b are identical
>0b precedes a

Function Documentation

◆ alias_sort_name()

static int alias_sort_name ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Aliases by their short names - Implements sort_t -.

Note
Non-visible Aliases are sorted to the end

Definition at line 46 of file sort.c.

47{
48 const struct AliasView *av_a = a;
49 const struct AliasView *av_b = b;
50 const bool sort_reverse = *(bool *) sdata;
51
52 if (av_a->is_visible != av_b->is_visible)
53 return av_a->is_visible ? -1 : 1;
54
55 if (!av_a->is_visible)
56 return 0;
57
58 int rc = mutt_str_coll(av_a->alias->name, av_b->alias->name);
59 return sort_reverse ? -rc : rc;
60}
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:509
GUI data wrapping an Alias.
Definition: gui.h:38
bool is_visible
Is visible?
Definition: gui.h:45
struct Alias * alias
Alias.
Definition: gui.h:46
char * name
Short name.
Definition: alias.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alias_sort_address()

static int alias_sort_address ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Aliases by their Addresses - Implements sort_t -.

Note
Non-visible Aliases are sorted to the end

Definition at line 67 of file sort.c.

68{
69 const struct AliasView *av_a = a;
70 const struct AliasView *av_b = b;
71 const bool sort_reverse = *(bool *) sdata;
72
73 const struct AddressList *al_a = &av_a->alias->addr;
74 const struct AddressList *al_b = &av_b->alias->addr;
75
76 if (av_a->is_visible != av_b->is_visible)
77 return av_a->is_visible ? -1 : 1;
78
79 if (!av_a->is_visible)
80 return 0;
81
82 int rc;
83 if (al_a == al_b)
84 {
85 rc = 0;
86 }
87 else if (!al_a)
88 {
89 rc = -1;
90 }
91 else if (!al_b)
92 {
93 rc = 1;
94 }
95 else
96 {
97 const struct Address *addr_a = TAILQ_FIRST(al_a);
98 const struct Address *addr_b = TAILQ_FIRST(al_b);
99 if (addr_a && addr_a->personal)
100 {
101 if (addr_b && addr_b->personal)
102 rc = buf_coll(addr_a->personal, addr_b->personal);
103 else
104 rc = 1;
105 }
106 else if (addr_b && addr_b->personal)
107 {
108 rc = -1;
109 }
110 else if (addr_a && addr_b)
111 {
112 rc = buf_coll(addr_a->mailbox, addr_b->mailbox);
113 }
114 else
115 {
116 rc = 0;
117 }
118 }
119
120 return sort_reverse ? -rc : rc;
121}
int buf_coll(const struct Buffer *a, const struct Buffer *b)
Collate two strings (compare using locale)
Definition: buffer.c:725
#define TAILQ_FIRST(head)
Definition: queue.h:723
An email address.
Definition: address.h:36
struct Buffer * personal
Real name of address.
Definition: address.h:37
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
struct AddressList addr
List of Addresses the Alias expands to.
Definition: alias.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alias_sort_unsort()

static int alias_sort_unsort ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Aliases by their original configuration position - Implements sort_t -.

Note
Non-visible Aliases are sorted to the end

Definition at line 128 of file sort.c.

129{
130 const struct AliasView *av_a = a;
131 const struct AliasView *av_b = b;
132 const bool sort_reverse = *(bool *) sdata;
133
134 if (av_a->is_visible != av_b->is_visible)
135 return av_a->is_visible ? -1 : 1;
136
137 if (!av_a->is_visible)
138 return 0;
139
140 int rc = mutt_numeric_cmp(av_a->orig_seq, av_b->orig_seq);
141 return sort_reverse ? -rc : rc;
142}
#define mutt_numeric_cmp(a, b)
Definition: sort.h:35
int orig_seq
Sequence in alias config file.
Definition: gui.h:40
+ Here is the caller graph for this function:

◆ browser_sort_subject()

static int browser_sort_subject ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two browser entries by their subject - Implements sort_t -.

Definition at line 54 of file sort.c.

55{
56 const struct FolderFile *pa = (const struct FolderFile *) a;
57 const struct FolderFile *pb = (const struct FolderFile *) b;
58
59 /* inbox should be sorted ahead of its siblings */
60 int rc = mutt_str_inbox_cmp(pa->name, pb->name);
61 if (rc == 0)
62 rc = mutt_str_coll(pa->name, pb->name);
63
64 return rc;
65}
int mutt_str_inbox_cmp(const char *a, const char *b)
Do two folders share the same path and one is an inbox -.
Definition: string.c:887
Browser entry representing a folder/dir.
Definition: lib.h:77
char * name
Name of file/dir/mailbox.
Definition: lib.h:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ browser_sort_order()

static int browser_sort_order ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two browser entries by their order - Implements sort_t -.

Note
This only affects browsing mailboxes and is a no-op for folders.

Definition at line 72 of file sort.c.

73{
74 const struct FolderFile *pa = (const struct FolderFile *) a;
75 const struct FolderFile *pb = (const struct FolderFile *) b;
76
77 return mutt_numeric_cmp(pa->gen, pb->gen);
78}
int gen
Unique id, used for (un)sorting.
Definition: lib.h:104
+ Here is the caller graph for this function:

◆ browser_sort_desc()

static int browser_sort_desc ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two browser entries by their descriptions - Implements sort_t -.

Definition at line 83 of file sort.c.

84{
85 const struct FolderFile *pa = (const struct FolderFile *) a;
86 const struct FolderFile *pb = (const struct FolderFile *) b;
87
88 return mutt_str_coll(pa->desc, pb->desc);
89}
char * desc
Description of mailbox.
Definition: lib.h:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ browser_sort_date()

static int browser_sort_date ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two browser entries by their date - Implements sort_t -.

Definition at line 94 of file sort.c.

95{
96 const struct FolderFile *pa = (const struct FolderFile *) a;
97 const struct FolderFile *pb = (const struct FolderFile *) b;
98
99 return mutt_numeric_cmp(pa->mtime, pb->mtime);
100}
time_t mtime
Modification time.
Definition: lib.h:80
+ Here is the caller graph for this function:

◆ browser_sort_size()

static int browser_sort_size ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two browser entries by their size - Implements sort_t -.

Definition at line 105 of file sort.c.

106{
107 const struct FolderFile *pa = (const struct FolderFile *) a;
108 const struct FolderFile *pb = (const struct FolderFile *) b;
109
110 return mutt_numeric_cmp(pa->size, pb->size);
111}
off_t size
File size.
Definition: lib.h:79
+ Here is the caller graph for this function:

◆ browser_sort_count()

static int browser_sort_count ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two browser entries by their message count - Implements sort_t -.

Definition at line 116 of file sort.c.

117{
118 const struct FolderFile *pa = (const struct FolderFile *) a;
119 const struct FolderFile *pb = (const struct FolderFile *) b;
120
121 int rc = 0;
122 if (pa->has_mailbox && pb->has_mailbox)
123 rc = mutt_numeric_cmp(pa->msg_count, pb->msg_count);
124 else if (pa->has_mailbox)
125 rc = -1;
126 else
127 rc = 1;
128
129 return rc;
130}
bool has_mailbox
This is a mailbox.
Definition: lib.h:97
int msg_count
total number of messages
Definition: lib.h:89
+ Here is the caller graph for this function:

◆ browser_sort_count_new()

static int browser_sort_count_new ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two browser entries by their new count - Implements sort_t -.

Definition at line 135 of file sort.c.

136{
137 const struct FolderFile *pa = (const struct FolderFile *) a;
138 const struct FolderFile *pb = (const struct FolderFile *) b;
139
140 int rc = 0;
141 if (pa->has_mailbox && pb->has_mailbox)
143 else if (pa->has_mailbox)
144 rc = -1;
145 else
146 rc = 1;
147
148 return rc;
149}
int msg_unread
number of unread messages
Definition: lib.h:90
+ Here is the caller graph for this function:

◆ browser_sort_helper()

static int browser_sort_helper ( const void *  a,
const void *  b,
void *  sdata 
)
static

Helper to sort the items in the browser - Implements sort_t -.

Wild compare function that calls the others. It's useful because it provides a way to tell "../" is always on the top of the list, independently of the sort method. $browser_sort_dirs_first is also handled here.

Definition at line 158 of file sort.c.

159{
160 const struct FolderFile *pa = (const struct FolderFile *) a;
161 const struct FolderFile *pb = (const struct FolderFile *) b;
162 const struct CompareData *cd = (struct CompareData *) sdata;
163
164 if ((mutt_str_coll(pa->desc, "../") == 0) || (mutt_str_coll(pa->desc, "..") == 0))
165 return -1;
166 if ((mutt_str_coll(pb->desc, "../") == 0) || (mutt_str_coll(pb->desc, "..") == 0))
167 return 1;
168
169 if (cd->sort_dirs_first)
170 if (S_ISDIR(pa->mode) != S_ISDIR(pb->mode))
171 return S_ISDIR(pa->mode) ? -1 : 1;
172
173 int rc = cd->sort_fn(a, b, NULL);
174
175 return cd->sort_reverse ? -rc : rc;
176}
Private data for browser_sort_helper()
Definition: sort.c:45
bool sort_dirs_first
$browser_sort_dirs_first = yes
Definition: sort.c:46
sort_t sort_fn
Function to perform $browser_sort.
Definition: sort.c:48
bool sort_reverse
$browser_sort contains 'reverse-'
Definition: sort.c:47
mode_t mode
File permissions.
Definition: lib.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ envlist_sort()

static int envlist_sort ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two environment strings - Implements sort_t -.

Definition at line 910 of file commands.c.

911{
912 return strcmp(*(const char **) a, *(const char **) b);
913}
+ Here is the caller graph for this function:

◆ label_sort()

static int label_sort ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two label strings - Implements sort_t -.

Definition at line 298 of file helpers.c.

299{
300 return strcasecmp(*(const char **) a, *(const char **) b);
301}
+ Here is the caller graph for this function:

◆ elem_list_sort()

int elem_list_sort ( const void *  a,
const void *  b,
void *  sdata 
)

Compare two HashElem pointers to config - Implements sort_t -.

Definition at line 63 of file subset.c.

64{
65 if (!a || !b)
66 return 0;
67
68 const struct HashElem *hea = *(struct HashElem const *const *) a;
69 const struct HashElem *heb = *(struct HashElem const *const *) b;
70
71 return mutt_istr_cmp(hea->key.strkey, heb->key.strkey);
72}
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:412
The item stored in a Hash Table.
Definition: hash.h:43
union HashKey key
Key representing the data.
Definition: hash.h:45
const char * strkey
String key.
Definition: hash.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ commands_sort()

static int commands_sort ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two commands by name - Implements sort_t -.

Definition at line 40 of file command.c.

41{
42 struct Command x = *(const struct Command *) a;
43 struct Command y = *(const struct Command *) b;
44
45 return mutt_str_cmp(x.name, y.name);
46}
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:399
const char * name
Name of the command.
Definition: command.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_sort_email_uid()

static int imap_sort_email_uid ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Emails by UID - Implements sort_t -.

Definition at line 900 of file imap.c.

901{
902 const struct Email *ea = *(struct Email const *const *) a;
903 const struct Email *eb = *(struct Email const *const *) b;
904
905 const unsigned int ua = imap_edata_get((struct Email *) ea)->uid;
906 const unsigned int ub = imap_edata_get((struct Email *) eb)->uid;
907
908 return mutt_numeric_cmp(ua, ub);
909}
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:67
The envelope/body of an email.
Definition: email.h:39
unsigned int uid
32-bit Message UID
Definition: edata.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_sort_uid()

int imap_sort_uid ( const void *  a,
const void *  b,
void *  sdata 
)

Compare two UIDs - Implements sort_t -.

Definition at line 55 of file msg_set.c.

56{
57 unsigned int ua = *(unsigned int *) a;
58 unsigned int ub = *(unsigned int *) b;
59
60 return mutt_numeric_cmp(ua, ub);
61}
+ Here is the caller graph for this function:

◆ maildir_sort_inode()

static int maildir_sort_inode ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Maildirs by inode number - Implements sort_t -.

Definition at line 251 of file mailbox.c.

252{
253 const struct MdEmail *ma = *(struct MdEmail **) a;
254 const struct MdEmail *mb = *(struct MdEmail **) b;
255
256 return mutt_numeric_cmp(ma->inode, mb->inode);
257}
A Maildir Email helper.
Definition: mdemail.h:34
ino_t inode
Inode number of the file.
Definition: mdemail.h:38
+ Here is the caller graph for this function:

◆ maildir_sort_flags()

static int maildir_sort_flags ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two flag characters - Implements sort_t -.

Definition at line 62 of file message.c.

63{
64 return mutt_numeric_cmp(*((const char *) a), *((const char *) b));
65}
+ Here is the caller graph for this function:

◆ mh_sort_path()

static int mh_sort_path ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Mh Mailboxes by path - Implements sort_t -.

Definition at line 496 of file mh.c.

497{
498 struct MhEmail const *pa = *(struct MhEmail const *const *) a;
499 struct MhEmail const *pb = *(struct MhEmail const *const *) b;
500 return mutt_str_cmp(pa->email->path, pb->email->path);
501}
char * path
Path of Email (for local Mailboxes)
Definition: email.h:70
A Mh Email helper.
Definition: mhemail.h:36
struct Email * email
Temporary Email.
Definition: mhemail.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_inbox_cmp()

int mutt_str_inbox_cmp ( const char *  a,
const char *  b 
)

Do two folders share the same path and one is an inbox -.

Parameters
aFirst path
bSecond path
Return values
-1a is INBOX of b
0None is INBOX
1b is INBOX for a

This function compares two folder paths. It first looks for the position of the last common '/' character. If a valid position is found and it's not the last character in any of the two paths, the remaining parts of the paths are compared (case insensitively) with the string "INBOX" followed by a non alpha character, e.g., '.' or '/'. If only one of the two paths matches, it's reported as being less than the other and the function returns -1 (a < b) or 1 (a > b). If both or no paths match the requirements, the two paths are considered equivalent and this function returns 0.

Examples:

  • mutt_str_inbox_cmp("/foo/bar", "/foo/baz") --> 0
  • mutt_str_inbox_cmp("/foo/bar/", "/foo/bar/inbox") --> 0
  • mutt_str_inbox_cmp("/foo/bar/sent", "/foo/bar/inbox") --> 1
  • mutt_str_inbox_cmp("=INBOX", "=Drafts") --> -1
  • mutt_str_inbox_cmp("=INBOX", "=INBOX.Foo") --> 0
  • mutt_str_inbox_cmp("=INBOX.Foo", "=Drafts") --> -1

Definition at line 887 of file string.c.

888{
889#define IS_INBOX(s) (mutt_istrn_equal(s, "inbox", 5) && !isalnum((s)[5]))
890#define CMP_INBOX(a, b) (IS_INBOX(b) - IS_INBOX(a))
891
892 /* fast-track in case the paths have been mutt_pretty_mailbox'ified */
893 if ((a[0] == '+') && (b[0] == '+'))
894 {
895 return CMP_INBOX(a + 1, b + 1);
896 }
897
898 const char *a_end = strrchr(a, '/');
899 const char *b_end = strrchr(b, '/');
900
901 /* If one path contains a '/', but not the other */
902 if ((!a_end) ^ (!b_end))
903 return 0;
904
905 /* If neither path contains a '/' */
906 if (!a_end)
907 return 0;
908
909 /* Compare the subpaths */
910 size_t a_len = a_end - a;
911 size_t b_len = b_end - b;
912 size_t min = MIN(a_len, b_len);
913 int same = (a[min] == '/') && (b[min] == '/') && (a[min + 1] != '\0') &&
914 (b[min + 1] != '\0') && mutt_istrn_equal(a, b, min);
915
916 if (!same)
917 return 0;
918
919 return CMP_INBOX(a + 1 + min, b + 1 + min);
920
921#undef CMP_INBOX
922#undef IS_INBOX
923}
#define MIN(a, b)
Definition: memory.h:32
#define CMP_INBOX(a, b)
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
Definition: string.c:453
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compare_threads()

static int compare_threads ( const void *  a,
const void *  b,
void *  sdata 
)
static

Helper to sort email threads - Implements sort_t -.

Definition at line 750 of file mutt_thread.c.

751{
752 const struct MuttThread *ta = *(struct MuttThread const *const *) a;
753 const struct MuttThread *tb = *(struct MuttThread const *const *) b;
754 const struct ThreadsContext *tctx = sdata;
755 ASSERT(ta->parent == tb->parent);
756
757 /* If c_sort ties, remember we are building the thread array in
758 * reverse from the index the mails had in the mailbox. */
759 struct Mailbox *m = tctx->mailbox_view->mailbox;
760 const enum MailboxType mtype = mx_type(m);
761 if (ta->parent)
762 {
763 return mutt_compare_emails(ta->sort_aux_key, tb->sort_aux_key, mtype,
765 }
766 else
767 {
770 }
771}
MailboxType
Supported mailbox formats.
Definition: mailbox.h:41
int mutt_compare_emails(const struct Email *a, const struct Email *b, enum MailboxType type, short sort, short sort_aux)
Compare two emails using up to two sort methods -.
Definition: sort.c:324
enum MailboxType mx_type(struct Mailbox *m)
Return the type of the Mailbox.
Definition: mx.c:1796
#define ASSERT(COND)
Definition: signal2.h:58
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:40
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:71
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:51
A mailbox.
Definition: mailbox.h:79
An Email conversation.
Definition: thread.h:34
struct MuttThread * parent
Parent of this Thread.
Definition: thread.h:44
struct Email * sort_aux_key
Email that controls how subthread siblings sort.
Definition: thread.h:51
struct Email * sort_thread_key
Email that controls how top thread sorts.
Definition: thread.h:50
The "current" threading state.
Definition: mutt_thread.h:43
struct MailboxView * mailbox_view
Current mailbox.
Definition: mutt_thread.h:44
enum SortType c_sort_aux
Last sort_aux method.
Definition: mutt_thread.h:48
enum SortType c_sort
Last sort method.
Definition: mutt_thread.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_sort_address()

static int crypt_sort_address ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two keys by their addresses - Implements sort_t -.

Definition at line 109 of file dlg_gpgme.c.

110{
111 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
112 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
113 const bool sort_reverse = *(bool *) sdata;
114
115 int rc = mutt_istr_cmp(s->uid, t->uid);
116 if (rc != 0)
117 goto done;
118
120
121done:
122 return sort_reverse ? -rc : rc;
123}
const char * crypt_fpr_or_lkeyid(struct CryptKeyInfo *k)
Find the fingerprint of a key.
Definition: crypt_gpgme.c:214
A stored PGP key.
Definition: crypt_gpgme.h:44
const char * uid
and for convenience point to this user ID
Definition: crypt_gpgme.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_sort_keyid()

static int crypt_sort_keyid ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two keys by their IDs - Implements sort_t -.

Definition at line 128 of file dlg_gpgme.c.

129{
130 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
131 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
132 const bool sort_reverse = *(bool *) sdata;
133
135 if (rc != 0)
136 goto done;
137
138 rc = mutt_istr_cmp(s->uid, t->uid);
139
140done:
141 return sort_reverse ? -rc : rc;
142}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_sort_date()

static int crypt_sort_date ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two keys by their dates - Implements sort_t -.

Definition at line 147 of file dlg_gpgme.c.

148{
149 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
150 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
151 const bool sort_reverse = *(bool *) sdata;
152
153 unsigned long ts = 0;
154 unsigned long tt = 0;
155 int rc = 0;
156
157 if (s->kobj->subkeys && (s->kobj->subkeys->timestamp > 0))
158 ts = s->kobj->subkeys->timestamp;
159 if (t->kobj->subkeys && (t->kobj->subkeys->timestamp > 0))
160 tt = t->kobj->subkeys->timestamp;
161
162 if (ts > tt)
163 {
164 rc = 1;
165 goto done;
166 }
167
168 if (ts < tt)
169 {
170 rc = -1;
171 goto done;
172 }
173
174 rc = mutt_istr_cmp(s->uid, t->uid);
175
176done:
177 return sort_reverse ? -rc : rc;
178}
gpgme_key_t kobj
Definition: crypt_gpgme.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_sort_trust()

static int crypt_sort_trust ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two keys by their trust levels - Implements sort_t -.

Definition at line 183 of file dlg_gpgme.c.

184{
185 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
186 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
187 const bool sort_reverse = *(bool *) sdata;
188
189 unsigned long ts = 0;
190 unsigned long tt = 0;
191
193 if (rc != 0)
194 goto done;
195
196 // Note: reversed
198 if (rc != 0)
199 return rc;
200
201 ts = 0;
202 tt = 0;
203 if (s->kobj->subkeys)
204 ts = s->kobj->subkeys->length;
205 if (t->kobj->subkeys)
206 tt = t->kobj->subkeys->length;
207
208 // Note: reversed
209 rc = mutt_numeric_cmp(tt, ts);
210 if (rc != 0)
211 goto done;
212
213 ts = 0;
214 tt = 0;
215 if (s->kobj->subkeys && (s->kobj->subkeys->timestamp > 0))
216 ts = s->kobj->subkeys->timestamp;
217 if (t->kobj->subkeys && (t->kobj->subkeys->timestamp > 0))
218 tt = t->kobj->subkeys->timestamp;
219
220 // Note: reversed
221 rc = mutt_numeric_cmp(tt, ts);
222 if (rc != 0)
223 goto done;
224
225 rc = mutt_istr_cmp(s->uid, t->uid);
226 if (rc != 0)
227 goto done;
228
230
231done:
232 return sort_reverse ? -rc : rc;
233}
#define KEYFLAG_RESTRICTIONS
Definition: lib.h:140
gpgme_validity_t validity
uid validity (cached for convenience)
Definition: crypt_gpgme.h:50
KeyFlags flags
global and per uid flags (for convenience)
Definition: crypt_gpgme.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_sort_address()

static int pgp_sort_address ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two keys by their addresses - Implements sort_t -.

Definition at line 110 of file dlg_pgp.c.

111{
112 struct PgpUid const *s = *(struct PgpUid const *const *) a;
113 struct PgpUid const *t = *(struct PgpUid const *const *) b;
114 const bool sort_reverse = *(bool *) sdata;
115
116 int rc = mutt_istr_cmp(s->addr, t->addr);
117 if (rc != 0)
118 goto done;
119
121
122done:
123 return sort_reverse ? -rc : rc;
124}
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:234
PGP User ID.
Definition: pgplib.h:35
struct PgpKeyInfo * parent
Parent key.
Definition: pgplib.h:39
char * addr
Definition: pgplib.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_sort_date()

static int pgp_sort_date ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two keys by their dates - Implements sort_t -.

Definition at line 129 of file dlg_pgp.c.

130{
131 struct PgpUid const *s = *(struct PgpUid const *const *) a;
132 struct PgpUid const *t = *(struct PgpUid const *const *) b;
133 const bool sort_reverse = *(bool *) sdata;
134
136 if (rc != 0)
137 goto done;
138
139 rc = mutt_istr_cmp(s->addr, t->addr);
140
141done:
142 return sort_reverse ? -rc : rc;
143}
time_t gen_time
Definition: pgplib.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_sort_keyid()

static int pgp_sort_keyid ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two keys by their IDs - Implements sort_t -.

Definition at line 148 of file dlg_pgp.c.

149{
150 struct PgpUid const *s = *(struct PgpUid const *const *) a;
151 struct PgpUid const *t = *(struct PgpUid const *const *) b;
152 const bool sort_reverse = *(bool *) sdata;
153
155 if (rc != 0)
156 goto done;
157
158 rc = mutt_istr_cmp(s->addr, t->addr);
159
160done:
161 return sort_reverse ? -rc : rc;
162}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_sort_trust()

static int pgp_sort_trust ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two keys by their trust levels - Implements sort_t -.

Definition at line 167 of file dlg_pgp.c.

168{
169 struct PgpUid const *s = *(struct PgpUid const *const *) a;
170 struct PgpUid const *t = *(struct PgpUid const *const *) b;
171 const bool sort_reverse = *(bool *) sdata;
172
175 if (rc != 0)
176 goto done;
177
178 // Note: reversed
179 rc = mutt_numeric_cmp(t->trust, s->trust);
180 if (rc != 0)
181 goto done;
182
183 // Note: reversed
185 if (rc != 0)
186 goto done;
187
188 // Note: reversed
190 if (rc != 0)
191 goto done;
192
193 rc = mutt_istr_cmp(s->addr, t->addr);
194 if (rc != 0)
195 goto done;
196
198
199done:
200 return sort_reverse ? -rc : rc;
201}
KeyFlags flags
Definition: pgplib.h:51
short keylen
Definition: pgplib.h:52
short trust
Definition: pgplib.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_count()

static int sb_sort_count ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Sidebar entries by count - Implements sort_t -.

Definition at line 42 of file sort.c.

43{
44 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
45 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
46 const struct Mailbox *m1 = sbe1->mailbox;
47 const struct Mailbox *m2 = sbe2->mailbox;
48 const bool sort_reverse = *(bool *) sdata;
49
50 int rc = 0;
51 if (m1->msg_count == m2->msg_count)
53 else
55
56 return sort_reverse ? -rc : rc;
57}
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
int msg_count
Total number of messages.
Definition: mailbox.h:88
Info about folders in the sidebar.
Definition: private.h:41
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_desc()

static int sb_sort_desc ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Sidebar entries by description - Implements sort_t -.

Definition at line 62 of file sort.c.

63{
64 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
65 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
66 const struct Mailbox *m1 = sbe1->mailbox;
67 const struct Mailbox *m2 = sbe2->mailbox;
68 const bool sort_reverse = *(bool *) sdata;
69
70 int rc = mutt_str_cmp(m1->name, m2->name);
71 return sort_reverse ? -rc : rc;
72}
char * name
A short name for the Mailbox.
Definition: mailbox.h:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_flagged()

static int sb_sort_flagged ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Sidebar entries by flagged - Implements sort_t -.

Definition at line 77 of file sort.c.

78{
79 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
80 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
81 const struct Mailbox *m1 = sbe1->mailbox;
82 const struct Mailbox *m2 = sbe2->mailbox;
83 const bool sort_reverse = *(bool *) sdata;
84
85 int rc = 0;
86 if (m1->msg_flagged == m2->msg_flagged)
88 else
90
91 return sort_reverse ? -rc : rc;
92}
int msg_flagged
Number of flagged messages.
Definition: mailbox.h:90
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_path()

static int sb_sort_path ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Sidebar entries by path - Implements sort_t -.

Definition at line 97 of file sort.c.

98{
99 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
100 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
101 const struct Mailbox *m1 = sbe1->mailbox;
102 const struct Mailbox *m2 = sbe2->mailbox;
103 const bool sort_reverse = *(bool *) sdata;
104
105 int rc = 0;
107 if (rc == 0)
109
110 return sort_reverse ? -rc : rc;
111}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_unread()

static int sb_sort_unread ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Sidebar entries by unread - Implements sort_t -.

Definition at line 116 of file sort.c.

117{
118 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
119 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
120 const struct Mailbox *m1 = sbe1->mailbox;
121 const struct Mailbox *m2 = sbe2->mailbox;
122 const bool sort_reverse = *(bool *) sdata;
123
124 int rc = 0;
125 if (m1->msg_unread == m2->msg_unread)
127 else
129
130 return sort_reverse ? -rc : rc;
131}
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_order()

static int sb_sort_order ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Sidebar entries by order of creation - Implements sort_t -.

Definition at line 136 of file sort.c.

137{
138 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
139 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
140 const struct Mailbox *m1 = sbe1->mailbox;
141 const struct Mailbox *m2 = sbe2->mailbox;
142 const bool sort_reverse = *(bool *) sdata;
143
144 int rc = mutt_numeric_cmp(m1->gen, m2->gen);
145 return sort_reverse ? -rc : rc;
146}
int gen
Generation number, for sorting.
Definition: mailbox.h:147
+ Here is the caller graph for this function:

◆ sb_sort_unsorted()

static int sb_sort_unsorted ( const void *  a,
const void *  b,
void *  sdata 
)
static

Compare two Sidebar entries into their original order - Implements sort_t -.

Definition at line 151 of file sort.c.

152{
153 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
154 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
155
156 // This sort method isn't affected by the reverse flag
157 return (sbe1->mailbox->gen - sbe2->mailbox->gen);
158}
+ Here is the caller graph for this function:

◆ compare_email_shim()

static int compare_email_shim ( const void *  a,
const void *  b,
void *  sdata 
)
static

Helper to sort emails - Implements sort_t -.

Definition at line 64 of file sort.c.

65{
66 const struct Email *ea = *(struct Email const *const *) a;
67 const struct Email *eb = *(struct Email const *const *) b;
68 const struct EmailCompare *cmp = sdata;
69 return mutt_compare_emails(ea, eb, cmp->type, cmp->sort, cmp->sort_aux);
70}
Context for compare_email_shim()
Definition: sort.c:55
short sort_aux
Secondary sort.
Definition: sort.c:58
short sort
Primary sort.
Definition: sort.c:57
enum MailboxType type
Current mailbox type.
Definition: sort.c:56
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_compare_emails()

int mutt_compare_emails ( const struct Email a,
const struct Email b,
enum MailboxType  type,
short  sort,
short  sort_aux 
)

Compare two emails using up to two sort methods -.

Parameters
aFirst email
bSecond email
typeMailbox type
sortPrimary sort to use (generally $sort)
sort_auxSecondary sort (generally $sort_aux or SORT_ORDER)
Return values
<0a precedes b
0a and b are identical (should not happen in practice)
>0b precedes a

Definition at line 324 of file sort.c.

326{
327 sort_mail_t func = get_sort_func(sort & SORT_MASK, type);
328 int rc = func(a, b, (sort & SORT_REVERSE) != 0);
329 if (rc == 0)
330 {
331 func = get_sort_func(sort_aux & SORT_MASK, type);
332 rc = func(a, b, (sort_aux & SORT_REVERSE) != 0);
333 }
334 if (rc == 0)
335 {
336 /* Fallback of last resort to preserve stable order; will only
337 * return 0 if a and b have the same index, which is probably a
338 * bug in the code. */
339 func = compare_order;
340 rc = func(a, b, false);
341 }
342 return rc;
343}
static int compare_order(const struct Email *a, const struct Email *b, bool reverse)
Restore the 'unsorted' order of emails - Implements sort_mail_t -.
Definition: sort.c:190
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:70
static sort_mail_t get_sort_func(enum SortType method, enum MailboxType type)
Get the sort function for a given sort id.
Definition: sort.c:279
int(* sort_mail_t)(const struct Email *a, const struct Email *b, bool reverse)
Definition: sort.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function: