From f6ad2583a768bfb1ddbc85a5a74e39d4167240ff Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 7 Aug 2015 20:46:22 +0200 Subject: sfeed_mbox: use simple hash for Message-Id --- sfeed_mbox.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/sfeed_mbox.c b/sfeed_mbox.c index 2e315f1..878a3f6 100644 --- a/sfeed_mbox.c +++ b/sfeed_mbox.c @@ -1,7 +1,9 @@ #include #include +#include #include +#include #include #include #include @@ -13,6 +15,23 @@ static char *line = NULL; static size_t linesize = 0; +/* jenkins one-at-a-time hash, used for Message-Id */ +static uint32_t +jenkins1(const char *s) +{ + uint32_t hash = 0; + + for (; *s; s++) { + hash += (int)*s; + hash += (hash << 10); + hash ^= (hash >> 6); + } + hash += (hash << 3); + hash ^= (hash >> 11); + + return hash + (hash << 15); +} + /* Unescape / decode fields printed by string_print_encoded() * "\\" to "\", "\t", to TAB, "\n" to newline. Unrecognised escape sequences * are ignored: "\z" etc. Mangle "From " in mboxrd style (always prefix >). */ @@ -89,14 +108,17 @@ printfeed(FILE *fp, const char *feedname) "From: %s \n" "To: %s <%s@%s>\n" "Subject: %s\n" - "Message-ID: <%s-%s-sfeed>\n" + "Message-ID: <%s%s%"PRIu32"@sfeed>\n" "Content-Type: text/%s; charset=UTF-8\n" "Content-Transfer-Encoding: binary\n" "X-Feedname: %s\n" "\n", - mtimebuf, timebuf, fields[FieldAuthor], + mtimebuf, timebuf, + fields[FieldAuthor][0] ? fields[FieldAuthor] : "anonymous", user, user, host, fields[FieldTitle], - fields[FieldUnixTimestamp], fields[FieldId], + fields[FieldUnixTimestamp], + fields[FieldUnixTimestamp][0] ? "." : "", + jenkins1(fields[FieldTitle]), fields[FieldContentType], feedname); if (!strcmp(fields[FieldContentType], "html")) { -- cgit v1.2.3