phproject icon indicating copy to clipboard operation
phproject copied to clipboard

UTF8 encode error when receiving emails

Open bestkiller92 opened this issue 3 years ago • 6 comments

Hi, not sure of what this is, but i have an issue with incoming emails. the subjects seems to be the only field affected, it tried to find the root cause but i couldn't:

"Test d'intégration #5" becomes " =?UTF-8?Q?Test_int=C3=A9gration_=233?= #5"

Could you please help me ? This might be related to the email directly : i've seen in the header that the issue is already there, but if this is a new way of sending mails .... the app needs to be updated to right ?

bestkiller92 avatar Jan 26 '22 12:01 bestkiller92

I added this function at the beginning of the "cron/checkmail2.php" file :

function utf8_decode_email_subject($str)
{
	$wordStart = '=\?UTF-8\?Q\?';
	$wordEnd = '\?='; 
	$output = "";

	$output = preg_replace('#' . $wordStart . '#', '', $str);//Remove start of UTF8 encoding
	$output = preg_replace('#' . $wordEnd . '#', '', $output);//Remove end of tUTF8 encoding
	$output = quoted_printable_decode($output);//decode special chars
	$output = preg_replace('#_#', ' ', $output);//replace spacing

	return $output;
}

Then I declared the variable $subject a bit earlier in the code and replaced occurences of "$header->subject" by "$subject": L144 >> $subject = utf8_decode_email_subject($header->subject); //early declaration L150 >> $log->write(sprintf('No matching user, using default - From: %s; Subject: %s', $from, $subject)); L152 >> $log->write(sprintf('Skipping message, no matching user - From: %s; Subject: %s', $from, $subject)); L177 >> $subject = trim(preg_replace("/^((Re|Fwd?):\s)*/i", "", $subject));//previous declaration L178 >> $issue->load(array('name=? AND deleted_date IS NULL AND closed_date IS NULL', $subject)); L192 >> 'name' => $subject,

This should do the trick... I'm currently testing on my server but the cron is only once an hour... I will let you know if it works fine

bestkiller92 avatar Jan 29 '22 00:01 bestkiller92

It's working ;)

bestkiller92 avatar Jan 30 '22 22:01 bestkiller92

Dude, I have to say that i'm having so much fun right now ! I've added a new function with this fix allowing groups to define a "group mailbox", incoming mails to that address will generate issue assigned to the group and not to the user... Testing... code is coming

bestkiller92 avatar Jan 31 '22 01:01 bestkiller92

Ok it's working :p But code is difficult to explain without a new fork... so ....

You basicaly have to reproduce the function used to set a manager in a group. add a "mailbox" field in the related view. Then update the check-mail script to take that information into account.

{ //No matching issue, creating a new issue //if user is mailbox of the group, the issue is assigned to the group. $is_group_mailbox = new \Model\Custom("user_group_user"); $is_group_mailbox->load(array("user_id = ? AND deleted_date IS NULL", $owner)); if($is_group_mailbox->mailbox){ $owner = $is_group_mailbox->group_id; } }

Resulting functionnality is quite interesting.

bestkiller92 avatar Mar 24 '22 16:03 bestkiller92

updated the following files: cron\checkmail2.php db\database.sql app\dict\en.ini app\routes.ini app\controller\admin.php app\view\admin\groups\edit.html

bestkiller92 avatar Mar 24 '22 17:03 bestkiller92

see #407

bestkiller92 avatar Mar 24 '22 19:03 bestkiller92