After an upgrade to PHP v5.4.32, Mailhandler is failing to process downloaded messages.
There is a long series of errors but this is the first one:
Warning: preg_match(): Compilation failed: invalid range in character class at offset 15 in MailhandlerCommandsDefault->getCommands() (line 132 of /path/to/mailhandler/plugins/mailhandler/commands/MailhandlerCommandsDefault.class.php).
Here's line 132:
preg_match('/^([a-zA-Z0-9_-\s\.]+):{1}\s+(.+)$/', $line, $matches);
This suggests that the "_-\s" part might be a problem:
http://stackoverflow.com/questions/24764212/preg-match-compilation-faile...
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | mailhandler-fix-regex-2333087-2.patch | 790 bytes | rclemings |
Comments
Comment #1
rclemings commentedFollowup: I'm not entirely clear on what this regex is supposed to do, but I found that putting a backslash in front of the hyphen solves the immediate problem and allows Mailhandler to process my commands correctly.
Was:
preg_match('/^([a-zA-Z0-9_-\s\.]+):{1}\s+(.+)$/', $line, $matches);Now:
preg_match('/^([a-zA-Z0-9_\-\s\.]+):{1}\s+(.+)$/', $line, $matches);If that sounds like a solution I can roll a patch.
Comment #2
rclemings commentedHere's the patch in case it's of use to anybody else. It has solved the problem for me at least.
Comment #3
jurgenhaasCame across the same issue and patch #2 resolved the issue.
Comment #4
bombjack commentedYeah I have the same problem with PHP 5.5.30
Originally came across the problem using Open Atrium and filed an issue thinking the plugin was OA specific. https://www.drupal.org/node/2651534
Looking around the web some regex testers will accept either version, and some require the hyphen character to be escaped given it is sometimes used to separate a range of characters.
Seems to me that it is safe to escape the hyphen, and probably best practice given it does break the regex, but does solve problems with more picky regex parsers.
Comment #5
abarpetia commented#2 patch worked for me. +1 to commit.
Comment #6
Anonymous (not verified) commented#2 fixed the problem.
In our case the problem was shown by the fact that the imported comments were set to unpublished. The mailhandler Extra commands are: /tls/novalidate-cert
On our dev server where the mailhandler mailhandler Extra commands are set to the default /notls, there is no problem.
Comment #7
caspianroach commented_-\sin that regex is supposed to mean "literal underscore, literal hyphen, any whitespace". However, since the symbol for hyphen '-' is also used in character ranges (for example, 0-9 means "from 0 to 9", meaning all numerals) and character class subtractions, it can trip certain RegExp parsers.
All the symbols inside square brackets except for ^-[]\ are parsed as literal tokens. To make these literal you need to escape them with a backslash \
In short, this patch does exactly what is needed and should be commited.
Comment #8
alexh commentedThe mailhandler commands did not work at all for me due to this bug. Patch in #2 worked and solved it for me.
I don't understand, why this simple but essential patch has not been committed in 4 years.
Comment #9
rclemings commentedMake that eight years. I guess this module is abandoned now.