NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mutt_thread.h File Reference

Create/manipulate threading in emails. More...

#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include "config/lib.h"
+ Include dependency graph for mutt_thread.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ThreadsContext
 The "current" threading state. More...
 

Macros

#define MUTT_THREAD_NO_FLAGS   0
 No flags are set.
 
#define MUTT_THREAD_COLLAPSE   (1 << 0)
 Collapse an email thread.
 
#define MUTT_THREAD_UNCOLLAPSE   (1 << 1)
 Uncollapse an email thread.
 
#define MUTT_THREAD_UNREAD   (1 << 2)
 Count unread emails in a thread.
 
#define MUTT_THREAD_NEXT_UNREAD   (1 << 3)
 Find the next unread email.
 
#define MUTT_THREAD_FLAGGED   (1 << 4)
 Count flagged emails in a thread.
 
#define mutt_collapse_thread(e)   mutt_traverse_thread(e, MUTT_THREAD_COLLAPSE)
 
#define mutt_uncollapse_thread(e)   mutt_traverse_thread(e, MUTT_THREAD_UNCOLLAPSE)
 
#define mutt_thread_contains_unread(e)   mutt_traverse_thread(e, MUTT_THREAD_UNREAD)
 
#define mutt_thread_contains_flagged(e)   mutt_traverse_thread(e, MUTT_THREAD_FLAGGED)
 
#define mutt_thread_next_unread(e)   mutt_traverse_thread(e, MUTT_THREAD_NEXT_UNREAD)
 
#define mutt_using_threads()   (mutt_thread_style() > UT_FLAT)
 
#define mutt_next_thread(e)   mutt_aside_thread(e, true, false)
 
#define mutt_previous_thread(e)   mutt_aside_thread(e, false, false)
 
#define mutt_next_subthread(e)   mutt_aside_thread(e, true, true)
 
#define mutt_previous_subthread(e)   mutt_aside_thread(e, false, true)
 

Typedefs

typedef uint8_t MuttThreadFlags
 Flags, e.g. MUTT_THREAD_COLLAPSE.
 

Enumerations

enum  TreeChar {
  MUTT_TREE_LLCORNER = 1 , MUTT_TREE_ULCORNER , MUTT_TREE_LTEE , MUTT_TREE_HLINE ,
  MUTT_TREE_VLINE , MUTT_TREE_SPACE , MUTT_TREE_RARROW , MUTT_TREE_STAR ,
  MUTT_TREE_HIDDEN , MUTT_TREE_EQUALS , MUTT_TREE_TTEE , MUTT_TREE_BTEE ,
  MUTT_TREE_MISSING , MUTT_TREE_MAX , MUTT_SPECIAL_INDEX = MUTT_TREE_MAX
}
 Tree characters for menus. More...
 
enum  MessageInThread { MIT_NUM_MESSAGES , MIT_POSITION }
 Flags for mutt_messages_in_thread() More...
 
enum  UseThreads { UT_UNSET , UT_FLAT , UT_THREADS , UT_REVERSE }
 Which threading style is active, $use_threads. More...
 

Functions

int mutt_traverse_thread (struct Email *e, MuttThreadFlags flag)
 Recurse through an email thread, matching messages.
 
enum UseThreads mutt_thread_style (void)
 Which threading style is active?
 
const char * get_use_threads_str (enum UseThreads value)
 Convert UseThreads enum to string.
 
int sort_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate values of "sort" - Implements ConfigDef::validator() -.
 
int mutt_aside_thread (struct Email *e, bool forwards, bool subthreads)
 Find the next/previous (sub)thread.
 
struct ThreadsContextmutt_thread_ctx_init (struct MailboxView *mv)
 Initialize a threading context.
 
void mutt_thread_ctx_free (struct ThreadsContext **ptr)
 Finalize a threading context.
 
void mutt_thread_collapse_collapsed (struct ThreadsContext *tctx)
 Re-collapse threads marked as collapsed.
 
void mutt_thread_collapse (struct ThreadsContext *tctx, bool collapse)
 Toggle collapse.
 
bool mutt_thread_can_collapse (struct Email *e)
 Check whether a thread can be collapsed.
 
void mutt_clear_threads (struct ThreadsContext *tctx)
 Clear the threading of message in a mailbox.
 
void mutt_draw_tree (struct ThreadsContext *tctx)
 Draw a tree of threaded emails.
 
bool mutt_link_threads (struct Email *parent, struct EmailArray *children, struct Mailbox *m)
 Forcibly link threads together.
 
struct HashTablemutt_make_id_hash (struct Mailbox *m)
 Create a Hash Table for message-ids.
 
int mutt_messages_in_thread (struct Mailbox *m, struct Email *e, enum MessageInThread mit)
 Count the messages in a thread.
 
int mutt_parent_message (struct Email *e, bool find_root)
 Find the parent of a message.
 
off_t mutt_set_vnum (struct Mailbox *m)
 Set the virtual index number of all the messages in a mailbox.
 
void mutt_sort_threads (struct ThreadsContext *tctx, bool init)
 Sort email threads.
 

Variables

const struct EnumDef UseThreadsTypeDef
 Data for the $use_threads enumeration.
 

Detailed Description

Create/manipulate threading in emails.

Authors
  • Richard Russon

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 mutt_thread.h.

Macro Definition Documentation

◆ MUTT_THREAD_NO_FLAGS

#define MUTT_THREAD_NO_FLAGS   0

No flags are set.

Definition at line 75 of file mutt_thread.h.

◆ MUTT_THREAD_COLLAPSE

#define MUTT_THREAD_COLLAPSE   (1 << 0)

Collapse an email thread.

Definition at line 76 of file mutt_thread.h.

◆ MUTT_THREAD_UNCOLLAPSE

#define MUTT_THREAD_UNCOLLAPSE   (1 << 1)

Uncollapse an email thread.

Definition at line 77 of file mutt_thread.h.

◆ MUTT_THREAD_UNREAD

#define MUTT_THREAD_UNREAD   (1 << 2)

Count unread emails in a thread.

Definition at line 78 of file mutt_thread.h.

◆ MUTT_THREAD_NEXT_UNREAD

#define MUTT_THREAD_NEXT_UNREAD   (1 << 3)

Find the next unread email.

Definition at line 79 of file mutt_thread.h.

◆ MUTT_THREAD_FLAGGED

#define MUTT_THREAD_FLAGGED   (1 << 4)

Count flagged emails in a thread.

Definition at line 80 of file mutt_thread.h.

◆ mutt_collapse_thread

#define mutt_collapse_thread (   e)    mutt_traverse_thread(e, MUTT_THREAD_COLLAPSE)

Definition at line 105 of file mutt_thread.h.

◆ mutt_uncollapse_thread

#define mutt_uncollapse_thread (   e)    mutt_traverse_thread(e, MUTT_THREAD_UNCOLLAPSE)

Definition at line 106 of file mutt_thread.h.

◆ mutt_thread_contains_unread

#define mutt_thread_contains_unread (   e)    mutt_traverse_thread(e, MUTT_THREAD_UNREAD)

Definition at line 107 of file mutt_thread.h.

◆ mutt_thread_contains_flagged

#define mutt_thread_contains_flagged (   e)    mutt_traverse_thread(e, MUTT_THREAD_FLAGGED)

Definition at line 108 of file mutt_thread.h.

◆ mutt_thread_next_unread

#define mutt_thread_next_unread (   e)    mutt_traverse_thread(e, MUTT_THREAD_NEXT_UNREAD)

Definition at line 109 of file mutt_thread.h.

◆ mutt_using_threads

#define mutt_using_threads ( )    (mutt_thread_style() > UT_FLAT)

Definition at line 112 of file mutt_thread.h.

◆ mutt_next_thread

#define mutt_next_thread (   e)    mutt_aside_thread(e, true, false)

Definition at line 118 of file mutt_thread.h.

◆ mutt_previous_thread

#define mutt_previous_thread (   e)    mutt_aside_thread(e, false, false)

Definition at line 119 of file mutt_thread.h.

◆ mutt_next_subthread

#define mutt_next_subthread (   e)    mutt_aside_thread(e, true, true)

Definition at line 120 of file mutt_thread.h.

◆ mutt_previous_subthread

#define mutt_previous_subthread (   e)    mutt_aside_thread(e, false, true)

Definition at line 121 of file mutt_thread.h.

Typedef Documentation

◆ MuttThreadFlags

typedef uint8_t MuttThreadFlags

Flags, e.g. MUTT_THREAD_COLLAPSE.

Definition at line 74 of file mutt_thread.h.

Enumeration Type Documentation

◆ TreeChar

enum TreeChar

Tree characters for menus.

See also
linearize_tree(), print_enriched_string()
Enumerator
MUTT_TREE_LLCORNER 

Lower left corner.

MUTT_TREE_ULCORNER 

Upper left corner.

MUTT_TREE_LTEE 

Left T-piece.

MUTT_TREE_HLINE 

Horizontal line.

MUTT_TREE_VLINE 

Vertical line.

MUTT_TREE_SPACE 

Blank space.

MUTT_TREE_RARROW 

Right arrow.

MUTT_TREE_STAR 

Star character (for threads)

MUTT_TREE_HIDDEN 

Ampersand character (for threads)

MUTT_TREE_EQUALS 

Equals (for threads)

MUTT_TREE_TTEE 

Top T-piece.

MUTT_TREE_BTEE 

Bottom T-piece.

MUTT_TREE_MISSING 

Question mark.

MUTT_TREE_MAX 
MUTT_SPECIAL_INDEX 

Colour indicator.

Definition at line 54 of file mutt_thread.h.

55{
70
72};
@ MUTT_TREE_MAX
Definition: mutt_thread.h:69
@ MUTT_TREE_LLCORNER
Lower left corner.
Definition: mutt_thread.h:56
@ MUTT_TREE_RARROW
Right arrow.
Definition: mutt_thread.h:62
@ MUTT_SPECIAL_INDEX
Colour indicator.
Definition: mutt_thread.h:71
@ MUTT_TREE_ULCORNER
Upper left corner.
Definition: mutt_thread.h:57
@ MUTT_TREE_EQUALS
Equals (for threads)
Definition: mutt_thread.h:65
@ MUTT_TREE_HIDDEN
Ampersand character (for threads)
Definition: mutt_thread.h:64
@ MUTT_TREE_STAR
Star character (for threads)
Definition: mutt_thread.h:63
@ MUTT_TREE_LTEE
Left T-piece.
Definition: mutt_thread.h:58
@ MUTT_TREE_VLINE
Vertical line.
Definition: mutt_thread.h:60
@ MUTT_TREE_MISSING
Question mark.
Definition: mutt_thread.h:68
@ MUTT_TREE_TTEE
Top T-piece.
Definition: mutt_thread.h:66
@ MUTT_TREE_HLINE
Horizontal line.
Definition: mutt_thread.h:59
@ MUTT_TREE_SPACE
Blank space.
Definition: mutt_thread.h:61
@ MUTT_TREE_BTEE
Bottom T-piece.
Definition: mutt_thread.h:67

◆ MessageInThread

Flags for mutt_messages_in_thread()

Enumerator
MIT_NUM_MESSAGES 

How many messages are in the thread.

MIT_POSITION 

Our position in the thread.

Definition at line 85 of file mutt_thread.h.

86{
89};
@ MIT_NUM_MESSAGES
How many messages are in the thread.
Definition: mutt_thread.h:87
@ MIT_POSITION
Our position in the thread.
Definition: mutt_thread.h:88

◆ UseThreads

enum UseThreads

Which threading style is active, $use_threads.

Enumerator
UT_UNSET 

Not yet set by user, stick to legacy semantics.

UT_FLAT 

Unthreaded.

UT_THREADS 

Normal threading (root above subthreads)

UT_REVERSE 

Reverse threading (subthreads above root)

Definition at line 94 of file mutt_thread.h.

95{
96 UT_UNSET,
97 UT_FLAT,
100};
@ UT_FLAT
Unthreaded.
Definition: mutt_thread.h:97
@ UT_UNSET
Not yet set by user, stick to legacy semantics.
Definition: mutt_thread.h:96
@ UT_THREADS
Normal threading (root above subthreads)
Definition: mutt_thread.h:98
@ UT_REVERSE
Reverse threading (subthreads above root)
Definition: mutt_thread.h:99

Function Documentation

◆ mutt_traverse_thread()

int mutt_traverse_thread ( struct Email e_cur,
MuttThreadFlags  flag 
)

Recurse through an email thread, matching messages.

Parameters
e_curCurrent Email
flagFlag to set, see MuttThreadFlags
Return values
numNumber of matches

Definition at line 1435 of file mutt_thread.c.

1436{
1437 struct MuttThread *thread = NULL, *top = NULL;
1438 struct Email *e_root = NULL;
1439 const enum UseThreads threaded = mutt_thread_style();
1440 int final, reverse = (threaded == UT_REVERSE), minmsgno;
1441 int num_hidden = 0, new_mail = 0, old_mail = 0;
1442 bool flagged = false;
1443 int min_unread_msgno = INT_MAX, min_unread = e_cur->vnum;
1444
1445 if (threaded == UT_FLAT)
1446 {
1447 mutt_error(_("Threading is not enabled"));
1448 return e_cur->vnum;
1449 }
1450
1451 if (!e_cur->thread)
1452 {
1453 return e_cur->vnum;
1454 }
1455
1456 final = e_cur->vnum;
1457 thread = e_cur->thread;
1458 while (thread->parent)
1459 thread = thread->parent;
1460 top = thread;
1461 while (!thread->message)
1462 thread = thread->child;
1463 e_cur = thread->message;
1464 minmsgno = e_cur->msgno;
1465
1466 if (!e_cur->read && e_cur->visible)
1467 {
1468 if (e_cur->old)
1469 old_mail = 2;
1470 else
1471 new_mail = 1;
1472 if (e_cur->msgno < min_unread_msgno)
1473 {
1474 min_unread = e_cur->vnum;
1475 min_unread_msgno = e_cur->msgno;
1476 }
1477 }
1478
1479 if (e_cur->flagged && e_cur->visible)
1480 flagged = true;
1481
1482 if ((e_cur->vnum == -1) && e_cur->visible)
1483 num_hidden++;
1484
1486 {
1487 e_cur->attr_color = NULL; /* force index entry's color to be re-evaluated */
1488 e_cur->collapsed = flag & MUTT_THREAD_COLLAPSE;
1489 if (e_cur->vnum != -1)
1490 {
1491 e_root = e_cur;
1492 if (flag & MUTT_THREAD_COLLAPSE)
1493 final = e_root->vnum;
1494 }
1495 }
1496
1497 if ((thread == top) && !(thread = thread->child))
1498 {
1499 /* return value depends on action requested */
1501 {
1502 e_cur->num_hidden = num_hidden;
1503 return final;
1504 }
1505 if (flag & MUTT_THREAD_UNREAD)
1506 return (old_mail && new_mail) ? new_mail : (old_mail ? old_mail : new_mail);
1507 if (flag & MUTT_THREAD_NEXT_UNREAD)
1508 return min_unread;
1509 if (flag & MUTT_THREAD_FLAGGED)
1510 return flagged;
1511 }
1512
1513 while (true)
1514 {
1515 e_cur = thread->message;
1516
1517 if (e_cur)
1518 {
1520 {
1521 e_cur->attr_color = NULL; /* force index entry's color to be re-evaluated */
1522 e_cur->collapsed = flag & MUTT_THREAD_COLLAPSE;
1523 if (!e_root && e_cur->visible)
1524 {
1525 e_root = e_cur;
1526 if (flag & MUTT_THREAD_COLLAPSE)
1527 final = e_root->vnum;
1528 }
1529
1530 if (reverse && (flag & MUTT_THREAD_COLLAPSE) &&
1531 (e_cur->msgno < minmsgno) && e_cur->visible)
1532 {
1533 minmsgno = e_cur->msgno;
1534 final = e_cur->vnum;
1535 }
1536
1537 if (flag & MUTT_THREAD_COLLAPSE)
1538 {
1539 if (e_cur != e_root)
1540 e_cur->vnum = -1;
1541 }
1542 else
1543 {
1544 if (e_cur->visible)
1545 e_cur->vnum = e_cur->msgno;
1546 }
1547 }
1548
1549 if (!e_cur->read && e_cur->visible)
1550 {
1551 if (e_cur->old)
1552 old_mail = 2;
1553 else
1554 new_mail = 1;
1555 if (e_cur->msgno < min_unread_msgno)
1556 {
1557 min_unread = e_cur->vnum;
1558 min_unread_msgno = e_cur->msgno;
1559 }
1560 }
1561
1562 if (e_cur->flagged && e_cur->visible)
1563 flagged = true;
1564
1565 if ((e_cur->vnum == -1) && e_cur->visible)
1566 num_hidden++;
1567 }
1568
1569 if (thread->child)
1570 {
1571 thread = thread->child;
1572 }
1573 else if (thread->next)
1574 {
1575 thread = thread->next;
1576 }
1577 else
1578 {
1579 bool done = false;
1580 while (!thread->next)
1581 {
1582 thread = thread->parent;
1583 if (thread == top)
1584 {
1585 done = true;
1586 break;
1587 }
1588 }
1589 if (done)
1590 break;
1591 thread = thread->next;
1592 }
1593 }
1594
1595 /* re-traverse the thread and store num_hidden in all headers, with or
1596 * without a virtual index. this will allow ~v to match all collapsed
1597 * messages when switching sort order to non-threaded. */
1598 if (flag & MUTT_THREAD_COLLAPSE)
1599 {
1600 thread = top;
1601 while (true)
1602 {
1603 e_cur = thread->message;
1604 if (e_cur)
1605 e_cur->num_hidden = num_hidden + 1;
1606
1607 if (thread->child)
1608 {
1609 thread = thread->child;
1610 }
1611 else if (thread->next)
1612 {
1613 thread = thread->next;
1614 }
1615 else
1616 {
1617 bool done = false;
1618 while (!thread->next)
1619 {
1620 thread = thread->parent;
1621 if (thread == top)
1622 {
1623 done = true;
1624 break;
1625 }
1626 }
1627 if (done)
1628 break;
1629 thread = thread->next;
1630 }
1631 }
1632 }
1633
1634 /* return value depends on action requested */
1636 return final;
1637 if (flag & MUTT_THREAD_UNREAD)
1638 return (old_mail && new_mail) ? new_mail : (old_mail ? old_mail : new_mail);
1639 if (flag & MUTT_THREAD_NEXT_UNREAD)
1640 return min_unread;
1641 if (flag & MUTT_THREAD_FLAGGED)
1642 return flagged;
1643
1644 return 0;
1645}
#define mutt_error(...)
Definition: logging2.h:92
#define _(a)
Definition: message.h:28
enum UseThreads mutt_thread_style(void)
Which threading style is active?
Definition: mutt_thread.c:79
#define MUTT_THREAD_UNREAD
Count unread emails in a thread.
Definition: mutt_thread.h:78
UseThreads
Which threading style is active, $use_threads.
Definition: mutt_thread.h:95
#define MUTT_THREAD_UNCOLLAPSE
Uncollapse an email thread.
Definition: mutt_thread.h:77
#define MUTT_THREAD_NEXT_UNREAD
Find the next unread email.
Definition: mutt_thread.h:79
#define MUTT_THREAD_COLLAPSE
Collapse an email thread.
Definition: mutt_thread.h:76
#define MUTT_THREAD_FLAGGED
Count flagged emails in a thread.
Definition: mutt_thread.h:80
The envelope/body of an email.
Definition: email.h:37
bool read
Email is read.
Definition: email.h:48
bool visible
Is this message part of the view?
Definition: email.h:120
bool collapsed
Is this message part of a collapsed thread?
Definition: email.h:119
bool old
Email is seen, but unread.
Definition: email.h:47
size_t num_hidden
Number of hidden messages in this view (only valid when collapsed is set)
Definition: email.h:122
bool flagged
Marked important?
Definition: email.h:45
bool threaded
Used for threading.
Definition: email.h:107
const struct AttrColor * attr_color
Color-pair to use when displaying in the index.
Definition: email.h:111
int vnum
Virtual message number.
Definition: email.h:113
int msgno
Number displayed to the user.
Definition: email.h:110
struct MuttThread * thread
Thread of Emails.
Definition: email.h:118
An Email conversation.
Definition: thread.h:34
struct MuttThread * parent
Parent of this Thread.
Definition: thread.h:44
struct MuttThread * child
Child of this Thread.
Definition: thread.h:45
struct Email * message
Email this Thread refers to.
Definition: thread.h:49
struct MuttThread * next
Next sibling Thread.
Definition: thread.h:46
+ Here is the call graph for this function:

◆ mutt_thread_style()

enum UseThreads mutt_thread_style ( void  )

Which threading style is active?

Return values
UT_FLATNo threading in use
UT_THREADSNormal threads (root above subthread)
UT_REVERSEReverse threads (subthread above root)
Note
UT_UNSET is never returned; rather, this function considers the interaction between $use_threads and $sort.

Definition at line 79 of file mutt_thread.c.

80{
81 const unsigned char c_use_threads = cs_subset_enum(NeoMutt->sub, "use_threads");
82 const enum SortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
83 if (c_use_threads > UT_FLAT)
84 return c_use_threads;
85 if ((c_sort & SORT_MASK) != SORT_THREADS)
86 return UT_FLAT;
87 if (c_sort & SORT_REVERSE)
88 return UT_REVERSE;
89 return UT_THREADS;
90}
unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
Get a enumeration config item by name.
Definition: helpers.c:72
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:267
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:74
SortType
Methods for sorting.
Definition: sort2.h:38
@ SORT_THREADS
Sort by email threads.
Definition: sort2.h:45
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:75
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_use_threads_str()

const char * get_use_threads_str ( enum UseThreads  value)

Convert UseThreads enum to string.

Parameters
valueValue to convert
Return values
ptrString form of value

Definition at line 97 of file mutt_thread.c.

98{
100}
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
static const struct Mapping UseThreadsMethods[]
Choices for '$use_threads' for the index.
Definition: mutt_thread.c:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_aside_thread()

int mutt_aside_thread ( struct Email e,
bool  forwards,
bool  subthreads 
)

Find the next/previous (sub)thread.

Parameters
eSearch from this Email
forwardsDirection to search: 'true' forwards, 'false' backwards
subthreadsSearch subthreads: 'true' subthread, 'false' not
Return values
numIndex into the virtual email table
-1Error

Definition at line 1284 of file mutt_thread.c.

1285{
1286 if (!e)
1287 return -1;
1288
1289 struct MuttThread *cur = NULL;
1290 struct Email *e_tmp = NULL;
1291
1292 const enum UseThreads threaded = mutt_thread_style();
1293 if (threaded == UT_FLAT)
1294 {
1295 mutt_error(_("Threading is not enabled"));
1296 return e->vnum;
1297 }
1298
1299 cur = e->thread;
1300
1301 if (subthreads)
1302 {
1303 if (forwards ^ (threaded == UT_REVERSE))
1304 {
1305 while (!cur->next && cur->parent)
1306 cur = cur->parent;
1307 }
1308 else
1309 {
1310 while (!cur->prev && cur->parent)
1311 cur = cur->parent;
1312 }
1313 }
1314 else
1315 {
1316 while (cur->parent)
1317 cur = cur->parent;
1318 }
1319
1320 if (forwards ^ (threaded == UT_REVERSE))
1321 {
1322 do
1323 {
1324 cur = cur->next;
1325 if (!cur)
1326 return -1;
1327 e_tmp = find_virtual(cur, false);
1328 } while (!e_tmp);
1329 }
1330 else
1331 {
1332 do
1333 {
1334 cur = cur->prev;
1335 if (!cur)
1336 return -1;
1337 e_tmp = find_virtual(cur, true);
1338 } while (!e_tmp);
1339 }
1340
1341 return e_tmp->vnum;
1342}
struct MuttThread * prev
Previous sibling Thread.
Definition: thread.h:47
struct Email * find_virtual(struct MuttThread *cur, bool reverse)
Find an email with a Virtual message number.
Definition: thread.c:121
+ Here is the call graph for this function:

◆ mutt_thread_ctx_init()

struct ThreadsContext * mutt_thread_ctx_init ( struct MailboxView mv)

Initialize a threading context.

Parameters
mvMailbox view
Return values
ptrThreading context

Definition at line 354 of file mutt_thread.c.

355{
356 struct ThreadsContext *tctx = mutt_mem_calloc(1, sizeof(struct ThreadsContext));
357 tctx->mailbox_view = mv;
358 return tctx;
359}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
The "current" threading state.
Definition: mutt_thread.h:41
struct MailboxView * mailbox_view
Current mailbox.
Definition: mutt_thread.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_thread_ctx_free()

void mutt_thread_ctx_free ( struct ThreadsContext **  ptr)

Finalize a threading context.

Parameters
ptrThreading context to free

Definition at line 365 of file mutt_thread.c.

366{
367 if (!ptr || !*ptr)
368 {
369 return;
370 }
371
372 struct ThreadsContext *tctx = *ptr;
373
374 mutt_hash_free(&tctx->hash);
375
376 FREE(ptr);
377}
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
#define FREE(x)
Definition: memory.h:45
struct HashTable * hash
Hash Table: "message-id" -> MuttThread.
Definition: mutt_thread.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_thread_collapse_collapsed()

void mutt_thread_collapse_collapsed ( struct ThreadsContext tctx)

Re-collapse threads marked as collapsed.

Parameters
tctxThreading context

Definition at line 1765 of file mutt_thread.c.

1766{
1767 struct MuttThread *thread = NULL;
1768 struct MuttThread *top = tctx->tree;
1769 while ((thread = top))
1770 {
1771 while (!thread->message)
1772 thread = thread->child;
1773
1774 struct Email *e = thread->message;
1775 if (e->collapsed)
1777 top = top->next;
1778 }
1779}
#define mutt_collapse_thread(e)
Definition: mutt_thread.h:105
struct MuttThread * tree
Top of thread tree.
Definition: mutt_thread.h:43
+ Here is the caller graph for this function:

◆ mutt_thread_collapse()

void mutt_thread_collapse ( struct ThreadsContext tctx,
bool  collapse 
)

Toggle collapse.

Parameters
tctxThreading context
collapseCollapse / uncollapse

Definition at line 1786 of file mutt_thread.c.

1787{
1788 struct MuttThread *thread = NULL;
1789 struct MuttThread *top = tctx->tree;
1790 while ((thread = top))
1791 {
1792 while (!thread->message)
1793 thread = thread->child;
1794
1795 struct Email *e = thread->message;
1796
1797 if (e->collapsed != collapse)
1798 {
1799 if (e->collapsed)
1801 else if (mutt_thread_can_collapse(e))
1803 }
1804 top = top->next;
1805 }
1806}
bool mutt_thread_can_collapse(struct Email *e)
Check whether a thread can be collapsed.
Definition: mutt_thread.c:1814
#define mutt_uncollapse_thread(e)
Definition: mutt_thread.h:106
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_thread_can_collapse()

bool mutt_thread_can_collapse ( struct Email e)

Check whether a thread can be collapsed.

Parameters
eHead of the thread
Return values
trueCan be collapsed
falseCannot be collapsed

Definition at line 1814 of file mutt_thread.c.

1815{
1816 const bool c_collapse_flagged = cs_subset_bool(NeoMutt->sub, "collapse_flagged");
1817 const bool c_collapse_unread = cs_subset_bool(NeoMutt->sub, "collapse_unread");
1818 return (c_collapse_unread || !mutt_thread_contains_unread(e)) &&
1819 (c_collapse_flagged || !mutt_thread_contains_flagged(e));
1820}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
#define mutt_thread_contains_flagged(e)
Definition: mutt_thread.h:108
#define mutt_thread_contains_unread(e)
Definition: mutt_thread.h:107
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_clear_threads()

void mutt_clear_threads ( struct ThreadsContext tctx)

Clear the threading of message in a mailbox.

Parameters
tctxThreading context

Definition at line 717 of file mutt_thread.c.

718{
719 if (!tctx || !tctx->tree)
720 return;
721
722 struct MailboxView *mv = tctx->mailbox_view;
723 if (!mv)
724 return;
725
726 struct Mailbox *m = mv->mailbox;
727 if (!m || !m->emails)
728 return;
729
730 for (int i = 0; i < m->msg_count; i++)
731 {
732 struct Email *e = m->emails[i];
733 if (!e)
734 break;
735
736 /* mailbox may have been only partially read */
737 e->thread = NULL;
738 e->threaded = false;
739 }
740 tctx->tree = NULL;
741 mutt_hash_free(&tctx->hash);
742}
View of a Mailbox.
Definition: mview.h:39
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:50
A mailbox.
Definition: mailbox.h:79
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_draw_tree()

void mutt_draw_tree ( struct ThreadsContext tctx)

Draw a tree of threaded emails.

Parameters
tctxThreading context

Since the graphics characters have a value >255, I have to resort to using escape sequences to pass the information to print_enriched_string(). These are the macros MUTT_TREE_* defined in mutt.h.

ncurses should automatically use the default ASCII characters instead of graphics chars on terminals which don't support them (see the man page for curs_addch).

Definition at line 391 of file mutt_thread.c.

392{
393 char *pfx = NULL, *mypfx = NULL, *arrow = NULL, *myarrow = NULL, *new_tree = NULL;
394 const bool reverse = (mutt_thread_style() == UT_REVERSE);
395 enum TreeChar corner = reverse ? MUTT_TREE_ULCORNER : MUTT_TREE_LLCORNER;
396 enum TreeChar vtee = reverse ? MUTT_TREE_BTEE : MUTT_TREE_TTEE;
397 const bool c_narrow_tree = cs_subset_bool(NeoMutt->sub, "narrow_tree");
398 int depth = 0, start_depth = 0, max_depth = 0, width = c_narrow_tree ? 1 : 2;
399 struct MuttThread *nextdisp = NULL, *pseudo = NULL, *parent = NULL;
400
401 struct MuttThread *tree = tctx->tree;
402
403 /* Do the visibility calculations and free the old thread chars.
404 * From now on we can simply ignore invisible subtrees */
405 calculate_visibility(tree, &max_depth);
406 pfx = mutt_mem_malloc((width * max_depth) + 2);
407 arrow = mutt_mem_malloc((width * max_depth) + 2);
408 const bool c_hide_limited = cs_subset_bool(NeoMutt->sub, "hide_limited");
409 const bool c_hide_missing = cs_subset_bool(NeoMutt->sub, "hide_missing");
410 while (tree)
411 {
412 if (depth != 0)
413 {
414 myarrow = arrow + (depth - start_depth - ((start_depth != 0) ? 0 : 1)) * width;
415 if (start_depth == depth)
416 myarrow[0] = nextdisp ? MUTT_TREE_LTEE : corner;
417 else if (parent->message && !c_hide_limited)
418 myarrow[0] = MUTT_TREE_HIDDEN;
419 else if (!parent->message && !c_hide_missing)
420 myarrow[0] = MUTT_TREE_MISSING;
421 else
422 myarrow[0] = vtee;
423 if (width == 2)
424 {
425 myarrow[1] = pseudo ? MUTT_TREE_STAR :
427 }
428 if (tree->visible)
429 {
430 myarrow[width] = MUTT_TREE_RARROW;
431 myarrow[width + 1] = 0;
432 new_tree = mutt_mem_malloc(((size_t) depth * width) + 2);
433 if (start_depth > 1)
434 {
435 strncpy(new_tree, pfx, (size_t) width * (start_depth - 1));
436 mutt_str_copy(new_tree + (start_depth - 1) * width, arrow,
437 (1 + depth - start_depth) * width + 2);
438 }
439 else
440 {
441 mutt_str_copy(new_tree, arrow, ((size_t) depth * width) + 2);
442 }
443 tree->message->tree = new_tree;
444 }
445 }
446 if (tree->child && (depth != 0))
447 {
448 mypfx = pfx + (depth - 1) * width;
449 mypfx[0] = nextdisp ? MUTT_TREE_VLINE : MUTT_TREE_SPACE;
450 if (width == 2)
451 mypfx[1] = MUTT_TREE_SPACE;
452 }
453 parent = tree;
454 nextdisp = NULL;
455 pseudo = NULL;
456 do
457 {
458 if (tree->child && tree->subtree_visible)
459 {
460 if (tree->deep)
461 depth++;
462 if (tree->visible)
463 start_depth = depth;
464 tree = tree->child;
465
466 /* we do this here because we need to make sure that the first child thread
467 * of the old tree that we deal with is actually displayed if any are,
468 * or we might set the parent variable wrong while going through it. */
469 while (!tree->subtree_visible && tree->next)
470 tree = tree->next;
471 }
472 else
473 {
474 while (!tree->next && tree->parent)
475 {
476 if (tree == pseudo)
477 pseudo = NULL;
478 if (tree == nextdisp)
479 nextdisp = NULL;
480 if (tree->visible)
481 start_depth = depth;
482 tree = tree->parent;
483 if (tree->deep)
484 {
485 if (start_depth == depth)
486 start_depth--;
487 depth--;
488 }
489 }
490 if (tree == pseudo)
491 pseudo = NULL;
492 if (tree == nextdisp)
493 nextdisp = NULL;
494 if (tree->visible)
495 start_depth = depth;
496 tree = tree->next;
497 if (!tree)
498 break;
499 }
500 if (!pseudo && tree->fake_thread)
501 pseudo = tree;
502 if (!nextdisp && tree->next_subtree_visible)
503 nextdisp = tree;
504 } while (!tree->deep);
505 }
506
507 FREE(&pfx);
508 FREE(&arrow);
509}
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
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
static void calculate_visibility(struct MuttThread *tree, int *max_depth)
Are tree nodes visible.
Definition: mutt_thread.c:233
TreeChar
Tree characters for menus.
Definition: mutt_thread.h:55
char * tree
Character string to print thread tree.
Definition: email.h:124
bool visible
Is this Thread visible?
Definition: thread.h:42
bool fake_thread
Emails grouped by Subject.
Definition: thread.h:38
bool deep
Is the Thread deeply nested?
Definition: thread.h:36
unsigned int subtree_visible
Is this Thread subtree visible?
Definition: thread.h:41
bool duplicate_thread
Duplicated Email in Thread.
Definition: thread.h:37
bool next_subtree_visible
Is the next Thread subtree visible?
Definition: thread.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_link_threads()

bool mutt_link_threads ( struct Email parent,
struct EmailArray *  children,
struct Mailbox m 
)

Forcibly link threads together.

Parameters
parentParent Email
childrenArray of children Emails
mMailbox
Return values
trueOn success

Definition at line 1744 of file mutt_thread.c.

1745{
1746 if (!parent || !children || !m)
1747 return false;
1748
1749 bool changed = false;
1750
1751 struct Email **ep = NULL;
1752 ARRAY_FOREACH(ep, children)
1753 {
1754 struct Email *e = *ep;
1755 changed |= link_threads(parent, e, m);
1756 }
1757
1758 return changed;
1759}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
static bool link_threads(struct Email *parent, struct Email *child, struct Mailbox *m)
Forcibly link messages together.
Definition: mutt_thread.c:1723
bool changed
Email has been edited.
Definition: email.h:75
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_make_id_hash()

struct HashTable * mutt_make_id_hash ( struct Mailbox m)

Create a Hash Table for message-ids.

Parameters
mMailbox
Return values
ptrNewly allocated Hash Table

Definition at line 1699 of file mutt_thread.c.

1700{
1701 struct HashTable *hash = mutt_hash_new(m->msg_count * 2, MUTT_HASH_NO_FLAGS);
1702
1703 for (int i = 0; i < m->msg_count; i++)
1704 {
1705 struct Email *e = m->emails[i];
1706 if (!e || !e->env)
1707 continue;
1708
1709 if (e->env->message_id)
1710 mutt_hash_insert(hash, e->env->message_id, e);
1711 }
1712
1713 return hash;
1714}
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
Definition: hash.c:335
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
Definition: hash.c:259
#define MUTT_HASH_NO_FLAGS
No flags are set.
Definition: hash.h:110
struct Envelope * env
Envelope information.
Definition: email.h:66
char * message_id
Message ID.
Definition: envelope.h:73
A Hash Table.
Definition: hash.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_messages_in_thread()

int mutt_messages_in_thread ( struct Mailbox m,
struct Email e,
enum MessageInThread  mit 
)

Count the messages in a thread.

Parameters
mMailbox
eEmail
mitFlag, e.g. MIT_NUM_MESSAGES
Return values
numNumber of message / Our position

Definition at line 1654 of file mutt_thread.c.

1655{
1656 if (!m || !e)
1657 return 1;
1658
1659 struct MuttThread *threads[2];
1660 int rc;
1661
1662 const enum UseThreads threaded = mutt_thread_style();
1663 if ((threaded == UT_FLAT) || !e->thread)
1664 return 1;
1665
1666 threads[0] = e->thread;
1667 while (threads[0]->parent)
1668 threads[0] = threads[0]->parent;
1669
1670 threads[1] = (mit == MIT_POSITION) ? e->thread : threads[0]->next;
1671
1672 for (int i = 0; i < (((mit == MIT_POSITION) || !threads[1]) ? 1 : 2); i++)
1673 {
1674 while (!threads[i]->message)
1675 threads[i] = threads[i]->child;
1676 }
1677
1678 if (threaded == UT_REVERSE)
1679 {
1680 rc = threads[0]->message->msgno - (threads[1] ? threads[1]->message->msgno : -1);
1681 }
1682 else
1683 {
1684 rc = (threads[1] ? threads[1]->message->msgno : m->msg_count) -
1685 threads[0]->message->msgno;
1686 }
1687
1688 if (mit == MIT_POSITION)
1689 rc += 1;
1690
1691 return rc;
1692}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parent_message()

int mutt_parent_message ( struct Email e,
bool  find_root 
)

Find the parent of a message.

Parameters
eCurrent Email
find_rootIf true, find the root message
Return values
>=0Virtual index number of parent/root message
-1Error

Definition at line 1351 of file mutt_thread.c.

1352{
1353 if (!e)
1354 return -1;
1355
1356 struct MuttThread *thread = NULL;
1357 struct Email *e_parent = NULL;
1358
1359 if (!mutt_using_threads())
1360 {
1361 mutt_error(_("Threading is not enabled"));
1362 return e->vnum;
1363 }
1364
1365 /* Root may be the current message */
1366 if (find_root)
1367 e_parent = e;
1368
1369 for (thread = e->thread->parent; thread; thread = thread->parent)
1370 {
1371 e = thread->message;
1372 if (e)
1373 {
1374 e_parent = e;
1375 if (!find_root)
1376 break;
1377 }
1378 }
1379
1380 if (!e_parent)
1381 {
1382 mutt_error(_("Parent message is not available"));
1383 return -1;
1384 }
1385 if (!is_visible(e_parent))
1386 {
1387 if (find_root)
1388 mutt_error(_("Root message is not visible in this limited view"));
1389 else
1390 mutt_error(_("Parent message is not visible in this limited view"));
1391 return -1;
1392 }
1393 return e_parent->vnum;
1394}
static bool is_visible(struct Email *e)
Is the message visible?
Definition: mutt_thread.c:121
#define mutt_using_threads()
Definition: mutt_thread.h:112
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_set_vnum()

off_t mutt_set_vnum ( struct Mailbox m)

Set the virtual index number of all the messages in a mailbox.

Parameters
mMailbox
Return values
numSize in bytes of all messages shown

Definition at line 1401 of file mutt_thread.c.

1402{
1403 if (!m)
1404 return 0;
1405
1406 off_t vsize = 0;
1407 const int padding = mx_msg_padding_size(m);
1408
1409 m->vcount = 0;
1410
1411 for (int i = 0; i < m->msg_count; i++)
1412 {
1413 struct Email *e = m->emails[i];
1414 if (!e)
1415 break;
1416
1417 if (e->vnum >= 0)
1418 {
1419 e->vnum = m->vcount;
1420 m->v2r[m->vcount] = i;
1421 m->vcount++;
1422 vsize += e->body->length + e->body->offset - e->body->hdr_offset + padding;
1423 }
1424 }
1425
1426 return vsize;
1427}
int mx_msg_padding_size(struct Mailbox *m)
Bytes of padding between messages - Wrapper for MxOps::msg_padding_size()
Definition: mx.c:1566
LOFF_T offset
offset where the actual data begins
Definition: body.h:52
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
long hdr_offset
Offset in stream where the headers begin.
Definition: body.h:80
struct Body * body
List of MIME parts.
Definition: email.h:67
int vcount
The number of virtual messages.
Definition: mailbox.h:99
int * v2r
Mapping from virtual to real msgno.
Definition: mailbox.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_sort_threads()

void mutt_sort_threads ( struct ThreadsContext tctx,
bool  init 
)

Sort email threads.

Parameters
tctxThreading context
initIf true, rebuild the thread

Definition at line 1028 of file mutt_thread.c.

1029{
1030 if (!tctx || !tctx->mailbox_view)
1031 return;
1032
1033 struct MailboxView *mv = tctx->mailbox_view;
1034 struct Mailbox *m = mv->mailbox;
1035
1036 struct Email *e = NULL;
1037 int i, using_refs = 0;
1038 struct MuttThread *thread = NULL, *tnew = NULL, *tmp = NULL;
1039 struct MuttThread top = { 0 };
1040 struct ListNode *ref = NULL;
1041
1042 assert(m->msg_count > 0);
1043 if (!tctx->hash)
1044 init = true;
1045
1046 if (init)
1047 {
1050 }
1051
1052 /* we want a quick way to see if things are actually attached to the top of the
1053 * thread tree or if they're just dangling, so we attach everything to a top
1054 * node temporarily */
1055 top.parent = NULL;
1056 top.next = NULL;
1057 top.prev = NULL;
1058
1059 top.child = tctx->tree;
1060 for (thread = tctx->tree; thread; thread = thread->next)
1061 thread->parent = &top;
1062
1063 /* put each new message together with the matching messageless MuttThread if it
1064 * exists. otherwise, if there is a MuttThread that already has a message, thread
1065 * new message as an identical child. if we didn't attach the message to a
1066 * MuttThread, make a new one for it. */
1067 const bool c_duplicate_threads = cs_subset_bool(NeoMutt->sub, "duplicate_threads");
1068 for (i = 0; i < m->msg_count; i++)
1069 {
1070 e = m->emails[i];
1071 if (!e)
1072 continue;
1073
1074 if (e->thread)
1075 {
1076 /* unlink pseudo-threads because they might be children of newly
1077 * arrived messages */
1078 thread = e->thread;
1079 for (tnew = thread->child; tnew;)
1080 {
1081 tmp = tnew->next;
1082 if (tnew->fake_thread)
1083 {
1084 unlink_message(&thread->child, tnew);
1085 insert_message(&top.child, &top, tnew);
1086 tnew->fake_thread = false;
1087 }
1088 tnew = tmp;
1089 }
1090 }
1091 else
1092 {
1093 if ((!init || c_duplicate_threads) && e->env->message_id)
1094 thread = mutt_hash_find(tctx->hash, e->env->message_id);
1095 else
1096 thread = NULL;
1097
1098 if (thread && !thread->message)
1099 {
1100 /* this is a message which was missing before */
1101 thread->message = e;
1102 e->thread = thread;
1103 thread->check_subject = true;
1104
1105 /* mark descendants as needing subject_changed checked */
1106 for (tmp = (thread->child ? thread->child : thread); tmp != thread;)
1107 {
1108 while (!tmp->message)
1109 tmp = tmp->child;
1110 tmp->check_subject = true;
1111 while (!tmp->next && (tmp != thread))
1112 tmp = tmp->parent;
1113 if (tmp != thread)
1114 tmp = tmp->next;
1115 }
1116
1117 if (thread->parent)
1118 {
1119 /* remove threading info above it based on its children, which we'll
1120 * recalculate based on its headers. make sure not to leave
1121 * dangling missing messages. note that we haven't kept track
1122 * of what info came from its children and what from its siblings'
1123 * children, so we just remove the stuff that's definitely from it */
1124 do
1125 {
1126 tmp = thread->parent;
1127 unlink_message(&tmp->child, thread);
1128 thread->parent = NULL;
1129 thread->sort_thread_key = NULL;
1130 thread->sort_aux_key = NULL;
1131 thread->fake_thread = false;
1132 thread = tmp;
1133 } while (thread != &top && !thread->child && !thread->message);
1134 }
1135 }
1136 else
1137 {
1138 tnew = (c_duplicate_threads ? thread : NULL);
1139
1140 thread = mutt_mem_calloc(1, sizeof(struct MuttThread));
1141 thread->message = e;
1142 thread->check_subject = true;
1143 e->thread = thread;
1144 mutt_hash_insert(tctx->hash, e->env->message_id ? e->env->message_id : "", thread);
1145
1146 if (tnew)
1147 {
1148 if (tnew->duplicate_thread)
1149 tnew = tnew->parent;
1150
1151 thread = e->thread;
1152
1153 insert_message(&tnew->child, tnew, thread);
1154 thread->duplicate_thread = true;
1155 thread->message->threaded = true;
1156 }
1157 }
1158 }
1159 }
1160
1161 /* thread by references */
1162 for (i = 0; i < m->msg_count; i++)
1163 {
1164 e = m->emails[i];
1165 if (!e)
1166 break;
1167
1168 if (e->threaded)
1169 continue;
1170 e->threaded = true;
1171
1172 thread = e->thread;
1173 if (!thread)
1174 continue;
1175 using_refs = 0;
1176
1177 while (true)
1178 {
1179 if (using_refs == 0)
1180 {
1181 /* look at the beginning of in-reply-to: */
1182 ref = STAILQ_FIRST(&e->env->in_reply_to);
1183 if (ref)
1184 {
1185 using_refs = 1;
1186 }
1187 else
1188 {
1189 ref = STAILQ_FIRST(&e->env->references);
1190 using_refs = 2;
1191 }
1192 }
1193 else if (using_refs == 1)
1194 {
1195 /* if there's no references header, use all the in-reply-to:
1196 * data that we have. otherwise, use the first reference
1197 * if it's different than the first in-reply-to, otherwise use
1198 * the second reference (since at least eudora puts the most
1199 * recent reference in in-reply-to and the rest in references) */
1200 if (STAILQ_EMPTY(&e->env->references))
1201 {
1202 ref = STAILQ_NEXT(ref, entries);
1203 }
1204 else
1205 {
1206 if (!mutt_str_equal(ref->data, STAILQ_FIRST(&e->env->references)->data))
1207 ref = STAILQ_FIRST(&e->env->references);
1208 else
1209 ref = STAILQ_NEXT(STAILQ_FIRST(&e->env->references), entries);
1210
1211 using_refs = 2;
1212 }
1213 }
1214 else
1215 {
1216 ref = STAILQ_NEXT(ref, entries); /* go on with references */
1217 }
1218
1219 if (!ref)
1220 break;
1221
1222 tnew = mutt_hash_find(tctx->hash, ref->data);
1223 if (tnew)
1224 {
1225 if (tnew->duplicate_thread)
1226 tnew = tnew->parent;
1227 if (is_descendant(tnew, thread)) /* no loops! */
1228 continue;
1229 }
1230 else
1231 {
1232 tnew = mutt_mem_calloc(1, sizeof(struct MuttThread));
1233 mutt_hash_insert(tctx->hash, ref->data, tnew);
1234 }
1235
1236 if (thread->parent)
1237 unlink_message(&top.child, thread);
1238 insert_message(&tnew->child, tnew, thread);
1239 thread = tnew;
1240 if (thread->message || (thread->parent && (thread->parent != &top)))
1241 break;
1242 }
1243
1244 if (!thread->parent)
1245 insert_message(&top.child, &top, thread);
1246 }
1247
1248 /* detach everything from the temporary top node */
1249 for (thread = top.child; thread; thread = thread->next)
1250 {
1251 thread->parent = NULL;
1252 }
1253 tctx->tree = top.child;
1254
1255 check_subjects(mv, init);
1256
1257 const bool c_strict_threads = cs_subset_bool(NeoMutt->sub, "strict_threads");
1258 if (!c_strict_threads)
1259 pseudo_threads(tctx);
1260
1261 /* if $sort_aux or similar changed after the mailbox is sorted, then
1262 * all the subthreads need to be resorted */
1263 if (tctx->tree)
1264 {
1266 OptSortSubthreads = false;
1267
1268 /* Put the list into an array. */
1269 linearize_tree(tctx);
1270
1271 /* Draw the thread tree. */
1272 mutt_draw_tree(tctx);
1273 }
1274}
bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition: globals.c:82
static void thread_hash_destructor(int type, void *obj, intptr_t data)
Hash Destructor callback - Implements hash_hdata_free_t -.
Definition: mutt_thread.c:1018
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:362
void mutt_hash_set_destructor(struct HashTable *table, hash_hdata_free_t fn, intptr_t fn_data)
Set the destructor for a Hash Table.
Definition: hash.c:301
#define MUTT_HASH_ALLOW_DUPS
allow duplicate keys to be inserted
Definition: hash.h:113
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:798
static void linearize_tree(struct ThreadsContext *tctx)
Flatten an email thread.
Definition: mutt_thread.c:180
static void mutt_sort_subthreads(struct ThreadsContext *tctx, bool init)
Sort the children of a thread.
Definition: mutt_thread.c:775
void mutt_draw_tree(struct ThreadsContext *tctx)
Draw a tree of threaded emails.
Definition: mutt_thread.c:391
static void pseudo_threads(struct ThreadsContext *tctx)
Thread messages by subject.
Definition: mutt_thread.c:646
static void check_subjects(struct MailboxView *mv, bool init)
Find out which emails' subjects differ from their parent's.
Definition: mutt_thread.c:976
#define STAILQ_FIRST(head)
Definition: queue.h:350
#define STAILQ_EMPTY(head)
Definition: queue.h:348
#define STAILQ_NEXT(elm, field)
Definition: queue.h:400
struct ListHead references
message references (in reverse order)
Definition: envelope.h:85
struct ListHead in_reply_to
in-reply-to header content
Definition: envelope.h:86
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
struct Email * sort_aux_key
Email that controls how subthread siblings sort.
Definition: thread.h:51
bool check_subject
Should the Subject be checked?
Definition: thread.h:35
struct Email * sort_thread_key
Email that controls how top thread sorts.
Definition: thread.h:50
void unlink_message(struct MuttThread **old, struct MuttThread *cur)
Break the message out of the thread.
Definition: thread.c:63
bool is_descendant(const struct MuttThread *a, const struct MuttThread *b)
Is one thread a descendant of another.
Definition: thread.c:43
void insert_message(struct MuttThread **add, struct MuttThread *parent, struct MuttThread *cur)
Insert a message into a thread.
Definition: thread.c:101
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ UseThreadsTypeDef

const struct EnumDef UseThreadsTypeDef
extern

Data for the $use_threads enumeration.

Definition at line 64 of file mutt_thread.c.