NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
Mail Sorting API

Prototype for an email comparison function. More...

Functions

int nntp_compare_order (const struct Email *a, const struct Email *b, bool reverse)
 Sort to mailbox order - Implements sort_mail_t -. More...
 
static int compare_score (const struct Email *a, const struct Email *b, bool reverse)
 Compare two emails using their scores - Implements sort_mail_t -. More...
 
static int compare_size (const struct Email *a, const struct Email *b, bool reverse)
 Compare the size of two emails - Implements sort_mail_t -. More...
 
static int compare_date_sent (const struct Email *a, const struct Email *b, bool reverse)
 Compare the sent date of two emails - Implements sort_mail_t -. More...
 
static int compare_subject (const struct Email *a, const struct Email *b, bool reverse)
 Compare the subject of two emails - Implements sort_mail_t -. More...
 
static int compare_to (const struct Email *a, const struct Email *b, bool reverse)
 Compare the 'to' fields of two emails - Implements sort_mail_t -. More...
 
static int compare_from (const struct Email *a, const struct Email *b, bool reverse)
 Compare the 'from' fields of two emails - Implements sort_mail_t -. More...
 
static int compare_date_received (const struct Email *a, const struct Email *b, bool reverse)
 Compare the date received of two emails - Implements sort_mail_t -. More...
 
static int compare_order (const struct Email *a, const struct Email *b, bool reverse)
 Restore the 'unsorted' order of emails - Implements sort_mail_t -. More...
 
static int compare_spam (const struct Email *a, const struct Email *b, bool reverse)
 Compare the spam values of two emails - Implements sort_mail_t -. More...
 
static int compare_label (const struct Email *a, const struct Email *b, bool reverse)
 Compare the labels of two emails - Implements sort_mail_t -. More...
 

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

◆ nntp_compare_order()

int nntp_compare_order ( const struct Email a,
const struct Email b,
bool  reverse 
)

Sort to mailbox order - Implements sort_mail_t -.

Definition at line 2313 of file nntp.c.

2314{
2315 anum_t na = nntp_edata_get((struct Email *) a)->article_num;
2316 anum_t nb = nntp_edata_get((struct Email *) b)->article_num;
2317 int result = (na == nb) ? 0 : (na > nb) ? 1 : -1;
2318 return reverse ? -result : result;
2319}
struct NntpEmailData * nntp_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:57
#define anum_t
Definition: lib.h:60
The envelope/body of an email.
Definition: email.h:37
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:

◆ compare_score()

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

Compare two emails using their scores - Implements sort_mail_t -.

Definition at line 81 of file sort.c.

82{
83 int result = mutt_numeric_cmp(b->score, a->score); /* note that this is reverse */
84 return reverse ? -result : result;
85}
#define mutt_numeric_cmp(a, b)
Definition: sort.h:34
int score
Message score.
Definition: email.h:112
+ Here is the caller graph for this function:

◆ compare_size()

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

Compare the size of two emails - Implements sort_mail_t -.

Definition at line 90 of file sort.c.

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

◆ compare_date_sent()

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

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

Definition at line 99 of file sort.c.

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

◆ compare_subject()

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

Compare the subject of two emails - Implements sort_mail_t -.

Definition at line 108 of file sort.c.

109{
110 int rc;
111
112 if (!a->env->real_subj)
113 {
114 if (!b->env->real_subj)
115 rc = compare_date_sent(a, b, false);
116 else
117 rc = -1;
118 }
119 else if (!b->env->real_subj)
120 {
121 rc = 1;
122 }
123 else
124 {
125 rc = mutt_istr_cmp(a->env->real_subj, b->env->real_subj);
126 }
127 return reverse ? -rc : rc;
128}
static int compare_date_sent(const struct Email *a, const struct Email *b, bool reverse)
Compare the sent date of two emails - Implements sort_mail_t -.
Definition: sort.c:99
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:484
struct Envelope * env
Envelope information.
Definition: email.h:66
char * 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:

◆ compare_to()

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

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

Definition at line 161 of file sort.c.

162{
163 char fa[128] = { 0 };
164
165 mutt_str_copy(fa, mutt_get_name(TAILQ_FIRST(&a->env->to)), sizeof(fa));
166 const char *fb = mutt_get_name(TAILQ_FIRST(&b->env->to));
167 int result = mutt_istrn_cmp(fa, fb, sizeof(fa));
168 return reverse ? -result : result;
169}
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:511
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:653
#define TAILQ_FIRST(head)
Definition: queue.h:723
const char * mutt_get_name(const struct Address *a)
Pick the best name to display from an address.
Definition: sort.c:140
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:

◆ compare_from()

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

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

Definition at line 174 of file sort.c.

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

◆ compare_date_received()

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

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

Definition at line 187 of file sort.c.

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

◆ compare_order()

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

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

Definition at line 196 of file sort.c.

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

◆ compare_spam()

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

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

Definition at line 205 of file sort.c.

206{
207 char *aptr = NULL, *bptr = NULL;
208 int ahas, 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:303
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:471
char * data
Pointer to data.
Definition: buffer.h:35
struct Buffer spam
Spam header.
Definition: envelope.h:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compare_label()

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

Compare the labels of two emails - Implements sort_mail_t -.

Definition at line 254 of file sort.c.

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