NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
hdrline.c File Reference

String processing routines to generate the mail index. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "alias/lib.h"
#include "gui/lib.h"
#include "hdrline.h"
#include "attach/lib.h"
#include "color/lib.h"
#include "ncrypt/lib.h"
#include "format_flags.h"
#include "hook.h"
#include "maillist.h"
#include "mutt_thread.h"
#include "muttlib.h"
#include "mx.h"
#include "sort.h"
#include "subjectrx.h"
#include "notmuch/lib.h"
+ Include dependency graph for hdrline.c:

Go to the source code of this file.

Data Structures

struct  HdrFormatInfo
 Data passed to index_format_str() More...
 

Enumerations

enum  FieldType {
  DISP_TO , DISP_CC , DISP_BCC , DISP_FROM ,
  DISP_PLAIN , DISP_MAX
}
 Header types. More...
 

Functions

static size_t add_index_color (char *buf, size_t buflen, MuttFormatFlags flags, enum ColorId color)
 Insert a color marker into a string.
 
static const char * make_from_prefix (enum FieldType disp)
 Create a prefix for an author field.
 
static void make_from (struct Envelope *env, char *buf, size_t buflen, bool do_lists, MuttFormatFlags flags)
 Generate a From: field (with optional prefix)
 
static void make_from_addr (struct Envelope *env, char *buf, size_t buflen, bool do_lists)
 Create a 'from' address for a reply email.
 
static bool user_in_addr (struct AddressList *al)
 Do any of the addresses refer to the user?
 
static enum ToChars user_is_recipient (struct Email *e)
 Is the user a recipient of the message.
 
static bool thread_is_new (struct Email *e)
 Does the email thread contain any new emails?
 
static bool thread_is_old (struct Email *e)
 Does the email thread contain any unread emails?
 
static const char * index_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
 Format a string for the index list - Implements format_t -.
 
void mutt_make_string (char *buf, size_t buflen, int cols, const char *s, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
 Create formatted strings using mailbox expandos.
 

Detailed Description

String processing routines to generate the mail index.

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

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

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

Definition in file hdrline.c.

Enumeration Type Documentation

◆ FieldType

enum FieldType

Header types.

Strings for printing headers

Enumerator
DISP_TO 

To: string.

DISP_CC 

Cc: string.

DISP_BCC 

Bcc: string.

DISP_FROM 

From: string.

DISP_PLAIN 

Empty string.

DISP_MAX 

Definition at line 78 of file hdrline.c.

79{
80 DISP_TO,
81 DISP_CC,
82 DISP_BCC,
83 DISP_FROM,
86};
@ DISP_PLAIN
Empty string.
Definition: hdrline.c:84
@ DISP_TO
To: string.
Definition: hdrline.c:80
@ DISP_CC
Cc: string.
Definition: hdrline.c:81
@ DISP_BCC
Bcc: string.
Definition: hdrline.c:82
@ DISP_MAX
Definition: hdrline.c:85
@ DISP_FROM
From: string.
Definition: hdrline.c:83

Function Documentation

◆ add_index_color()

static size_t add_index_color ( char *  buf,
size_t  buflen,
MuttFormatFlags  flags,
enum ColorId  color 
)
static

Insert a color marker into a string.

Parameters
bufBuffer to store marker
buflenBuffer length
flagsFlags, see MuttFormatFlags
colorColor, e.g. MT_COLOR_MESSAGE
Return values
numCharacters written

The colors are stored as "magic" strings embedded in the text.

Definition at line 98 of file hdrline.c.

99{
100 /* only add color markers if we are operating on main index entries. */
101 if (!(flags & MUTT_FORMAT_INDEX))
102 return 0;
103
104 /* this item is going to be passed to an external filter */
105 if (flags & MUTT_FORMAT_NOFILTER)
106 return 0;
107
108 if (color == MT_COLOR_INDEX)
109 { /* buf might be uninitialized other cases */
110 const size_t len = mutt_str_len(buf);
111 buf += len;
112 buflen -= len;
113 }
114
115 if (buflen <= 2)
116 return 0;
117
118 buf[0] = MUTT_SPECIAL_INDEX;
119 buf[1] = color;
120 buf[2] = '\0';
121
122 return 2;
123}
@ MT_COLOR_INDEX
Index: default colour.
Definition: color.h:83
#define MUTT_FORMAT_NOFILTER
Do not allow filtering on this pass.
Definition: format_flags.h:37
#define MUTT_FORMAT_INDEX
This is a main index entry.
Definition: format_flags.h:36
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:568
@ MUTT_SPECIAL_INDEX
Colour indicator.
Definition: mutt_thread.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_from_prefix()

static const char * make_from_prefix ( enum FieldType  disp)
static

Create a prefix for an author field.

Parameters
dispType of field
Return values
ptrPrefix string (do not free it)

If $from_chars is set, pick an appropriate character from it. If not, use the default prefix: "To", "Cc", etc

Definition at line 133 of file hdrline.c.

134{
135 /* need 2 bytes at the end, one for the space, another for NUL */
136 static char padded[8];
137 static const char *long_prefixes[DISP_MAX] = {
138 [DISP_TO] = "To ", [DISP_CC] = "Cc ", [DISP_BCC] = "Bcc ",
139 [DISP_FROM] = "", [DISP_PLAIN] = "",
140 };
141
142 const struct MbTable *c_from_chars = cs_subset_mbtable(NeoMutt->sub, "from_chars");
143
144 if (!c_from_chars || !c_from_chars->chars || (c_from_chars->len == 0))
145 return long_prefixes[disp];
146
147 const char *pchar = mbtable_get_nth_wchar(c_from_chars, disp);
148 if (mutt_str_len(pchar) == 0)
149 return "";
150
151 snprintf(padded, sizeof(padded), "%s ", pchar);
152 return padded;
153}
struct MbTable * cs_subset_mbtable(const struct ConfigSubset *sub, const char *name)
Get a Multibyte table config item by name.
Definition: helpers.c:120
const char * mbtable_get_nth_wchar(const struct MbTable *table, int index)
Extract one char from a multi-byte table.
Definition: mbtable.c:302
Multibyte character table.
Definition: mbtable.h:34
int len
Number of characters.
Definition: mbtable.h:36
char ** chars
The array of multibyte character strings.
Definition: mbtable.h:37
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_from()

static void make_from ( struct Envelope env,
char *  buf,
size_t  buflen,
bool  do_lists,
MuttFormatFlags  flags 
)
static

Generate a From: field (with optional prefix)

Parameters
envEnvelope of the email
bufBuffer to store the result
buflenSize of the buffer
do_listsShould we check for mailing lists?
flagsFormat flags, see MuttFormatFlags

Generate the F or L field in $index_format. This is the author, or recipient of the email.

The field can optionally be prefixed by a character from $from_chars. If $from_chars is not set, the prefix will be, "To", "Cc", etc

Definition at line 169 of file hdrline.c.

171{
172 if (!env || !buf)
173 return;
174
175 bool me;
176 enum FieldType disp;
177 struct AddressList *name = NULL;
178
180
181 if (do_lists || me)
182 {
183 if (check_for_mailing_list(&env->to, make_from_prefix(DISP_TO), buf, buflen))
184 return;
185 if (check_for_mailing_list(&env->cc, make_from_prefix(DISP_CC), buf, buflen))
186 return;
187 }
188
189 if (me && !TAILQ_EMPTY(&env->to))
190 {
191 disp = (flags & MUTT_FORMAT_PLAIN) ? DISP_PLAIN : DISP_TO;
192 name = &env->to;
193 }
194 else if (me && !TAILQ_EMPTY(&env->cc))
195 {
196 disp = DISP_CC;
197 name = &env->cc;
198 }
199 else if (me && !TAILQ_EMPTY(&env->bcc))
200 {
201 disp = DISP_BCC;
202 name = &env->bcc;
203 }
204 else if (!TAILQ_EMPTY(&env->from))
205 {
206 disp = DISP_FROM;
207 name = &env->from;
208 }
209 else
210 {
211 *buf = '\0';
212 return;
213 }
214
215 snprintf(buf, buflen, "%s%s", make_from_prefix(disp), mutt_get_name(TAILQ_FIRST(name)));
216}
bool mutt_addr_is_user(const struct Address *addr)
Does the address belong to the user.
Definition: alias.c:570
#define MUTT_FORMAT_PLAIN
Do not prepend DISP_TO, DISP_CC ...
Definition: format_flags.h:38
static const char * make_from_prefix(enum FieldType disp)
Create a prefix for an author field.
Definition: hdrline.c:133
FieldType
Header types.
Definition: hdrline.c:79
bool check_for_mailing_list(struct AddressList *al, const char *pfx, char *buf, int buflen)
Search list of addresses for a mailing list.
Definition: maillist.c:78
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_EMPTY(head)
Definition: queue.h:721
const char * mutt_get_name(const struct Address *a)
Pick the best name to display from an address.
Definition: sort.c:134
struct AddressList to
Email's 'To' list.
Definition: envelope.h:60
struct AddressList cc
Email's 'Cc' list.
Definition: envelope.h:61
struct AddressList bcc
Email's 'Bcc' list.
Definition: envelope.h:62
struct AddressList from
Email's 'From' list.
Definition: envelope.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_from_addr()

static void make_from_addr ( struct Envelope env,
char *  buf,
size_t  buflen,
bool  do_lists 
)
static

Create a 'from' address for a reply email.

Parameters
envEnvelope of current email
bufBuffer for the result
buflenLength of buffer
do_listsIf true, check for mailing lists

Definition at line 225 of file hdrline.c.

226{
227 if (!env || !buf)
228 return;
229
230 bool me = mutt_addr_is_user(TAILQ_FIRST(&env->from));
231
232 if (do_lists || me)
233 {
234 if (check_for_mailing_list_addr(&env->to, buf, buflen))
235 return;
236 if (check_for_mailing_list_addr(&env->cc, buf, buflen))
237 return;
238 }
239
240 if (me && !TAILQ_EMPTY(&env->to))
241 snprintf(buf, buflen, "%s", buf_string(TAILQ_FIRST(&env->to)->mailbox));
242 else if (me && !TAILQ_EMPTY(&env->cc))
243 snprintf(buf, buflen, "%s", buf_string(TAILQ_FIRST(&env->cc)->mailbox));
244 else if (!TAILQ_EMPTY(&env->from))
245 mutt_str_copy(buf, buf_string(TAILQ_FIRST(&env->from)->mailbox), buflen);
246 else
247 *buf = '\0';
248}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
bool check_for_mailing_list_addr(struct AddressList *al, char *buf, int buflen)
Check an address list for a mailing list.
Definition: maillist.c:102
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:653
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ user_in_addr()

static bool user_in_addr ( struct AddressList *  al)
static

Do any of the addresses refer to the user?

Parameters
alAddressList
Return values
trueAny of the addresses match one of the user's addresses

Definition at line 255 of file hdrline.c.

256{
257 struct Address *a = NULL;
258 TAILQ_FOREACH(a, al, entries)
259 if (mutt_addr_is_user(a))
260 return true;
261 return false;
262}
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
An email address.
Definition: address.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ user_is_recipient()

static enum ToChars user_is_recipient ( struct Email e)
static

Is the user a recipient of the message.

Parameters
eEmail to test
Return values
enumCharacter index into the $to_chars config variable

Definition at line 269 of file hdrline.c.

270{
271 if (!e || !e->env)
273
274 struct Envelope *env = e->env;
275
276 if (!e->recip_valid)
277 {
278 e->recip_valid = true;
279
281 {
283 }
284 else if (user_in_addr(&env->to))
285 {
286 if (TAILQ_NEXT(TAILQ_FIRST(&env->to), entries) || !TAILQ_EMPTY(&env->cc))
287 e->recipient = FLAG_CHAR_TO_TO; /* non-unique recipient */
288 else
289 e->recipient = FLAG_CHAR_TO_UNIQUE; /* unique recipient */
290 }
291 else if (user_in_addr(&env->cc))
292 {
294 }
295 else if (check_for_mailing_list(&env->to, NULL, NULL, 0))
296 {
298 }
299 else if (check_for_mailing_list(&env->cc, NULL, NULL, 0))
300 {
302 }
303 else if (user_in_addr(&env->reply_to))
304 {
306 }
307 else
308 {
310 }
311 }
312
313 return e->recipient;
314}
static bool user_in_addr(struct AddressList *al)
Do any of the addresses refer to the user?
Definition: hdrline.c:255
@ FLAG_CHAR_TO_ORIGINATOR
Character denoting that the user is originator.
Definition: hdrline.h:72
@ FLAG_CHAR_TO_UNIQUE
Character denoting that the user is unique recipient.
Definition: hdrline.h:69
@ FLAG_CHAR_TO_NOT_IN_THE_LIST
Character denoting that the user is not in list.
Definition: hdrline.h:68
@ FLAG_CHAR_TO_TO
Character denoting that the user is in the TO list.
Definition: hdrline.h:70
@ FLAG_CHAR_TO_CC
Character denoting that the user is in the CC list.
Definition: hdrline.h:71
@ FLAG_CHAR_TO_REPLY_TO
Character denoting that the user is in the Reply-To list.
Definition: hdrline.h:74
@ FLAG_CHAR_TO_SUBSCRIBED_LIST
Character denoting that the message is sent to a subscribed mailing list.
Definition: hdrline.h:73
#define TAILQ_NEXT(elm, field)
Definition: queue.h:832
bool recip_valid
Is_recipient is valid.
Definition: email.h:103
struct Envelope * env
Envelope information.
Definition: email.h:66
short recipient
User_is_recipient()'s return value, cached.
Definition: email.h:115
The header of an Email.
Definition: envelope.h:57
struct AddressList reply_to
Email's 'reply-to'.
Definition: envelope.h:64
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ thread_is_new()

static bool thread_is_new ( struct Email e)
static

Does the email thread contain any new emails?

Parameters
eEmail
Return values
trueThread contains new mail

Definition at line 321 of file hdrline.c.

322{
323 return e->collapsed && (e->num_hidden > 1) && (mutt_thread_contains_unread(e) == 1);
324}
#define mutt_thread_contains_unread(e)
Definition: mutt_thread.h:107
bool collapsed
Is this message part of a collapsed thread?
Definition: email.h:119
size_t num_hidden
Number of hidden messages in this view (only valid when collapsed is set)
Definition: email.h:122
+ Here is the caller graph for this function:

◆ thread_is_old()

static bool thread_is_old ( struct Email e)
static

Does the email thread contain any unread emails?

Parameters
eEmail
Return values
trueThread contains unread mail

Definition at line 331 of file hdrline.c.

332{
333 return e->collapsed && (e->num_hidden > 1) && (mutt_thread_contains_unread(e) == 2);
334}
+ Here is the caller graph for this function:

◆ mutt_make_string()

void mutt_make_string ( char *  buf,
size_t  buflen,
int  cols,
const char *  s,
struct Mailbox m,
int  inpgr,
struct Email e,
MuttFormatFlags  flags,
const char *  progress 
)

Create formatted strings using mailbox expandos.

Parameters
bufBuffer for the result
buflenBuffer length
colsNumber of screen columns (OPTIONAL)
sprintf-line format string
mMailbox
inpgrMessage shown in the pager
eEmail
flagsFlags, see MuttFormatFlags
progressPager progress string
See also
index_format_str()

Definition at line 1426 of file hdrline.c.

1429{
1430 struct HdrFormatInfo hfi = { 0 };
1431
1432 hfi.email = e;
1433 hfi.mailbox = m;
1434 hfi.msg_in_pager = inpgr;
1435 hfi.pager_progress = progress;
1436
1437 mutt_expando_format(buf, buflen, 0, cols, s, index_format_str, (intptr_t) &hfi, flags);
1438}
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string -.
Definition: muttlib.c:745
static const char * index_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format a string for the index list - Implements format_t -.
Definition: hdrline.c:393
Data passed to index_format_str()
Definition: hdrline.c:66
struct Email * email
Current Email.
Definition: hdrline.c:69
int msg_in_pager
Index of Email displayed in the Pager.
Definition: hdrline.c:68
struct Mailbox * mailbox
Current Mailbox.
Definition: hdrline.c:67
const char * pager_progress
String representing Pager position through Email.
Definition: hdrline.c:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function: