NeoMutt
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_flags (const void *a, const void *b, void *sdata)
 Compare two flag characters - 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 mh_sort_path (const void *a, const void *b, void *sdata)
 Compare two Maildirs 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 44 of file sort.c.

45{
46 const struct AliasView *av_a = a;
47 const struct AliasView *av_b = b;
48 const bool sort_reverse = *(bool *) sdata;
49
50 if (av_a->is_visible != av_b->is_visible)
51 return av_a->is_visible ? -1 : 1;
52
53 if (!av_a->is_visible)
54 return 0;
55
56 int rc = mutt_str_coll(av_a->alias->name, av_b->alias->name);
57 return sort_reverse ? -rc : rc;
58}
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:581
GUI data wrapping an Alias.
Definition: gui.h:36
bool is_visible
Is visible?
Definition: gui.h:43
struct Alias * alias
Alias.
Definition: gui.h:44
char * name
Short name.
Definition: alias.h:35
+ 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 65 of file sort.c.

66{
67 const struct AliasView *av_a = a;
68 const struct AliasView *av_b = b;
69 const bool sort_reverse = *(bool *) sdata;
70
71 const struct AddressList *al_a = &av_a->alias->addr;
72 const struct AddressList *al_b = &av_b->alias->addr;
73
74 if (av_a->is_visible != av_b->is_visible)
75 return av_a->is_visible ? -1 : 1;
76
77 if (!av_a->is_visible)
78 return 0;
79
80 int rc;
81 if (al_a == al_b)
82 {
83 rc = 0;
84 }
85 else if (!al_a)
86 {
87 rc = -1;
88 }
89 else if (!al_b)
90 {
91 rc = 1;
92 }
93 else
94 {
95 const struct Address *addr_a = TAILQ_FIRST(al_a);
96 const struct Address *addr_b = TAILQ_FIRST(al_b);
97 if (addr_a && addr_a->personal)
98 {
99 if (addr_b && addr_b->personal)
100 rc = buf_coll(addr_a->personal, addr_b->personal);
101 else
102 rc = 1;
103 }
104 else if (addr_b && addr_b->personal)
105 {
106 rc = -1;
107 }
108 else if (addr_a && addr_b)
109 {
110 rc = buf_coll(addr_a->mailbox, addr_b->mailbox);
111 }
112 else
113 {
114 rc = 0;
115 }
116 }
117
118 return sort_reverse ? -rc : rc;
119}
int buf_coll(const struct Buffer *a, const struct Buffer *b)
Collate two strings (compare using locale)
Definition: buffer.c:690
#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:36
+ 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 126 of file sort.c.

127{
128 const struct AliasView *av_a = a;
129 const struct AliasView *av_b = b;
130 const bool sort_reverse = *(bool *) sdata;
131
132 if (av_a->is_visible != av_b->is_visible)
133 return av_a->is_visible ? -1 : 1;
134
135 if (!av_a->is_visible)
136 return 0;
137
138 int rc = mutt_numeric_cmp(av_a->orig_seq, av_b->orig_seq);
139 return sort_reverse ? -rc : rc;
140}
#define mutt_numeric_cmp(a, b)
Definition: sort.h:34
int orig_seq
Sequence in alias config file.
Definition: gui.h:38
+ 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_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_inbox_cmp(const char *a, const char *b)
Do two folders share the same path and one is an inbox -.
Definition: muttlib.c:1583
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 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:109
+ 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: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 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: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 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: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 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:100
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 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: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 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: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 884 of file commands.c.

885{
886 return strcmp(*(const char **) a, *(const char **) b);
887}
+ 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 296 of file helpers.c.

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

55{
56 if (!a || !b)
57 return 0;
58
59 const struct HashElem *hea = *(struct HashElem const *const *) a;
60 const struct HashElem *heb = *(struct HashElem const *const *) b;
61
62 return mutt_istr_cmp(hea->key.strkey, heb->key.strkey);
63}
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:484
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 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:471
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 892 of file imap.c.

893{
894 const struct Email *ea = *(struct Email const *const *) a;
895 const struct Email *eb = *(struct Email const *const *) b;
896
897 const unsigned int ua = imap_edata_get((struct Email *) ea)->uid;
898 const unsigned int ub = imap_edata_get((struct Email *) eb)->uid;
899
900 return mutt_numeric_cmp(ua, ub);
901}
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:66
The envelope/body of an email.
Definition: email.h:37
unsigned int uid
32-bit Message UID
Definition: edata.h:44
+ 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:

◆ 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 195 of file maildir.c.

196{
197 return mutt_numeric_cmp(*((const char *) a), *((const char *) b));
198}
+ 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 514 of file maildir.c.

515{
516 const struct MdEmail *ma = *(struct MdEmail **) a;
517 const struct MdEmail *mb = *(struct MdEmail **) b;
518
519 return mutt_numeric_cmp(ma->inode, mb->inode);
520}
A Maildir Email helper.
Definition: mdemail.h:34
ino_t inode
Definition: mdemail.h:38
+ 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 Maildirs by path - Implements sort_t -.

Definition at line 545 of file mh.c.

546{
547 struct MdEmail const *pa = *(struct MdEmail const *const *) a;
548 struct MdEmail const *pb = *(struct MdEmail const *const *) b;
549 return mutt_str_cmp(pa->email->path, pb->email->path);
550}
char * path
Path of Email (for local Mailboxes)
Definition: email.h:68
struct Email * email
Definition: mdemail.h:35
+ 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 747 of file mutt_thread.c.

748{
749 const struct MuttThread *ta = *(struct MuttThread const *const *) a;
750 const struct MuttThread *tb = *(struct MuttThread const *const *) b;
751 const struct ThreadsContext *tctx = sdata;
752 assert(ta->parent == tb->parent);
753
754 /* If c_sort ties, remember we are building the thread array in
755 * reverse from the index the mails had in the mailbox. */
756 struct Mailbox *m = tctx->mailbox_view->mailbox;
757 const enum MailboxType mtype = mx_type(m);
758 if (ta->parent)
759 {
760 return mutt_compare_emails(ta->sort_aux_key, tb->sort_aux_key, mtype,
762 }
763 else
764 {
767 }
768}
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:326
MailboxType
Supported mailbox formats.
Definition: mailbox.h:41
enum MailboxType mx_type(struct Mailbox *m)
Return the type of the Mailbox.
Definition: mx.c:1857
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:44
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:75
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:50
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:41
struct MailboxView * mailbox_view
Current mailbox.
Definition: mutt_thread.h:42
enum SortType c_sort_aux
Last sort_aux method.
Definition: mutt_thread.h:46
enum SortType c_sort
Last sort method.
Definition: mutt_thread.h:45
+ 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 1583 of file muttlib.c.

1584{
1585 /* fast-track in case the paths have been mutt_pretty_mailbox'ified */
1586 if ((a[0] == '+') && (b[0] == '+'))
1587 {
1588 return mutt_istr_equal(a + 1, "inbox") ? -1 :
1589 mutt_istr_equal(b + 1, "inbox") ? 1 :
1590 0;
1591 }
1592
1593 const char *a_end = strrchr(a, '/');
1594 const char *b_end = strrchr(b, '/');
1595
1596 /* If one path contains a '/', but not the other */
1597 if ((!a_end) ^ (!b_end))
1598 return 0;
1599
1600 /* If neither path contains a '/' */
1601 if (!a_end)
1602 return 0;
1603
1604 /* Compare the subpaths */
1605 size_t a_len = a_end - a;
1606 size_t b_len = b_end - b;
1607 size_t min = MIN(a_len, b_len);
1608 int same = (a[min] == '/') && (b[min] == '/') && (a[min + 1] != '\0') &&
1609 (b[min + 1] != '\0') && mutt_istrn_equal(a, b, min);
1610
1611 if (!same)
1612 return 0;
1613
1614 if (mutt_istr_equal(&a[min + 1], "inbox"))
1615 return -1;
1616
1617 if (mutt_istr_equal(&b[min + 1], "inbox"))
1618 return 1;
1619
1620 return 0;
1621}
#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:810
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:525
+ 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 115 of file dlg_gpgme.c.

116{
117 struct CryptKeyInfo *s = *(struct CryptKeyInfo **) a;
118 struct CryptKeyInfo *t = *(struct CryptKeyInfo **) b;
119 const bool sort_reverse = *(bool *) sdata;
120
121 int rc = mutt_istr_cmp(s->uid, t->uid);
122 if (rc != 0)
123 goto done;
124
126
127done:
128 return sort_reverse ? -rc : rc;
129}
const char * crypt_fpr_or_lkeyid(struct CryptKeyInfo *k)
Find the fingerprint of a key.
Definition: crypt_gpgme.c:213
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 134 of file dlg_gpgme.c.

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

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

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

119{
120 struct PgpUid const *s = *(struct PgpUid const *const *) a;
121 struct PgpUid const *t = *(struct PgpUid const *const *) b;
122 const bool sort_reverse = *(bool *) sdata;
123
124 int rc = mutt_istr_cmp(s->addr, t->addr);
125 if (rc != 0)
126 goto done;
127
129
130done:
131 return sort_reverse ? -rc : rc;
132}
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:235
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 137 of file dlg_pgp.c.

138{
139 struct PgpUid const *s = *(struct PgpUid const *const *) a;
140 struct PgpUid const *t = *(struct PgpUid const *const *) b;
141 const bool sort_reverse = *(bool *) sdata;
142
144 if (rc != 0)
145 goto done;
146
147 rc = mutt_istr_cmp(s->addr, t->addr);
148
149done:
150 return sort_reverse ? -rc : rc;
151}
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 156 of file dlg_pgp.c.

157{
158 struct PgpUid const *s = *(struct PgpUid const *const *) a;
159 struct PgpUid const *t = *(struct PgpUid const *const *) b;
160 const bool sort_reverse = *(bool *) sdata;
161
163 if (rc != 0)
164 goto done;
165
166 rc = mutt_istr_cmp(s->addr, t->addr);
167
168done:
169 return sort_reverse ? -rc : rc;
170}
+ 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 175 of file dlg_pgp.c.

176{
177 struct PgpUid const *s = *(struct PgpUid const *const *) a;
178 struct PgpUid const *t = *(struct PgpUid const *const *) b;
179 const bool sort_reverse = *(bool *) sdata;
180
183 if (rc != 0)
184 goto done;
185
186 // Note: reversed
187 rc = mutt_numeric_cmp(t->trust, s->trust);
188 if (rc != 0)
189 goto done;
190
191 // Note: reversed
193 if (rc != 0)
194 goto done;
195
196 // Note: reversed
198 if (rc != 0)
199 goto done;
200
201 rc = mutt_istr_cmp(s->addr, t->addr);
202 if (rc != 0)
203 goto done;
204
206
207done:
208 return sort_reverse ? -rc : rc;
209}
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 41 of file sort.c.

42{
43 const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
44 const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
45 const struct Mailbox *m1 = sbe1->mailbox;
46 const struct Mailbox *m2 = sbe2->mailbox;
47 const bool sort_reverse = *(bool *) sdata;
48
49 int rc = 0;
50 if (m1->msg_count == m2->msg_count)
52 else
54
55 return sort_reverse ? -rc : rc;
56}
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:210
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 61 of file sort.c.

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

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

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

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

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

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

328{
329 sort_mail_t func = get_sort_func(sort & SORT_MASK, type);
330 int rc = func(a, b, (sort & SORT_REVERSE) != 0);
331 if (rc == 0)
332 {
333 func = get_sort_func(sort_aux & SORT_MASK, type);
334 rc = func(a, b, (sort_aux & SORT_REVERSE) != 0);
335 }
336 if (rc == 0)
337 {
338 /* Fallback of last resort to preserve stable order; will only
339 * return 0 if a and b have the same index, which is probably a
340 * bug in the code. */
341 func = compare_order;
342 rc = func(a, b, false);
343 }
344 return rc;
345}
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:74
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:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function: