diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2001-02-27 03:56:58 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2001-02-27 03:56:58 +0800 |
commit | a596227e1c1b3225751a276e9efab60e9eea4110 (patch) | |
tree | ca810c809d303abf0c4d94d37b888b51124a07a3 | |
parent | 43f2a52819c061bd0df80388d3877df508590485 (diff) | |
download | gsoc2013-evolution-a596227e1c1b3225751a276e9efab60e9eea4110.tar.gz gsoc2013-evolution-a596227e1c1b3225751a276e9efab60e9eea4110.tar.zst gsoc2013-evolution-a596227e1c1b3225751a276e9efab60e9eea4110.zip |
Made thread-safe and moved to above the test code.
2001-02-26 Jeffrey Stedfast <fejj@ximian.com>
* camel-mime-utils.c: Made thread-safe and moved to above the test
code.
* camel-mime-message.c (camel_mime_message_init): Set the
message_id to NULL.
(camel_mime_message_finalize): Free the message_id.
(camel_mime_message_set_message_id): New function to set the
Message-Id.
(camel_mime_message_get_message_id): New function to get the
Message-Id.
(process_header): Decode the message-id.
svn path=/trunk/; revision=8393
-rw-r--r-- | camel/ChangeLog | 14 | ||||
-rw-r--r-- | camel/camel-mime-message.c | 50 | ||||
-rw-r--r-- | camel/camel-mime-message.h | 5 | ||||
-rw-r--r-- | camel/camel-mime-utils.c | 53 |
4 files changed, 105 insertions, 17 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 0ab171ce23..fb17283447 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,17 @@ +2001-02-26 Jeffrey Stedfast <fejj@ximian.com> + + * camel-mime-utils.c: Made thread-safe and moved to above the test + code. + + * camel-mime-message.c (camel_mime_message_init): Set the + message_id to NULL. + (camel_mime_message_finalize): Free the message_id. + (camel_mime_message_set_message_id): New function to set the + Message-Id. + (camel_mime_message_get_message_id): New function to get the + Message-Id. + (process_header): Decode the message-id. + 2001-02-24 Jeffrey Stedfast <fejj@ximian.com> * camel-store.c (construct): init the vTrash folder here instead diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c index 40199eac21..9e0fb7de11 100644 --- a/camel/camel-mime-message.c +++ b/camel/camel-mime-message.c @@ -51,12 +51,13 @@ typedef enum { HEADER_TO, HEADER_CC, HEADER_BCC, - HEADER_DATE + HEADER_DATE, + HEADER_MESSAGE_ID } CamelHeaderType; static char *header_names[] = { /* dont include HEADER_UNKNOWN string */ - "From", "Reply-To", "Subject", "To", "Cc", "Bcc", "Date", NULL + "From", "Reply-To", "Subject", "To", "Cc", "Bcc", "Date", "Message-Id", NULL }; static GHashTable *header_name_table; @@ -124,6 +125,7 @@ camel_mime_message_init (gpointer object, gpointer klass) mime_message->date_offset = 0; mime_message->date_received = CAMEL_MESSAGE_DATE_CURRENT; mime_message->date_received_offset = 0; + mime_message->message_id = NULL; } static void @@ -133,6 +135,8 @@ camel_mime_message_finalize (CamelObject *object) g_free(message->subject); + g_free(message->message_id); + if (message->reply_to) camel_object_unref((CamelObject *)message->reply_to); @@ -235,6 +239,37 @@ camel_mime_message_get_date_received(CamelMimeMessage *msg, int *offset) return msg->date_received; } +/* **** Message-Id: */ + +void +camel_mime_message_set_message_id (CamelMimeMessage *mime_message, const char *message_id) +{ + char *id; + + g_assert (mime_message); + + g_free (mime_message->message_id); + + if (message_id) { + id = g_strstrip (g_strdup (message_id)); + } else { + id = header_msgid_generate (); + } + + mime_message->message_id = id; + id = g_strdup_printf ("<%s>", mime_message->message_id); + CAMEL_MEDIUM_CLASS (parent_class)->set_header (CAMEL_MEDIUM (mime_message), "Message-Id", id); + g_free (id); +} + +const char * +camel_mime_message_get_message_id (CamelMimeMessage *mime_message) +{ + g_assert (mime_message); + + return mime_message->message_id; +} + /* **** Reply-To: */ void @@ -429,6 +464,10 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) g_warning("Application did not set subject, creating one"); camel_mime_message_set_subject(mm, "No Subject"); } + if (mm->message_id == NULL) { + g_warning ("Application did not set message-id, creating one"); + camel_mime_message_set_message_id (mm, NULL); + } /* FIXME: "To" header needs to be set explicitly as well ... */ @@ -481,6 +520,13 @@ process_header (CamelMedium *medium, const char *header_name, const char *header message->date_offset = 0; } break; + case HEADER_MESSAGE_ID: + g_free (message->message_id); + if (header_value) + message->message_id = header_msgid_decode (header_value); + else + message->message_id = NULL; + break; default: return FALSE; } diff --git a/camel/camel-mime-message.h b/camel/camel-mime-message.h index b386632a86..0ab406c27e 100644 --- a/camel/camel-mime-message.h +++ b/camel/camel-mime-message.h @@ -65,6 +65,8 @@ struct _CamelMimeMessage char *subject; + char *message_id; + CamelInternetAddress *reply_to; CamelInternetAddress *from; @@ -93,6 +95,9 @@ time_t camel_mime_message_get_date (CamelMimeMess int *offset); time_t camel_mime_message_get_date_received (CamelMimeMessage *mime_message, int *offset); +void camel_mime_message_set_message_id (CamelMimeMessage *mime_message, + const char *message_id); +const char *camel_mime_message_get_message_id (CamelMimeMessage *mime_message); void camel_mime_message_set_reply_to (CamelMimeMessage *mime_message, const CamelInternetAddress *reply_to); const CamelInternetAddress *camel_mime_message_get_reply_to (CamelMimeMessage *mime_message); diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index 448c3dc077..10d2c99001 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -27,11 +27,16 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/param.h> /* for MAXHOSTNAMELEN */ #include <fcntl.h> #include <stdlib.h> #include <string.h> #include <unistd.h> +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 1024 +#endif + #include <unicode.h> #include <iconv.h> @@ -46,6 +51,10 @@ #include "camel-mime-utils.h" #include "camel-charset-map.h" +#ifdef ENABLE_THREADS +#include <pthread.h> +#endif + #ifndef CLEAN_DATE #include "broken-date-parser.h" #endif @@ -2895,6 +2904,35 @@ header_raw_clear(struct _header_raw **list) *list = NULL; } +char * +header_msgid_generate (void) +{ + char host[MAXHOSTNAMELEN], domain[MAXHOSTNAMELEN]; +#ifdef ENABLE_THREADS + static pthread_mutex_t count_lock = PTHREAD_MUTEX_INITIALIZER; +#define COUNT_LOCK() pthread_mutex_lock (&count_lock) +#define COUNT_UNLOCK() pthread_mutex_unlock (&count_lock) +#else +#define COUNT_LOCK() +#define COUNT_UNLOCK() +#endif /* ENABLE_THREADS */ + static gint count = 0; + gint hrv, drv; + char *ret; + + hrv = gethostname (host, sizeof (host)); + drv = getdomainname (domain, sizeof (domain)); + + COUNT_LOCK (); + ret = g_strdup_printf ("%d.%d.%d.camel@%s.%s", (gint) time (NULL), getpid (), count++, + (hrv == 0 && host && *host) ? host : "unknown.host", + (drv && domain && *domain) ? domain : "unknown.domain"); + COUNT_UNLOCK (); + + return ret; +} + + static struct { char *name; char *pattern; @@ -3335,18 +3373,3 @@ void run_test(void) } #endif /* BUILD_TABLE */ - -char * -header_msgid_generate (void) -{ - gchar host [256], domain [768]; - static gint count = 0; - gint hrv, drv; - - hrv = gethostname (host, sizeof (host)); - drv = getdomainname (domain, sizeof (domain)); - - return g_strdup_printf ("%d.%d.%d.camel@%s.%s", (gint) time (NULL), getpid (), count++, - (hrv == 0 && host && *host) ? host : "unknown.host", - (drv && domain && *domain) ? domain : "unknown.domain"); -} |