
Hello,
Apologies for the OT post, but I've been struggling with a regex for a long time, trying to get it to work with my postfixadmin vacation.pl, and for the life of me, I can't seem to get it right. I've asked numerous times on the postfixadmin list, but no one there has been able to help.
If this is too OT or no one can help, that is ok, but I just thought maybe someone here might be able to see why this line isn't working...
Here is the line with the regex in it:
elsif (/^from:.*+(bounce|do-not-reply|facebook|linkedin|list-|myspace|twitter)/i) { $logger->debug("Multi-string From header matching $1: $2 found; exiting"); exit (0); }
What I want is for it to match any 'From' header that contains any one of the strings in it (ie, bounce, do-not-reply, etc). We get a lot of list related stuff that the vacation.pl responds to that I don't want it to respond to, so I want a one-liner that I can manually add these strings too whenever I see one go out that shouldn't, so we don't respond to things that shouldn't be responded to.
Does anything jump out at you as to why it isn't catching anything?
Thanks in advance (to Mark or anyone who might be able to help)...
On 2013-02-12 1:37 AM, Mark Sapiro <mark@msapiro.net> wrote:> METU E-List Admin wrote:

On 2013-02-15 9:41 AM, Tanstaafl <tanstaafl@libertytrek.org> wrote:
We get a lot of list related stuff that the vacation.pl responds to that I don't want it to respond to,
To clarify - by 'list-related', I mean announce/newsletter type junk that our users subscribe to, not necessarily mailman list posts...
Also, I want not respond to *any* social networking messages at all, I just want a single custom line that I can add any string that I want to test for.
I would never use anything like this to reject or otherwise interfere with *receiving* mail, but I have a much lower bar when it comes to stuff I don't want my vacation.pl to reply to, so false positives are not a real concern for me here.

elsif (/^from:.*+(bounce|do-not-reply|facebook|linkedin|list-|myspace|twitter)/i) { $logger->debug("Multi-string From header matching $1: $2 found; exiting"); exit (0); }
Examine the logic of the 'if' and any 'elsif' above this line.
I am uncertain what /.*+/ would do. Remove either * or +.
Otherwise this looks reasonable to me.
Joseph Brennan Columbia University Information Technology

On 2013-02-15 10:25 AM, Joseph Brennan <brennan@columbia.edu> wrote:
Thanks for the help Joseph (and Stephen)...
This 'if' block is just a bunch of separate one line tests that, if any of them match, result in the vacation response not being sent, so it doesn't really matter what is above them (they are all the defaults, this is the only line I am modifying)...
This line should simply examine any from header, and if any of the included strings are found *anywhere* in the from address, local or domain part, so, either side of the '@' sign, and regardless of any dots anywhere in the string.
I imagine that is why the guys from postfixadmin used the * and maybe the +? Like I said, I've got no experience with regex at all - guess its time to learn eh? ;)
Anyway, I want the regex such that any/all of the following from addresses would match (along with all of the other strings):
bounce-anything@example.com anything@bounce.example.com anything@bounce-reply.example.com facebook@example.com anything.facebook@example.com anything-facebook@example.com anything@something.facebook.com
Hopefully that is enough examples...
Basically, if *any* of the strings I might specify inside the parenthesis match individually anywhere in the from address, then don't send the response (ie, positive match).
Thanks again, it is really appreciated...

Tanstaafl writes:
On 2013-02-15 10:25 AM, Joseph Brennan <brennan@columbia.edu> wrote:
I am uncertain what /.*+/ would do. Remove either * or +.
As Joseph says, change the first part of your regexp from "^From:.*+" to "^from:.*" or "^from:.+" (I would choose the former because it's more inclusive, thus less backscatter to those addresses).
Like I said, I've got no experience with regex at all - guess its time to learn eh? ;)
Yes. I don't know specifically about Perl/Python, but there are definitely tools out there which will help you build regexps from such lists of strings.

--On Saturday, February 16, 2013 8:08 AM -0500 Tanstaafl <tanstaafl@libertytrek.org> wrote:
Not exactly. If you chain them with elsif then the conditions are tested in order until one matches, and any after that are not tested. If one of the earlier conditions matched then your rule would never match.
Remove the + mark (and learn what .* means) and you're probably done.
In the debug statement, $1 will be the string in ( ) that matched, but $2 is not defined since there is no other ( ) string.
Joe Brennan

On 2013-02-16 9:54 AM, Joseph Brennan <brennan@columbia.edu> wrote:
Correct... what I meant was, if one of the prior tests match, then the vacation message will NOT be sent, so my test is irrelevant, since it only has the potential to do the same thing (prevent the message from being generated).
None of these tests are used to send the message, only prevent it from being sent...
Remove the + mark (and learn what .* means) and you're probably done.
Done... hopefully this will fix things up... thanks again!
In the debug statement, $1 will be the string in ( ) that matched, but $2 is not defined since there is no other ( ) string.
Ok, fixed that too...
Thanks again! If this works as expected I should be able to get the postfixadmin guys to add this to the default vacation.pl, with a description of how to use it...

On 2013-02-15 9:41 AM, Tanstaafl <tanstaafl@libertytrek.org> wrote:
We get a lot of list related stuff that the vacation.pl responds to that I don't want it to respond to,
To clarify - by 'list-related', I mean announce/newsletter type junk that our users subscribe to, not necessarily mailman list posts...
Also, I want not respond to *any* social networking messages at all, I just want a single custom line that I can add any string that I want to test for.
I would never use anything like this to reject or otherwise interfere with *receiving* mail, but I have a much lower bar when it comes to stuff I don't want my vacation.pl to reply to, so false positives are not a real concern for me here.

elsif (/^from:.*+(bounce|do-not-reply|facebook|linkedin|list-|myspace|twitter)/i) { $logger->debug("Multi-string From header matching $1: $2 found; exiting"); exit (0); }
Examine the logic of the 'if' and any 'elsif' above this line.
I am uncertain what /.*+/ would do. Remove either * or +.
Otherwise this looks reasonable to me.
Joseph Brennan Columbia University Information Technology

On 2013-02-15 10:25 AM, Joseph Brennan <brennan@columbia.edu> wrote:
Thanks for the help Joseph (and Stephen)...
This 'if' block is just a bunch of separate one line tests that, if any of them match, result in the vacation response not being sent, so it doesn't really matter what is above them (they are all the defaults, this is the only line I am modifying)...
This line should simply examine any from header, and if any of the included strings are found *anywhere* in the from address, local or domain part, so, either side of the '@' sign, and regardless of any dots anywhere in the string.
I imagine that is why the guys from postfixadmin used the * and maybe the +? Like I said, I've got no experience with regex at all - guess its time to learn eh? ;)
Anyway, I want the regex such that any/all of the following from addresses would match (along with all of the other strings):
bounce-anything@example.com anything@bounce.example.com anything@bounce-reply.example.com facebook@example.com anything.facebook@example.com anything-facebook@example.com anything@something.facebook.com
Hopefully that is enough examples...
Basically, if *any* of the strings I might specify inside the parenthesis match individually anywhere in the from address, then don't send the response (ie, positive match).
Thanks again, it is really appreciated...

Tanstaafl writes:
On 2013-02-15 10:25 AM, Joseph Brennan <brennan@columbia.edu> wrote:
I am uncertain what /.*+/ would do. Remove either * or +.
As Joseph says, change the first part of your regexp from "^From:.*+" to "^from:.*" or "^from:.+" (I would choose the former because it's more inclusive, thus less backscatter to those addresses).
Like I said, I've got no experience with regex at all - guess its time to learn eh? ;)
Yes. I don't know specifically about Perl/Python, but there are definitely tools out there which will help you build regexps from such lists of strings.

--On Saturday, February 16, 2013 8:08 AM -0500 Tanstaafl <tanstaafl@libertytrek.org> wrote:
Not exactly. If you chain them with elsif then the conditions are tested in order until one matches, and any after that are not tested. If one of the earlier conditions matched then your rule would never match.
Remove the + mark (and learn what .* means) and you're probably done.
In the debug statement, $1 will be the string in ( ) that matched, but $2 is not defined since there is no other ( ) string.
Joe Brennan

On 2013-02-16 9:54 AM, Joseph Brennan <brennan@columbia.edu> wrote:
Correct... what I meant was, if one of the prior tests match, then the vacation message will NOT be sent, so my test is irrelevant, since it only has the potential to do the same thing (prevent the message from being generated).
None of these tests are used to send the message, only prevent it from being sent...
Remove the + mark (and learn what .* means) and you're probably done.
Done... hopefully this will fix things up... thanks again!
In the debug statement, $1 will be the string in ( ) that matched, but $2 is not defined since there is no other ( ) string.
Ok, fixed that too...
Thanks again! If this works as expected I should be able to get the postfixadmin guys to add this to the default vacation.pl, with a description of how to use it...
participants (3)
-
Joseph Brennan
-
Stephen J. Turnbull
-
Tanstaafl