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

Message Id Expando definitions. More...

#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "email/lib.h"
#include "expando_msgid.h"
#include "expando/lib.h"
#include "globals.h"
#include "sendlib.h"
+ Include dependency graph for expando_msgid.c:

Go to the source code of this file.

Functions

static void msgid_counter (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
 Message Id: Step Counter - Implements get_string_t -.
 
static long msgid_day_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Message Id: Day - Implements get_number_t -.
 
static void msgid_hostname (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
 Message Id: Hostname - Implements get_string_t -.
 
static long msgid_hour_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Message Id: Hour - Implements get_number_t -.
 
static long msgid_minute_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Message Id: Minute - 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 long msgid_pid_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Message Id: Process Id - Implements get_number_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_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_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 -.
 
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 char * msgid_gen_random (void)
 Generate a random Message ID.
 
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.c.

Function Documentation

◆ msgid_gen_random()

static char * msgid_gen_random ( void )
static

Generate a random Message ID.

Return values
ptrMessage ID

The length of the message id is chosen such that it is maximal and fits in the recommended 78 character line length for the headers Message-ID:, References:, and In-Reply-To:, this leads to 62 available characters (excluding @ and >). Since we choose from 32 letters, we have 32^62 = 2^310 different message ids.

Examples:

Message-ID: <12345678901111111111222222222233333333334444444444@123456789011>
In-Reply-To: <12345678901111111111222222222233333333334444444444@123456789011>
References: <12345678901111111111222222222233333333334444444444@123456789011>
A local copy of an email.
Definition message.h:34

The distribution of the characters to left-of-@ and right-of-@ was arbitrary. The choice was made to put more into the left-id and shorten the right-id to slightly mimic a common length domain name.

Note
The caller should free the string

Definition at line 227 of file expando_msgid.c.

228{
229 const int ID_LEFT_LEN = 50;
230 const int ID_RIGHT_LEN = 12;
231 char rnd_id_left[ID_LEFT_LEN + 1];
232 char rnd_id_right[ID_RIGHT_LEN + 1];
233 char buf[128] = { 0 };
234
235 mutt_rand_base32(rnd_id_left, sizeof(rnd_id_left) - 1);
236 mutt_rand_base32(rnd_id_right, sizeof(rnd_id_right) - 1);
237 rnd_id_left[ID_LEFT_LEN] = 0;
238 rnd_id_right[ID_RIGHT_LEN] = 0;
239
240 snprintf(buf, sizeof(buf), "<%s@%s>", rnd_id_left, rnd_id_right);
241 return mutt_str_dup(buf);
242}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:255
void mutt_rand_base32(char *buf, size_t buflen)
Fill a buffer with a base32-encoded random string.
Definition random.c:106
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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[]
Initial value:
= {
{ -1, -1, NULL, NULL },
}
@ ED_MSG_ID
Message Id ED_MSG_ ExpandoDataMsgId.
Definition domain.h:49
@ 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')
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 -.

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};