NeoMutt  2025-09-05-43-g177ed6
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_alias (const void *a, const void *b, void *sdata)
 Compare two Aliases by their short names - Implements sort_t -.
 
static int alias_sort_email (const void *a, const void *b, void *sdata)
 Compare two Aliases by their Email Addresses - Implements sort_t -.
 
static int alias_sort_name (const void *a, const void *b, void *sdata)
 Compare two Aliases by their Names - Implements sort_t -.
 
static int alias_sort_unsorted (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_unsorted (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_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 email_sort_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 -.
 
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 -.
 
int binding_sort (const void *a, const void *b, void *sdata)
 Compare two BindingInfo by their keybinding - 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_unsorted (const void *a, const void *b, void *sdata)
 Compare two Sidebar entries by order of creation - Implements sort_t -.
 

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_alias()

static int alias_sort_alias ( 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:511
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_email()

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

Compare two Aliases by their Email 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->mailbox)
100 {
101 if (addr_b && addr_b->mailbox)
102 rc = buf_coll(addr_a->mailbox, addr_b->mailbox);
103 else
104 rc = 1;
105 }
106 else if (addr_b && addr_b->mailbox)
107 {
108 rc = -1;
109 }
110 else if (addr_a && addr_b)
111 {
112 rc = buf_coll(addr_a->personal, addr_b->personal);
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:723
#define TAILQ_FIRST(head)
Definition queue.h:780
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_name()

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

Compare two Aliases by their Names - 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 const struct AddressList *al_a = &av_a->alias->addr;
135 const struct AddressList *al_b = &av_b->alias->addr;
136
137 if (av_a->is_visible != av_b->is_visible)
138 return av_a->is_visible ? -1 : 1;
139
140 if (!av_a->is_visible)
141 return 0;
142
143 int rc;
144 if (al_a == al_b)
145 {
146 rc = 0;
147 }
148 else if (!al_a)
149 {
150 rc = -1;
151 }
152 else if (!al_b)
153 {
154 rc = 1;
155 }
156 else
157 {
158 const struct Address *addr_a = TAILQ_FIRST(al_a);
159 const struct Address *addr_b = TAILQ_FIRST(al_b);
160 if (addr_a && addr_a->personal)
161 {
162 if (addr_b && addr_b->personal)
163 rc = buf_coll(addr_a->personal, addr_b->personal);
164 else
165 rc = 1;
166 }
167 else if (addr_b && addr_b->personal)
168 {
169 rc = -1;
170 }
171 else if (addr_a && addr_b)
172 {
173 rc = buf_coll(addr_a->mailbox, addr_b->mailbox);
174 }
175 else
176 {
177 rc = 0;
178 }
179 }
180
181 return sort_reverse ? -rc : rc;
182}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alias_sort_unsorted()

static int alias_sort_unsorted ( 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 189 of file sort.c.

190{
191 const struct AliasView *av_a = a;
192 const struct AliasView *av_b = b;
193 const bool sort_reverse = *(bool *) sdata;
194
195 if (av_a->is_visible != av_b->is_visible)
196 return av_a->is_visible ? -1 : 1;
197
198 if (!av_a->is_visible)
199 return 0;
200
201 int rc = mutt_numeric_cmp(av_a->orig_seq, av_b->orig_seq);
202 return sort_reverse ? -rc : rc;
203}
#define mutt_numeric_cmp(a, b)
Definition sort.h:26
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 55 of file sort.c.

56{
57 const struct FolderFile *pa = (const struct FolderFile *) a;
58 const struct FolderFile *pb = (const struct FolderFile *) b;
59
60 /* inbox should be sorted ahead of its siblings */
61 int rc = mutt_str_inbox_cmp(pa->name, pb->name);
62 if (rc == 0)
63 rc = mutt_str_coll(pa->name, pb->name);
64
65 return rc;
66}
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:78
char * name
Name of file/dir/mailbox.
Definition lib.h:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ browser_sort_unsorted()

static int browser_sort_unsorted ( 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 73 of file sort.c.

74{
75 const struct FolderFile *pa = (const struct FolderFile *) a;
76 const struct FolderFile *pb = (const struct FolderFile *) b;
77
78 return mutt_numeric_cmp(pa->gen, pb->gen);
79}
int gen
Unique id, used for (un)sorting.
Definition lib.h:105
+ 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 84 of file sort.c.

85{
86 const struct FolderFile *pa = (const struct FolderFile *) a;
87 const struct FolderFile *pb = (const struct FolderFile *) b;
88
89 return mutt_str_coll(pa->desc, pb->desc);
90}
char * desc
Description of mailbox.
Definition lib.h:87
+ 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 95 of file sort.c.

96{
97 const struct FolderFile *pa = (const struct FolderFile *) a;
98 const struct FolderFile *pb = (const struct FolderFile *) b;
99
100 return mutt_numeric_cmp(pa->mtime, pb->mtime);
101}
time_t mtime
Modification time.
Definition lib.h:81
+ 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 106 of file sort.c.

107{
108 const struct FolderFile *pa = (const struct FolderFile *) a;
109 const struct FolderFile *pb = (const struct FolderFile *) b;
110
111 return mutt_numeric_cmp(pa->size, pb->size);
112}
off_t size
File size.
Definition lib.h:80
+ 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 117 of file sort.c.

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

◆ browser_sort_new()

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

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

Definition at line 136 of file sort.c.

137{
138 const struct FolderFile *pa = (const struct FolderFile *) a;
139 const struct FolderFile *pb = (const struct FolderFile *) b;
140
141 int rc = 0;
142 if (pa->has_mailbox && pb->has_mailbox)
144 else if (pa->has_mailbox)
145 rc = -1;
146 else
147 rc = 1;
148
149 return rc;
150}
int msg_unread
number of unread messages
Definition lib.h:91
+ 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 159 of file sort.c.

160{
161 const struct FolderFile *pa = (const struct FolderFile *) a;
162 const struct FolderFile *pb = (const struct FolderFile *) b;
163 const struct CompareData *cd = (struct CompareData *) sdata;
164
165 if ((mutt_str_coll(pa->desc, "../") == 0) || (mutt_str_coll(pa->desc, "..") == 0))
166 return -1;
167 if ((mutt_str_coll(pb->desc, "../") == 0) || (mutt_str_coll(pb->desc, "..") == 0))
168 return 1;
169
170 if (cd->sort_dirs_first)
171 if (S_ISDIR(pa->mode) != S_ISDIR(pb->mode))
172 return S_ISDIR(pa->mode) ? -1 : 1;
173
174 int rc = cd->sort_fn(a, b, NULL);
175
176 return cd->sort_reverse ? -rc : rc;
177}
Private data for browser_sort_helper()
Definition sort.c:46
bool sort_dirs_first
$browser_sort_dirs_first = yes
Definition sort.c:47
sort_t sort_fn
Function to perform $browser_sort.
Definition sort.c:49
bool sort_reverse
$browser_sort contains 'reverse-'
Definition sort.c:48
mode_t mode
File permissions.
Definition lib.h:79
+ 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 927 of file commands.c.

928{
929 return strcmp(*(const char **) a, *(const char **) b);
930}
+ 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 297 of file helpers.c.

298{
299 return strcasecmp(*(const char **) a, *(const char **) b);
300}
+ 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 64 of file subset.c.

65{
66 if (!a || !b)
67 return 0;
68
69 const struct HashElem *hea = *(struct HashElem const *const *) a;
70 const struct HashElem *heb = *(struct HashElem const *const *) b;
71
72 return mutt_istr_cmp(hea->key.strkey, heb->key.strkey);
73}
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition string.c:414
The item stored in a Hash Table.
Definition hash.h:44
union HashKey key
Key representing the data.
Definition hash.h:46
const char * strkey
String key.
Definition hash.h:36
+ 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 37 of file command.c.

38{
39 const struct Command *x = *(const struct Command **) a;
40 const struct Command *y = *(const struct Command **) b;
41
42 return mutt_str_cmp(x->name, y->name);
43}
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition string.c:401
const char * name
Name of the command.
Definition command.h:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ email_sort_shim()

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

Helper to sort emails - Implements sort_t -.

Definition at line 69 of file sort.c.

70{
71 const struct Email *ea = *(struct Email const *const *) a;
72 const struct Email *eb = *(struct Email const *const *) b;
73 const struct EmailCompare *cmp = sdata;
74 return mutt_compare_emails(ea, eb, cmp->type, cmp->sort, cmp->sort_aux);
75}
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:329
Context for email_sort_shim()
Definition sort.c:60
short sort_aux
Secondary sort.
Definition sort.c:63
short sort
Primary sort.
Definition sort.c:62
enum MailboxType type
Current mailbox type.
Definition sort.c:61
The envelope/body of an email.
Definition email.h:39
+ 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 EMAIL_SORT_UNSORTED)
Return values
<0a precedes b
0a and b are identical (should not happen in practice)
>0b precedes a

Definition at line 329 of file sort.c.

331{
332 sort_email_t func = get_sort_func(sort & SORT_MASK, type);
333 int rc = func(a, b, (sort & SORT_REVERSE) != 0);
334 if (rc == 0)
335 {
336 func = get_sort_func(sort_aux & SORT_MASK, type);
337 rc = func(a, b, (sort_aux & SORT_REVERSE) != 0);
338 }
339 if (rc == 0)
340 {
341 /* Fallback of last resort to preserve stable order; will only
342 * return 0 if a and b have the same index, which is probably a
343 * bug in the code. */
344 func = email_sort_unsorted;
345 rc = func(a, b, false);
346 }
347 return rc;
348}
#define SORT_MASK
Mask for the sort id.
Definition sort.h:38
#define SORT_REVERSE
Reverse the order of the sort.
Definition sort.h:39
static sort_email_t get_sort_func(enum EmailSortType method, enum MailboxType type)
Get the sort function for a given sort id.
Definition sort.c:284
int(* sort_email_t)(const struct Email *a, const struct Email *b, bool reverse)
Definition sort.h:47
static int email_sort_unsorted(const struct Email *a, const struct Email *b, bool reverse)
Restore the 'unsorted' order of emails - Implements sort_email_t -.
Definition sort.c:195
+ 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 902 of file imap.c.

903{
904 const struct Email *ea = *(struct Email const *const *) a;
905 const struct Email *eb = *(struct Email const *const *) b;
906
907 const unsigned int ua = imap_edata_get((struct Email *) ea)->uid;
908 const unsigned int ub = imap_edata_get((struct Email *) eb)->uid;
909
910 return mutt_numeric_cmp(ua, ub);
911}
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition edata.c:67
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 54 of file msg_set.c.

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

◆ binding_sort()

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

Compare two BindingInfo by their keybinding - Implements sort_t -.

Definition at line 411 of file lib.c.

412{
413 const struct BindingInfo *x = (const struct BindingInfo *) a;
414 const struct BindingInfo *y = (const struct BindingInfo *) b;
415
416 int rc = mutt_str_cmp(x->a[0], y->a[0]);
417 if (rc != 0)
418 return rc;
419
420 // No binding, sort by function instead
421 return mutt_str_cmp(x->a[1], y->a[1]);
422}
Info about one keybinding.
Definition lib.h:95
const char * a[3]
Array of info.
Definition lib.h:96
+ Here is the call graph for this function:
+ 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 255 of file mailbox.c.

256{
257 const struct MdEmail *ma = *(struct MdEmail **) a;
258 const struct MdEmail *mb = *(struct MdEmail **) b;
259
260 return mutt_numeric_cmp(ma->inode, mb->inode);
261}
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 61 of file message.c.

62{
63 return mutt_numeric_cmp(*((const char *) a), *((const char *) b));
64}
+ 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 494 of file mh.c.

495{
496 struct MhEmail const *pa = *(struct MhEmail const *const *) a;
497 struct MhEmail const *pb = *(struct MhEmail const *const *) b;
498 return mutt_str_cmp(pa->email->path, pb->email->path);
499}
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) && !mutt_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:37
#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:455
+ 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 748 of file mutt_thread.c.

749{
750 const struct MuttThread *ta = *(struct MuttThread const *const *) a;
751 const struct MuttThread *tb = *(struct MuttThread const *const *) b;
752 const struct ThreadsContext *tctx = sdata;
753 ASSERT(ta->parent == tb->parent);
754
755 /* If c_sort ties, remember we are building the thread array in
756 * reverse from the index the mails had in the mailbox. */
757 struct Mailbox *m = tctx->mailbox_view->mailbox;
758 const enum MailboxType mtype = mx_type(m);
759 if (ta->parent)
760 {
761 return mutt_compare_emails(ta->sort_aux_key, tb->sort_aux_key, mtype,
763 }
764 else
765 {
768 }
769}
MailboxType
Supported mailbox formats.
Definition mailbox.h:41
@ EMAIL_SORT_UNSORTED
Sort by the order the messages appear in the mailbox.
Definition sort.h:64
enum MailboxType mx_type(struct Mailbox *m)
Return the type of the Mailbox.
Definition mx.c:1801
#define ASSERT(COND)
Definition signal2.h:60
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:42
struct MailboxView * mailbox_view
Current mailbox.
Definition mutt_thread.h:43
enum EmailSortType c_sort
Last sort method.
Definition mutt_thread.h:46
enum EmailSortType c_sort_aux
Last sort_aux 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 43 of file sort_gpgme.c.

44{
45 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
46 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
47 const bool sort_reverse = *(bool *) sdata;
48
49 int rc = mutt_istr_cmp(s->uid, t->uid);
50 if (rc != 0)
51 goto done;
52
54
55done:
56 return sort_reverse ? -rc : rc;
57}
const char * crypt_fpr_or_lkeyid(struct CryptKeyInfo *k)
Find the fingerprint of a key.
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 62 of file sort_gpgme.c.

63{
64 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
65 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
66 const bool sort_reverse = *(bool *) sdata;
67
69 if (rc != 0)
70 goto done;
71
72 rc = mutt_istr_cmp(s->uid, t->uid);
73
74done:
75 return sort_reverse ? -rc : rc;
76}
+ 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 81 of file sort_gpgme.c.

82{
83 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
84 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
85 const bool sort_reverse = *(bool *) sdata;
86
87 unsigned long ts = 0;
88 unsigned long tt = 0;
89 int rc = 0;
90
91 if (s->kobj->subkeys && (s->kobj->subkeys->timestamp > 0))
92 ts = s->kobj->subkeys->timestamp;
93 if (t->kobj->subkeys && (t->kobj->subkeys->timestamp > 0))
94 tt = t->kobj->subkeys->timestamp;
95
96 if (ts > tt)
97 {
98 rc = 1;
99 goto done;
100 }
101
102 if (ts < tt)
103 {
104 rc = -1;
105 goto done;
106 }
107
108 rc = mutt_istr_cmp(s->uid, t->uid);
109
110done:
111 return sort_reverse ? -rc : rc;
112}
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 117 of file sort_gpgme.c.

118{
119 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
120 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
121 const bool sort_reverse = *(bool *) sdata;
122
123 unsigned long ts = 0;
124 unsigned long tt = 0;
125
127 if (rc != 0)
128 goto done;
129
130 // Note: reversed
132 if (rc != 0)
133 return rc;
134
135 ts = 0;
136 tt = 0;
137 if (s->kobj->subkeys)
138 ts = s->kobj->subkeys->length;
139 if (t->kobj->subkeys)
140 tt = t->kobj->subkeys->length;
141
142 // Note: reversed
143 rc = mutt_numeric_cmp(tt, ts);
144 if (rc != 0)
145 goto done;
146
147 ts = 0;
148 tt = 0;
149 if (s->kobj->subkeys && (s->kobj->subkeys->timestamp > 0))
150 ts = s->kobj->subkeys->timestamp;
151 if (t->kobj->subkeys && (t->kobj->subkeys->timestamp > 0))
152 tt = t->kobj->subkeys->timestamp;
153
154 // Note: reversed
155 rc = mutt_numeric_cmp(tt, ts);
156 if (rc != 0)
157 goto done;
158
159 rc = mutt_istr_cmp(s->uid, t->uid);
160 if (rc != 0)
161 goto done;
162
164
165done:
166 return sort_reverse ? -rc : rc;
167}
#define KEYFLAG_RESTRICTIONS
Definition lib.h:146
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 43 of file sort_pgp.c.

44{
45 struct PgpUid const *s = *(struct PgpUid const *const *) a;
46 struct PgpUid const *t = *(struct PgpUid const *const *) b;
47 const bool sort_reverse = *(bool *) sdata;
48
49 int rc = mutt_istr_cmp(s->addr, t->addr);
50 if (rc != 0)
51 goto done;
52
54
55done:
56 return sort_reverse ? -rc : rc;
57}
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition pgp.c:234
PGP User ID.
Definition pgplib.h:36
struct PgpKeyInfo * parent
Parent key.
Definition pgplib.h:40
char * addr
Definition pgplib.h:37
+ 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 62 of file sort_pgp.c.

63{
64 struct PgpUid const *s = *(struct PgpUid const *const *) a;
65 struct PgpUid const *t = *(struct PgpUid const *const *) b;
66 const bool sort_reverse = *(bool *) sdata;
67
69 if (rc != 0)
70 goto done;
71
72 rc = mutt_istr_cmp(s->addr, t->addr);
73
74done:
75 return sort_reverse ? -rc : rc;
76}
time_t gen_time
Definition pgplib.h:55
+ 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 81 of file sort_pgp.c.

82{
83 struct PgpUid const *s = *(struct PgpUid const *const *) a;
84 struct PgpUid const *t = *(struct PgpUid const *const *) b;
85 const bool sort_reverse = *(bool *) sdata;
86
88 if (rc != 0)
89 goto done;
90
91 rc = mutt_istr_cmp(s->addr, t->addr);
92
93done:
94 return sort_reverse ? -rc : rc;
95}
+ 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 100 of file sort_pgp.c.

101{
102 struct PgpUid const *s = *(struct PgpUid const *const *) a;
103 struct PgpUid const *t = *(struct PgpUid const *const *) b;
104 const bool sort_reverse = *(bool *) sdata;
105
108 if (rc != 0)
109 goto done;
110
111 // Note: reversed
112 rc = mutt_numeric_cmp(t->trust, s->trust);
113 if (rc != 0)
114 goto done;
115
116 // Note: reversed
118 if (rc != 0)
119 goto done;
120
121 // Note: reversed
123 if (rc != 0)
124 goto done;
125
126 rc = mutt_istr_cmp(s->addr, t->addr);
127 if (rc != 0)
128 goto done;
129
131
132done:
133 return sort_reverse ? -rc : rc;
134}
KeyFlags flags
Definition pgplib.h:53
short keylen
Definition pgplib.h:54
short trust
Definition pgplib.h:38
+ 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 44 of file sort.c.

45{
46 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
47 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
48 const struct Mailbox *m1 = sbe1->mailbox;
49 const struct Mailbox *m2 = sbe2->mailbox;
50 const bool sort_reverse = *(bool *) sdata;
51
52 int rc = 0;
53 if (m1->msg_count == m2->msg_count)
55 else
57
58 return sort_reverse ? -rc : rc;
59}
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 64 of file sort.c.

65{
66 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
67 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
68 const struct Mailbox *m1 = sbe1->mailbox;
69 const struct Mailbox *m2 = sbe2->mailbox;
70 const bool sort_reverse = *(bool *) sdata;
71
72 int rc = mutt_str_cmp(m1->name, m2->name);
73 return sort_reverse ? -rc : rc;
74}
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 79 of file sort.c.

80{
81 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
82 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
83 const struct Mailbox *m1 = sbe1->mailbox;
84 const struct Mailbox *m2 = sbe2->mailbox;
85 const bool sort_reverse = *(bool *) sdata;
86
87 int rc = 0;
88 if (m1->msg_flagged == m2->msg_flagged)
90 else
92
93 return sort_reverse ? -rc : rc;
94}
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 99 of file sort.c.

100{
101 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
102 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
103 const struct Mailbox *m1 = sbe1->mailbox;
104 const struct Mailbox *m2 = sbe2->mailbox;
105 const bool sort_reverse = *(bool *) sdata;
106
107 int rc = 0;
109 if (rc == 0)
111
112 return sort_reverse ? -rc : rc;
113}
+ 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 118 of file sort.c.

119{
120 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
121 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
122 const struct Mailbox *m1 = sbe1->mailbox;
123 const struct Mailbox *m2 = sbe2->mailbox;
124 const bool sort_reverse = *(bool *) sdata;
125
126 int rc = 0;
127 if (m1->msg_unread == m2->msg_unread)
129 else
131
132 return sort_reverse ? -rc : rc;
133}
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_unsorted()

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

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

Definition at line 138 of file sort.c.

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