1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/*--------------------------------*-C-*---------------------------------*
*
* Copyright 2000, Matt Loper <matt@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 <gnome.h>
#include <camel/camel.h>
#include <camel/camel-mime-message.h>
#include <camel/camel-stream.h>
#include <camel/camel-stream-fs.h>
#include <camel/gmime-utils.h>
static void
handle_tree_item (CamelDataWrapper* object, GtkWidget* tree_ctrl)
{
GtkWidget* tree_item;
gchar* label = gmime_content_field_get_mime_type (object->mime_type);
tree_item = gtk_tree_item_new_with_label (label);
gtk_tree_append (GTK_TREE (tree_ctrl), tree_item);
if (CAMEL_IS_MULTIPART (object))
{
CamelMultipart* multipart = CAMEL_MULTIPART (object);
GtkWidget* subtree = NULL;
int max_multiparts = camel_multipart_get_number (multipart);
int i;
g_print ("found a multipart w/ %d parts\n", max_multiparts);
if (max_multiparts > 0) {
subtree = gtk_tree_new();
gtk_tree_item_set_subtree (GTK_TREE_ITEM(tree_item),
GTK_WIDGET (subtree));
}
for (i = 0; i < max_multiparts; i++) {
CamelMimeBodyPart* body_part =
camel_multipart_get_part (multipart, i);
g_print ("handling part %d\n", i);
handle_tree_item (CAMEL_DATA_WRAPPER (body_part),
GTK_WIDGET (subtree));
}
}
gtk_widget_show(tree_item);
}
static GtkWidget*
get_message_tree_ctrl (CamelMimeMessage* message)
{
GtkWidget* tree_ctrl = gtk_tree_new ();
CamelDataWrapper* message_contents =
camel_medium_get_content_object (CAMEL_MEDIUM (message));
/*
* Set up the scroll window
*/
GtkWidget* scroll_wnd = gtk_scrolled_window_new (NULL,NULL);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scroll_wnd),
tree_ctrl);
gtk_widget_set_usize (scroll_wnd, 150, 200);
/*
* Recursively insert tree items in the tree
*/
handle_tree_item (message_contents, tree_ctrl);
return scroll_wnd;
}
static CamelMimeMessage*
filename_to_camel_msg (gchar* filename)
{
CamelMimeMessage* message;
CamelStream* input_stream;
camel_init();
message = camel_mime_message_new_with_session (
(CamelSession *)NULL);
input_stream = camel_stream_fs_new_with_name (
filename, CAMEL_STREAM_FS_READ);
camel_data_wrapper_construct_from_stream (
CAMEL_DATA_WRAPPER (message), input_stream);
camel_stream_close (input_stream);
return message;
}
static void
print_usage_and_quit()
{
g_print ("Usage: message-browser [FILENAME]\n");
g_print ("Where FILENAME is the filename of a mime message ");
g_print ("in \"message/rfc822\" format.\n");
exit (0);
}
int
main (int argc, char *argv[])
{
GtkWidget* app;
CamelMimeMessage* message;
if (argc != 2)
print_usage_and_quit();
gnome_init ("MessageBrowser", "1.0", argc, argv);
app = gnome_app_new ("Message Browser Test", NULL);
message = filename_to_camel_msg (argv[1]);
#if 0
if (!message) {
g_print ("Couldn't open message \"%s\", bailing...\n",
argv[1]);
exit (0);
}
#endif
gnome_app_set_contents (GNOME_APP (app),
get_message_tree_ctrl (message));
gtk_widget_show_all (app);
gtk_signal_connect (GTK_OBJECT (app), "destroy",
GTK_SIGNAL_FUNC(gtk_main_quit),
&app);
gtk_main();
return 1;
}
|