1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
4  *
5  * This library is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12  * for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Authors: Jeffrey Stedfast <fejj@ximian.com>
18  */
19 
20 #include <stdio.h>
21 #include <string.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <unistd.h>
25 #include <dirent.h>
26 
27 #include "camel-test.h"
28 #include "messages.h"
29 
30 #if 0
31 static void
32 dump_mime_struct (CamelMimePart *mime_part,
33                   gint depth)
34 {
35 	CamelDataWrapper *content;
36 	gchar *mime_type;
37 	gint i = 0;
38 
39 	while (i < depth) {
40 		printf ("   ");
41 		i++;
42 	}
43 
44 	content = camel_medium_get_content ((CamelMedium *) mime_part);
45 
46 	mime_type = camel_data_wrapper_get_mime_type (content);
47 	printf ("Content-Type: %s\n", mime_type);
48 	g_free (mime_type);
49 
50 	if (CAMEL_IS_MULTIPART (content)) {
51 		guint num, index = 0;
52 
53 		num = camel_multipart_get_number ((CamelMultipart *) content);
54 		while (index < num) {
55 			mime_part = camel_multipart_get_part ((CamelMultipart *) content, index);
56 			dump_mime_struct (mime_part, depth + 1);
57 			index++;
58 		}
59 	} else if (CAMEL_IS_MIME_MESSAGE (content)) {
60 		dump_mime_struct ((CamelMimePart *) content, depth + 1);
61 	}
62 }
63 #endif
64 
main(gint argc,gchar ** argv)65 gint main (gint argc, gchar **argv)
66 {
67 	struct dirent *dent;
68 	DIR *dir;
69 	gint fd;
70 
71 	camel_test_init (argc, argv);
72 
73 	camel_test_start ("Message Test Suite");
74 
75 	if (!(dir = opendir ("../data/messages")))
76 		return 77;
77 
78 	while ((dent = readdir (dir)) != NULL) {
79 		CamelMimeMessage *message;
80 		CamelStream *stream;
81 		gchar *filename;
82 		struct stat st;
83 
84 		if (dent->d_name[0] == '.')
85 			continue;
86 
87 		filename = g_strdup_printf ("../data/messages/%s", dent->d_name);
88 		if (g_stat (filename, &st) == -1 || !S_ISREG (st.st_mode)) {
89 			g_free (filename);
90 			continue;
91 		}
92 
93 		if ((fd = open (filename, O_RDONLY)) == -1) {
94 			g_free (filename);
95 			continue;
96 		}
97 
98 		push ("testing message '%s'", filename);
99 		g_free (filename);
100 
101 		stream = camel_stream_fs_new_with_fd (fd);
102 		message = camel_mime_message_new ();
103 		camel_data_wrapper_construct_from_stream_sync (
104 			CAMEL_DATA_WRAPPER (message), stream, NULL, NULL);
105 		g_seekable_seek (
106 			G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, NULL);
107 
108 		/*dump_mime_struct ((CamelMimePart *) message, 0);*/
109 		test_message_compare (message);
110 
111 		g_object_unref (message);
112 		g_object_unref (stream);
113 
114 		pull ();
115 	}
116 
117 	closedir (dir);
118 
119 	camel_test_end ();
120 
121 	return 0;
122 }
123