diff --git a/lib/mu-msg-part.c b/lib/mu-msg-part.c index 1681c0d4..65f5e33b 100644 --- a/lib/mu-msg-part.c +++ b/lib/mu-msg-part.c @@ -251,6 +251,30 @@ cleanup_filename (char *fname) } +/* + * when a part doesn't have a filename, it can be useful to 'guess' one based on + * its mime-type, which allows other tools to handle them correctly, e.g. from + * mu4e. + * + * For now, we only handle calendar invitations in that way, but others may + * follow. + */ +static char* +guess_file_name (GMimeObject *mobj, unsigned index) +{ + GMimeContentType *ctype; + + ctype = g_mime_object_get_content_type (mobj); + + /* special case for calendars; map to '.vcs' */ + if (g_mime_content_type_is_type (ctype, "text", "calendar")) + return g_strdup_printf ("vcal-%u.vcs", index); + + /* fallback */ + return g_strdup_printf ("%u.part", index); +} + + static char* mime_part_get_filename (GMimeObject *mobj, unsigned index, gboolean construct_if_needed) @@ -279,10 +303,11 @@ mime_part_get_filename (GMimeObject *mobj, unsigned index, } if (!fname) - fname = g_strdup_printf ("%u.part", index); - + fname = guess_file_name (mobj, index); + /* remove slashes, spaces, colons... */ cleanup_filename (fname); + return fname; }