aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-mime-message.c
diff options
context:
space:
mode:
authorNotZed <NotZed@HelixCode.com>2000-04-23 18:10:44 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-04-23 18:10:44 +0800
commit5fcb83b5fb1294a781e3f7139200aa3486650db4 (patch)
treea890998dfce162ec25eb55b238e537f506abb6c1 /camel/camel-mime-message.c
parentf229f08168b0666469e0fc35d065860f2da58303 (diff)
downloadgsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.tar
gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.tar.gz
gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.tar.bz2
gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.tar.lz
gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.tar.xz
gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.tar.zst
gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.zip
Whole swag of changes. Still lots of cleanup remaining ...
2000-04-23 NotZed <NotZed@HelixCode.com> * camel-data-wrapper.c (set_mime_type_field): Ref the content_field when we get it? * camel-mime-parser.c (camel_mime_parser_unstep): New function. Cause a subsequent call to mime_parser_step() to return the same state over again. * providers/mbox/camel-mbox-folder.c (_get_message_by_uid): Initial test code using the mime parser to construct the message. * camel-mime-part.c (construct_from_parser): part constructor. (camel_mime_part_construct_content): Basically a simpler replacement for the datawrapper repository. (camel_mime_part_init): Set the default type to text/plain. * camel-simple-data-wrapper.c (construct_from_parser): Initial implementation of a content constructor. * camel-multipart.c (construct_from_parser): Multipart construction routine. (camel_multipart_init): Set the default multipart type to multipart/mixed. Duh, no subtype is not allowed anyway. 2000-04-22 NotZed <NotZed@HelixCode.com> * camel-mime-message.h (struct _CamelMimeMessage): Removed send_date, and received_date, and replaced it with a time_t 'date' (this is what the header is called), and date_offset to store the GMT offset of the date. * camel-mime-message.c (camel_mime_message_set_from): Update raw header as we go. (_set_from): Removed. (_get_from): Removed. (camel_mime_message_get_from): Moved implementation here. (camel_mime_message_get_subject): Move implementation here. (_get_subject): Nuked. (camel_mime_message_set_subject): Handle utf-8 input, and also update raw header when changed. (_set_subject): Removed. (_set_received_date): Removed. (camel_mime_message_set_received_date): Removed. (_get_received_date): Removed. (camel_mime_message_get_received_date): Removed. (_get_sent_date): Removed. (camel_mime_message_get_sent_date): Removed. (camel_mime_message_get_date): New function to get the date as a time_t/offset. (camel_mime_message_set_date): Set the date as a time_t/offset. (camel_mime_message_get_date_string): Get the date as a string. (camel_mime_message_init): Initialise the current date as 'CMAEL_MESSAGE_DATE_CURRENT'. (_set_reply_to): Removed. (camel_mime_message_set_reply_to): Moved implementation here. This is still broken, reply-to can have multiple addresses. (_get_reply_to): Removed. (_set_field): Removed, no longer used anywhere. (_get_field): Also removed. (_init_header_name_table): Add the Date header. (process_header): Also handle snooping of Date header here. * camel-stream-filter.c (finalise): Unref the source stream on finalise, and also call the parent class (oops). * camel-mime-parser.c (camel_mime_parser_state): New function to get the current parser state. (camel_mime_parser_stream): Allow you to get the stream back from the mime_parser. (camel_mime_parser_fd): Alternative to allow you to get the fd back from the mime_parser. (folder_scan_init_with_stream): Properly ref/unref the stream. (folder_scan_close): Properly unref the stream/close the fd on exit. (folder_scan_init_with_fd): Close the old fd if there is one. * camel-data-wrapper.c (camel_data_wrapper_construct_from_parser): New method, construct a data wrapper from an initialised parser. (construct_from_parser): Empty implementation. * providers/mbox/camel-mbox-summary.c (message_struct_new): Convert subject line to unicode, before storing in the summary. (strdup_trim): Removed, no longer needed. * providers/mbox/camel-mbox-folder.c (_get_message_by_uid): Ref the folder after setting it in the new message. * camel-mime-part.c (my_set_content_object): Have the headers follow the content-type change here too. (my_write_to_stream): Dont write content-type here, automatically stored in the headers ... (my_write_to_stream): Use header_disposition_format() to format the content-disposition header. (my_write_to_stream): Removed old code, all headers are now stored in the camel-medium level, always. Need to do the same with camel-mime-message i suppose ... (my_write_to_stream): Write the content using the parent class, not some weird function. (camel_mime_part_class_init): Dont override get_output_stream. (camel_mime_part_encoding_from_string): Bleh, make it case-insensitive. * camel-mime-utils.c (header_content_type_is): Handle empty types. (header_encode_string): Start of an implementation of the rfc2047 encoder. It does iso-8859-1, and us-ascii, and utf-8 (others get tricky *sigh*) (rfc2047_encode_word): Convert a single word/string into rfc2047 encoding. (quoted_encode): Different quoted-printable encoding for rfc2047 encoding of headers. * gmime-content-field.c (gmime_content_field_write_to_stream): Use header_content_type_format() to format it. svn path=/trunk/; revision=2560
Diffstat (limited to 'camel/camel-mime-message.c')
-rw-r--r--camel/camel-mime-message.c254
1 files changed, 102 insertions, 152 deletions
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index 7ae14766d5..6561515ec3 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -1,11 +1,9 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* camelMimeMessage.c : class for a mime_message */
-
/*
- *
- * Author :
- * Bertrand Guiheneuf <bertrand@helixcode.com>
+ * Authors: Bertrand Guiheneuf <bertrand@helixcode.com>
+ * Michael Zucchi <notzed@helixcode.com>
*
* Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
*
@@ -24,6 +22,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
+
#include <config.h>
#include "camel-mime-message.h"
#include <stdio.h>
@@ -39,30 +38,21 @@ typedef enum {
HEADER_SUBJECT,
HEADER_TO,
HEADER_CC,
- HEADER_BCC
+ HEADER_BCC,
+ HEADER_DATE
} CamelHeaderType;
static GHashTable *header_name_table;
-
-
static CamelMimePartClass *parent_class=NULL;
+/* WTF are these for?? */
static gchar *received_date_str;
static gchar *sent_date_str;
static gchar *reply_to_str;
static gchar *subject_str;
static gchar *from_str;
-static void _set_received_date (CamelMimeMessage *mime_message, const gchar *received_date);
-static const gchar *_get_received_date (CamelMimeMessage *mime_message);
-static const gchar *_get_sent_date (CamelMimeMessage *mime_message);
-static void _set_reply_to (CamelMimeMessage *mime_message, const gchar *reply_to);
-static const gchar *_get_reply_to (CamelMimeMessage *mime_message);
-static void _set_subject (CamelMimeMessage *mime_message, const gchar *subject);
-static const gchar *_get_subject (CamelMimeMessage *mime_message);
-static void _set_from (CamelMimeMessage *mime_message, const gchar *from);
-static const gchar *_get_from (CamelMimeMessage *mime_message);
static void _add_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient);
static void _remove_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient);
static const GList *_get_recipients (CamelMimeMessage *mime_message, const gchar *recipient_type);
@@ -80,6 +70,7 @@ static void remove_header (CamelMedium *medium, const char *header_name);
/* Returns the class for a CamelMimeMessage */
#define CMM_CLASS(so) CAMEL_MIME_MESSAGE_CLASS (GTK_OBJECT(so)->klass)
#define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (GTK_OBJECT(so)->klass)
+#define CMD_CLASS(so) CAMEL_MEDIUM_CLASS (GTK_OBJECT(so)->klass)
static void
@@ -92,7 +83,7 @@ _init_header_name_table()
g_hash_table_insert (header_name_table, "To", (gpointer)HEADER_TO);
g_hash_table_insert (header_name_table, "Cc", (gpointer)HEADER_CC);
g_hash_table_insert (header_name_table, "Bcc", (gpointer)HEADER_BCC);
-
+ g_hash_table_insert (header_name_table, "Date", (gpointer)HEADER_DATE);
}
static void
@@ -113,15 +104,6 @@ camel_mime_message_class_init (CamelMimeMessageClass *camel_mime_message_class)
from_str = "From";
/* virtual method definition */
- camel_mime_message_class->set_received_date = _set_received_date;
- camel_mime_message_class->get_received_date = _get_received_date;
- camel_mime_message_class->get_sent_date = _get_sent_date;
- camel_mime_message_class->set_reply_to = _set_reply_to;
- camel_mime_message_class->get_reply_to = _get_reply_to;
- camel_mime_message_class->set_subject = _set_subject;
- camel_mime_message_class->get_subject = _get_subject;
- camel_mime_message_class->set_from = _set_from;
- camel_mime_message_class->get_from = _get_from;
camel_mime_message_class->add_recipient = _add_recipient;
camel_mime_message_class->remove_recipient = _remove_recipient;
camel_mime_message_class->get_recipients = _get_recipients;
@@ -156,12 +138,13 @@ camel_mime_message_init (gpointer object, gpointer klass)
camel_mime_message->flags =
g_hash_table_new (g_strcase_hash, g_strcase_equal);
- camel_mime_message->received_date = NULL;
- camel_mime_message->sent_date = NULL;
camel_mime_message->subject = NULL;
camel_mime_message->reply_to = NULL;
camel_mime_message->from = NULL;
camel_mime_message->folder = NULL;
+ camel_mime_message->date = CAMEL_MESSAGE_DATE_CURRENT;
+ camel_mime_message->date_offset = 0;
+ camel_mime_message->date_str = NULL;
}
GtkType
@@ -194,8 +177,7 @@ _finalize (GtkObject *object)
{
CamelMimeMessage *message = CAMEL_MIME_MESSAGE (object);
- g_free (message->received_date);
- g_free (message->sent_date);
+ g_free (message->date_str);
g_free (message->subject);
g_free (message->reply_to);
g_free (message->from);
@@ -222,182 +204,118 @@ camel_mime_message_new (void)
}
-/* some utils func */
+/* **** Date: */
-static void
-_set_field (CamelMimeMessage *mime_message, gchar *name, const gchar *value, gchar **variable)
-{
- if (variable) {
- g_free (*variable);
- if (value)
- *variable = g_strdup (value);
- else
- *variable = NULL;
+void
+camel_mime_message_set_date(CamelMimeMessage *message, time_t date, int offset)
+{
+ g_assert(message);
+ if (date == CAMEL_MESSAGE_DATE_CURRENT) {
+ struct tm *local;
+ int tz;
+
+ date = time(0);
+ local = localtime(&date);
+ offset = 0;
+#if defined(HAVE_TIMEZONE)
+ tz = timezone;
+#elif defined(HAVE_TM_GMTOFF)
+ tz = local->tm_gmtoff;
+#endif
+ offset = ((tz/60/60) * 100) + (tz/60 % 60);
}
-}
+ message->date = date;
+ message->date_offset = offset;
+ g_free(message->date_str);
+ message->date_str = header_format_date(date, offset);
-/* for future use */
-/* for the moment, only @variable is used */
-static gchar *
-_get_field (CamelMimeMessage *mime_message, gchar *name, gchar *variable)
-{
- return variable;
-}
-
-/* * */
-
-
-static void
-_set_received_date (CamelMimeMessage *mime_message, const gchar *received_date)
-{
- _set_field (mime_message, received_date_str, received_date, &(mime_message->received_date));
+ CMD_CLASS(parent_class)->set_header((CamelMedium *)message, "Date", message->date_str);
}
void
-camel_mime_message_set_received_date (CamelMimeMessage *mime_message, const gchar *received_date)
-{
- g_assert (mime_message);
- g_return_if_fail (!mime_message->expunged);
- CMM_CLASS (mime_message)->set_received_date (mime_message, received_date);
-}
-
-
-static const gchar *
-_get_received_date (CamelMimeMessage *mime_message)
-{
- return _get_field (mime_message, received_date_str, mime_message->received_date);
-}
-
-const gchar *
-camel_mime_message_get_received_date (CamelMimeMessage *mime_message)
-{
- g_assert (mime_message);
- g_return_val_if_fail (!mime_message->expunged, NULL);
- return CMM_CLASS (mime_message)->get_received_date (mime_message);
-}
-
-
-static const gchar *
-_get_sent_date (CamelMimeMessage *mime_message)
+camel_mime_message_get_date(CamelMimeMessage *message, time_t *date, int *offset)
{
- return _get_field (mime_message, sent_date_str, mime_message->sent_date);
+ if (message->date == CAMEL_MESSAGE_DATE_CURRENT)
+ camel_mime_message_set_date(message, CAMEL_MESSAGE_DATE_CURRENT, 0);
+ if (date)
+ *date = message->date;
+ if (offset)
+ *offset = message->date_offset;
}
-const gchar *
-camel_mime_message_get_sent_date (CamelMimeMessage *mime_message)
+char *
+camel_mime_message_get_date_string(CamelMimeMessage *message)
{
- g_assert (mime_message);
- g_return_val_if_fail (!mime_message->expunged, NULL);
- return CMM_CLASS (mime_message)->get_sent_date (mime_message);
+ if (message->date == CAMEL_MESSAGE_DATE_CURRENT)
+ camel_mime_message_set_date(message, CAMEL_MESSAGE_DATE_CURRENT, 0);
+ return message->date_str;
}
-
-static void
-_set_reply_to (CamelMimeMessage *mime_message, const gchar *reply_to)
-{
- _set_field (mime_message, reply_to_str, reply_to, &(mime_message->reply_to));
-}
+/* **** Reply-To: */
void
camel_mime_message_set_reply_to (CamelMimeMessage *mime_message, const gchar *reply_to)
{
g_assert (mime_message);
- g_return_if_fail (!mime_message->expunged);
- CMM_CLASS (mime_message)->set_reply_to (mime_message, reply_to);
-}
+ /* FIXME: check format of string, handle it nicer ... */
-static const gchar *
-_get_reply_to (CamelMimeMessage *mime_message)
-{
- return _get_field (mime_message, reply_to_str, mime_message->reply_to);
+ g_free(mime_message->reply_to);
+ mime_message->reply_to = g_strdup(reply_to);
+ CMD_CLASS(parent_class)->set_header((CamelMedium *)mime_message, "Reply-To", reply_to);
}
const gchar *
camel_mime_message_get_reply_to (CamelMimeMessage *mime_message)
{
g_assert (mime_message);
- g_return_val_if_fail (!mime_message->expunged, NULL);
- return CMM_CLASS (mime_message)->get_reply_to (mime_message);
-}
-
-
-
-static void
-_set_subject (CamelMimeMessage *mime_message, const gchar *subject)
-{
- _set_field (mime_message, subject_str, subject, &(mime_message->subject));
+ return mime_message->reply_to;
}
void
camel_mime_message_set_subject (CamelMimeMessage *mime_message,
const gchar *subject)
{
+ char *text;
g_assert (mime_message);
- g_return_if_fail (!mime_message->expunged);
- CMM_CLASS (mime_message)->set_subject (mime_message, subject);
-}
-
-static const gchar *
-_get_subject (CamelMimeMessage *mime_message)
-{
- return _get_field (mime_message, subject_str, mime_message->subject);
+ g_free(mime_message->subject);
+ mime_message->subject = g_strdup(subject);
+ text = header_encode_string(subject);
+ CMD_CLASS(parent_class)->set_header((CamelMedium *)mime_message, "Subject", text);
+ g_free(text);
}
const gchar *
camel_mime_message_get_subject (CamelMimeMessage *mime_message)
{
g_assert (mime_message);
- g_return_val_if_fail (!mime_message->expunged, NULL);
- return CMM_CLASS (mime_message)->get_subject (mime_message);
-}
-
-
-
-static void
-_set_from (CamelMimeMessage *mime_message, const gchar *from)
-{
- _set_field (mime_message, from_str, from, &(mime_message->from));
+ return mime_message->subject;
}
+/* *** From: */
void
camel_mime_message_set_from (CamelMimeMessage *mime_message, const gchar *from)
{
g_assert (mime_message);
- g_return_if_fail (!mime_message->expunged);
- CMM_CLASS (mime_message)->set_from (mime_message, from);
-}
-
-static const gchar *
-_get_from (CamelMimeMessage *mime_message)
-{
- return _get_field (mime_message, from_str, mime_message->from);
+ g_free(mime_message->from);
+ mime_message->from = g_strdup(from);
+ CMD_CLASS(parent_class)->set_header((CamelMedium *)mime_message, "From", from);
}
const gchar *
camel_mime_message_get_from (CamelMimeMessage *mime_message)
{
g_assert (mime_message);
- g_return_val_if_fail (!mime_message->expunged, NULL);
- return CMM_CLASS (mime_message)->get_from (mime_message);
-}
-
-
-
-
-
+ return mime_message->from;
+}
/* **** */
-
-
-
-
static void
_add_recipient (CamelMimeMessage *mime_message,
const gchar *recipient_type,
@@ -588,13 +506,33 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelMimeMessage *mm = CAMEL_MIME_MESSAGE (data_wrapper);
+#if 0
#warning each header should be stored in the raw headers
WHPT (stream, "From", mm->from);
WHPT (stream, "Reply-To", mm->reply_to);
- _write_recipients_to_stream (mm, stream);
WHPT (stream, "Date", mm->received_date);
WHPT (stream, "Subject", mm->subject);
+#endif
+ /* force mandatory headers ... */
+ if (mm->from == NULL) {
+ g_warning("No from set for message");
+ camel_mime_message_set_from(mm, "");
+ }
+ if (mm->date_str == NULL) {
+ g_warning("Application did not set date, using 'now'");
+ camel_mime_message_set_date(mm, CAMEL_MESSAGE_DATE_CURRENT, 0);
+ }
+ if (mm->subject == NULL) {
+ g_warning("Application did not set subject, creating one");
+ camel_mime_message_set_subject(mm, "No Subject");
+ }
+
+#warning need to store receipients lists to headers
+#if 0
+ /* FIXME: remove this snot ... */
+ _write_recipients_to_stream (mm, stream);
+#endif
/* FIXME correct to do it here? */
WHPT (stream, "Mime-Version", "1.0");
@@ -630,13 +568,16 @@ process_header(CamelMedium *medium, const char *header_name, const char *header_
header_type = (CamelHeaderType) g_hash_table_lookup (header_name_table, header_name);
switch (header_type) {
case HEADER_FROM:
- camel_mime_message_set_from (message, header_value);
+ g_free(message->from); /* FIXME: parse the from line into something useful */
+ message->from = g_strdup(header_value);
break;
case HEADER_REPLY_TO:
- camel_mime_message_set_reply_to (message, header_value);
+ g_free(message->reply_to); /* FIXME: parse the from line into something useful */
+ message->reply_to = g_strdup(header_value);
break;
case HEADER_SUBJECT:
- camel_mime_message_set_subject (message, header_value);
+ g_free(message->subject);
+ message->subject = header_decode_string(header_value);
break;
case HEADER_TO:
if (header_value)
@@ -656,6 +597,15 @@ process_header(CamelMedium *medium, const char *header_name, const char *header_
else
camel_recipient_table_remove_type (message->recipients, "Bcc");
break;
+ case HEADER_DATE:
+ g_free(message->date_str);
+ message->date_str = g_strdup(header_value);
+ if (header_value) {
+ message->date = header_decode_date(header_value, &message->date_offset);
+ } else {
+ message->date = CAMEL_MESSAGE_DATE_CURRENT;
+ }
+ break;
default:
return FALSE;
}