NeoMutt  2024-04-25-76-g20fe7b
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 1438 of file mutt_thread.c.

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

1288{
1289 if (!e)
1290 return -1;
1291
1292 struct MuttThread *cur = NULL;
1293 struct Email *e_tmp = NULL;
1294
1295 const enum UseThreads threaded = mutt_thread_style();
1296 if (threaded == UT_FLAT)
1297 {
1298 mutt_error(_("Threading is not enabled"));
1299 return e->vnum;
1300 }
1301
1302 cur = e->thread;
1303
1304 if (subthreads)
1305 {
1306 if (forwards ^ (threaded == UT_REVERSE))
1307 {
1308 while (!cur->next && cur->parent)
1309 cur = cur->parent;
1310 }
1311 else
1312 {
1313 while (!cur->prev && cur->parent)
1314 cur = cur->parent;
1315 }
1316 }
1317 else
1318 {
1319 while (cur->parent)
1320 cur = cur->parent;
1321 }
1322
1323 if (forwards ^ (threaded == UT_REVERSE))
1324 {
1325 do
1326 {
1327 cur = cur->next;
1328 if (!cur)
1329 return -1;
1330 e_tmp = find_virtual(cur, false);
1331 } while (!e_tmp);
1332 }
1333 else
1334 {
1335 do
1336 {
1337 cur = cur->prev;
1338 if (!cur)
1339 return -1;
1340 e_tmp = find_virtual(cur, true);
1341 } while (!e_tmp);
1342 }
1343
1344 return e_tmp->vnum;
1345}
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, sizeof(struct ThreadsContext));
360 tctx->mailbox_view = mv;
361 return tctx;
362}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
The "current" threading state.
Definition: mutt_thread.h:43
struct MailboxView * mailbox_view
Current mailbox.
Definition: mutt_thread.h:44
+ 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 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:45
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 1768 of file mutt_thread.c.

1769{
1770 struct MuttThread *thread = NULL;
1771 struct MuttThread *top = tctx->tree;
1772 while ((thread = top))
1773 {
1774 while (!thread->message)
1775 thread = thread->child;
1776
1777 struct Email *e = thread->message;
1778 if (e->collapsed)
1780 top = top->next;
1781 }
1782}
#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 1789 of file mutt_thread.c.

1790{
1791 struct MuttThread *thread = NULL;
1792 struct MuttThread *top = tctx->tree;
1793 while ((thread = top))
1794 {
1795 while (!thread->message)
1796 thread = thread->child;
1797
1798 struct Email *e = thread->message;
1799
1800 if (e->collapsed != collapse)
1801 {
1802 if (e->collapsed)
1804 else if (mutt_thread_can_collapse(e))
1806 }
1807 top = top->next;
1808 }
1809}
bool mutt_thread_can_collapse(struct Email *e)
Check whether a thread can be collapsed.
Definition: mutt_thread.c:1817
#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 1817 of file mutt_thread.c.

1818{
1819 const bool c_collapse_flagged = cs_subset_bool(NeoMutt->sub, "collapse_flagged");
1820 const bool c_collapse_unread = cs_subset_bool(NeoMutt->sub, "collapse_unread");
1821 return (c_collapse_unread || !mutt_thread_contains_unread(e)) &&
1822 (c_collapse_flagged || !mutt_thread_contains_flagged(e));
1823}
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);
410 arrow = mutt_mem_malloc((width * max_depth) + 2);
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);
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}
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:91
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:128
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 1747 of file mutt_thread.c.

1748{
1749 if (!parent || !children || !m)
1750 return false;
1751
1752 bool changed = false;
1753
1754 struct Email **ep = NULL;
1755 ARRAY_FOREACH(ep, children)
1756 {
1757 struct Email *e = *ep;
1758 changed |= link_threads(parent, e, m);
1759 }
1760
1761 return changed;
1762}
#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:1726
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 1702 of file mutt_thread.c.

1703{
1704 struct HashTable *hash = mutt_hash_new(m->msg_count * 2, MUTT_HASH_NO_FLAGS);
1705
1706 for (int i = 0; i < m->msg_count; i++)
1707 {
1708 struct Email *e = m->emails[i];
1709 if (!e || !e->env)
1710 continue;
1711
1712 if (e->env->message_id)
1713 mutt_hash_insert(hash, e->env->message_id, e);
1714 }
1715
1716 return hash;
1717}
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 1657 of file mutt_thread.c.

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

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

1405{
1406 if (!m)
1407 return 0;
1408
1409 off_t vsize = 0;
1410 const int padding = mx_msg_padding_size(m);
1411
1412 m->vcount = 0;
1413
1414 for (int i = 0; i < m->msg_count; i++)
1415 {
1416 struct Email *e = m->emails[i];
1417 if (!e)
1418 break;
1419
1420 if (e->vnum >= 0)
1421 {
1422 e->vnum = m->vcount;
1423 m->v2r[m->vcount] = i;
1424 m->vcount++;
1425 vsize += e->body->length + e->body->offset - e->body->hdr_offset + padding;
1426 }
1427 }
1428
1429 return vsize;
1430}
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:80
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 1031 of file mutt_thread.c.

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