コード例 #1
0
ファイル: gmime.c プロジェクト: awesome/joyent-connector
int main (int argc, const char* argv[])
{
	GMimeMessage *message;
	GMimeParser  *parser;
	GMimeStream  *stream;
	const char   *file = argv[1];

	int fd;

	if (argc < 2) {
		printf("No file name given\n");
		return 1;
	}
	
	if (argc == 3) {
		text_only = 1;
		file = argv[2];
	}
	
	g_mime_init(0);
	g_mime_iconv_init();
	
	if ((fd = open(file, O_RDONLY)) == -1) {
		printf("Error opening file %s\n", file);
		return 1;
	}
	
	stream = g_mime_stream_fs_new(fd);
	parser = g_mime_parser_new_with_stream(stream);
	
	g_mime_parser_set_scan_from(parser, FALSE);
	g_object_unref(stream);
	
	message = g_mime_parser_construct_message(parser);
	g_object_unref(parser);
	
	if (message) {
		write_part(message->mime_part);
	} else {
		printf("Error constructing message\n");
		return 1;
	}
	
	g_mime_iconv_shutdown();
	return 0;
}
コード例 #2
0
ファイル: gmime.c プロジェクト: staceyson/gmime-2.6
/**
 * g_mime_init:
 * @flags: initialization flags
 *
 * Initializes GMime.
 *
 * Note: Calls g_mime_charset_map_init() and g_mime_iconv_init() as
 * well.
 **/
void
g_mime_init (guint32 flags)
{
	if (initialized++)
		return;
	
#if defined (HAVE_TIMEZONE) || defined (HAVE__TIMEZONE)
	/* initialize timezone */
	tzset ();
#endif
	
	enable = flags;
	
#if !GLIB_CHECK_VERSION(2, 35, 1)
	g_type_init ();
#endif
	
	g_mime_charset_map_init ();
	g_mime_iconv_utils_init ();
	g_mime_iconv_init ();
	
#ifdef ENABLE_SMIME
	/* gpgme_check_version() initializes GpgMe */
	gpgme_check_version (NULL);
#endif /* ENABLE_SMIME */
	
	gmime_gpgme_error_quark = g_quark_from_static_string ("gmime-gpgme");
	gmime_error_quark = g_quark_from_static_string ("gmime");
	
#ifdef G_THREADS_ENABLED
	g_mutex_init (&G_LOCK_NAME (iconv_cache));
	g_mutex_init (&G_LOCK_NAME (iconv_utils));
	g_mutex_init (&G_LOCK_NAME (charset));
	g_mutex_init (&G_LOCK_NAME (msgid));
#endif
	
	/* register our GObject types with the GType system */
	g_mime_crypto_context_get_type ();
	g_mime_decrypt_result_get_type ();
	g_mime_certificate_list_get_type ();
	g_mime_signature_list_get_type ();
	g_mime_certificate_get_type ();
	g_mime_signature_get_type ();
#ifdef ENABLE_CRYPTOGRAPHY
	g_mime_gpg_context_get_type ();
	g_mime_pkcs7_context_get_type ();
#endif
	
	g_mime_filter_get_type ();
	g_mime_filter_basic_get_type ();
	g_mime_filter_best_get_type ();
	g_mime_filter_charset_get_type ();
	g_mime_filter_crlf_get_type ();
	g_mime_filter_enriched_get_type ();
	g_mime_filter_from_get_type ();
	g_mime_filter_gzip_get_type ();
	g_mime_filter_html_get_type ();
	g_mime_filter_md5_get_type ();
	g_mime_filter_strip_get_type ();
	g_mime_filter_windows_get_type ();
	g_mime_filter_yenc_get_type ();
	
	g_mime_stream_get_type ();
	g_mime_stream_buffer_get_type ();
	g_mime_stream_cat_get_type ();
	g_mime_stream_file_get_type ();
	g_mime_stream_filter_get_type ();
	g_mime_stream_fs_get_type ();
	g_mime_stream_gio_get_type ();
	g_mime_stream_mem_get_type ();
	g_mime_stream_mmap_get_type ();
	g_mime_stream_null_get_type ();
	g_mime_stream_pipe_get_type ();
	
	g_mime_parser_get_type ();
	g_mime_message_get_type ();
	g_mime_data_wrapper_get_type ();
	g_mime_content_type_get_type ();
	g_mime_content_disposition_get_type ();
	
	internet_address_get_type ();
	internet_address_list_get_type ();
	internet_address_group_get_type ();
	internet_address_mailbox_get_type ();
	
	/* register our default mime object types */
	g_mime_object_type_registry_init ();
	g_mime_object_register_type ("*", "*", g_mime_part_get_type ());
	g_mime_object_register_type ("multipart", "*", g_mime_multipart_get_type ());
	g_mime_object_register_type ("multipart", "encrypted", g_mime_multipart_encrypted_get_type ());
	g_mime_object_register_type ("multipart", "signed", g_mime_multipart_signed_get_type ());
	g_mime_object_register_type ("message", "rfc822", g_mime_message_part_get_type ());
	g_mime_object_register_type ("message", "rfc2822", g_mime_message_part_get_type ());
	g_mime_object_register_type ("message", "news", g_mime_message_part_get_type ());
	g_mime_object_register_type ("message", "partial", g_mime_message_partial_get_type ());
}