summaryrefslogtreecommitdiff
path: root/sfeed_mbox.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2015-08-07 20:46:22 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2015-08-07 20:46:22 +0200
commitf6ad2583a768bfb1ddbc85a5a74e39d4167240ff (patch)
tree5b4b9028edcc6d3a11be04182d9c4057adcdb3f6 /sfeed_mbox.c
parent853a6fdd6a689ab0e96fd11362ad55fff887f0ab (diff)
sfeed_mbox: use simple hash for Message-Id
Diffstat (limited to 'sfeed_mbox.c')
-rw-r--r--sfeed_mbox.c28
1 files 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 <sys/types.h>
#include <err.h>
+#include <inttypes.h>
#include <limits.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -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 <sfeed@>\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")) {