NeoMutt  2025-12-11-177-g48e272
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()

static 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)
Definition sort.h:26
int score
Message score.
Definition email.h:113
+ Here is the caller graph for this function:

◆ email_sort_size()

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

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

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

static 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:583
#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()

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

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

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

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

static 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 252 of file sort.c.

253{
254 int ahas, bhas, result = 0;
255
256 /* As with email_sort_spam, not all messages will have the x-label
257 * property. Blank X-Labels are treated as null in the index
258 * display, so we'll consider them as null for sort, too. */
259 ahas = a->env && a->env->x_label && *(a->env->x_label);
260 bhas = b->env && b->env->x_label && *(b->env->x_label);
261
262 /* First we bias toward a message with a label, if the other does not. */
263 if (ahas && !bhas)
264 return reverse ? 1 : -1;
265 if (!ahas && bhas)
266 return reverse ? -1 : 1;
267
268 /* If neither has a label, use aux sort. */
269 if (!ahas && !bhas)
270 return 0;
271
272 /* If both have a label, we just do a lexical compare. */
273 result = mutt_istr_cmp(a->env->x_label, b->env->x_label);
274 return reverse ? -result : result;
275}
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 2353 of file nntp.c.

2354{
2355 anum_t na = nntp_edata_get((struct Email *) a)->article_num;
2356 anum_t nb = nntp_edata_get((struct Email *) b)->article_num;
2357 int result = (na == nb) ? 0 : (na > nb) ? 1 : -1;
2358 return reverse ? -result : result;
2359}
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: