diff options
Diffstat (limited to 'camel')
-rw-r--r-- | camel/Makefile.am | 2 | ||||
-rw-r--r-- | camel/camel-formatter.c | 199 | ||||
-rw-r--r-- | camel/camel-formatter.h | 63 |
3 files changed, 264 insertions, 0 deletions
diff --git a/camel/Makefile.am b/camel/Makefile.am index 2fae06080d..9e46826c64 100644 --- a/camel/Makefile.am +++ b/camel/Makefile.am @@ -41,6 +41,7 @@ libcamel_la_SOURCES = \ camel-folder.c \ camel-folder-summary.c \ camel-folder-utils.c \ + camel-formatter.c \ camel-medium.c \ camel-marshal-utils.c \ camel-mime-body-part.c \ @@ -80,6 +81,7 @@ libcamelinclude_HEADERS = \ camel-folder.h \ camel-folder-summary.h \ camel-folder-utils.h \ + camel-formatter.h \ camel-mime-body-part.h \ camel-marshal-utils.h \ camel-medium.h \ diff --git a/camel/camel-formatter.c b/camel/camel-formatter.c new file mode 100644 index 0000000000..a7d72e0b04 --- /dev/null +++ b/camel/camel-formatter.c @@ -0,0 +1,199 @@ + +/*--------------------------------*-C-*---------------------------------* + * + * Author : + * Matt Loper <matt@helixcode.com> + * + * Copyright 2000, Helix Code, Inc. (http://www.helixcode.com) . + * + * 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 Street #330, Boston, MA 02111-1307, USA. + * + * + *----------------------------------------------------------------------*/ + +#include <config.h> +#include "camel-formatter.h" + +static GtkObjectClass *parent_class=NULL; +static void _finalize (GtkObject *object); + +struct _CamelFormatterPrivate { + CamelMimeMessage *msg; +}; + +static void +write_field_to_stream (gchar* description, gchar* value, CamelStream *stream) +{ + gchar *s; + g_assert (description && value); + + s = g_strdup_printf ("<b>%s: %s</b><br>\n", + description, value); + camel_stream_write_string (stream, s); + g_free (s); +} + +static void +write_recipients_to_stream (const gchar *recipient_type, + GList *recipients, + CamelStream* stream_out) +{ + gchar *s; + g_assert (recipient_type && stream_out); + + s = g_strdup_printf ("<b>%s: <br>\n", recipient_type); + camel_stream_write_string (stream_out, s); + g_free (s); + + while (recipients) { + camel_stream_write_string (stream_out, recipients->data); + recipients = recipients->next; + if (recipients) + camel_stream_write_string (stream_out, "; "); + } + camel_stream_write_string (stream_out, "</b><br>\n"); +} + +void +set_mime_message (CamelFormatter* cfm, CamelMimeMessage* msg) +{ + g_assert(cfm && msg); + cfm->priv->msg = msg; +} + + + +/** + * camel_formatter_to_html: write data content in a byte stream + * @data_wrapper: the camel formatter object + * @stream_out byte stream where data will be written + * + * This method must be overriden by subclasses + * Data must be written in the bytes stream + * in a architecture independant fashion. + * If data is a standard data (for example an jpg image) + * it must be serialized in the strea exactly as it + * would be saved on disk. A simple dump of the stream in + * a file should be sufficient for the data to be + * re-read by a foreign application. + * + **/ +void +camel_formatter_make_html (CamelFormatter *mhs, + CamelStream* stream_out) +{ + gchar *s = NULL; + GList *recipients = NULL; + CamelMimeMessage *mime_message; + + g_assert (mhs && stream_out); + g_assert (mhs->priv->msg); + + mime_message = mhs->priv->msg; + + camel_stream_write_string (stream_out, "Content type: text/html\n"); + + if ((s = (gchar*)camel_mime_message_get_subject (mime_message))) { + write_field_to_stream ("Subject: ", s, stream_out); + } + + if ((s = (gchar*)camel_mime_message_get_from (mime_message))) { + write_field_to_stream ("From: ", s, stream_out); + } + + if ((s = (gchar*)camel_mime_message_get_received_date (mime_message))) { + write_field_to_stream ("Received Date: ", s, stream_out); + } + + if ((s = (gchar*)camel_mime_message_get_sent_date (mime_message))) { + write_field_to_stream ("Sent Date: ", s, stream_out); + } + + /* Fill out the "To:" recipients line */ + recipients = camel_mime_message_get_recipients ( + mime_message, CAMEL_RECIPIENT_TYPE_TO); + if (recipients) + write_recipients_to_stream ("To:", recipients, stream_out); + + /* Fill out the "CC:" recipients line */ + recipients = camel_mime_message_get_recipients ( + mime_message, CAMEL_RECIPIENT_TYPE_CC); + if (recipients) + write_recipients_to_stream ("CC:", recipients, stream_out); + /* Fill out the "BCC:" recipients line */ + recipients = camel_mime_message_get_recipients ( + mime_message, CAMEL_RECIPIENT_TYPE_BCC); + if (recipients) + write_recipients_to_stream ("BCC:", recipients, stream_out); +} + +static void +camel_formatter_class_init (CamelFormatterClass *camel_formatter_class) +{ + GtkObjectClass *gtk_object_class = + GTK_OBJECT_CLASS (camel_formatter_class); + + parent_class = gtk_type_class (gtk_object_get_type ()); + + /* virtual method overload */ + gtk_object_class->finalize = _finalize; +} + +static void +camel_formatter_init (gpointer object, gpointer klass) +{ + CamelFormatter* cmf = CAMEL_FORMATTER (object); + cmf->priv->msg = NULL; +} + + +GtkType +camel_formatter_get_type (void) +{ + static GtkType camel_formatter_type = 0; + + if (!camel_formatter_type) { + GtkTypeInfo camel_formatter_info = + { + "CamelFormatter", + sizeof (CamelFormatter), + sizeof (CamelFormatterClass), + (GtkClassInitFunc) camel_formatter_class_init, + (GtkObjectInitFunc) camel_formatter_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + camel_formatter_type = gtk_type_unique ( + gtk_object_get_type (), + &camel_formatter_info); + } + + return camel_formatter_type; +} + + +static void +_finalize (GtkObject *object) +{ + CamelFormatter *mhs = CAMEL_FORMATTER (object); + + g_free (mhs->priv); + + GTK_OBJECT_CLASS (parent_class)->finalize (object); +} + + diff --git a/camel/camel-formatter.h b/camel/camel-formatter.h new file mode 100644 index 0000000000..d2ed5bd12c --- /dev/null +++ b/camel/camel-formatter.h @@ -0,0 +1,63 @@ +/*--------------------------------*-C-*---------------------------------* + * + * Author : + * Matt Loper <matt@helixcode.com> + * + * Copyright 2000, Helix Code, Inc. (http://www.helixcode.com) . + * + * 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 Street #330, Boston, MA 02111-1307, USA. + * + * + *----------------------------------------------------------------------*/ + +#ifndef CAMEL_FORMATTER_H +#define CAMEL_FORMATTER_H + +#include <gtk/gtk.h> +#include "camel-mime-message.h" + +#define CAMEL_FORMATTER_TYPE (camel_formatter_get_type ()) +#define CAMEL_FORMATTER(obj) (GTK_CHECK_CAST((obj), CAMEL_FORMATTER_TYPE, CamelDataWrapper)) +#define CAMEL_FORMATTER_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_FORMATTER_TYPE, CamelDataWrapperClass)) +#define CAMEL_IS_CAMEL_FORMATTER(o) (GTK_CHECK_TYPE((o), CAMEL_FORMATTER_TYPE)) + +typedef struct _CamelFormatterPrivate CamelFormatterPrivate; + +typedef struct +{ + GtkObject parent_object; + CamelFormatterPrivate *priv; +} CamelFormatter; + +typedef struct { + GtkObjectClass parent_class; +} CamelFormatterClass; + + +/* Standard Gtk function */ +GtkType camel_formatter_get_type (void); + +/* Public functions */ +CamelFormatter* camel_formatter_new (CamelMimeMessage* msg); + +void set_mime_message (CamelFormatter* cfm, CamelMimeMessage* msg); + +/* The main job of CamelFormatter is to take a mime message, and + produce html from it. */ +void camel_formatter_make_html (CamelFormatter* cmf, + CamelStream* stream_out); + +#endif // CAMEL_FORMATTER_H + |