For the benefit of anyone wanting to duplicate my email piping hack ... here is my modified code. Please be gentle .. I'm not a PHP programmer so if you have fixes or improvements I'd really appreciate them.
For some reason I could not make my new code work if I included the hesk_dbEscape wrapper around the column names. Probably missed something simple so, if you're more familiar with PHP than I am, please post a modification that works.
However, this has been working reliably for me for a while now ..
This is the modified section of /inc/mail/hesk_pipe.php ..
Code: Select all
/* parse the incoming e-mail */
$results = parser();
/* Variables */
$categorymail = $results['to'][0]['address'];
if ($categorymail) {
$sql = "SELECT `category_id` FROM `".$hesk_settings['db_pfix']."category_email` WHERE `email` = '".$categorymail."' LIMIT 1";
$result = hesk_dbQuery($sql);
}
if ($myresult = hesk_dbFetchAssoc($result)) {
if ($myresult['category_id']) {
$tmpvar['category'] = $myresult['category_id'];
}
}
else {
$tmpvar['category'] = 1;
}
$tmpvar['name'] = hesk_input($results['from'][0]['name']) or $tmpvar['name'] = $hesklang['unknown'];
$tmpvar['email'] = hesk_validateEmail($results['from'][0]['address'],'ERR',0);
$tmpvar['priority'] = 3;
$tmpvar['subject'] = hesk_input($results['subject']) or $tmpvar['subject'] = '['.$hesklang['unknown'].']';
$tmpvar['message'] = hesk_input($results['message']);
$_SERVER['REMOTE_ADDR'] = $hesklang['unknown'];
$IS_REPLY = 0;
$trackingID = '';
For this code to work you'll need to create the category_email table in your Hesk database (don't forget to add your hesk prefix - default naming would be hesk_category_email). I did this via cpanel / phpmyadmin (at the bottom of the "structure" tab). You'll need two fields in your table.
category_id (smallint) - this is your primary key
email (varchar(150)) - this holds the email address (make this whatever length you feel is appropriate).
I also added a unique index on the email field so that each email address can only be associated with a single category.
Lastly, I noticed some strange behaviour in the parsing of the email body when creating the ticket. I modified the regular expression substitution in the file email_parser.php ... I think the replacement of newline characters was broken so that it replaced occurrences of "rs" or "ns" instead (just a guess). Anywhere this character sequence appeared we got strange unprintable chars in the ticket.
I also tried to preserve HTML break tags as new lines in the text of the ticket (eg. <br />). Here's my modified function ... please feel free to correct it.
Code: Select all
function convert_html_to_text($data)
{
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<br>|<br />|<BR>|<BR />'i", // Turn HTML break into newline
"'<[/!]*?[^<>]*?>'si", // Strip out HTML tags
"'&(quot|#34);'i", // Replace HTML entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(d+);'e"); // evaluate as php
$replace = array ("",
"\n",
"",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\1)");
return preg_replace($search, $replace, $data);
}
I hope this helps ...