NeoMutt  2025-12-11-58-g09398d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
expando_msgid.h File Reference

Message Id Expando definitions. More...

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

Go to the source code of this file.

Data Structures

struct  MsgIdData
 Data to generate a Message-Id. More...
 

Enumerations

enum  ExpandoDataMsgId {
  ED_MSG_COUNTER = 1 , ED_MSG_DAY , ED_MSG_HOSTNAME , ED_MSG_HOUR ,
  ED_MSG_MINUTE , ED_MSG_MONTH , ED_MSG_PID , ED_MSG_RANDOM_1 ,
  ED_MSG_RANDOM_3 , ED_MSG_RANDOM_12 , ED_MSG_SECOND , ED_MSG_YEAR
}
 Expando Fields for the Message-Id. More...
 

Functions

char * msgid_generate (void)
 Generate a Message-Id.
 

Variables

const struct ExpandoRenderCallback MsgIdRenderCallbacks []
 Callbacks for Message Id Expandos.
 

Detailed Description

Message Id Expando definitions.

Authors
  • Richard Russon

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

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

Definition in file expando_msgid.h.

Enumeration Type Documentation

◆ ExpandoDataMsgId

Expando Fields for the Message-Id.

See also
ED_MSG, ExpandoDomain
Enumerator
ED_MSG_COUNTER 

Step counter looping from 'A' to 'Z'.

ED_MSG_DAY 

Current day of the month (GMT)

ED_MSG_HOSTNAME 

$hostname

ED_MSG_HOUR 

Current hour using a 24-hour clock (GMT)

ED_MSG_MINUTE 

Current month number (GMT)

ED_MSG_MONTH 

Current minute of the hour (GMT)

ED_MSG_PID 

PID of the running mutt process.

ED_MSG_RANDOM_1 

3 bytes of pseudo-random data encoded in Base64

ED_MSG_RANDOM_3 

Current second of the minute (GMT)

ED_MSG_RANDOM_12 

1 byte of pseudo-random data hex encoded (example: '1b')

ED_MSG_SECOND 

Current year using 4 digits (GMT)

ED_MSG_YEAR 

4 byte timestamp + 8 bytes of pseudo-random data encoded in Base64

Definition at line 44 of file expando_msgid.h.

45{
46 ED_MSG_COUNTER = 1,
58};
@ ED_MSG_COUNTER
Step counter looping from 'A' to 'Z'.
@ ED_MSG_SECOND
Current year using 4 digits (GMT)
@ ED_MSG_YEAR
4 byte timestamp + 8 bytes of pseudo-random data encoded in Base64
@ ED_MSG_HOUR
Current hour using a 24-hour clock (GMT)
@ ED_MSG_PID
PID of the running mutt process.
@ ED_MSG_RANDOM_1
3 bytes of pseudo-random data encoded in Base64
@ ED_MSG_MINUTE
Current month number (GMT)
@ ED_MSG_RANDOM_3
Current second of the minute (GMT)
@ ED_MSG_DAY
Current day of the month (GMT)
@ ED_MSG_HOSTNAME
$hostname
@ ED_MSG_MONTH
Current minute of the hour (GMT)
@ ED_MSG_RANDOM_12
1 byte of pseudo-random data hex encoded (example: '1b')

Function Documentation

◆ msgid_generate()

char * msgid_generate ( void )

Generate a Message-Id.

Return values
ptrMessage ID
Note
The caller should free the string

Definition at line 250 of file expando_msgid.c.

251{
252 const struct Expando *c_message_id_format = cs_subset_expando(NeoMutt->sub, "message_id_format");
253 if (!c_message_id_format)
254 return msgid_gen_random();
255
256 struct MsgIdData mid = { 0 };
257
258 mid.now = time(NULL);
259 mid.tm = mutt_date_gmtime(mid.now);
260
261 mid.fqdn = mutt_fqdn(false, NeoMutt->sub);
262 if (!mid.fqdn)
264
265 struct Buffer *buf = buf_pool_get();
266
267 expando_filter(c_message_id_format, MsgIdRenderCallbacks, &mid,
269 if (buf_is_empty(buf))
270 {
271 buf_pool_release(&buf);
272 return msgid_gen_random();
273 }
274
275 if (buf_at(buf, 0) != '<')
276 buf_insert(buf, 0, "<");
277
278 const int last = buf_len(buf) - 1;
279 if (buf_at(buf, last) != '>')
280 buf_addch(buf, '>');
281
282 char *msgid = buf_strdup(buf);
283 buf_pool_release(&buf);
284
285 return msgid;
286}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:491
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
Definition buffer.c:668
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:241
size_t buf_insert(struct Buffer *buf, size_t offset, const char *s)
Add a string in the middle of a buffer.
Definition buffer.c:256
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
int expando_filter(const struct Expando *exp, const struct ExpandoRenderCallback *erc, void *data, MuttFormatFlags flags, int max_cols, char **env_list, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition filter.c:138
static char * msgid_gen_random(void)
Generate a random Message ID.
const struct ExpandoRenderCallback MsgIdRenderCallbacks[]
Callbacks for Message Id Expandos.
char * ShortHostname
Short version of the hostname.
Definition globals.c:37
struct tm mutt_date_gmtime(time_t t)
Converts calendar time to a broken-down time structure expressed in UTC timezone.
Definition date.c:926
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:96
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition render.h:33
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
Definition sendlib.c:707
#define NONULL(x)
Definition string2.h:43
String manipulation buffer.
Definition buffer.h:36
size_t dsize
Length of data.
Definition buffer.h:39
Parsed Expando trees.
Definition expando.h:41
Data to generate a Message-Id.
struct tm tm
Time Now (tm)
time_t now
Time Now (seconds)
const char * fqdn
Fully-qualified Domain Name.
Container for Accounts, Notifications.
Definition neomutt.h:43
char ** env
Private copy of the environment variables.
Definition neomutt.h:56
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MsgIdRenderCallbacks

const struct ExpandoRenderCallback MsgIdRenderCallbacks[]
extern

Callbacks for Message Id Expandos.

See also
MsgIdFormatDef, ExpandoDataEnvelope

Definition at line 186 of file expando_msgid.c.

186 {
187 // clang-format off
200 { -1, -1, NULL, NULL },
201 // clang-format on
202};
@ ED_MSG_ID
Message Id ED_MSG_ ExpandoDataMsgId.
Definition domain.h:49
static long msgid_minute_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Message Id: Minute - Implements get_number_t -.
static long msgid_second_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Message Id: Second - Implements get_number_t -.
static long msgid_year_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Message Id: Year (4 digit) - Implements get_number_t -.
static long msgid_day_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Message Id: Day - Implements get_number_t -.
static long msgid_pid_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Message Id: Process Id - Implements get_number_t -.
static long msgid_hour_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Message Id: Hour - Implements get_number_t -.
static long msgid_month_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Message Id: Month - Implements get_number_t -.
static void msgid_random_3(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Message Id: 3 Random Bytes of Base64 - Implements get_string_t -.
static void msgid_hostname(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Message Id: Hostname - Implements get_string_t -.
static void msgid_random_1(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Message Id: 1 Random Hex Byte - Implements get_string_t -.
static void msgid_counter(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Message Id: Step Counter - Implements get_string_t -.
static void msgid_random_12(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Message Id: Timestamp + 8 Random Bytes of Base64 - Implements get_string_t -.