NeoMutt  2024-03-23-142-g2b2e76
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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)
 Restore the 'unsorted' order of emails - Implements sort_mail_t -.
 
static int compare_score (const struct Email *a, const struct Email *b, bool reverse)
 Compare two emails using their scores - Implements sort_mail_t -.
 
static int compare_size (const struct Email *a, const struct Email *b, bool reverse)
 Compare the size of two emails - Implements sort_mail_t -.
 
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 -.
 
static int compare_subject (const struct Email *a, const struct Email *b, bool reverse)
 Compare the subject of two emails - Implements sort_mail_t -.
 
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 -.
 
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 -.
 
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 -.
 
static int compare_order (const struct Email *a, const struct Email *b, bool reverse)
 Restore the 'unsorted' order of emails - Implements sort_mail_t -.
 
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 -.
 
static int compare_label (const struct Email *a, const struct Email *b, bool reverse)
 Compare the labels of two emails - Implements sort_mail_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

◆ nntp_compare_order()

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

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

Definition at line 2308 of file nntp.c.

2309{
2310 anum_t na = nntp_edata_get((struct Email *) a)->article_num;
2311 anum_t nb = nntp_edata_get((struct Email *) b)->article_num;
2312 int result = (na == nb) ? 0 : (na > nb) ? 1 : -1;
2313 return reverse ? -result : result;
2314}
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:60
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:

◆ 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 75 of file sort.c.

76{
77 int result = mutt_numeric_cmp(b->score, a->score); /* note that this is reverse */
78 return reverse ? -result : result;
79}
#define mutt_numeric_cmp(a, b)
Definition: sort.h:35
int score
Message score.
Definition: email.h:116
+ 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 84 of file sort.c.

85{
86 int result = mutt_numeric_cmp(a->body->length, b->body->length);
87 return reverse ? -result : result;
88}
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:

◆ 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 93 of file sort.c.

94{
95 int result = mutt_numeric_cmp(a->date_sent, b->date_sent);
96 return reverse ? -result : result;
97}
time_t date_sent
Time when the message was sent (UTC)
Definition: email.h:60
+ 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 102 of file sort.c.

103{
104 int rc;
105
106 if (!a->env->real_subj)
107 {
108 if (!b->env->real_subj)
109 rc = compare_date_sent(a, b, false);
110 else
111 rc = -1;
112 }
113 else if (!b->env->real_subj)
114 {
115 rc = 1;
116 }
117 else
118 {
119 rc = mutt_istr_cmp(a->env->real_subj, b->env->real_subj);
120 }
121 return reverse ? -rc : rc;
122}
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:93
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:461
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:

◆ 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 155 of file sort.c.

156{
157 char fa[128] = { 0 };
158
159 mutt_str_copy(fa, mutt_get_name(TAILQ_FIRST(&a->env->to)), sizeof(fa));
160 const char *fb = mutt_get_name(TAILQ_FIRST(&b->env->to));
161 int result = mutt_istrn_cmp(fa, fb, sizeof(fa));
162 return reverse ? -result : result;
163}
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:488
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:630
#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:134
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 168 of file sort.c.

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

182{
183 int result = mutt_numeric_cmp(a->received, b->received);
184 return reverse ? -result : result;
185}
time_t received
Time when the message was placed in the mailbox.
Definition: email.h:61
+ 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 190 of file sort.c.

191{
192 int result = mutt_numeric_cmp(a->index, b->index);
193 return reverse ? -result : result;
194}
int index
The absolute (unsorted) message number.
Definition: email.h:113
+ 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 199 of file sort.c.

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

◆ 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 248 of file sort.c.

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