X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/ec68c7d9fca00e976df02842dc2c9d5a523567af..2b60a54adb3b0bf5a9b927708085492b816a6015:/sbr/message_id.c diff --git a/sbr/message_id.c b/sbr/message_id.c index 8c138665..a66d8764 100644 --- a/sbr/message_id.c +++ b/sbr/message_id.c @@ -7,6 +7,8 @@ */ #include +#include "m_rand.h" +#include "message_id.h" #include /* for gettimeofday() */ @@ -36,18 +38,19 @@ char * message_id (time_t tclock, int content_id) { switch (message_id_style) { case NMH_MESSAGE_ID_LOCALNAME: { - char *format = content_id ? "<%d.%ld.%%d@%s>" : "<%d.%ld@%s>"; - - snprintf (message_id_, sizeof message_id_, format, - (int) getpid (), (long) tclock, LocalName (1)); - +#define P(fmt) \ + snprintf(message_id_, sizeof message_id_, \ + (fmt), (int)getpid(), (long)tclock, LocalName(1)) + + if (content_id) + P("<%d.%ld.%%d@%s>"); + else + P("<%d.%ld@%s>"); +#undef P break; } case NMH_MESSAGE_ID_RANDOM: { - char *format = content_id - ? "<%d-%ld.%06ld%%d@%.*s.%.*s.%.*s>" - : "<%d-%ld.%06ld@%.*s.%.*s.%.*s>"; /* Use a sequence of digits divisible by 3 because that will expand to base64 without any waste. Must be shorter than 58, see below. */ @@ -93,11 +96,18 @@ message_id (time_t tclock, int content_id) { /* The format string inserts a couple of dots, for the benefit of spam filters that want to see a message id with a final part that resembles a hostname. */ - snprintf (message_id_, sizeof message_id_, format, - getpid (), (long) now.tv_sec, (long) now.tv_usec, - one_third, rnd_base64, - one_third, &rnd_base64[one_third], - one_third, &rnd_base64[2*one_third]); +#define P(fmt) \ + snprintf(message_id_, sizeof message_id_, (fmt), \ + getpid(), (long)now.tv_sec, (long)now.tv_usec, \ + (int)one_third, rnd_base64, \ + (int)one_third, &rnd_base64[one_third], \ + (int)one_third, &rnd_base64[2*one_third]) + + if (content_id) + P("<%d-%ld.%06ld%%d@%.*s.%.*s.%.*s>"); + else + P("<%d-%ld.%06ld@%.*s.%.*s.%.*s>"); +#undef P } break;