X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fgetthreadid.c;fp=sbr%2Fgetthreadid.c;h=99a7d67beb4db420331d7082c5c1a5d54bfbbcac;hp=0000000000000000000000000000000000000000;hb=c5368b86d4a3a42f9efe8aa56374d953a7faa9a4;hpb=ca984be73bdba8c9e807aa56be6403a7b790ed21 diff --git a/sbr/getthreadid.c b/sbr/getthreadid.c new file mode 100644 index 0000000..99a7d67 --- /dev/null +++ b/sbr/getthreadid.c @@ -0,0 +1,61 @@ +#include +#include +#include + +static char *threadid(char *, char *); + +char * +getthreadid(const char *path) +{ + char *msgid = NULL; + char *referens = NULL; + char *ret; + struct field f = {{0}}; + enum state state = FLD2; + FILE *file = fopen(path, "r"); + + while (state == FLD2 && !msgid && !referens) { + switch (state = m_getfld2(state, &f, file)) { + case FLD2: + if (strncasecmp("message-id", f.name, f.namelen)==0) { + msgid = f.value; + f.value = NULL; + } else if (strncasecmp("references", f.name, f.namelen)==0) { + referens = f.value; + f.value = NULL; + } + break; + default: + fclose(file); + break; + } + } + + ret = threadid(msgid, referens); + + mh_free0(&msgid); + mh_free0(&referens); + + return ret; +} + +static char * +threadid(char *msgid, char *referens) +{ + char *threadfrom; + char *start, *end; + char *cp; + + threadfrom = referens ? referens : msgid; + + start = strchr(threadfrom, '<'); + end = strchr(start, '>'); + if (!(*start) || !(*end)) { + return NULL; + } + *end = '\0'; + cp = mh_xstrdup(start + 1); + *end = '>'; + + return cp; +}