NeoMutt  2024-11-14-34-g5aaf0d
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 the "sort" config variable - 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
  • Pietro Cerutti
  • Eric Blake

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 77 of file mutt_thread.h.

◆ MUTT_THREAD_COLLAPSE

#define MUTT_THREAD_COLLAPSE   (1 << 0)

Collapse an email thread.

Definition at line 78 of file mutt_thread.h.

◆ MUTT_THREAD_UNCOLLAPSE

#define MUTT_THREAD_UNCOLLAPSE   (1 << 1)

Uncollapse an email thread.

Definition at line 79 of file mutt_thread.h.

◆ MUTT_THREAD_UNREAD

#define MUTT_THREAD_UNREAD   (1 << 2)

Count unread emails in a thread.

Definition at line 80 of file mutt_thread.h.

◆ MUTT_THREAD_NEXT_UNREAD

#define MUTT_THREAD_NEXT_UNREAD   (1 << 3)

Find the next unread email.

Definition at line 81 of file mutt_thread.h.

◆ MUTT_THREAD_FLAGGED

#define MUTT_THREAD_FLAGGED   (1 << 4)

Count flagged emails in a thread.

Definition at line 82 of file mutt_thread.h.

◆ mutt_collapse_thread

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

Definition at line 107 of file mutt_thread.h.

◆ mutt_uncollapse_thread

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

Definition at line 108 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 109 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 110 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 111 of file mutt_thread.h.

◆ mutt_using_threads

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

Definition at line 114 of file mutt_thread.h.

◆ mutt_next_thread

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

Definition at line 120 of file mutt_thread.h.

◆ mutt_previous_thread

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

Definition at line 121 of file mutt_thread.h.

◆ mutt_next_subthread

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

Definition at line 122 of file mutt_thread.h.

◆ mutt_previous_subthread

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

Definition at line 123 of file mutt_thread.h.

Typedef Documentation

◆ MuttThreadFlags

typedef uint8_t MuttThreadFlags

Flags, e.g. MUTT_THREAD_COLLAPSE.

Definition at line 76 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 56 of file mutt_thread.h.

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

◆ 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 87 of file mutt_thread.h.

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

◆ 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 96 of file mutt_thread.h.

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

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 1441 of file mutt_thread.c.

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

83{
84 const unsigned char c_use_threads = cs_subset_enum(NeoMutt->sub, "use_threads");
85 const enum SortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
86 if (c_use_threads > UT_FLAT)
87 return c_use_threads;
88 if ((c_sort & SORT_MASK) != SORT_THREADS)
89 return UT_FLAT;
90 if (c_sort & SORT_REVERSE)
91 return UT_REVERSE;
92 return UT_THREADS;
93}
unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
Get a enumeration config item by name.
Definition: helpers.c:71
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:70
SortType
Methods for sorting.
Definition: sort2.h:34
@ SORT_THREADS
Sort by email threads.
Definition: sort2.h:41
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:71
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:

◆ 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 100 of file mutt_thread.c.

101{
103}
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:53
+ 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 1290 of file mutt_thread.c.

1291{
1292 if (!e)
1293 return -1;
1294
1295 struct MuttThread *cur = NULL;
1296 struct Email *e_tmp = NULL;
1297
1298 const enum UseThreads threaded = mutt_thread_style();
1299 if (threaded == UT_FLAT)
1300 {
1301 mutt_error(_("Threading is not enabled"));
1302 return e->vnum;
1303 }
1304
1305 cur = e->thread;
1306
1307 if (subthreads)
1308 {
1309 if (forwards ^ (threaded == UT_REVERSE))
1310 {
1311 while (!cur->next && cur->parent)
1312 cur = cur->parent;
1313 }
1314 else
1315 {
1316 while (!cur->prev && cur->parent)
1317 cur = cur->parent;
1318 }
1319 }
1320 else
1321 {
1322 while (cur->parent)
1323 cur = cur->parent;
1324 }
1325
1326 if (forwards ^ (threaded == UT_REVERSE))
1327 {
1328 do
1329 {
1330 cur = cur->next;
1331 if (!cur)
1332 return -1;
1333 e_tmp = find_virtual(cur, false);
1334 } while (!e_tmp);
1335 }
1336 else
1337 {
1338 do
1339 {
1340 cur = cur->prev;
1341 if (!cur)
1342 return -1;
1343 e_tmp = find_virtual(cur, true);
1344 } while (!e_tmp);
1345 }
1346
1347 return e_tmp->vnum;
1348}
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:124
+ 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 357 of file mutt_thread.c.

358{
359 struct ThreadsContext *tctx = MUTT_MEM_CALLOC(1, struct ThreadsContext);
360 tctx->mailbox_view = mv;
361 return tctx;
362}
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
The "current" threading state.
Definition: mutt_thread.h:43
struct MailboxView * mailbox_view
Current mailbox.
Definition: mutt_thread.h:44
+ 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 368 of file mutt_thread.c.

369{
370 if (!ptr || !*ptr)
371 {
372 return;
373 }
374
375 struct ThreadsContext *tctx = *ptr;
376
377 mutt_hash_free(&tctx->hash);
378
379 FREE(ptr);
380}
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
#define FREE(x)
Definition: memory.h:55
struct HashTable * hash
Hash Table: "message-id" -> MuttThread.
Definition: mutt_thread.h:46
+ 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 1771 of file mutt_thread.c.

1772{
1773 struct MuttThread *thread = NULL;
1774 struct MuttThread *top = tctx->tree;
1775 while ((thread = top))
1776 {
1777 while (!thread->message)
1778 thread = thread->child;
1779
1780 struct Email *e = thread->message;
1781 if (e->collapsed)
1783 top = top->next;
1784 }
1785}
#define mutt_collapse_thread(e)
Definition: mutt_thread.h:107
struct MuttThread * tree
Top of thread tree.
Definition: mutt_thread.h:45
+ 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 1792 of file mutt_thread.c.

1793{
1794 struct MuttThread *thread = NULL;
1795 struct MuttThread *top = tctx->tree;
1796 while ((thread = top))
1797 {
1798 while (!thread->message)
1799 thread = thread->child;
1800
1801 struct Email *e = thread->message;
1802
1803 if (e->collapsed != collapse)
1804 {
1805 if (e->collapsed)
1807 else if (mutt_thread_can_collapse(e))
1809 }
1810 top = top->next;
1811 }
1812}
bool mutt_thread_can_collapse(struct Email *e)
Check whether a thread can be collapsed.
Definition: mutt_thread.c:1820
#define mutt_uncollapse_thread(e)
Definition: mutt_thread.h:108
+ 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 1820 of file mutt_thread.c.

1821{
1822 const bool c_collapse_flagged = cs_subset_bool(NeoMutt->sub, "collapse_flagged");
1823 const bool c_collapse_unread = cs_subset_bool(NeoMutt->sub, "collapse_unread");
1824 return (c_collapse_unread || !mutt_thread_contains_unread(e)) &&
1825 (c_collapse_flagged || !mutt_thread_contains_flagged(e));
1826}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
#define mutt_thread_contains_flagged(e)
Definition: mutt_thread.h:110
#define mutt_thread_contains_unread(e)
Definition: mutt_thread.h:109
+ 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 720 of file mutt_thread.c.

721{
722 if (!tctx || !tctx->tree)
723 return;
724
725 struct MailboxView *mv = tctx->mailbox_view;
726 if (!mv)
727 return;
728
729 struct Mailbox *m = mv->mailbox;
730 if (!m || !m->emails)
731 return;
732
733 for (int i = 0; i < m->msg_count; i++)
734 {
735 struct Email *e = m->emails[i];
736 if (!e)
737 break;
738
739 /* mailbox may have been only partially read */
740 e->thread = NULL;
741 e->threaded = false;
742 }
743 tctx->tree = NULL;
744 mutt_hash_free(&tctx->hash);
745}
View of a Mailbox.
Definition: mview.h:40
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:51
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 394 of file mutt_thread.c.

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

1751{
1752 if (!parent || !children || !m)
1753 return false;
1754
1755 bool changed = false;
1756
1757 struct Email **ep = NULL;
1758 ARRAY_FOREACH(ep, children)
1759 {
1760 struct Email *e = *ep;
1761 changed |= link_threads(parent, e, m);
1762 }
1763
1764 return changed;
1765}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
static bool link_threads(struct Email *parent, struct Email *child, struct Mailbox *m)
Forcibly link messages together.
Definition: mutt_thread.c:1729
bool changed
Email has been edited.
Definition: email.h:77
+ 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 1705 of file mutt_thread.c.

1706{
1707 struct HashTable *hash = mutt_hash_new(m->msg_count * 2, MUTT_HASH_NO_FLAGS);
1708
1709 for (int i = 0; i < m->msg_count; i++)
1710 {
1711 struct Email *e = m->emails[i];
1712 if (!e || !e->env)
1713 continue;
1714
1715 if (e->env->message_id)
1716 mutt_hash_insert(hash, e->env->message_id, e);
1717 }
1718
1719 return hash;
1720}
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:109
struct Envelope * env
Envelope information.
Definition: email.h:68
char * message_id
Message ID.
Definition: envelope.h:73
A Hash Table.
Definition: hash.h:97
+ 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 1660 of file mutt_thread.c.

1661{
1662 if (!m || !e)
1663 return 1;
1664
1665 struct MuttThread *threads[2];
1666 int rc;
1667
1668 const enum UseThreads threaded = mutt_thread_style();
1669 if ((threaded == UT_FLAT) || !e->thread)
1670 return 1;
1671
1672 threads[0] = e->thread;
1673 while (threads[0]->parent)
1674 threads[0] = threads[0]->parent;
1675
1676 threads[1] = (mit == MIT_POSITION) ? e->thread : threads[0]->next;
1677
1678 for (int i = 0; i < (((mit == MIT_POSITION) || !threads[1]) ? 1 : 2); i++)
1679 {
1680 while (!threads[i]->message)
1681 threads[i] = threads[i]->child;
1682 }
1683
1684 if (threaded == UT_REVERSE)
1685 {
1686 rc = threads[0]->message->msgno - (threads[1] ? threads[1]->message->msgno : -1);
1687 }
1688 else
1689 {
1690 rc = (threads[1] ? threads[1]->message->msgno : m->msg_count) -
1691 threads[0]->message->msgno;
1692 }
1693
1694 if (mit == MIT_POSITION)
1695 rc += 1;
1696
1697 return rc;
1698}
+ 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 1357 of file mutt_thread.c.

1358{
1359 if (!e)
1360 return -1;
1361
1362 struct MuttThread *thread = NULL;
1363 struct Email *e_parent = NULL;
1364
1365 if (!mutt_using_threads())
1366 {
1367 mutt_error(_("Threading is not enabled"));
1368 return e->vnum;
1369 }
1370
1371 /* Root may be the current message */
1372 if (find_root)
1373 e_parent = e;
1374
1375 for (thread = e->thread->parent; thread; thread = thread->parent)
1376 {
1377 e = thread->message;
1378 if (e)
1379 {
1380 e_parent = e;
1381 if (!find_root)
1382 break;
1383 }
1384 }
1385
1386 if (!e_parent)
1387 {
1388 mutt_error(_("Parent message is not available"));
1389 return -1;
1390 }
1391 if (!is_visible(e_parent))
1392 {
1393 if (find_root)
1394 mutt_error(_("Root message is not visible in this limited view"));
1395 else
1396 mutt_error(_("Parent message is not visible in this limited view"));
1397 return -1;
1398 }
1399 return e_parent->vnum;
1400}
static bool is_visible(struct Email *e)
Is the message visible?
Definition: mutt_thread.c:124
#define mutt_using_threads()
Definition: mutt_thread.h:114
+ 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 1407 of file mutt_thread.c.

1408{
1409 if (!m)
1410 return 0;
1411
1412 off_t vsize = 0;
1413 const int padding = mx_msg_padding_size(m);
1414
1415 m->vcount = 0;
1416
1417 for (int i = 0; i < m->msg_count; i++)
1418 {
1419 struct Email *e = m->emails[i];
1420 if (!e)
1421 break;
1422
1423 if (e->vnum >= 0)
1424 {
1425 e->vnum = m->vcount;
1426 m->v2r[m->vcount] = i;
1427 m->vcount++;
1428 vsize += e->body->length + e->body->offset - e->body->hdr_offset + padding;
1429 }
1430 }
1431
1432 return vsize;
1433}
int mx_msg_padding_size(struct Mailbox *m)
Bytes of padding between messages - Wrapper for MxOps::msg_padding_size()
Definition: mx.c:1505
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:81
struct Body * body
List of MIME parts.
Definition: email.h:69
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 1034 of file mutt_thread.c.

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