/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* tests mime message file parsing */
#include "stdio.h"
#include "camel-mime-message.h"
#include "camel-mime-part.h"
#include "camel-stream.h"
#include "camel-stream-fs.h"
#include "camel.h"


static void
dump_message_content(CamelDataWrapper *object)
{
	CamelDataWrapper *containee;
	CamelStream *stream;
	int parts, i;
	int len;
	int left;
	char buffer[128];

	printf("Dumping message ...");

	containee = camel_medium_get_content_object(CAMEL_MEDIUM(object));

	if (containee) {
		char *type = gmime_content_field_get_mime_type(containee->mime_type);

		printf("type = %s\n", type);
		
		if (CAMEL_IS_MULTIPART(containee)) {
			parts = camel_multipart_get_number (CAMEL_MULTIPART(containee));
			printf("multipart message, scanning contents  %d parts ...\n", parts);
			for (i=0;i<parts;i++) {
				dump_message_content(CAMEL_DATA_WRAPPER (camel_multipart_get_part(CAMEL_MULTIPART(containee), i)));
			}
		} else if (CAMEL_IS_MIME_MESSAGE(containee)) {
			dump_message_content((CamelDataWrapper *)containee);
		} else {
			stream = camel_data_wrapper_get_output_stream(containee);
			left = 0;

			if (stream) {
				while ( (len = camel_stream_read(stream, buffer+left, sizeof(buffer)-left, NULL)) > 0) {
					fwrite(buffer, len, 1, stdout);
				}
				printf("\n");
			} else {
				g_warning("cannot get stream for message?");
			}
		}

		g_free(type);
	} else {
		printf("no containee?\n");
	}
}

int
main (int argc, char**argv)
{
	CamelMimeMessage *message;
	CamelStream *input_stream, *output_stream;
	CamelMimeParser *parser;

	gtk_init (&argc, &argv);
	camel_init ();

/* should have another program to test all this internationalisation/header parsing stuff */
#if 0
	{
		char *s, *o;
		s = "This is a test, simple ascii text";
		o = header_encode_string(s);
		printf("%s -> %s\n", s, o);
		s = "To: Markus \"D�Åhr\" <doehrm@aubi.de>";
		o = header_encode_string(s);
		printf("%s -> %s\n", s, o);

		s = "From: =?iso-8859-1?Q?Kenneth_ll=E9phaane_Christiansen?= <kenneth@ripen.dk>";
		o = header_encode_string(s);
		printf("%s -> %s\n", s, o);

		printf("decoding ... \n");
		s = "From: =?iso-8859-1?Q?Kenneth_ll=E9phaane_Christiansen?= <kenneth@ripen.dk>";
		o = header_decode_string(s);
		printf("%s -> %s\n", s, o);

		printf("reencoded\n");
		s = header_encode_string(o);
		printf("%s -> %s\n", o, s);
		return 0;
	}
#endif
		
	message = camel_mime_message_new ();

	
	input_stream = camel_stream_fs_new_with_name ("mail.test", O_RDONLY, 0, NULL);
	if (!input_stream) {
		perror ("could not open input file\n");
		printf ("You must create the file mail.test before running this test\n");
		exit(2);
	}

	printf("creating parser to create message\n");
	parser = camel_mime_parser_new();
	camel_mime_parser_init_with_stream(parser, input_stream);
	camel_mime_part_construct_from_parser(CAMEL_MIME_PART (message),
					      parser);

	dump_message_content(CAMEL_DATA_WRAPPER (message));

	gtk_object_unref (GTK_OBJECT (input_stream));

	output_stream = camel_stream_fs_new_with_name ("mail2.test", O_WRONLY|O_CREAT|O_TRUNC, 0600, NULL);
	camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), output_stream, NULL);
	camel_stream_flush (output_stream, NULL);
	gtk_object_unref (GTK_OBJECT (output_stream));
	
	//gtk_object_unref (GTK_OBJECT (message));
	return 0;

}
pm_and_yarn/devel/electron6/files/elliptic-6.5.4</option>
<option value='dependabot/npm_and_yarn/devel/electron6/files/ini-1.3.8'>dependabot/npm_and_yarn/devel/electron6/files/ini-1.3.8</option>
<option value='dependabot/npm_and_yarn/devel/electron6/files/lodash-4.17.19'>dependabot/npm_and_yarn/devel/electron6/files/lodash-4.17.19</option>
<option value='dependabot/npm_and_yarn/devel/electron6/files/lodash.merge-4.6.2'>dependabot/npm_and_yarn/devel/electron6/files/lodash.merge-4.6.2</option>
<option value='dependabot/npm_and_yarn/devel/electron6/files/node-fetch-2.6.1'>dependabot/npm_and_yarn/devel/electron6/files/node-fetch-2.6.1</option>
<option value='dependabot/npm_and_yarn/devel/electron6/files/serve-10.1.2'>dependabot/npm_and_yarn/devel/electron6/files/serve-10.1.2</option>
<option value='gnome-3.22'>gnome-3.22</option>
<option value='gnome-3.24'>gnome-3.24</option>
<option value='gnome-3.26'>gnome-3.26</option>
<option value='gnome-3.28'>gnome-3.28</option>
<option value='gnome-3.32'>gnome-3.32</option>
<option value='gnome-3.36'>gnome-3.36</option>
<option value='gstreamer'>gstreamer</option>
<option value='gstreamer-1.16'>gstreamer-1.16</option>
<option value='gstreamer0.10-removal' selected='selected'>gstreamer0.10-removal</option>
<option value='main'>main</option>
<option value='master'>master</option>
<option value='mate-1.16'>mate-1.16</option>
<option value='mate-1.18'>mate-1.18</option>
<option value='mate-1.20'>mate-1.20</option>
<option value='mate-1.22'>mate-1.22</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>FreeBSD GNOME current development ports (https://github.com/freebsd/freebsd-ports-gnome)</td><td class='sub right'></td></tr></table>
<table class='tabs'><tr><td>
<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/about/?h=gstreamer0.10-removal'>about</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/?h=gstreamer0.10-removal'>summary</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/refs/?h=gstreamer0.10-removal&amp;id=c6e2302a4058bd6b8c65410671fee363bf0a8a62'>refs</a><a class='active' href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/databases/mysql41-server?h=gstreamer0.10-removal'>log</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/tree/databases/mysql41-server?h=gstreamer0.10-removal&amp;id=c6e2302a4058bd6b8c65410671fee363bf0a8a62'>tree</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/databases/mysql41-server?h=gstreamer0.10-removal&amp;id=c6e2302a4058bd6b8c65410671fee363bf0a8a62'>commit</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/diff/databases/mysql41-server?h=gstreamer0.10-removal&amp;id=c6e2302a4058bd6b8c65410671fee363bf0a8a62'>diff</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/stats/databases/mysql41-server?h=gstreamer0.10-removal'>stats</a></td><td class='form'><form class='right' method='get' action='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/databases/mysql41-server'>
<input type='hidden' name='h' value='gstreamer0.10-removal'/><input type='hidden' name='id' value='c6e2302a4058bd6b8c65410671fee363bf0a8a62'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/?h=gstreamer0.10-removal&amp;id=c6e2302a4058bd6b8c65410671fee363bf0a8a62'>root</a>/<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/databases?h=gstreamer0.10-removal&amp;id=c6e2302a4058bd6b8c65410671fee363bf0a8a62'>databases</a>/<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/databases/mysql41-server?h=gstreamer0.10-removal&amp;id=c6e2302a4058bd6b8c65410671fee363bf0a8a62'>mysql41-server</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th></th><th class='left'>Commit message (<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/databases/mysql41-server?h=gstreamer0.10-removal&amp;id=c6e2302a4058bd6b8c65410671fee363bf0a8a62&amp;showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Age</th><th class='left'>Files</th><th class='left'>Lines</th></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/databases/mysql41-server?h=gstreamer0.10-removal&amp;id=8d9d5197561118544281733430b48b0b60884450'>Mass-conversion to the USE_AUTOTOOLS New World Order.  The code present</a></td><td>ade</td><td><span title='2005-11-15 14:52:12 +0800'>2005-11-15</span>