NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
sort.h File Reference

Assorted sorting methods. More...

#include <stdbool.h>
#include "core/lib.h"
+ Include dependency graph for sort.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

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

Enumerations

enum  EmailSortType {
  EMAIL_SORT_DATE , EMAIL_SORT_DATE_RECEIVED , EMAIL_SORT_FROM , EMAIL_SORT_LABEL ,
  EMAIL_SORT_SCORE , EMAIL_SORT_SIZE , EMAIL_SORT_SPAM , EMAIL_SORT_SUBJECT ,
  EMAIL_SORT_THREADS , EMAIL_SORT_TO , EMAIL_SORT_UNSORTED
}
 Methods for sorting Emails. More...
 

Functions

int mutt_compare_emails (const struct Email *a, const struct Email *b, enum MailboxType type, short sort, short sort_aux)
 Compare two emails using up to two sort methods -.
 
void mutt_sort_headers (struct MailboxView *mv, bool init)
 Sort emails by their headers.
 
void mutt_sort_unsorted (struct Mailbox *m)
 Sort emails by their disk order.
 
const char * mutt_get_name (const struct Address *a)
 Pick the best name to display from an address.
 

Detailed Description

Assorted sorting methods.

Authors
  • Michael R. Elkins
  • Richard Russon
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file sort.h.

Typedef Documentation

◆ sort_email_t

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

Definition at line 47 of file sort.h.

Enumeration Type Documentation

◆ EmailSortType

Methods for sorting Emails.

Enumerator
EMAIL_SORT_DATE 

Sort by the date the email was sent.

EMAIL_SORT_DATE_RECEIVED 

Sort by when the message were delivered locally.

EMAIL_SORT_FROM 

Sort by the email's From field.

EMAIL_SORT_LABEL 

Sort by the emails label.

EMAIL_SORT_SCORE 

Sort by the email's score.

EMAIL_SORT_SIZE 

Sort by the size of the email.

EMAIL_SORT_SPAM 

Sort by the email's spam score.

EMAIL_SORT_SUBJECT 

Sort by the email's subject.

EMAIL_SORT_THREADS 

Sort by email threads.

EMAIL_SORT_TO 

Sort by the email's To field.

EMAIL_SORT_UNSORTED 

Sort by the order the messages appear in the mailbox.

Definition at line 52 of file sort.h.

53{
65};
@ EMAIL_SORT_LABEL
Sort by the emails label.
Definition: sort.h:57
@ EMAIL_SORT_DATE_RECEIVED
Sort by when the message were delivered locally.
Definition: sort.h:55
@ EMAIL_SORT_SPAM
Sort by the email's spam score.
Definition: sort.h:60
@ EMAIL_SORT_SCORE
Sort by the email's score.
Definition: sort.h:58
@ EMAIL_SORT_DATE
Sort by the date the email was sent.
Definition: sort.h:54
@ EMAIL_SORT_THREADS
Sort by email threads.
Definition: sort.h:62
@ EMAIL_SORT_SUBJECT
Sort by the email's subject.
Definition: sort.h:61
@ EMAIL_SORT_FROM
Sort by the email's From field.
Definition: sort.h:56
@ EMAIL_SORT_UNSORTED
Sort by the order the messages appear in the mailbox.
Definition: sort.h:64
@ EMAIL_SORT_SIZE
Sort by the size of the email.
Definition: sort.h:59
@ EMAIL_SORT_TO
Sort by the email's To field.
Definition: sort.h:63

Function Documentation

◆ mutt_sort_headers()

void mutt_sort_headers ( struct MailboxView mv,
bool  init 
)

Sort emails by their headers.

Parameters
mvMailbox View
initIf true, rebuild the thread

Definition at line 355 of file sort.c.

356{
357 if (!mv)
358 return;
359
360 struct Mailbox *m = mv->mailbox;
361 if (!m || !m->emails[0])
362 return;
363
364 OptNeedResort = false;
365
366 if (m->msg_count == 0)
367 {
368 /* this function gets called by mutt_sync_mailbox(), which may have just
369 * deleted all the messages. the virtual message numbers are not updated
370 * in that routine, so we must make sure to zero the vcount member. */
371 m->vcount = 0;
373 mv->vsize = 0;
374 return; /* nothing to do! */
375 }
376
377 if (m->verbose)
378 mutt_message(_("Sorting mailbox..."));
379
380 const bool c_score = cs_subset_bool(NeoMutt->sub, "score");
381 if (OptNeedRescore && c_score)
382 {
383 for (int i = 0; i < m->msg_count; i++)
384 {
385 struct Email *e = m->emails[i];
386 if (!e)
387 break;
388 mutt_score_message(m, e, true);
389 }
390 }
391 OptNeedRescore = false;
392
393 if (OptResortInit)
394 {
395 OptResortInit = false;
396 init = true;
397 }
398
399 if (init)
401
402 const bool threaded = mutt_using_threads();
403 if (threaded)
404 {
405 mutt_sort_threads(mv->threads, init);
406 }
407 else
408 {
409 struct EmailCompare cmp = { 0 };
410 cmp.type = mx_type(m);
411 cmp.sort = cs_subset_sort(NeoMutt->sub, "sort");
412 cmp.sort_aux = cs_subset_sort(NeoMutt->sub, "sort_aux");
413 mutt_qsort_r((void *) m->emails, m->msg_count, sizeof(struct Email *),
414 email_sort_shim, &cmp);
415 }
416
417 /* adjust the virtual message numbers */
418 m->vcount = 0;
419 for (int i = 0; i < m->msg_count; i++)
420 {
421 struct Email *e_cur = m->emails[i];
422 if (!e_cur)
423 break;
424
425 if ((e_cur->vnum != -1) || (e_cur->collapsed && e_cur->visible))
426 {
427 e_cur->vnum = m->vcount;
428 m->v2r[m->vcount] = i;
429 m->vcount++;
430 }
431 e_cur->msgno = i;
432 }
433
434 /* re-collapse threads marked as collapsed */
435 if (threaded)
436 {
438 mv->vsize = mutt_set_vnum(m);
439 }
440
441 if (m->verbose)
443}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
bool OptNeedRescore
(pseudo) set when the 'score' command is used
Definition: globals.c:65
bool OptResortInit
(pseudo) used to force the next resort to be from scratch
Definition: globals.c:71
bool OptNeedResort
(pseudo) used to force a re-sort
Definition: globals.c:66
#define mutt_message(...)
Definition: logging2.h:91
static int email_sort_shim(const void *a, const void *b, void *sdata)
Helper to sort emails - Implements sort_t -.
Definition: sort.c:69
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
void mutt_clear_threads(struct ThreadsContext *tctx)
Clear the threading of message in a mailbox.
Definition: mutt_thread.c:719
void mutt_thread_collapse_collapsed(struct ThreadsContext *tctx)
Re-collapse threads marked as collapsed.
Definition: mutt_thread.c:1770
void mutt_sort_threads(struct ThreadsContext *tctx, bool init)
Sort email threads.
Definition: mutt_thread.c:1033
off_t mutt_set_vnum(struct Mailbox *m)
Set the virtual index number of all the messages in a mailbox.
Definition: mutt_thread.c:1406
#define mutt_using_threads()
Definition: mutt_thread.h:114
enum MailboxType mx_type(struct Mailbox *m)
Return the type of the Mailbox.
Definition: mx.c:1796
void mutt_qsort_r(void *base, size_t nmemb, size_t size, sort_t compar, void *sdata)
Sort an array, where the comparator has access to opaque data rather than requiring global variables.
Definition: qsort_r.c:67
void mutt_score_message(struct Mailbox *m, struct Email *e, bool upd_mbox)
Apply scoring to an email.
Definition: score.c:165
Context for email_sort_shim()
Definition: sort.c:60
short sort_aux
Secondary sort.
Definition: sort.c:63
short sort
Primary sort.
Definition: sort.c:62
enum MailboxType type
Current mailbox type.
Definition: sort.c:61
The envelope/body of an email.
Definition: email.h:39
bool visible
Is this message part of the view?
Definition: email.h:121
bool collapsed
Is this message part of a collapsed thread?
Definition: email.h:120
bool threaded
Used for threading.
Definition: email.h:108
int vnum
Virtual message number.
Definition: email.h:114
int msgno
Number displayed to the user.
Definition: email.h:111
off_t vsize
Size (in bytes) of the messages shown.
Definition: mview.h:41
struct ThreadsContext * threads
Threads context.
Definition: mview.h:44
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:51
A mailbox.
Definition: mailbox.h:79
int vcount
The number of virtual messages.
Definition: mailbox.h:99
int * v2r
Mapping from virtual to real msgno.
Definition: mailbox.h:98
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
bool verbose
Display status messages?
Definition: mailbox.h:117
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_sort_unsorted()

void mutt_sort_unsorted ( struct Mailbox m)

Sort emails by their disk order.

Parameters
mMailbox

Definition at line 449 of file sort.c.

450{
451 if (!m)
452 return;
453
454 struct EmailCompare cmp = { 0 };
455 cmp.type = mx_type(m);
457 mutt_qsort_r((void *) m->emails, m->msg_count, sizeof(struct Email *),
458 email_sort_shim, &cmp);
459}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_get_name()

const char * mutt_get_name ( const struct Address a)

Pick the best name to display from an address.

Parameters
aAddress to use
Return values
ptrDisplay name

This function uses:

  1. Alias for email address
  2. Personal name
  3. Email address

Definition at line 139 of file sort.c.

140{
141 struct Address *ali = NULL;
142
143 if (a)
144 {
145 const bool c_reverse_alias = cs_subset_bool(NeoMutt->sub, "reverse_alias");
146 if (c_reverse_alias && (ali = alias_reverse_lookup(a)) && ali->personal)
147 return buf_string(ali->personal);
148 if (a->personal)
149 return buf_string(a->personal);
150 if (a->mailbox)
151 return mutt_addr_for_display(a);
152 }
153 /* don't return NULL to avoid segfault when printing/comparing */
154 return "";
155}
const char * mutt_addr_for_display(const struct Address *a)
Convert an Address for display purposes.
Definition: address.c:1012
struct Address * alias_reverse_lookup(const struct Address *addr)
Does the user have an alias for the given address.
Definition: reverse.c:105
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
An email address.
Definition: address.h:36
struct Buffer * personal
Real name of address.
Definition: address.h:37
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function: