On Sun, Oct 02, 2016 at 04:46:44PM -0700, Kevin J. McCarthy wrote:
> On Sun, Oct 02, 2016 at 08:43:38PM +0500, Konstantin Ovsov wrote:
> > The function mutt_sanitize_filename (char * f, short slash) (from
> > lib.c) which forms a "safe" file name, i.e. it replaces all non-Latin
> > characters with "_".  Because of this attachments with the names in
> > UTF-8, while viewing (select the attachment and press 'Enter') or
> > forward (select the attachment, and press 'f') obtained name from the
> > "_".  For example, "Шрифт.zip" -> "__________.zip". This unpleasant
> > behavior.  This behavior mutt justified, or should create the patch,
> > which will mutt work with unicode characters?
> 
> The issue when forwarding should probably be fixed in mutt_copy_body().
> 
> We create the sanitized tempfile, but don't try to preserve the original
> filename in d_filename.  I'll take a look at this.

This patch preserves the filename in the content-disposition filename=""
header for the attachment.

Unfortunately, the compose menu will still show the actual filename
inside /tmp, but the sender will see Шрифт.zip.

While I was in mutt_copy_body() I noticed b->filename was being
strdup'ed twice, generating a memleak, so this patch removes the second
copy too.

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
# HG changeset patch
# User Kevin McCarthy <[email protected]>
# Date 1475458704 25200
#      Sun Oct 02 18:38:24 2016 -0700
# Node ID 202ee7c2f8b31bed745f53d8d4da396d659c338a
# Parent  8963e77577adf7812a8b74fc9fa78d9afb4412c2
Preserve forwarded attachment names in d_filename.

When forwarding an attachment with an non-ascii name, mutt_copy_body()
mangles the filename by calling mutt_adv_mktemp.  Preserve attachment
filenames in d_filename.

Fix memory leak by removing the double copy of b->filename.

diff --git a/muttlib.c b/muttlib.c
--- a/muttlib.c
+++ b/muttlib.c
@@ -127,18 +127,21 @@
   b->unlink = 1;
 
   if (mutt_is_text_part (b))
     b->noconv = 1;
 
   b->xtype = safe_strdup (b->xtype);
   b->subtype = safe_strdup (b->subtype);
   b->form_name = safe_strdup (b->form_name);
-  b->filename = safe_strdup (b->filename);
   b->d_filename = safe_strdup (b->d_filename);
+  /* mutt_adv_mktemp() will mangle the filename in tmp,
+   * so preserve it in d_filename */
+  if (!b->d_filename && use_disp)
+    b->d_filename = safe_strdup (src->filename);
   b->description = safe_strdup (b->description);
 
   /* 
    * we don't seem to need the HEADER structure currently.
    * XXX - this may change in the future
    */
 
   if (b->hdr) b->hdr = NULL;

Attachment: signature.asc
Description: PGP signature

Reply via email to