Merge pull request #853 from liweitianux/master
Use Unicode characters when cleaning up attachment filename
This commit is contained in:
@ -239,15 +239,26 @@ get_part_size (GMimePart *part)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static char*
|
||||||
cleanup_filename (char *fname)
|
cleanup_filename (char *fname)
|
||||||
{
|
{
|
||||||
|
GString *gstr;
|
||||||
gchar *cur;
|
gchar *cur;
|
||||||
|
gunichar uc;
|
||||||
|
|
||||||
/* replace control characters, slashes,colons by a '-' */
|
gstr = g_string_sized_new (strlen (fname));
|
||||||
for (cur = fname; *cur; ++cur)
|
|
||||||
if (*cur < ' ' || *cur == '/' || *cur == ':')
|
/* replace control characters, slashes, and colons by '-' */
|
||||||
*cur = '-';
|
for (cur = fname; cur && *cur; cur = g_utf8_next_char (cur)) {
|
||||||
|
uc = g_utf8_get_char (cur);
|
||||||
|
if (g_unichar_iscntrl (uc) || uc == '/' || uc == ':')
|
||||||
|
g_string_append_unichar (gstr, '-');
|
||||||
|
else
|
||||||
|
g_string_append_unichar (gstr, uc);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (fname);
|
||||||
|
return g_string_free (gstr, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -304,9 +315,9 @@ mime_part_get_filename (GMimeObject *mobj, unsigned index,
|
|||||||
|
|
||||||
if (!fname)
|
if (!fname)
|
||||||
fname = guess_file_name (mobj, index);
|
fname = guess_file_name (mobj, index);
|
||||||
|
|
||||||
/* remove slashes, spaces, colons... */
|
/* replace control characters, slashes, and colons */
|
||||||
cleanup_filename (fname);
|
fname = cleanup_filename (fname);
|
||||||
|
|
||||||
return fname;
|
return fname;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user