
Enjoy!

Auto-assign Categories Based on Piped Email Address
Subject: HESK e-mail piping public BETA (test version)
colin65 wrote: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.
I hope this helps ...