Hi again,
As I mentioned in a my previous post http://drupal.org/node/901522, I have inbound email integrated with a client and the support emails are generated by customer messages sent to our our eBay store.
I am having problems getting the emails to thread properly, because of "Re:" in the subject of the follow up messages sent by email.
I tried enabling "Thread emails using mail headers" on the settings page, but it seems that the message headers in the emails sent by eBay are not allowing for the matching of replies with original tickets. I disabled this feature, and the "Thread emails using subject" works better, but still results in new tickets being created when "Re:" is in the subject of the email.
I read the following post about a hook for fetch_message_alter here http://drupal.org/node/581806.
I hoped that by using this hook to strip "Re:" from the subject, it would solve the problem. I set up a module based on the example code in the above post. (module name = clean_subject)
I am new to PHP. But with what I have learned so far, I tried the following code.
function clean_subject_support_fetch_message_alter(&$message, $client) {
$junk3 = "Re: ";
if ($junk_pos = strpos($message['subject'], $junk3)) {
$message['subject'] = substr_replace($message['subject'], "", $junk_pos, 4);
$message['body'] .= "\nThis text was appended to the message body for testing\n";
}
}
If I set the $junk3 variable to "Re: " the above code does not work. It seems strpos() cannot find "Re: " in the subject. However, if I set the variable to another string (for example "junk") and try sending a test message with the string "junk" in the subject of the email, the above code successfully strips out the unwanted text from the $message['subject'] variable.
Could someone please explain why the code won't work with the string "Re: "?
Thanks and regards,
Rick
Comments
Comment #1
beesan commentedI received some help on the code and found my mistake.
The working code to remove Re: is as follows:
<?php
function clean_subject_support_fetch_message_alter(&$message, $client) {
$junk3 = "Re: ";
$junk_pos = strpos($message['subject'], $junk3);
if ($junk_pos !== FALSE) {
$message['subject'] = trim(substr_replace($message['subject'], "", $junk_pos, strlen($junk3)));
$message['body'] .= "\nThis text was appended $junk_pos to the message body.\n";
}
}
After trying this though, I realize it won't solve the problem of new tickets being created because of the "Re: ".
Any suggestions would be appreciated.
Thanks and regards,
Rick
Comment #2
lyricnz commentedIf you don't mind hacking the module, it should be as simple as adding a line of code to fiddle with $message['subject'] to remove any leading "Re: ". Something like
add this right above the "Search for the the ticket number in the subject." comment.
Comment #3
beesan commentedThank you for you help lyricnz.
Your code worked for me.
Since my previous post, I upgraded my version of the module to 6.x-1.x-dev.
In the support.module file, I added lyricnz code just above the following comment.
"// A) Check for ticket number defined in the Subject."
When receiving email messages from the server, my messages correctly thread now even with the string "Re:" at the begining of the subject in an email.
For my settings, I am only using the "Thread emails using subject". I do not have the option "Thread emails using mail headers" on.
Appreciate your taking time to help me out.
Regards,
Rick
Comment #4
beesan commented