Page 1 of 1

original names of attachments by IMAP fetching

Posted: Mon Sep 02, 2019 6:48 pm
by drr.media
Hello.

I have problems with the original names of attachments by IMAP fetching. By fetching an email with an attachment name not in English (in my case in Russian language) - the attachment in the ticket has an absolute different name.

I had this problem also by attaching files in replies in tickets (not by fetching), but i found this code and it helped me: http://srv.nsk.ru/support/knowledgebase.php?article=67

Can anybody help me please with the names of attachments by incomming emails? I need the original names of files in tickets.
I found this php file and i think it can be edited, maybe i'm wrong: pipe_functions.inc.php. Can anybody tell me what i must to edit to resolve my problem? Maybe can anybody send me the proper php files. I'm not a developer. Thank you!

Re: original names of attachments by IMAP fetching

Posted: Mon Sep 02, 2019 7:05 pm
by Klemen
Hesk does that for security reasons as it can't properly check all situations for all encodings.

Can you send a sample email to pop3test AT hesk DOT com? I will have a look and see if there is a quick fix (it may take a while as I am super busy this week). If not, you will most likely need to hire a developer.

Re: original names of attachments by IMAP fetching

Posted: Mon Sep 02, 2019 7:21 pm
by drr.media
Klemen, thank you for answer!

I sended an email with two attachments.
The first one is an empty txt file with original name. The second in an png how the name see.

Re: original names of attachments by IMAP fetching

Posted: Mon Sep 02, 2019 7:51 pm
by Klemen
If you change

Code: Select all

$myatt['real_name'] = hesk_cleanFileName($v['orig_name']);
to

Code: Select all

$v['orig_name'] = hesk_encodeUTF8($v['orig_name'], $results['encoding']);
$myatt['real_name'] = hesk_htmlspecialchars($v['orig_name']);
in inc/pipe_functions.inc.php it works for your test.

However, please note that this is NOT fully tested and I take no responsibility for any misbehavior and I don't know how this will behave if your customers send emails not in utf-8 encoding. It also assumes you have PHP iconv function enabled on your server.

Re: original names of attachments by IMAP fetching

Posted: Mon Sep 02, 2019 8:49 pm
by drr.media
Klemen,

I changed the code in inc/pipe_functions.inc.php, but now i have other symbols in file names.
I use xampp, how i can enable the PHP iconv function? Can you please help. Google helped not :(

Re: original names of attachments by IMAP fetching

Posted: Tue Sep 03, 2019 5:29 am
by Klemen
That probably means some encodings aren't properly parsed.

Open phpinfo.php in your browser (it's in the "read this before posting" thread) and search for iconv to see if it is enabled.

You can also try changing this in pipe_functions

Code: Select all

return function_exists('iconv') ? iconv($encoding, 'UTF-8', $in) : utf8_encode($in);
to this and see if it makes any difference:

Code: Select all

return mb_convert_encoding($in, 'UTF-8', $encoding);
Or to:

Code: Select all

return mb_convert_encoding($in, 'UTF-8', mb_detect_encoding($str));
If that doesn't work for NEW emails I would have to see a sample email that doesn't work (full email with headers).

Re: original names of attachments by IMAP fetching

Posted: Tue Sep 03, 2019 9:52 am
by drr.media
Klemen,

changing to return mb_convert_encoding($in, 'UTF-8', $encoding); in pipe_functions helped me for recieving emails with right attachment names from a big mail service. I think they have utf-8 as default by sending emails. Almost all our customers are using Outlook and here by default sended emails are in KOI8-R, so the attachments have wrong names. If i change in Outlook the charset for sending emails to UTF-8 all attachments have the right name.

What can i change to recieve the right attachments names by using KOI8-R? It is impossible to say the customers to sending mails in utf-8.

by the way, the iconv is enabled. In all 3 lines local value and master value is empty.

Re: original names of attachments by IMAP fetching

Posted: Tue Sep 03, 2019 5:42 pm
by Klemen
Send a KOI8-R encoded email with attachments to my test address and I will check.

Re: original names of attachments by IMAP fetching

Posted: Wed Sep 04, 2019 7:05 am
by drr.media
I sent an email with theme: KOI8-R email

Re: original names of attachments by IMAP fetching

Posted: Sat Sep 07, 2019 1:01 pm
by Klemen
Try uploading this to your "inc" folder and see if there is any difference:
https://hesk.com/extras/284_pipe_functions_name.zip

Note that I haven't been able to fully test it so please test using different emails yourself.

Re: original names of attachments by IMAP fetching

Posted: Mon Sep 09, 2019 4:02 pm
by drr.media
Klemen,

Thank you very much for support! I'll change my answer a bit.

We asked our clients to send emails in utf-8. Now we have much more less problems with the attachment names. But there is just one moment. If the name of attachments have a comma (,) then the file fetched in hesk, lose all symbols in attachment name what follows next the comma. Is there anything we can do about it?

And one more question. Is it possible to fetch emails with attached .msg files? Its an Outlook email extension. Now they don't fall into hesk. I added this extension to allowed file types.