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:
@ -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*
|
static char*
|
||||||
mime_part_get_filename (GMimeObject *mobj, unsigned index,
|
mime_part_get_filename (GMimeObject *mobj, unsigned index,
|
||||||
gboolean construct_if_needed)
|
gboolean construct_if_needed)
|
||||||
@ -279,10 +303,11 @@ mime_part_get_filename (GMimeObject *mobj, unsigned index,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!fname)
|
if (!fname)
|
||||||
fname = g_strdup_printf ("%u.part", index);
|
fname = guess_file_name (mobj, index);
|
||||||
|
|
||||||
/* remove slashes, spaces, colons... */
|
/* remove slashes, spaces, colons... */
|
||||||
cleanup_filename (fname);
|
cleanup_filename (fname);
|
||||||
|
|
||||||
return fname;
|
return fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user