Page 1 of 2
Attachments
Posted: Thu Aug 04, 2022 5:56 am
by Noke101
Script URL:
Version of script: 3.3.1
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:
Write your message below:
Hello! I have a question regarding the file attachment script.
If the file has a name in Russian, then this script automatically renames it, and if the name is in English, then it does not rename it.
Can I somehow change the work of the script so that it recognizes the Cyrillic alphabet and saves the original file name?
Re: Attachments
Posted: Thu Aug 04, 2022 6:21 am
by Klemen
Hesk indeed removes anything except a-z, A-Z, 0-9, ._- from the file name.
This is both for security reasons (to clean up any attempts to pass invalid file names to Hesk) and to prevent encoding-related issues (for example, if file name is in different encoding than utf-8, for example from emails).
If you want to change that, you will need to delete or comment this line in "inc/posting_functions.inc.php":
Code: Select all
$filename = preg_replace('/[^A-Za-z0-9\.\-_]/','', $filename);
Re: Attachments
Posted: Thu Aug 04, 2022 7:10 am
by Noke101
Many thanks! Its works!
Re: Attachments
Posted: Fri Sep 16, 2022 2:40 pm
by Noke101
Hi! I have some problems with the name of the attachments, please tell me how to fix it?
Code: Select all
function hesk_cleanFileName($filename)
{
$parts = pathinfo($filename);
if ( ! isset($parts['extension']))
{
global $hesklang;
die($hesklang['nofex']);
}
$parts['extension'] = preg_replace('/[^A-Za-z0-9\-_]/', '', $parts['extension']);
if ( isset($parts['filename']) )
{
$filename = $parts['filename'];
}
// PHP < 5.2 needs special care
elseif ( version_compare(PHP_VERSION, '5.2','<') )
{
$filename = rtrim( str_ireplace($parts['extension'], '', $filename), '.');
}
else
{
$filename = '';
}
$filename = str_replace( array( '%20', '+' ), '-', $filename );
// $filename = preg_replace('/[\s-]+/', '-', $filename);
$filename = remove_accents($filename);
// $filename = preg_replace('/[^A-Za-z0-9\.\-_]/','', $filename);
$filename = trim($filename, '-_');
if ( strlen($filename) < 1 || strpos($filename, '.') === 0 )
{
$filename = mt_rand(10000,99999) . $filename;
}
return $filename . '.' . $parts['extension'];
} // END hesk_cleanFileName()
This is my code.
I have attached two images of what the files are named and how they are renamed to HESK.
https://ibb.co/VNnk4SJ - names
https://ibb.co/6mkcSNx - names in HESK
I tried to figure out what RegEx is and what it is eaten with, but unfortunately I choked after an hour.

Re: Attachments
Posted: Fri Sep 16, 2022 5:05 pm
by Klemen
Not sure what's causing that for you; have you tried to also comment out
Code: Select all
$filename = remove_accents($filename);
?
Are the files attached via form or via email?
Re: Attachments
Posted: Sun Sep 18, 2022 7:28 am
by Noke101
Klemen wrote: Fri Sep 16, 2022 5:05 pm
Not sure what's causing that for you; have you tried to also comment out
Code: Select all
$filename = remove_accents($filename);
?
Are the files attached via form or via email?
Attached via form
Re: Attachments
Posted: Sun Sep 18, 2022 8:10 am
by Klemen
Can you email the two files to pop3test AT hesk DOT com and I will test it locally.
Re: Attachments
Posted: Sun Sep 18, 2022 10:39 am
by Noke101
Klemen wrote: Sun Sep 18, 2022 8:10 am
Can you email the two files to pop3test AT hesk DOT com and I will test it locally.
Done

Re: Attachments
Posted: Sun Sep 18, 2022 12:04 pm
by Klemen
There were no files attached to your email.
If your files contain confidential information simply attach a test file with the same name.
Re: Attachments
Posted: Mon Sep 19, 2022 6:22 am
by Noke101
I send it
Re: Attachments
Posted: Mon Sep 19, 2022 2:09 pm
by Klemen
It imported just fine in my test setup?
I have just this part commented out:
Code: Select all
$filename = preg_replace('/[^A-Za-z0-9\.\-_]/','', $filename);
Re: Attachments
Posted: Mon Sep 19, 2022 3:00 pm
by Noke101
Klemen wrote: Mon Sep 19, 2022 2:09 pm
It imported just fine in my test setup?
I have just this part commented out:
Code: Select all
$filename = preg_replace('/[^A-Za-z0-9\.\-_]/','', $filename);
Сan you try to insert files when you create a ticket via the form? cuz my clients only use the form, they don't use pop3
Re: Attachments
Posted: Mon Sep 19, 2022 3:56 pm
by Klemen
Same thing, works normally if I attach the two files in the form.
Not sure what is going on on your side

Re: Attachments
Posted: Tue Sep 20, 2022 6:12 am
by Noke101
Klemen wrote: Mon Sep 19, 2022 3:56 pm
Same thing, works normally if I attach the two files in the form.
Not sure what is going on on your side
This is very strange, I even deleted just this line from code, HESK still removes the first word in the title, and if the title consists of one word, it simply assigns a random name from numbers.

Re: Attachments
Posted: Tue Sep 20, 2022 10:29 am
by Noke101
Klemen wrote: Mon Sep 19, 2022 3:56 pm
Same thing, works normally if I attach the two files in the form.
Not sure what is going on on your side
For the sake of interest, I decided to install a clean HESK copy of the latest version and send a ticket with attachments.
I got the same issue.
Code: Select all
function hesk_cleanFileName($filename)
{
$parts = pathinfo($filename);
if ( ! isset($parts['extension']))
{
$parts['extension'] = 'unknown-file-type';
}
$parts['extension'] = preg_replace('/[^A-Za-z0-9\-_]/', '', $parts['extension']);
if ( isset($parts['filename']) )
{
$filename = $parts['filename'];
}
// PHP < 5.2 needs special care
elseif ( version_compare(PHP_VERSION, '5.2','<') )
{
$filename = rtrim( str_ireplace($parts['extension'], '', $filename), '.');
}
else
{
$filename = '';
}
$filename = str_replace( array( '%20', '+' ), '-', $filename );
$filename = preg_replace('/[\s-]+/', '-', $filename);
$filename = remove_accents($filename);
// $filename = preg_replace('/[^A-Za-z0-9\.\-_]/','', $filename);
$filename = trim($filename, '-_');
if ( strlen($filename) < 1 || strpos($filename, '.') === 0 )
{
$filename = mt_rand(10000,99999) . $filename;
}
return $filename . '.' . $parts['extension'];
} // END hesk_cleanFileName()
https://ibb.co/5KdGfcH
https://ibb.co/cLcPKzJ