Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF8 encode error when receiving emails #403

Open
bestkiller92 opened this issue Jan 26, 2022 · 6 comments
Open

UTF8 encode error when receiving emails #403

bestkiller92 opened this issue Jan 26, 2022 · 6 comments

Comments

@bestkiller92
Copy link

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
Copy link
Author

bestkiller92 commented Jan 29, 2022

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
Copy link
Author

It's working ;)

@bestkiller92
Copy link
Author

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
Copy link
Author

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
Copy link
Author

bestkiller92 commented Mar 24, 2022

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
Copy link
Author

see #407

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants