aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Loper <mloper@src.gnome.org>2000-02-14 08:27:01 +0800
committerMatthew Loper <mloper@src.gnome.org>2000-02-14 08:27:01 +0800
commit204e08f87074268e93e0ad5d04a1bb5764a0c91c (patch)
tree2f7c39fc3693cd51601fd9711e5e66d7b41e5665
parent7dbc45ac3e4a8f2ac0535e61bcb52d324aa28d2b (diff)
downloadgsoc2013-evolution-204e08f87074268e93e0ad5d04a1bb5764a0c91c.tar
gsoc2013-evolution-204e08f87074268e93e0ad5d04a1bb5764a0c91c.tar.gz
gsoc2013-evolution-204e08f87074268e93e0ad5d04a1bb5764a0c91c.tar.bz2
gsoc2013-evolution-204e08f87074268e93e0ad5d04a1bb5764a0c91c.tar.lz
gsoc2013-evolution-204e08f87074268e93e0ad5d04a1bb5764a0c91c.tar.xz
gsoc2013-evolution-204e08f87074268e93e0ad5d04a1bb5764a0c91c.tar.zst
gsoc2013-evolution-204e08f87074268e93e0ad5d04a1bb5764a0c91c.zip
+ * tests/ui-tests/message-browser.c (handle_tree_item): Expand tree
+ items. + (mime_message_to_html): New function; translates a + CamelMimeMessage into two strings (one for the header, and one for + the body). + (get_gtk_html_window): New function; fills out a window with + html. The html is taken from a processed rfc822 file, via a + CamelFormatter. + + * camel/camel-formatter.c: Added assertions. + (handle_text_html): Don't call text_to_html on something that's + already html. + (multipart_foreach): function deleted. + + * mail/html-stream.c (html_stream_new): Second param of + gtk_html_begin should be "", not NULL. + (html_stream_new): gtk_html_parse() is deprecated, so the call was + removed. svn path=/trunk/; revision=1766
-rw-r--r--ChangeLog16
-rw-r--r--camel/camel-formatter.c118
-rw-r--r--mail/ChangeLog5
-rw-r--r--mail/html-stream.c3
-rw-r--r--tests/ui-tests/message-browser.c121
5 files changed, 175 insertions, 88 deletions
diff --git a/ChangeLog b/ChangeLog
index 6747453789..3c11bca8e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,21 @@
2000-02-13 Matt Loper <matt@helixcode.com>
+ * tests/ui-tests/message-browser.c (handle_tree_item): Expand tree
+ items.
+ (mime_message_to_html): New function; translates a
+ CamelMimeMessage into two strings (one for the header, and one for
+ the body).
+ (get_gtk_html_window): New function; fills out a window with
+ html. The html is taken from a processed rfc822 file, via a
+ CamelFormatter.
+
+ * camel/camel-formatter.c: Added assertions.
+ (handle_text_html): Don't call text_to_html on something that's
+ already html.
+ (multipart_foreach): function deleted.
+
* tests/ui-tests/message-browser.c: Added preliminary support for
- the viewing of messages via gtkhtml. Lots of commenting.
+ the viewing of messages via gtkhtml. Lots of commenting.
2000-02-11 Christopher James Lahey <clahey@helixcode.com>
diff --git a/camel/camel-formatter.c b/camel/camel-formatter.c
index 49776243ff..32d6666847 100644
--- a/camel/camel-formatter.c
+++ b/camel/camel-formatter.c
@@ -128,6 +128,7 @@ camel_formatter_mime_message_to_html (CamelFormatter* formatter,
CamelFormatterPrivate* fmt = formatter->priv;
g_print ("camel_formatter_mime_message_to_html: entered\n");
+ g_assert (mime_message);
/* initialize members of our formatter */
fmt->current_root = mime_message;
@@ -138,18 +139,27 @@ camel_formatter_mime_message_to_html (CamelFormatter* formatter,
/* write the subj:, to:, from: etc. fields out as html to the
header stream */
- write_header_info_to_stream (mime_message,
- header_stream);
+ if (header_stream)
+ write_header_info_to_stream (mime_message,
+ header_stream);
/* write everything to the stream */
- camel_stream_write_string (fmt->stream, "<html><body>\n");
-
- handle_mime_message (
- formatter,
- CAMEL_DATA_WRAPPER (mime_message));
-
- camel_stream_write_string (fmt->stream,
- "\n</body></html>\n");
+ if (body_stream) {
+
+ camel_stream_write_string (fmt->stream, "<html><body>\n");
+
+ handle_mime_message (
+ formatter,
+ CAMEL_DATA_WRAPPER (mime_message));
+
+ camel_stream_write_string (fmt->stream,
+ "\n</body></html>\n");
+ }
+ else {
+ g_print ("camel-formatter.c: ");
+ g_print ("camel_formatter_mime_message_to_html: ");
+ g_print ("you don't want the body??\n");
+ }
}
/* we're maintaining a hashtable of mimetypes -> functions;
@@ -213,7 +223,10 @@ call_handler_function (CamelFormatter* formatter,
{
mime_handler_fn handler_function = NULL;
+ g_assert (formatter);
g_assert (mimetype_whole || mimetype_main);
+ g_assert (wrapper);
+
/*
* Try to find a handler function in our own lookup table
*/
@@ -544,13 +557,13 @@ handle_text_html (CamelFormatter *formatter, CamelDataWrapper *wrapper)
g_assert (simple_data_wrapper->byte_array->data);
/* replace '<' with '&lt;', etc. */
- text = text_to_html (simple_data_wrapper->byte_array->data,
- simple_data_wrapper->byte_array->len,
- &returned_strlen);
+ text = g_strndup (simple_data_wrapper->byte_array->data,
+ simple_data_wrapper->byte_array->len);
camel_stream_write_string (formatter->priv->stream,
"\n<!-- text/html below -->\n");
camel_stream_write_string (formatter->priv->stream, text);
+
g_free (text);
}
else
@@ -596,18 +609,23 @@ static void
handle_mime_message (CamelFormatter *formatter,
CamelDataWrapper *wrapper)
{
- CamelMimeMessage* mime_message =
- CAMEL_MIME_MESSAGE (wrapper);
-
- CamelDataWrapper* message_contents =
- camel_medium_get_content_object (CAMEL_MEDIUM (mime_message));
+ CamelMimeMessage* mime_message;
+ CamelDataWrapper* message_contents;
+ g_assert (formatter);
+ g_assert (wrapper);
+ mime_message = CAMEL_MIME_MESSAGE (wrapper);
+ message_contents =
+ camel_medium_get_content_object (CAMEL_MEDIUM (mime_message));
+
+ g_assert (message_contents);
+
debug ("handle_mime_message: entered\n");
camel_stream_write_string (formatter->priv->stream,
"\n<!-- mime message below -->\n");
- camel_stream_write_string (formatter->priv->stream,
- "<table width=95% border=1><tr><td>\n\n");
+// camel_stream_write_string (formatter->priv->stream,
+// "<table width=95% border=1><tr><td>\n\n");
/* dispatch the correct handler function for the mime type */
call_handler_function (formatter, message_contents,
@@ -615,8 +633,8 @@ handle_mime_message (CamelFormatter *formatter,
MIME_TYPE_MAIN (mime_message));
/* close up the table we opened */
- camel_stream_write_string (formatter->priv->stream,
- "\n\n</td></tr></table>\n\n");
+// camel_stream_write_string (formatter->priv->stream,
+// "\n\n</td></tr></table>\n\n");
debug ("handle_mime_message: exiting\n");
}
@@ -660,32 +678,8 @@ find_preferred_displayable_body_part_in_multipart_alternative (
return NULL;
}
-/* we're maintaining a hashtable of mimetypes -> functions;
- * those functions have the following signature...*/
-typedef void (*multipart_foreach_fn) (CamelMimeBodyPart* mime_part,
- CamelFormatter* stream,
- gpointer user_data);
-
-static void
-multipart_foreach (CamelMultipart *multipart,
- multipart_foreach_fn* fn,
- CamelFormatter* formatter,
- gpointer user_data)
-{
- int i, max_multiparts;
-
- max_multiparts = camel_multipart_get_number (multipart);
- for (i = 0; i < max_multiparts; i++) {
- CamelMimeBodyPart* body_part =
- camel_multipart_get_part (multipart, i);
-
- (*fn)(body_part, formatter, user_data);
- }
-}
-
-/* called for each body part in a multipart/mixed, through
- 'multipart_foreach' */
+/* called for each body part in a multipart/mixed */
static void
print_camel_body_part (CamelMimeBodyPart* body_part,
CamelFormatter* formatter,
@@ -714,17 +708,33 @@ static void
handle_multipart_mixed (CamelFormatter *formatter,
CamelDataWrapper *wrapper)
{
- CamelMultipart* mp = CAMEL_MULTIPART (wrapper);
+ CamelMultipart* mp;
gboolean text_printed_yet = FALSE;
+
+ g_assert (formatter);
+ g_assert (wrapper);
+ g_assert (CAMEL_IS_MULTIPART (wrapper));
- debug ("handle_multipart_mixed: entered\n");
+ mp = CAMEL_MULTIPART (wrapper);
+ g_assert (mp);
+
+// debug ("handle_multipart_mixed: entered\n");
+
+
+ {
+ int i, max_multiparts;
+
+ max_multiparts = camel_multipart_get_number (mp);
+ for (i = 0; i < max_multiparts; i++) {
+ CamelMimeBodyPart* body_part =
+ camel_multipart_get_part (mp, i);
+
+ print_camel_body_part (body_part, formatter, &text_printed_yet);
+ }
+ }
- multipart_foreach (
- mp, (multipart_foreach_fn*)print_camel_body_part,
- formatter,
- &text_printed_yet);
- debug ("handle_multipart_mixed: exiting\n");
+// debug ("handle_multipart_mixed: exiting\n");
}
static void
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 18f37266c1..40ba1fca0d 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,5 +1,10 @@
2000-02-13 Matt Loper <matt@helixcode.com>
+ * html-stream.c (html_stream_new): Second param of gtk_html_begin
+ should be "", not NULL.
+ (html_stream_new): gtk_html_parse() is deprecated, so the call was
+ removed.
+
* html-stream.h: HTMLStreamClass's parent changed to
CamelStreamClass, not CamelStream.
diff --git a/mail/html-stream.c b/mail/html-stream.c
index 927f8f3593..d3028dcdcd 100644
--- a/mail/html-stream.c
+++ b/mail/html-stream.c
@@ -103,8 +103,7 @@ html_stream_new (GtkHTML *html)
gtk_object_ref (GTK_OBJECT (html));
- html_stream->gtk_html_stream = gtk_html_begin (html, NULL);
- gtk_html_parse (html);
+ html_stream->gtk_html_stream = gtk_html_begin (html, "");
html_stream->gtk_html = html;
diff --git a/tests/ui-tests/message-browser.c b/tests/ui-tests/message-browser.c
index 1ae4395f7e..d6a675a717 100644
--- a/tests/ui-tests/message-browser.c
+++ b/tests/ui-tests/message-browser.c
@@ -25,6 +25,7 @@
#include <camel/camel-stream-fs.h>
#include <camel/gmime-utils.h>
#include "../../mail/html-stream.h"
+#include <camel/camel-formatter.h>
/* gtkhtml stuff */
#include <gtkhtml/gtkhtml.h>
@@ -55,7 +56,6 @@ handle_tree_item (CamelDataWrapper* object, GtkWidget* tree_ctrl)
GtkWidget* subtree = NULL;
-
tree_item = gtk_tree_item_new_with_label (label);
gtk_tree_append (GTK_TREE (tree_ctrl), tree_item);
@@ -106,6 +106,7 @@ handle_tree_item (CamelDataWrapper* object, GtkWidget* tree_ctrl)
GTK_WIDGET (subtree));
}
}
+ gtk_tree_item_expand (GTK_TREE_ITEM (tree_item));
}
}
@@ -160,14 +161,93 @@ filename_to_camel_msg (gchar* filename)
}
/*----------------------------------------------------------------------*
+ * Filling out the HTML view of a mime message
+ *----------------------------------------------------------------------*/
+
+static void
+mime_message_to_html (CamelMimeMessage *msg, gchar** header_string,
+ gchar** body_string)
+{
+ CamelFormatter* cmf = camel_formatter_new();
+ CamelStream* header_stream =
+ camel_stream_mem_new (CAMEL_STREAM_FS_WRITE);
+ CamelStream* body_stream =
+ camel_stream_mem_new (CAMEL_STREAM_FS_WRITE);
+
+ g_assert (header_string && body_string);
+
+ camel_formatter_mime_message_to_html (
+ cmf, msg, header_stream, body_stream);
+
+ *header_string = g_strndup (
+ CAMEL_STREAM_MEM (header_stream)->buffer->data,
+ CAMEL_STREAM_MEM (header_stream)->buffer->len);
+ *body_string = g_strndup (
+ CAMEL_STREAM_MEM (body_stream)->buffer->data,
+ CAMEL_STREAM_MEM (body_stream)->buffer->len);
+}
+
+static GtkWidget*
+get_gtk_html_window (gchar* filename)
+{
+ static GtkWidget* scroll_wnd = NULL;
+ static GtkWidget* html_widget = NULL;
+ CamelMimeMessage* mime_message;
+ HTMLStream* html_stream;
+ gchar *body_string;
+ gchar *header_string;
+
+ g_assert (filename);
+ g_print ("filename: %s\n", filename);
+
+ /* create the html widget and scroll window, if they haven't
+ already been created */
+ if (!html_widget) {
+ html_widget = gtk_html_new();
+ scroll_wnd = gtk_scrolled_window_new (NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (scroll_wnd), html_widget);
+ }
+
+ html_stream = HTML_STREAM (html_stream_new (GTK_HTML (html_widget)));
+ mime_message = filename_to_camel_msg (filename);
+
+ g_assert (html_stream && mime_message);
+
+ /* turn the mime message into html, and
+ write it to the html stream */
+ mime_message_to_html (mime_message, &header_string, &body_string);
+ g_print ("strlen: %d\n%s\n", strlen (body_string), body_string);
+
+ camel_stream_write (CAMEL_STREAM (html_stream),
+ body_string,
+ strlen (body_string));
+
+ camel_stream_close (CAMEL_STREAM (html_stream));
+
+ g_free (header_string);
+ g_free (body_string);
+
+ gtk_widget_set_usize (scroll_wnd, 500, 400);
+ return scroll_wnd;
+}
+
+
+
+/*----------------------------------------------------------------------*
* Menu callbacks and information
*----------------------------------------------------------------------*/
+static gchar* fileselection_prev_file = NULL;
+
static void
open_ok (GtkWidget *widget, GtkFileSelection *fs)
{
int ret;
GtkWidget *error_dialog;
+
+ if (fileselection_prev_file)
+ g_free (fileselection_prev_file);
+
if(!g_file_exists (gtk_file_selection_get_filename (fs))) {
error_dialog = gnome_message_box_new (
_("File not found"),
@@ -183,8 +263,14 @@ open_ok (GtkWidget *widget, GtkFileSelection *fs)
else {
gchar *filename = gtk_file_selection_get_filename (fs);
CamelMimeMessage* message = filename_to_camel_msg (filename);
+
+ fileselection_prev_file = g_strdup (filename);
+
if (message)
+ {
get_message_tree_ctrl (message);
+ get_gtk_html_window (filename);
+ }
gtk_widget_destroy (GTK_WIDGET (fs));
}
@@ -195,9 +281,11 @@ static void
file_menu_open_cb (GtkWidget *widget, void* data)
{
GtkFileSelection *fs;
-
+
fs = GTK_FILE_SELECTION (
gtk_file_selection_new (_("Open Mime Message")));
+
+ gtk_file_selection_set_filename (fs, fileselection_prev_file);
gtk_signal_connect (GTK_OBJECT (fs->ok_button), "clicked",
(GtkSignalFunc) open_ok,
@@ -231,35 +319,6 @@ static GnomeUIInfo main_menu[] = {
};
-/*----------------------------------------------------------------------*
- * Filling out the HTML view of a mime message
- *----------------------------------------------------------------------*/
-
-static GtkWidget*
-get_gtk_html_window (gchar* filename)
-{
- static GtkWidget* scroll_wnd = NULL;
- static GtkWidget* html_widget = NULL;
- HTMLStream* html_stream;
-
- g_assert (filename);
-
- if (!html_widget) {
- html_widget = gtk_html_new();
- scroll_wnd = gtk_scrolled_window_new (NULL, NULL);
- gtk_container_add (GTK_CONTAINER (scroll_wnd), html_widget);
- }
-
- html_stream = html_stream_new (GTK_HTML (html_widget));
-
- camel_stream_write (CAMEL_STREAM (html_stream),
- "<html><body>hello</body></html>",
- sizeof("<html><body>hello</body></html>"));
-
- return scroll_wnd;
-}
-
-
int
main (int argc, char *argv[])
{