aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorMatthew Loper <mloper@src.gnome.org>2000-01-24 22:43:06 +0800
committerMatthew Loper <mloper@src.gnome.org>2000-01-24 22:43:06 +0800
commitf64b3bb5f2d3f4fa6e05fcc9223aff78fd8c2f12 (patch)
treef589a7f3b115af6076055c2b790b13af0fe2975c /camel
parent13429d5ff13d94a68148a7f16bf954c8939f3f19 (diff)
downloadgsoc2013-evolution-f64b3bb5f2d3f4fa6e05fcc9223aff78fd8c2f12.tar
gsoc2013-evolution-f64b3bb5f2d3f4fa6e05fcc9223aff78fd8c2f12.tar.gz
gsoc2013-evolution-f64b3bb5f2d3f4fa6e05fcc9223aff78fd8c2f12.tar.bz2
gsoc2013-evolution-f64b3bb5f2d3f4fa6e05fcc9223aff78fd8c2f12.tar.lz
gsoc2013-evolution-f64b3bb5f2d3f4fa6e05fcc9223aff78fd8c2f12.tar.xz
gsoc2013-evolution-f64b3bb5f2d3f4fa6e05fcc9223aff78fd8c2f12.tar.zst
gsoc2013-evolution-f64b3bb5f2d3f4fa6e05fcc9223aff78fd8c2f12.zip
new function, broken out from 'camel_formatter_make_html'.
* camel/camel-formatter.c (write_header_info_to_stream): new function, broken out from 'camel_formatter_make_html'. (write_mimepart_to_stream): same. (find_text_body_part_in_multipart_related): new function. (camel_formatter_make_html): Now tries to deal with multipart/related, multipart/alternate, and text/(plain|html). svn path=/trunk/; revision=1619
Diffstat (limited to 'camel')
-rw-r--r--camel/camel-formatter.c161
-rw-r--r--camel/camel-formatter.h20
2 files changed, 159 insertions, 22 deletions
diff --git a/camel/camel-formatter.c b/camel/camel-formatter.c
index f1347c7b0f..fec74db7e2 100644
--- a/camel/camel-formatter.c
+++ b/camel/camel-formatter.c
@@ -46,7 +46,7 @@ write_field_to_stream (gchar* description, gchar* value, CamelStream *stream)
static void
write_recipients_to_stream (const gchar *recipient_type,
- GList *recipients,
+ const GList *recipients,
CamelStream* stream_out)
{
gchar *s;
@@ -67,6 +67,7 @@ write_recipients_to_stream (const gchar *recipient_type,
camel_stream_write_string (stream_out, "<br><br>\n");
}
+
CamelFormatter*
camel_formatter_new ()
{
@@ -74,23 +75,14 @@ camel_formatter_new ()
}
-/**
- * camel_formatter_make_html:
- * @formatter: the camel formatter object
- * @stream_out: byte stream where data will be written
- *
- * Writes a CamelMimeMessage out, as html, into a stream passed in as
- * a parameter.
- **/
-void
-camel_formatter_make_html (CamelFormatter* formatter,
- CamelMimeMessage* mime_message,
- CamelStream* stream_out)
+static void
+write_header_info_to_stream (CamelMimeMessage* mime_message,
+ CamelStream* stream_out)
{
gchar *s = NULL;
- GList *recipients = NULL;
+ const GList *recipients = NULL;
- g_assert (formatter && mime_message && stream_out);
+ g_assert (mime_message && stream_out);
camel_stream_write_string (stream_out, "Content type: text/html\n");
@@ -112,10 +104,11 @@ camel_formatter_make_html (CamelFormatter* formatter,
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);
@@ -124,6 +117,7 @@ camel_formatter_make_html (CamelFormatter* formatter,
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);
@@ -131,6 +125,137 @@ camel_formatter_make_html (CamelFormatter* formatter,
write_recipients_to_stream ("BCC:", recipients, stream_out);
}
+
+#define MIME_TYPE_WHOLE(a) (gmime_content_field_get_mime_type ( \
+ camel_mime_part_get_content_type (CAMEL_MIME_PART (a))))
+#define MIME_TYPE_MAIN(a) ((camel_mime_part_get_content_type (CAMEL_MIME_PART (a)))->type)
+#define MIME_TYPE_SUB(a) ((camel_mime_part_get_content_type (CAMEL_MIME_PART (a)))->subtype)
+
+static gboolean
+strmatch (gchar *a, gchar *b)
+{
+ return (g_strcasecmp (a,b) == 0);
+}
+
+
+static void
+write_mimepart_to_stream (CamelMimePart* mime_part, CamelStream* stream)
+{
+ if (strmatch (MIME_TYPE_WHOLE(mime_part), "text/plain")) {
+ /* print out the shit plain-style */
+ }
+ else if (strmatch (MIME_TYPE_WHOLE(mime_part), "text/html")) {
+ /* print out the html */
+ }
+ else if (strmatch (MIME_TYPE_MAIN(mime_part), "image")) {
+ /* print out <img src="foofuck"> */
+ }
+}
+
+
+/* returns NULL if no text/html or text/plan msg is found */
+static CamelMimePart*
+find_text_body_part_in_multipart_related (CamelMultipart* multipart)
+{
+ int i, max_multiparts;
+ CamelMimePart* html_part = NULL;
+ CamelMimePart* plain_part = NULL;
+
+ /* find out out many parts are in it...*/
+ max_multiparts = camel_multipart_get_number (multipart);
+
+ /* ...and write each one, as html, into the stream. */
+ for (i = 0; i < max_multiparts; i++) {
+ CamelMimeBodyPart* body_part = camel_multipart_get_part (multipart, i);
+ if (strmatch (MIME_TYPE_SUB (body_part), "plain")) {
+ plain_part = CAMEL_MIME_PART (body_part);
+ }
+ else if (strmatch (MIME_TYPE_SUB (body_part), "html")) {
+ html_part = CAMEL_MIME_PART (body_part);
+ }
+ }
+
+ if (html_part)
+ return html_part;
+ if (plain_part)
+ return plain_part;
+ return NULL;
+}
+
+
+/**
+ * camel_formatter_make_html:
+ * @formatter: the camel formatter object
+ * @stream_out: byte stream where data will be written
+ *
+ * Writes a CamelMimeMessage out, as html, into a stream passed in as
+ * a parameter.
+ **/
+void
+camel_formatter_make_html (CamelFormatter* formatter,
+ CamelMimeMessage* mime_message,
+ CamelStream* stream_out)
+{
+ /* Get the mime-type of the mime message */
+ gchar* mime_type_whole = /* ex. "text/plain" */
+ MIME_TYPE_WHOLE (mime_message);
+
+ /* get the contents of the mime message */
+ CamelDataWrapper* message_contents = camel_medium_get_content_object (
+ CAMEL_MEDIUM (mime_message));
+
+ /* write the 'subject:', 'to:', 'from:', etc. into the output stream */
+ write_header_info_to_stream (mime_message, stream_out);
+
+ /* if we're dealing with a multipart/related message... */
+ if (strmatch (MIME_TYPE_WHOLE (mime_message), "multipart/related")) {
+
+ CamelMultipart *multipart = CAMEL_MULTIPART (
+ message_contents);
+
+ int i, max_multiparts;
+
+ /* find out out many parts are in it...*/
+ max_multiparts = camel_multipart_get_number (multipart);
+
+ /* ...and write each one, as html, into the stream. */
+ for (i = 0; i < max_multiparts; i++) {
+ CamelMimeBodyPart* body_part =
+ camel_multipart_get_part (multipart, i);
+
+ write_mimepart_to_stream (CAMEL_MIME_PART (body_part), stream_out);
+ }
+ }
+ else { /* okay, it's not multipart-related */
+
+ CamelMimePart* mime_part = NULL;
+
+ if (strmatch (mime_type_whole, "multipart/alternate")) {
+ mime_part =
+ find_text_body_part_in_multipart_related (
+ CAMEL_MULTIPART(message_contents));
+ }
+ else if (strmatch (mime_type_whole, "text/plain") ||
+ strmatch (mime_type_whole, "text/html")) {
+
+ mime_part = CAMEL_MIME_PART (message_contents);
+ }
+
+ if (message_contents) {
+
+ }
+ else {
+ gchar *error_string = g_strdup_printf (
+ "Sorry, but I don't know how to display items of type %s\n",
+ mime_type_whole);
+
+ camel_stream_write_string (stream_out, error_string);
+ g_free (error_string);
+ }
+ }
+}
+
+
static void
camel_formatter_class_init (CamelFormatterClass *camel_formatter_class)
{
@@ -143,14 +268,14 @@ camel_formatter_class_init (CamelFormatterClass *camel_formatter_class)
gtk_object_class->finalize = _finalize;
}
-static void
+void
camel_formatter_init (gpointer object, gpointer klass)
{
CamelFormatter* cmf = CAMEL_FORMATTER (object);
cmf->priv = g_new (CamelFormatterPrivate, 1);
}
-
+
GtkType
camel_formatter_get_type (void)
{
diff --git a/camel/camel-formatter.h b/camel/camel-formatter.h
index 16942fc5ce..1bcbb2d01a 100644
--- a/camel/camel-formatter.h
+++ b/camel/camel-formatter.h
@@ -25,8 +25,13 @@
#ifndef CAMEL_FORMATTER_H
#define CAMEL_FORMATTER_H
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus }*/
+
#include <gtk/gtk.h>
-#include "camel-mime-message.h"
+#include "camel.h"
#define CAMEL_FORMATTER_TYPE (camel_formatter_get_type ())
#define CAMEL_FORMATTER(obj) (GTK_CHECK_CAST((obj), CAMEL_FORMATTER_TYPE, CamelDataWrapper))
@@ -35,11 +40,13 @@
typedef struct _CamelFormatterPrivate CamelFormatterPrivate;
-typedef struct
+typedef struct _CamelFormatter CamelFormatter;
+
+struct _CamelFormatter
{
GtkObject parent_object;
CamelFormatterPrivate *priv;
-} CamelFormatter;
+};
typedef struct {
GtkObjectClass parent_class;
@@ -50,7 +57,7 @@ typedef struct {
GtkType camel_formatter_get_type (void);
/* Public functions */
-CamelFormatter* camel_formatter_new ();
+CamelFormatter* camel_formatter_new (void);
/* The main job of CamelFormatter is to take a mime message, and
produce html from it. */
@@ -58,5 +65,10 @@ void camel_formatter_make_html (CamelFormatter* cmf,
CamelMimeMessage *msg,
CamelStream* stream_out);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
#endif // CAMEL_FORMATTER_H