NeoMutt  2024-04-16-36-g75b6fb
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 -.
 
static int compare_threads (const void *a, const void *b, void *sdata)
 Helper to sort email threads - Implements sort_t -.
 
int mutt_inbox_cmp (const char *a, const char *b)
 Do two folders share the same path and one is an inbox -.
 
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:503
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:724
#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 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_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_inbox_cmp(const char *a, const char *b)
Do two folders share the same path and one is an inbox -.
Definition: muttlib.c:1033
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_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 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_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 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 909 of file commands.c.

910{
911 return strcmp(*(const char **) a, *(const char **) b);
912}
+ 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:406
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:393
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 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 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:

◆ 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 751 of file mutt_thread.c.

752{
753 const struct MuttThread *ta = *(struct MuttThread const *const *) a;
754 const struct MuttThread *tb = *(struct MuttThread const *const *) b;
755 const struct ThreadsContext *tctx = sdata;
756 assert(ta->parent == tb->parent);
757
758 /* If c_sort ties, remember we are building the thread array in
759 * reverse from the index the mails had in the mailbox. */
760 struct Mailbox *m = tctx->mailbox_view->mailbox;
761 const enum MailboxType mtype = mx_type(m);
762 if (ta->parent)
763 {
764 return mutt_compare_emails(ta->sort_aux_key, tb->sort_aux_key, mtype,
766 }
767 else
768 {
771 }
772}
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:1794
@ 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:

◆ mutt_inbox_cmp()

int mutt_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". If 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 no paths match the requirements, the two paths are considered equivalent and this function returns 0.

Examples:

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

Definition at line 1033 of file muttlib.c.

1034{
1035 /* fast-track in case the paths have been mutt_pretty_mailbox'ified */
1036 if ((a[0] == '+') && (b[0] == '+'))
1037 {
1038 return mutt_istr_equal(a + 1, "inbox") ? -1 :
1039 mutt_istr_equal(b + 1, "inbox") ? 1 :
1040 0;
1041 }
1042
1043 const char *a_end = strrchr(a, '/');
1044 const char *b_end = strrchr(b, '/');
1045
1046 /* If one path contains a '/', but not the other */
1047 if ((!a_end) ^ (!b_end))
1048 return 0;
1049
1050 /* If neither path contains a '/' */
1051 if (!a_end)
1052 return 0;
1053
1054 /* Compare the subpaths */
1055 size_t a_len = a_end - a;
1056 size_t b_len = b_end - b;
1057 size_t min = MIN(a_len, b_len);
1058 int same = (a[min] == '/') && (b[min] == '/') && (a[min + 1] != '\0') &&
1059 (b[min + 1] != '\0') && mutt_istrn_equal(a, b, min);
1060
1061 if (!same)
1062 return 0;
1063
1064 if (mutt_istr_equal(&a[min + 1], "inbox"))
1065 return -1;
1066
1067 if (mutt_istr_equal(&b[min + 1], "inbox"))
1068 return 1;
1069
1070 return 0;
1071}
#define MIN(a, b)
Definition: memory.h:32
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:666
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:447
+ 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 110 of file dlg_gpgme.c.

111{
112 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
113 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
114 const bool sort_reverse = *(bool *) sdata;
115
116 int rc = mutt_istr_cmp(s->uid, t->uid);
117 if (rc != 0)
118 goto done;
119
121
122done:
123 return sort_reverse ? -rc : rc;
124}
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 129 of file dlg_gpgme.c.

130{
131 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
132 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
133 const bool sort_reverse = *(bool *) sdata;
134
136 if (rc != 0)
137 goto done;
138
139 rc = mutt_istr_cmp(s->uid, t->uid);
140
141done:
142 return sort_reverse ? -rc : rc;
143}
+ 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 148 of file dlg_gpgme.c.

149{
150 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
151 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
152 const bool sort_reverse = *(bool *) sdata;
153
154 unsigned long ts = 0;
155 unsigned long tt = 0;
156 int rc = 0;
157
158 if (s->kobj->subkeys && (s->kobj->subkeys->timestamp > 0))
159 ts = s->kobj->subkeys->timestamp;
160 if (t->kobj->subkeys && (t->kobj->subkeys->timestamp > 0))
161 tt = t->kobj->subkeys->timestamp;
162
163 if (ts > tt)
164 {
165 rc = 1;
166 goto done;
167 }
168
169 if (ts < tt)
170 {
171 rc = -1;
172 goto done;
173 }
174
175 rc = mutt_istr_cmp(s->uid, t->uid);
176
177done:
178 return sort_reverse ? -rc : rc;
179}
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 184 of file dlg_gpgme.c.

185{
186 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
187 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
188 const bool sort_reverse = *(bool *) sdata;
189
190 unsigned long ts = 0;
191 unsigned long tt = 0;
192
194 if (rc != 0)
195 goto done;
196
197 // Note: reversed
199 if (rc != 0)
200 return rc;
201
202 ts = 0;
203 tt = 0;
204 if (s->kobj->subkeys)
205 ts = s->kobj->subkeys->length;
206 if (t->kobj->subkeys)
207 tt = t->kobj->subkeys->length;
208
209 // Note: reversed
210 rc = mutt_numeric_cmp(tt, ts);
211 if (rc != 0)
212 goto done;
213
214 ts = 0;
215 tt = 0;
216 if (s->kobj->subkeys && (s->kobj->subkeys->timestamp > 0))
217 ts = s->kobj->subkeys->timestamp;
218 if (t->kobj->subkeys && (t->kobj->subkeys->timestamp > 0))
219 tt = t->kobj->subkeys->timestamp;
220
221 // Note: reversed
222 rc = mutt_numeric_cmp(tt, ts);
223 if (rc != 0)
224 goto done;
225
226 rc = mutt_istr_cmp(s->uid, t->uid);
227 if (rc != 0)
228 goto done;
229
231
232done:
233 return sort_reverse ? -rc : rc;
234}
#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 111 of file dlg_pgp.c.

112{
113 struct PgpUid const *s = *(struct PgpUid const *const *) a;
114 struct PgpUid const *t = *(struct PgpUid const *const *) b;
115 const bool sort_reverse = *(bool *) sdata;
116
117 int rc = mutt_istr_cmp(s->addr, t->addr);
118 if (rc != 0)
119 goto done;
120
122
123done:
124 return sort_reverse ? -rc : rc;
125}
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 130 of file dlg_pgp.c.

131{
132 struct PgpUid const *s = *(struct PgpUid const *const *) a;
133 struct PgpUid const *t = *(struct PgpUid const *const *) b;
134 const bool sort_reverse = *(bool *) sdata;
135
137 if (rc != 0)
138 goto done;
139
140 rc = mutt_istr_cmp(s->addr, t->addr);
141
142done:
143 return sort_reverse ? -rc : rc;
144}
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 149 of file dlg_pgp.c.

150{
151 struct PgpUid const *s = *(struct PgpUid const *const *) a;
152 struct PgpUid const *t = *(struct PgpUid const *const *) b;
153 const bool sort_reverse = *(bool *) sdata;
154
156 if (rc != 0)
157 goto done;
158
159 rc = mutt_istr_cmp(s->addr, t->addr);
160
161done:
162 return sort_reverse ? -rc : rc;
163}
+ 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 168 of file dlg_pgp.c.

169{
170 struct PgpUid const *s = *(struct PgpUid const *const *) a;
171 struct PgpUid const *t = *(struct PgpUid const *const *) b;
172 const bool sort_reverse = *(bool *) sdata;
173
176 if (rc != 0)
177 goto done;
178
179 // Note: reversed
180 rc = mutt_numeric_cmp(t->trust, s->trust);
181 if (rc != 0)
182 goto done;
183
184 // Note: reversed
186 if (rc != 0)
187 goto done;
188
189 // Note: reversed
191 if (rc != 0)
192 goto done;
193
194 rc = mutt_istr_cmp(s->addr, t->addr);
195 if (rc != 0)
196 goto done;
197
199
200done:
201 return sort_reverse ? -rc : rc;
202}
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 43 of file sort.c.

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

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

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

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

118{
119 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
120 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
121 const struct Mailbox *m1 = sbe1->mailbox;
122 const struct Mailbox *m2 = sbe2->mailbox;
123 const bool sort_reverse = *(bool *) sdata;
124
125 int rc = 0;
126 if (m1->msg_unread == m2->msg_unread)
128 else
130
131 return sort_reverse ? -rc : rc;
132}
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 137 of file sort.c.

138{
139 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
140 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
141 const struct Mailbox *m1 = sbe1->mailbox;
142 const struct Mailbox *m2 = sbe2->mailbox;
143 const bool sort_reverse = *(bool *) sdata;
144
145 int rc = mutt_numeric_cmp(m1->gen, m2->gen);
146 return sort_reverse ? -rc : rc;
147}
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 152 of file sort.c.

153{
154 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
155 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
156
157 // This sort method isn't affected by the reverse flag
158 return (sbe1->mailbox->gen - sbe2->mailbox->gen);
159}
+ 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: