NeoMutt  2025-12-11-1009-ga75d9e
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Email Sorting API

Prototype for an email comparison function. More...

Functions

static int email_sort_score (const struct Email *a, const struct Email *b, bool reverse)
 Compare two emails using their scores - Implements sort_email_t -.
static int email_sort_size (const struct Email *a, const struct Email *b, bool reverse)
 Compare the size of two emails - Implements sort_email_t -.
static int email_sort_date (const struct Email *a, const struct Email *b, bool reverse)
 Compare the sent date of two emails - Implements sort_email_t -.
static int email_sort_subject (const struct Email *a, const struct Email *b, bool reverse)
 Compare the subject of two emails - Implements sort_email_t -.
static int email_sort_to (const struct Email *a, const struct Email *b, bool reverse)
 Compare the 'to' fields of two emails - Implements sort_email_t -.
static int email_sort_from (const struct Email *a, const struct Email *b, bool reverse)
 Compare the 'from' fields of two emails - Implements sort_email_t -.
static int email_sort_date_received (const struct Email *a, const struct Email *b, bool reverse)
 Compare the date received of two emails - Implements sort_email_t -.
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 -.
static int email_sort_spam (const struct Email *a, const struct Email *b, bool reverse)
 Compare the spam values of two emails - Implements sort_email_t -.
static int email_sort_label (const struct Email *a, const struct Email *b, bool reverse)
 Compare the labels of two emails - Implements sort_email_t -.
int nntp_sort_unsorted (const struct Email *a, const struct Email *b, bool reverse)
 Restore the 'unsorted' order of emails - Implements sort_email_t -.

Detailed Description

Prototype for an email comparison function.

Parameters
aFirst item
bSecond item
reversetrue if this is a reverse sort (smaller b precedes a)
Return values
<0a precedes b
0a and b are identical
>0b precedes a

Function Documentation

◆ email_sort_score()

int email_sort_score ( const struct Email * a,
const struct Email * b,
bool reverse )
static

Compare two emails using their scores - Implements sort_email_t -.

Definition at line 79 of file sort.c.

80{
81 int result = mutt_numeric_cmp(b->score, a->score); /* note that this is reverse */
82 return reverse ? -result : result;
83}
#define mutt_numeric_cmp(a, b)
Compare two numbers, return -1, 0, or 1.
Definition sort.h:27
int score
Message score.
Definition email.h:113
Here is the caller graph for this function:

◆ email_sort_size()

int email_sort_size ( const struct Email * a,
const struct Email * b,
bool reverse )
static

Compare the size of two emails - Implements sort_email_t -.

Definition at line 88 of file sort.c.

89{
90 int result = mutt_numeric_cmp(a->body->length, b->body->length);
91 return reverse ? -result : result;
92}
LOFF_T length
length (in bytes) of attachment
Definition body.h:53
struct Body * body
List of MIME parts.
Definition email.h:69
Here is the caller graph for this function:

◆ email_sort_date()

int email_sort_date ( const struct Email * a,
const struct Email * b,
bool reverse )
static

Compare the sent date of two emails - Implements sort_email_t -.

Definition at line 97 of file sort.c.

98{
99 int result = mutt_numeric_cmp(a->date_sent, b->date_sent);
100 return reverse ? -result : result;
101}
time_t date_sent
Time when the message was sent (UTC).
Definition email.h:60
Here is the caller graph for this function:

◆ email_sort_subject()

int email_sort_subject ( const struct Email * a,
const struct Email * b,
bool reverse )
static

Compare the subject of two emails - Implements sort_email_t -.

Definition at line 106 of file sort.c.

107{
108 int rc;
109
110 if (!a->env->real_subj)
111 {
112 if (!b->env->real_subj)
113 rc = email_sort_date(a, b, false);
114 else
115 rc = -1;
116 }
117 else if (!b->env->real_subj)
118 {
119 rc = 1;
120 }
121 else
122 {
123 rc = mutt_istr_cmp(a->env->real_subj, b->env->real_subj);
124 }
125 return reverse ? -rc : rc;
126}
static int email_sort_date(const struct Email *a, const struct Email *b, bool reverse)
Compare the sent date of two emails - Implements sort_email_t -.
Definition sort.c:97
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition string.c:416
struct Envelope * env
Envelope information.
Definition email.h:68
char *const real_subj
Offset of the real subject.
Definition envelope.h:71
Here is the call graph for this function:
Here is the caller graph for this function:

◆ email_sort_to()

int email_sort_to ( const struct Email * a,
const struct Email * b,
bool reverse )
static

Compare the 'to' fields of two emails - Implements sort_email_t -.

Definition at line 159 of file sort.c.

160{
161 char fa[128] = { 0 };
162
163 mutt_str_copy(fa, mutt_get_name(TAILQ_FIRST(&a->env->to)), sizeof(fa));
164 const char *fb = mutt_get_name(TAILQ_FIRST(&b->env->to));
165 int result = mutt_istrn_cmp(fa, fb, sizeof(fa));
166 return reverse ? -result : result;
167}
const char * mutt_get_name(const struct Address *a)
Pick the best name to display from an address.
Definition sort.c:138
int mutt_istrn_cmp(const char *a, const char *b, size_t num)
Compare two strings ignoring case (to a maximum), safely.
Definition string.c:443
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination).
Definition string.c:587
#define TAILQ_FIRST(head)
Definition queue.h:780
struct AddressList to
Email's 'To' list.
Definition envelope.h:60
Here is the call graph for this function:
Here is the caller graph for this function:

◆ email_sort_from()

int email_sort_from ( const struct Email * a,
const struct Email * b,
bool reverse )
static

Compare the 'from' fields of two emails - Implements sort_email_t -.

Definition at line 172 of file sort.c.

173{
174 char fa[128] = { 0 };
175
176 mutt_str_copy(fa, mutt_get_name(TAILQ_FIRST(&a->env->from)), sizeof(fa));
177 const char *fb = mutt_get_name(TAILQ_FIRST(&b->env->from));
178 int result = mutt_istrn_cmp(fa, fb, sizeof(fa));
179 return reverse ? -result : result;
180}
struct AddressList from
Email's 'From' list.
Definition envelope.h:59
Here is the call graph for this function:
Here is the caller graph for this function:

◆ email_sort_date_received()

int email_sort_date_received ( const struct Email * a,
const struct Email * b,
bool reverse )
static

Compare the date received of two emails - Implements sort_email_t -.

Definition at line 185 of file sort.c.

186{
187 int result = mutt_numeric_cmp(a->received, b->received);
188 return reverse ? -result : result;
189}
time_t received
Time when the message was placed in the mailbox.
Definition email.h:61
Here is the caller graph for this function:

◆ email_sort_unsorted()

int email_sort_unsorted ( const struct Email * a,
const struct Email * b,
bool reverse )
static

Restore the 'unsorted' order of emails - Implements sort_email_t -.

Definition at line 194 of file sort.c.

195{
196 int result = mutt_numeric_cmp(a->index, b->index);
197 return reverse ? -result : result;
198}
int index
The absolute (unsorted) message number.
Definition email.h:110
Here is the caller graph for this function:

◆ email_sort_spam()

int email_sort_spam ( const struct Email * a,
const struct Email * b,
bool reverse )
static

Compare the spam values of two emails - Implements sort_email_t -.

Definition at line 203 of file sort.c.

204{
205 char *aptr = NULL;
206 char *bptr = NULL;
207 int ahas;
208 int bhas;
209 int result = 0;
210 double difference;
211
212 /* Firstly, require spam attributes for both msgs */
213 /* to compare. Determine which msgs have one. */
214 ahas = a->env && !buf_is_empty(&a->env->spam);
215 bhas = b->env && !buf_is_empty(&b->env->spam);
216
217 /* If one msg has spam attr but other does not, sort the one with first. */
218 if (ahas && !bhas)
219 return reverse ? -1 : 1;
220 if (!ahas && bhas)
221 return reverse ? 1 : -1;
222
223 /* Else, if neither has a spam attr, presume equality. Fall back on aux. */
224 if (!ahas && !bhas)
225 return 0;
226
227 /* Both have spam attrs. */
228
229 /* preliminary numeric examination */
230 difference = (strtod(a->env->spam.data, &aptr) - strtod(b->env->spam.data, &bptr));
231
232 /* map double into comparison (-1, 0, or 1) */
233 result = ((difference < 0.0) ? -1 : (difference > 0.0) ? 1 : 0);
234
235 /* If either aptr or bptr is equal to data, there is no numeric */
236 /* value for that spam attribute. In this case, compare lexically. */
237 if ((aptr == a->env->spam.data) || (bptr == b->env->spam.data))
238 {
239 result = mutt_str_cmp(aptr, bptr);
240 return reverse ? -result : result;
241 }
242
243 /* Otherwise, we have numeric value for both attrs. If these values */
244 /* are equal, then we first fall back upon string comparison, then */
245 /* upon auxiliary sort. */
246 if (result == 0)
247 result = mutt_str_cmp(aptr, bptr);
248 return reverse ? -result : result;
249}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:298
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition string.c:403
char * data
Pointer to data.
Definition buffer.h:37
struct Buffer spam
Spam header.
Definition envelope.h:82
Here is the call graph for this function:
Here is the caller graph for this function:

◆ email_sort_label()

int email_sort_label ( const struct Email * a,
const struct Email * b,
bool reverse )
static

Compare the labels of two emails - Implements sort_email_t -.

Definition at line 254 of file sort.c.

255{
256 int ahas;
257 int bhas;
258 int result = 0;
259
260 /* As with email_sort_spam, not all messages will have the x-label
261 * property. Blank X-Labels are treated as null in the index
262 * display, so we'll consider them as null for sort, too. */
263 ahas = a->env && a->env->x_label && *(a->env->x_label);
264 bhas = b->env && b->env->x_label && *(b->env->x_label);
265
266 /* First we bias toward a message with a label, if the other does not. */
267 if (ahas && !bhas)
268 return reverse ? 1 : -1;
269 if (!ahas && bhas)
270 return reverse ? -1 : 1;
271
272 /* If neither has a label, use aux sort. */
273 if (!ahas && !bhas)
274 return 0;
275
276 /* If both have a label, we just do a lexical compare. */
277 result = mutt_istr_cmp(a->env->x_label, b->env->x_label);
278 return reverse ? -result : result;
279}
char * x_label
X-Label.
Definition envelope.h:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nntp_sort_unsorted()

int nntp_sort_unsorted ( const struct Email * a,
const struct Email * b,
bool reverse )

Restore the 'unsorted' order of emails - Implements sort_email_t -.

Definition at line 2364 of file nntp.c.

2365{
2366 anum_t na = nntp_edata_get((struct Email *) a)->article_num;
2367 anum_t nb = nntp_edata_get((struct Email *) b)->article_num;
2368 int result = (na == nb) ? 0 : (na > nb) ? 1 : -1;
2369 return reverse ? -result : result;
2370}
struct NntpEmailData * nntp_edata_get(struct Email *e)
Get the private data for this Email.
Definition edata.c:60
#define anum_t
Definition lib.h:63
The envelope/body of an email.
Definition email.h:39
anum_t article_num
NNTP article number.
Definition edata.h:36
Here is the call graph for this function:
Here is the caller graph for this function: