diff options
author | Kevin McCarthy <kevin@8t8.us> | 2021-01-15 13:21:27 -0800 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2021-01-17 14:47:02 -0800 |
commit | b5a807cadb499d3078aedbdb67e4c22fc1520f88 (patch) | |
tree | 8c232a43b3f5c19f8d7fa5979ce4ee63d38630b6 | |
parent | d4305208955c5cdd9fe96dfa61e7c1e14e176a14 (diff) |
Move mutt_gen_msgid() over to messageid.c.
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | messageid.c | 52 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | sendlib.c | 28 |
4 files changed, 54 insertions, 29 deletions
diff --git a/Makefile.am b/Makefile.am index 1c6e45fb..39ba7f52 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,7 +40,7 @@ mutt_SOURCES = \ status.c system.c thread.c charset.c history.c lib.c \ mutt_lisp.c muttlib.c editmsg.c mbyte.c \ url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c \ - mutt_random.c listmenu.c + mutt_random.c listmenu.c messageid.c nodist_mutt_SOURCES = $(BUILT_SOURCES) diff --git a/messageid.c b/messageid.c new file mode 100644 index 00000000..5a86fa33 --- /dev/null +++ b/messageid.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2021 Kevin J. McCarthy <kevin@8t8.us> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "mutt.h" +#include "mutt_random.h" + +char *mutt_gen_msgid (void) +{ + char buf[SHORT_STRING]; + time_t now = time (NULL); + char random_bytes[8]; + char localpart[12]; /* = 32 bit timestamp, plus 64 bit randomness */ + unsigned char localpart_B64[16+1]; /* = Base64 encoded value of localpart plus + terminating \0 */ + const char *fqdn; + + mutt_random_bytes (random_bytes, sizeof(random_bytes)); + + /* Convert the four least significant bytes of our timestamp and put it in + localpart, with proper endianness (for humans) taken into account. */ + for (int i = 0; i < 4; i++) + localpart[i] = (uint8_t) (now >> (3-i)*8u); + + memcpy (&localpart[4], &random_bytes, 8); + + mutt_to_base64 (localpart_B64, (unsigned char *) localpart, 12, 17); + + if (!(fqdn = mutt_fqdn (0))) + fqdn = NONULL (Hostname); + + snprintf (buf, sizeof (buf), "<%s@%s>", localpart_B64, fqdn); + return (safe_strdup (buf)); +} diff --git a/po/POTFILES.in b/po/POTFILES.in index 22b164d1..c7fdd935 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -49,6 +49,7 @@ listmenu.c main.c mbox.c menu.c +messageid.c mh.c mutt_lisp.c mutt_sasl.c @@ -2410,34 +2410,6 @@ const char *mutt_fqdn(short may_hide_host) return p; } -char *mutt_gen_msgid (void) -{ - char buf[SHORT_STRING]; - time_t now = time (NULL); - char random_bytes[8]; - char localpart[12]; /* = 32 bit timestamp, plus 64 bit randomness */ - unsigned char localpart_B64[16+1]; /* = Base64 encoded value of localpart plus - terminating \0 */ - const char *fqdn; - - mutt_random_bytes (random_bytes, sizeof(random_bytes)); - - /* Convert the four least significant bytes of our timestamp and put it in - localpart, with proper endianness (for humans) taken into account. */ - for (int i = 0; i < 4; i++) - localpart[i] = (uint8_t) (now >> (3-i)*8u); - - memcpy (&localpart[4], &random_bytes, 8); - - mutt_to_base64 (localpart_B64, (unsigned char *) localpart, 12, 17); - - if (!(fqdn = mutt_fqdn (0))) - fqdn = NONULL (Hostname); - - snprintf (buf, sizeof (buf), "<%s@%s>", localpart_B64, fqdn); - return (safe_strdup (buf)); -} - static void alarm_handler (int sig) { SigAlrm = 1; |