MailComment module - some regex help?

Events happening in the community are now at Drupal community events on www.drupal.org.
mudsurfer's picture

Hi all,
I need some regex confirmation -r better yet, advice re mailcomment module.
I'm working for a non-profit client, D6 with forums.
The have messaging and notifications active - so all members (300+) get emailed of any new forum topic AND any reply.
They want to facilitate more involvement from web-paranoid members, and have asked to enable functionality to allow them to comment by replying via email to a notification.

I have a test version of their site running with mailcomment (https://drupal.org/project/mailcomment), (and MailHandler and other dependancies...)

Took a while to sort out, but the email replies are now reliably creating comments on the site.
MailComment includes an input filter that strips out all the guff in the email surrounding the body text. I'm testing multiple email clients/webmail clients to see how they work. In some cases very well, in some cases OK but with some leftover guff.
For instance any post from iPad mail app, includes text:
On 11/06/2013, at 10:52 AM, name_here wrote:

It looks like in the mailcomment.module their is an array of regex filters that have been designed to strip out these types of lines - but of course every email client does it differently, and changes these things from time to time.
Mailcomment does not seem to be actively maintained recently - unfortunately. So I have had no luck on the Mailcomment issue queue.

I THINK all I really need is to add a few extra lines to the regex array, with the extra filtering I need to do for a few email clients.

I've tried but either my regex is no good (my 1st assumption) - OR this mail module is not working the way I thought.

  1. Could any regex gurus caste their eye over this and let me know how I've ballsed it up?

to find this:
On 11/06/2013, at 10:52 AM, site_name wrote:
I'm using this:
"On \d{1,2}[\/-]{1}\d{1,2}[\/-]{1}\d{4}, at \d{1,2}:\d{2} [AP]M, site_name wrote:", // iPad mail app

  1. Anyone have any suggestions for actively maintained alternatives to mailcomment? Happy to consider third party services - but have not been able to find any. Thought maybe there would be "listserv" integration of sometype, somewhere?

  2. Anyone have experience with mailcomment module - that I could ask a couple more questions about how the mailcomment message filter (post) interacts/overlaps with the code for the mailcomment input filters... I cant quite get my head around that.

Comments

Your text has a hyphen in

johnhorner's picture

Your text has a hyphen in 'site-name' but your regex has an underscore.

Thanks - Sorry about that,

mudsurfer's picture

Thanks - Sorry about that, that was just a type as I wrote this post, as I sanitised it and replaced the real site-name. I have edited post to correct.

Can you try the following? I

zyxware's picture

Can you try the following? I don't think you need site_name in the regex as that would change between different senders.

"On \d{1,2}[\/-]\d{1,2}[\/-]\d{4}, at \d{1,2}:\d{2} [AP]M, .* wrote:"

Thanks - Tried this, and

mudsurfer's picture

Thanks - Tried this, and although that makes sense to me, it did not work either.
Makes me think that the mailcomment-module regex array is NOT being used in the input filter - but if that is the case, niot sure where I find the input filter to change it...
Thank you for you help -
If I ever get it working, you approach above will take case of a number of different email client variants for me in one line - much appreciated.

Then maybe it's because

johnhorner's picture

Then maybe it's because you've got no delimiters around your pattern.

If I do this:

<?php
$text
= 'On 11/06/2013, at 10:52 AM, site-name wrote:';
$regex = "/On \d{1,2}[\/-]{1}\d{1,2}[\/-]{1}\d{4}, at \d{1,2}:\d{2} [AP]M, site-name wrote:/";

if(
preg_match($regex, $text)){
   echo
"this matches";
}else{
  echo
"this doesn't match";
}
?>

I get "this matches".

preg_match() needs non-alphanumeric delimiters around the pattern, as well as the quotes. I'm assuming it's preg_match() in use here.

Thanks - yes it does use

mudsurfer's picture

Thanks - yes it does use preg_match() further down in the function.
I tried your suggestion of extra delimiters - but that did not seem to have any effect either. Thank you though, much appreciated.
I'm pretty convinced now that the changes I'm making to the module (mailcomment.module) are not having any effect on the input filter....

If we're talking about the

johnhorner's picture

If we're talking about the alarmingly-named function

_mailcomment_filter_aggressive()

then it's adding its own delimiters when it runs:

$expression = '/('. implode('|', $delimiters) .')/';

putting all the items from the $delimiters array into one huge regex separated by pipes. What could possiblye go wrong? But if your regex is in that array, and that array is being used, it should work. Double-check the actual text that you're trying to match from the mail client before you give up. Whitespace can be deceptive for instance, you might be seeing one where there are two.

Thanks for that confirmation.

mudsurfer's picture

Thanks for that confirmation. I will go back to raw emails and double check everything.
Appreciated.

Use hook_mailcomment_alter to strip lines

zyxware's picture

You can implement your own hook_mailcomment_alter in your module to alter the node with the email content

http://drupalcode.org/project/mailcomment.git/blob/HEAD:/mailcomment.mod...

and then strip out whatever you want to strip out in your own module.

Thanks - That might be one

mudsurfer's picture

Thanks - That might be one step beyond my coding-anxiety threshold :) But I will have a lot at it and see if I can grasp the concept.
Really appreciate you help. Thanks.

Australia

Group categories

Location

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: