NeoMutt  2025-01-09-156-g99fdbd
Teaching an old dog new tricks
DOXYGEN
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 80 of file sort.c.

81{
82 int result = mutt_numeric_cmp(b->score, a->score); /* note that this is reverse */
83 return reverse ? -result : result;
84}
#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 89 of file sort.c.

90{
91 int result = mutt_numeric_cmp(a->body->length, b->body->length);
92 return reverse ? -result : result;
93}
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 98 of file sort.c.

99{
100 int result = mutt_numeric_cmp(a->date_sent, b->date_sent);
101 return reverse ? -result : result;
102}
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 107 of file sort.c.

108{
109 int rc;
110
111 if (!a->env->real_subj)
112 {
113 if (!b->env->real_subj)
114 rc = email_sort_date(a, b, false);
115 else
116 rc = -1;
117 }
118 else if (!b->env->real_subj)
119 {
120 rc = 1;
121 }
122 else
123 {
124 rc = mutt_istr_cmp(a->env->real_subj, b->env->real_subj);
125 }
126 return reverse ? -rc : rc;
127}
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:98
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:413
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 160 of file sort.c.

161{
162 char fa[128] = { 0 };
163
164 mutt_str_copy(fa, mutt_get_name(TAILQ_FIRST(&a->env->to)), sizeof(fa));
165 const char *fb = mutt_get_name(TAILQ_FIRST(&b->env->to));
166 int result = mutt_istrn_cmp(fa, fb, sizeof(fa));
167 return reverse ? -result : result;
168}
const char * mutt_get_name(const struct Address *a)
Pick the best name to display from an address.
Definition: sort.c:139
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:440
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:582
#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 173 of file sort.c.

174{
175 char fa[128] = { 0 };
176
177 mutt_str_copy(fa, mutt_get_name(TAILQ_FIRST(&a->env->from)), sizeof(fa));
178 const char *fb = mutt_get_name(TAILQ_FIRST(&b->env->from));
179 int result = mutt_istrn_cmp(fa, fb, sizeof(fa));
180 return reverse ? -result : result;
181}
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 186 of file sort.c.

187{
188 int result = mutt_numeric_cmp(a->received, b->received);
189 return reverse ? -result : result;
190}
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 195 of file sort.c.

196{
197 int result = mutt_numeric_cmp(a->index, b->index);
198 return reverse ? -result : result;
199}
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 204 of file sort.c.

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

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

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