I have some questions about the way g_mime_object_write_to_stream behaves with respect to headers (I suspect this is related to the change in message structure alluded to in PORTING). If the attached program is compiled with gmime-2.6, then the top level part has message headers (From, To, Subject, etc...) attached to it, while if compiled with gmime 3.0, only the part headers (Content-type, content-transfer-encoding) are included. The new behaviour seems sensible (there are other ways to get the message headers), but 0) Can you confirm this change is intentional? 1) Assuming so, another note for PORTING? 3) Is there a way to achieve the same output in gmime-2.6 as the new output in 3.0?
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* GMime * Copyright (C) 2000-2017 Jeffrey Stedfast * * 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <time.h> #include <gmime/gmime.h> static void print_mime_part_info (GMimeStream *ostream, const char *path, GMimeObject *object) { const GMimeContentType *type; GMimeHeaderList *list; int count; type = g_mime_object_get_content_type (object); g_mime_stream_printf (ostream, "\f\n<<<<%s\t%s/%s>>>>>\n", path, type->type, type->subtype); #if (GMIME_MAJOR_VERSION >= 3) g_mime_object_write_to_stream (object, NULL, ostream); #else g_mime_object_write_to_stream (object, ostream); #endif } static void print_mime_struct_iter (GMimeMessage *message) { GMimePartIter *iter; GMimeObject *parent; GMimeObject *part; char *path; GMimeStream *ostream = g_mime_stream_pipe_new (STDOUT_FILENO); g_mime_stream_pipe_set_owner (GMIME_STREAM_PIPE (ostream), FALSE); iter = g_mime_part_iter_new ((GMimeObject *) message); if (g_mime_part_iter_is_valid (iter)) { if ((parent = g_mime_part_iter_get_parent (iter))) print_mime_part_info (ostream, "TEXT", parent); do { part = g_mime_part_iter_get_current (iter); path = g_mime_part_iter_get_path (iter); print_mime_part_info (ostream, parent ? path : "TEXT", part); g_free (path); } while (g_mime_part_iter_next (iter)); } g_mime_part_iter_free (iter); g_mime_stream_flush (ostream); g_object_unref (ostream); } static void test_parser (GMimeStream *stream) { GMimeParser *parser; GMimeMessage *message; parser = g_mime_parser_new (); g_mime_parser_init_with_stream (parser, stream); #if (GMIME_MAJOR_VERSION >= 3) message = g_mime_parser_construct_message (parser, NULL); #else message = g_mime_parser_construct_message (parser); #endif g_object_unref (parser); print_mime_struct_iter (message); g_object_unref (message); } int main (int argc, char **argv) { char *filename = NULL; GMimeStream *stream; int fd; #if (GMIME_MAJOR_VERSION >= 3) g_mime_init (); #else g_mime_init (0); #endif if (argc > 1) filename = argv[1]; else return 0; if ((fd = open (filename, O_RDONLY, 0)) == -1) return 0; stream = g_mime_stream_fs_new (fd); GMimeStream *istream = g_mime_stream_buffer_new (stream, GMIME_STREAM_BUFFER_BLOCK_READ); g_object_unref (stream); stream = istream; test_parser (stream); g_object_unref (stream); g_mime_shutdown (); return 0; }
Attachment:
signature.asc
Description: PGP signature