mirror of https://github.com/djcb/mu.git
mu: special-case text/calendar parts
Set the name for (otherwise unnamed) mime-parts of type text/calendar to "vcal-<n>.vcs"; this allows for easier processing with external tools.
This commit is contained in:
parent
105809cd8e
commit
0678d31056
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue