From 297df938d615607d41f42068d39923cc64e9d292 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 23 May 2016 19:26:04 +0800 Subject: [PATCH 1/2] Use Unicode characters when cleaning up attachment filename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve the function ``cleanup_filename()`` of ``lib/mu-msg-part.c`` to use Unicode characters when replacing the control characters, slashes and colons with ``-``. Originally, this function just use plain C characters (i.e., assuming ASCII string) when checking each character is or not a control character, slash or colon. However, when the attachment filename contains non-ASCII (e.g., Chinese characters), all the non-ASCII characters are replaced with ``-``. For example: * Before: ``` > mu view test_chinese_attachment_filename.eml From: Tester To: Example Subject: Test email with attachment of Chinese filename Date: Mon 23 May 2016 05:22:09 PM CST Attachments: 'attachment-test.txt', '------------.txt', '-------test.txt' Hello, This is a simple test email with three attachments: 1. `attachment:test.txt`: filename is all English; 2. `测试附件.txt`: filename is all Chinese (exclude the extension); 3. `附件-test.txt`: filename mixes Chinese and English. ``` * After: ``` > ./build/mu/mu/mu view test_chinese_attachment_filename.eml From: Tester To: Example Subject: Test email with attachment of Chinese filename Date: Mon 23 May 2016 05:22:09 PM CST Attachments: 'attachment-test.txt', '测试附件.txt', '附件-test.txt' Hello, This is a simple test email with three attachments: 1. `attachment:test.txt`: filename is all English; 2. `测试附件.txt`: filename is all Chinese (exclude the extension); 3. `附件-test.txt`: filename mixes Chinese and English. ``` --- lib/mu-msg-part.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/mu-msg-part.c b/lib/mu-msg-part.c index b6bbffc3..f4242b32 100644 --- a/lib/mu-msg-part.c +++ b/lib/mu-msg-part.c @@ -239,15 +239,26 @@ get_part_size (GMimePart *part) } -static void +static char* cleanup_filename (char *fname) { + GString *gstr; gchar *cur; + gunichar uc; - /* replace control characters, slashes,colons by a '-' */ - for (cur = fname; *cur; ++cur) - if (*cur < ' ' || *cur == '/' || *cur == ':') - *cur = '-'; + gstr = g_string_sized_new (strlen (fname)); + + /* replace control characters, slashes, and colons by '-' */ + 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) fname = guess_file_name (mobj, index); - - /* remove slashes, spaces, colons... */ - cleanup_filename (fname); + + /* replace control characters, slashes, and colons */ + fname = cleanup_filename (fname); return fname; } From fe52c0e93269d2d05f40434a065f3fc14a1b7139 Mon Sep 17 00:00:00 2001 From: Jun Hao Date: Mon, 30 May 2016 23:31:25 +0800 Subject: [PATCH 2/2] mu4e: Make dvipng optional when convert from org to html --- mu4e/org-mu4e.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mu4e/org-mu4e.el b/mu4e/org-mu4e.el index b9e96882..545f5663 100644 --- a/mu4e/org-mu4e.el +++ b/mu4e/org-mu4e.el @@ -192,8 +192,6 @@ and images in a multipart/related part." "Convert the current body to html." (unless (fboundp 'org-export-string-as) (mu4e-error "require function 'org-export-string-as not found.")) - (unless (executable-find "dvipng") - (mu4e-error "Required program dvipng not found")) (let* ((begin (save-excursion (goto-char (point-min)) @@ -209,7 +207,9 @@ and images in a multipart/related part." ;; makes the replies with ">"s look nicer (org-export-preserve-breaks t) ;; dvipng for inline latex because MathJax doesn't work in mail - (org-export-with-LaTeX-fragments 'dvipng) + (org-export-with-LaTeX-fragments + (if (executable-find "dvipng") 'dvipng + (mu4e-message "Cannot find dvipng, ignore inline LaTeX") nil)) ;; to hold attachments for inline html images (html-and-images (org~mu4e-mime-replace-images