X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=sbr%2Fmessage_id.c;h=d1efd9d73904cc5793b2e3c6d3637280f33d0ff4;hb=015e83362f21a061bf268b878693d72309c21e55;hp=d0a6dd9dbd2da36dc2183124fbc88c4bef24cd42;hpb=9f8f8b1e1d553774865f2c177191c359c3dc652c;p=mmh diff --git a/sbr/message_id.c b/sbr/message_id.c index d0a6dd9..d1efd9d 100644 --- a/sbr/message_id.c +++ b/sbr/message_id.c @@ -8,8 +8,8 @@ */ #include -#include /* for getpid() */ -#include /* for gettimeofday() */ +#include /* for getpid() */ +#include /* for gettimeofday() */ #include @@ -43,14 +43,18 @@ message_id (time_t tclock, int content_id) { snprintf (message_id_, sizeof message_id_, format, (int) getpid (), (long) tclock, LocalName (1)); } else if (message_id_style == NMH_MESSAGE_ID_RANDOM) { - char *format = content_id ? "<%d-%ld.%06ld%%d@%s>" : "<%d-%ld.%06ld@%s>"; + 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. */ - unsigned char rnd[12]; + unsigned char rnd[9]; + /* The part after the '@' is divided into thirds. The base64 + encoded string will be 4/3 the size of rnd. */ + size_t one_third = sizeof rnd * 4/3/3; if (m_rand (rnd, sizeof rnd) == 0) { - pid_t pid; struct timeval now; /* All we really need is 4 * [sizeof rnd/3] + 2, as long as the base64 encoding stays shorter than 76 bytes so embedded @@ -70,12 +74,31 @@ message_id (time_t tclock, int content_id) { rnd_base64[i] = '\0'; } - /* Neither of these can fail according to the POSIX spec. */ - pid = getpid (); + { + char *cp; + /* Try to make the base64 string look a little more like a + hostname by replacing + with - and / with _. Also, the + format string inserts a couple of dots. */ + for (cp = (char *) rnd_base64; *cp; ++cp) { + char *plus, *slash; + if ((plus = strchr (cp, '+'))) { + *plus = '-'; + } else if ((slash = strchr (cp, '/'))) { + *slash = '_'; + } else { + break; + } + } + } + + /* gettimeofday() and getpid() shouldn't fail on POSIX platforms. */ gettimeofday (&now, 0); snprintf (message_id_, sizeof message_id_, format, - pid, (long) now.tv_sec, (long) now.tv_usec, rnd_base64); + 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]); } } else { /* Should never get here. */