Patch: new TnyCamelHtmlToTextStream



	Hi,

	This patch adds a new object, TnyCamelHtmlToTextStream, that wraps a
stream we expect to contain html format, and outputs that html format
converted to plain text.

	It uses CamelMimeFilterHtml and CamelMimeFilterStream.

Changelog entry:
	* New libtinymail-camel/tny-camel-html-to-text-stream.[ch]:
	new stream that wraps a stream with html format, so its output
	is a plain text version of that stream.

-- 
José Dapena Paz <jdapena igalia com>
Igalia
diff --git a/ChangeLog b/ChangeLog
index 946d7be..7ec8a36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-06-16  Jose Dapena Paz  <jdapena igalia com>
+
+	* New libtinymail-camel/tny-camel-html-to-text-stream.[ch]:
+	new stream that wraps a stream with html format, so its output
+	is a plain text version of that stream.
+
 2009-06-15  Sergio Villar Senin  <svillar igalia com>
 
 	* libtinymail-camel/tny-camel-send-queue.c (check_cancel): call
diff --git a/libtinymail-camel/Makefile.am b/libtinymail-camel/Makefile.am
index 20f3b76..59c8539 100644
--- a/libtinymail-camel/Makefile.am
+++ b/libtinymail-camel/Makefile.am
@@ -31,6 +31,7 @@ libtinymail_camel_1_0_headers =	\
 	tny-camel-transport-account.h \
 	tny-camel-stream.h \
 	tny-stream-camel.h \
+	tny-camel-html-to-text-stream.h \
 	tny-camel-shared.h \
 	tny-camel-send-queue.h \
 	tny-camel-mem-stream.h \
@@ -89,6 +90,7 @@ libtinymail_camel_1_0_la_SOURCES = \
 	tny-stream-camel.c \
 	tny-camel-send-queue.c \
 	tny-camel-mem-stream.c \
+	tny-camel-html-to-text-stream.c \
 	tny-session-camel.c \
 	tny-camel-queue.c \
 	tny-camel-bs-msg.c \
diff --git a/libtinymail-camel/tny-camel-html-to-text-stream.c b/libtinymail-camel/tny-camel-html-to-text-stream.c
new file mode 100644
index 0000000..4fd3e46
--- /dev/null
+++ b/libtinymail-camel/tny-camel-html-to-text-stream.c
@@ -0,0 +1,116 @@
+/* libtinymail-camel The Tiny Mail base library for Camel
+ * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with self library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <tny-camel-html-to-text-stream.h>
+#include "tny-camel-stream-priv.h"
+
+
+#include <camel/camel.h>
+
+static GObjectClass *parent_class = NULL;
+
+/**
+ * tny_camel_html_to_text_stream_new:
+ * @html_stream: a #TnyStream
+ *
+ * Create a new stream that converts original @html_stream to text
+ *
+ * Return value: a new #TnyStream instance
+ **/
+TnyStream*
+tny_camel_html_to_text_stream_new (TnyStream *html_stream)
+{
+	TnyCamelHtmlToTextStream *self = g_object_new (TNY_TYPE_CAMEL_HTML_TO_TEXT_STREAM, NULL);
+	TnyCamelStreamPriv *priv = TNY_CAMEL_STREAM_GET_PRIVATE (self);
+	CamelStream *wrap_html_stream;
+	CamelMimeFilter *mime_filter;
+
+	wrap_html_stream = tny_stream_camel_new (html_stream);
+
+	mime_filter = camel_mime_filter_html_new ();
+
+	priv->stream = camel_stream_filter_new_with_stream (wrap_html_stream);
+	camel_stream_filter_add (priv->stream, mime_filter);
+
+	camel_object_unref (mime_filter);
+	camel_object_unref (wrap_html_stream);
+
+	return TNY_STREAM (self);
+}
+
+static void
+tny_camel_html_to_text_stream_instance_init (GTypeInstance *instance, gpointer g_class)
+{
+	return;
+}
+
+static void
+tny_camel_html_to_text_stream_finalize (GObject *object)
+{
+	(*parent_class->finalize) (object);
+	return;
+}
+
+
+static void 
+tny_camel_html_to_text_stream_class_init (TnyFsStreamClass *class)
+{
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	object_class = (GObjectClass*) class;
+	object_class->finalize = tny_camel_html_to_text_stream_finalize;
+
+	return;
+}
+
+static gpointer 
+tny_camel_html_to_text_stream_register_type (gpointer notused)
+{
+	GType type = 0;
+
+	static const GTypeInfo info = 
+		{
+			sizeof (TnyCamelHtmlToTextStreamClass),
+			NULL,   /* base_init */
+			NULL,   /* base_finalize */
+			(GClassInitFunc) tny_camel_html_to_text_stream_class_init,   /* class_init */
+			NULL,   /* class_finalize */
+			NULL,   /* class_data */
+			sizeof (TnyCamelHtmlToTextStream),
+			0,      /* n_preallocs */
+			tny_camel_html_to_text_stream_instance_init,   /* instance_init */
+			NULL
+		};
+	
+	
+	type = g_type_register_static (TNY_TYPE_CAMEL_STREAM,
+				       "TnyCamelHtmlToTextStream",
+				       &info, 0);
+
+	return GUINT_TO_POINTER (type);
+}
+
+GType 
+tny_camel_html_to_text_stream_get_type (void)
+{
+	static GOnce once = G_ONCE_INIT;
+	g_once (&once, tny_camel_html_to_text_stream_register_type, NULL);
+	return GPOINTER_TO_UINT (once.retval);
+}
diff --git a/libtinymail-camel/tny-camel-html-to-text-stream.h b/libtinymail-camel/tny-camel-html-to-text-stream.h
new file mode 100644
index 0000000..bbe313b
--- /dev/null
+++ b/libtinymail-camel/tny-camel-html-to-text-stream.h
@@ -0,0 +1,56 @@
+#ifndef TNY_CAMEL_HTML_TO_TEXT_STREAM_H
+#define TNY_CAMEL_HTML_TO_TEXT_STREAM_H
+
+/* libtinymail-camel The Tiny Mail base library for Camel
+ * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with self library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <tny-camel-stream.h>
+
+G_BEGIN_DECLS
+
+#define TNY_TYPE_CAMEL_HTML_TO_TEXT_STREAM             (tny_camel_html_to_text_stream_get_type ())
+#define TNY_CAMEL_HTML_TO_TEXT_STREAM(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), TNY_TYPE_CAMEL_HTML_TO_TEXT_STREAM, TnyCamelHtmlToTextStream))
+#define TNY_CAMEL_HTML_TO_TEXT_STREAM_CLASS(vtable)    (G_TYPE_CHECK_CLASS_CAST ((vtable), TNY_TYPE_CAMEL_HTML_TO_TEXT_STREAM, TnyCamelHtmlToTextStreamClass))
+#define TNY_IS_CAMEL_HTML_TO_TEXT_STREAM(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TNY_TYPE_CAMEL_HTML_TO_TEXT_STREAM))
+#define TNY_IS_CAMEL_HTML_TO_TEXT_STREAM_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), TNY_TYPE_CAMEL_HTML_TO_TEXT_STREAM))
+#define TNY_CAMEL_HTML_TO_TEXT_STREAM_GET_CLASS(inst)  (G_TYPE_INSTANCE_GET_CLASS ((inst), TNY_TYPE_CAMEL_HTML_TO_TEXT_STREAM, TnyCamelHtmlToTextStreamClass))
+
+typedef struct _TnyCamelHtmlToTextStream TnyCamelHtmlToTextStream;
+typedef struct _TnyCamelHtmlToTextStreamClass TnyCamelHtmlToTextStreamClass;
+
+struct _TnyCamelHtmlToTextStream
+{
+	TnyCamelStream parent;
+};
+
+struct _TnyCamelHtmlToTextStreamClass 
+{
+	TnyCamelStreamClass parent;
+};
+
+GType  tny_camel_html_to_text_stream_get_type (void);
+TnyStream* tny_camel_html_to_text_stream_new (TnyStream *html_stream);
+
+G_END_DECLS
+
+#endif
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]