diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | camel/md5-utils.c | 6 | ||||
-rw-r--r-- | camel/md5-utils.h | 7 | ||||
-rw-r--r-- | camel/providers/MH/Makefile.am | 6 | ||||
-rw-r--r-- | camel/providers/MH/mh-uid.c | 68 | ||||
-rw-r--r-- | camel/providers/MH/mh-uid.h | 28 |
6 files changed, 120 insertions, 7 deletions
@@ -1,5 +1,15 @@ +1999-09-07 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/md5-utils.h : + raw routines are declared public now. + Md5 use has to be versatile. + + * camel/providers/MH/mh-uid.c (mh_uid_get_for_file): + new func. Returns an UID for an MH message. + 1999-09-06 bertrand <Bertrand.Guiheneuf@aful.org> - + + * camel/md5-utils.h: * camel/md5-utils.c: changed names to follow camel style. diff --git a/camel/md5-utils.c b/camel/md5-utils.c index aac720e8e9..30a750b12b 100644 --- a/camel/md5-utils.c +++ b/camel/md5-utils.c @@ -53,7 +53,7 @@ _byte_reverse (guchar *buf, guint32 longs) * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious * initialization constants. */ -static void +void md5_init (MD5Context *ctx) { ctx->buf[0] = 0x67452301; @@ -75,7 +75,7 @@ md5_init (MD5Context *ctx) * Update context to reflect the concatenation of another buffer full * of bytes. */ -static void +void md5_update (MD5Context *ctx, const guchar *buf, guint32 len) { guint32 t; @@ -130,7 +130,7 @@ md5_update (MD5Context *ctx, const guchar *buf, guint32 len) * Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ -static void +void md5_final (guchar digest[16], MD5Context *ctx) { guint32 count; diff --git a/camel/md5-utils.h b/camel/md5-utils.h index cb4768bbac..55dc5229d9 100644 --- a/camel/md5-utils.h +++ b/camel/md5-utils.h @@ -41,9 +41,14 @@ typedef struct { void md5_get_digest (const gchar *buffer, gint buffer_size, guchar digest[16]); void md5_get_digest_from_stream (CamelStream *stream, gint buffer_size, guchar digest[16]); -/* use this onr when speed is needed */ +/* use this one when speed is needed */ /* for use in provider code only */ void md5_get_digest_from_file (gchar *filename, gint buffer_size, guchar digest[16]); +/* raw routines */ +void md5_init (MD5Context *ctx); +void md5_update (MD5Context *ctx, const guchar *buf, guint32 len); +void md5_final (guchar digest[16], MD5Context *ctx); + #endif /* MD5_UTILS_H */ diff --git a/camel/providers/MH/Makefile.am b/camel/providers/MH/Makefile.am index 35403a7347..6ebdc765b3 100644 --- a/camel/providers/MH/Makefile.am +++ b/camel/providers/MH/Makefile.am @@ -14,11 +14,13 @@ INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \ libcamelmh_la_SOURCES = \ camel-mh-folder.c \ camel-mh-provider.c \ - camel-mh-store.c + camel-mh-store.c \ + mh-uid.c libcamelmhinclude_HEADERS = \ camel-mh-folder.h \ - camel-mh-store.h + camel-mh-store.h\ + mh-uid.h libcamelmh_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir) diff --git a/camel/providers/MH/mh-uid.c b/camel/providers/MH/mh-uid.c new file mode 100644 index 0000000000..d830a8f349 --- /dev/null +++ b/camel/providers/MH/mh-uid.c @@ -0,0 +1,68 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* + * + * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ + +#include "mh-uid.h" +#include "camel-stream.h" +#include "camel-stream-fs.h" +#include "camel-stream-buffered-fs.h" +#include "gmime-utils.h" +#include "md5-utils.h" + +guchar * +mh_uid_get_for_file (gchar *filename) +{ + CamelStream *message_stream; + GArray *header_array; + Rfc822Header *cur_header; + int i; + MD5Context ctx; + guchar *md5_digest_uid; + + + message_stream = camel_stream_buffered_fs_new_with_name (filename, + CAMEL_STREAM_BUFFERED_FS_READ); + header_array = get_header_array_from_stream (message_stream); + gtk_object_unref (GTK_OBJECT (message_stream)); + + md5_init (&ctx); + for (i=0; i<header_array->len; i++) { + cur_header = (Rfc822Header *)header_array->data + i; + if (!g_strcasecmp (cur_header->name, "subject")) { + md5_update (&ctx, cur_header->value, strlen (cur_header->value)); + } else if (!g_strcasecmp (cur_header->name, "sender")) { + md5_update (&ctx, cur_header->value, strlen (cur_header->value)); + } else if (!g_strcasecmp (cur_header->name, "date")) { + md5_update (&ctx, cur_header->value, strlen (cur_header->value)); + } + + g_free (cur_header->name); + g_free (cur_header->value); + + } + + g_array_free (header_array, TRUE); + + md5_digest_uid = g_new0 (guchar, 16); + md5_final (md5_digest_uid, &ctx); + + return md5_digest_uid; +} diff --git a/camel/providers/MH/mh-uid.h b/camel/providers/MH/mh-uid.h new file mode 100644 index 0000000000..32fe138a53 --- /dev/null +++ b/camel/providers/MH/mh-uid.h @@ -0,0 +1,28 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* + * + * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ + +#ifndef MH_UID_H +#define MH_UID_H 1 + +#include <glib.h> + +#endif /* MH_UID_H */ |