HighDots Forums  

regexp help

Python Python programming language mailing list


Discuss regexp help in the Python forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Savoy, Jim
 
Posts: n/a

Default regexp help - 10-21-2009 , 12:24 PM






Hi all - I am trying to have all of the mail sent to a certain email
account automatically forwarded

to a moderated mailing list (moderated to everyone accept the mail from
this particular email

account). So I created the account (we'll call it
unique.name (AT) some (DOT) domain) and set up the mailing

list (we'll call it abc-l (AT) some (DOT) domain).



The only way I can think of getting the mailing list to accept the
forwarded mail is to use the spam

filters under [Privacy Options]. I create a new Spam Filter Rule like
so:



/^.*unique.name.*$/



(I will make this more specific later)



But that doesn't seem to work. Mail sent to unique.name (AT) some (DOT) domain
returns the error message

"you are not allowed to post to this mailing list" to the original
sender. I assumed that unique.name

would be somewhere in the email headers, which is what the Spam rules
are filtering on, right?



Any ideas what I am doing wrong?



Thanks.



- jim -

-



------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #2  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 10-21-2009 , 05:22 PM






George Booth wrote:

Quote:
Why don't you just add the email account to the list, set it for no
mail,
and set it so it's unmoderated?

Well that was the first thing I did, but that didn't work because the
mail
is not technically coming from that account. It's coming from whoever
originally
sent it (the unique.name account just forwards). That is why I thought I
could
try to circumvent it by using the spam filter to just search all of the
headers for an occurance of "unique.name".

- jim -

------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #3  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 10-21-2009 , 05:36 PM



I looked at one of the actual headers (I am not posting the actual name
I am using as we don't want anyone to mail to it just yet!) but it
looked
like this:

To: "Name, Unique" <unique.name (AT) uleth (DOT) ca>

Since there is a dot in the username, I thought maybe that was fouling
up
the regular expression, so I tried all of these:

\nto: .*unique\.name
to: .*unique\.name
to: .*unique


to no avail...

- jim -

------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #4  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 10-21-2009 , 06:24 PM



Quote:
To: "Name, Unique" <unique.name (AT) uleth (DOT) ca

George Booth wrote:

Jim, I don't know if this will help, but this is what I use for our
lists'
spam filters to accept from our domain:

^[^@]+@(.+\.|)unique\.name$

Worth a shot?

OK, but the domain isn't "unique.name" - that is the username. The
domain is uleth.ca.
And when I think about it, the dot couldn't be messing up my regexp
because it
just means "a single character" so unique.name and unique\.name would
each
accept unique.name.

But I did find something in google (no date on it) from Mark Sapiro that
could
be at the root of my problem.

----------------
Mark wrote:

You can't bypass holds for bounce_matching_headers.
You can't bypass membership and moderation checks.
You can't bypass other holds such as message too big, etc.

This is because the Accept action on a header_filter_rules rule only
means pass the header_filter_rules tests. It doesn't mean
unconditionally accept the message.

So assuming that what you want is to bypass the other
header_filter_rules, you need to "add new item" before the current
rule 1 so the new rule becomes #1. Then the new rule 1 regexp should be

^from:.*(\s|<)some\.person\.name@gmail\.com(\s|>|$ )

and the action Accept.
-------------

So perhaps the problem is that I cannot over-ride the membership and
moderation checks, which state that only list members may post to this
particular list. That is my problem. I need to over-ride them.

- jim -


------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #5  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 10-21-2009 , 06:54 PM



Quote:
CNulk writes:

Hi Jim,

I may be completely wrong (heck, wouldn't be the first time), but why
not have your "unique.name" address be an alias to a simple
bash/perl/etc. script which simply accepts the email message, rewrites
the message to be from the unique.name address, and sends it on to the
list. When the list sees the message, it will appear to be "from"
unique.name and the standard mailman moderation and message acceptance
rules would apply. I had to do something similar for a different email
distribution package to get around a software limitation. It should
work unless you really need the from address to be from the actual
sender.

Yep - I could do that. Have exim rewrite the headers before it sends out
the message, but the people on the mailing list do want to know who the
email originally came from. They just don't want everyone to have access
to their mailing list, just this one account (an inquiries-type of
account).

I just re-read Mark's comments, and he says:

-------
So assuming that what you want is to bypass the other
header_filter_rules, you need to "add new item" before the current rule
1 so the new rule becomes #1. Then the new rule 1 regexp should be

^from:.*(\s|<)some\.person\.name@gmail\.com(\s|>|$ )

and the action Accept.
-------

and that is exactly what I want to do - bypass the header_filter_rules.
But I am
afraid I don't quite understand this advice, Mark. How can I make this
spam rule
supercede other rules (like the one that says the list is moderated).
There
is no "add new item" button when you haven't got any spam rules. That
only
comes up when after I create me first rule, which is not superceding the
moderation
rule.

I should probably not say anything else until Mark logs in. He's
probably looking at
this huge chain and wanting to crack our skulls together like Moe.

- jim -

------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #6  
Old   
Geoff Shang
 
Posts: n/a

Default Re: regexp help - 10-21-2009 , 07:05 PM



On Wed, 21 Oct 2009, Savoy, Jim wrote:

Quote:
Yep - I could do that. Have exim rewrite the headers before it sends out
the message, but the people on the mailing list do want to know who the
email originally came from. They just don't want everyone to have access
to their mailing list, just this one account (an inquiries-type of
account).
Ok, maybe I'm missing the point here. couldn't you just allow all
non-member postings and manually approve subscriptions? Define the
address as an alternate name for the list if you really don't want to give
out the list address.

On one site I administer, we've converted our simple Email forwarder
public Email address to a mailing list, with the project managers as the
ownly subscribers. Apart from the odd bit of fun we have with Reply-to,
it works pretty well. It helps to fascilitate discussion between the
managers and encourages managers to copy everyone else on messages sent
back to people outside the project.

Geoff.

------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #7  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 11-02-2009 , 05:17 PM



Quote:
Mark Sapiro wrote:

What you need is a custom handler. See the FAQ at
http://wiki.list.org/x/l4A9> for how to install one.

Thank you. Done.

Quote:
In your case, the handler is very simple - just 9 lines.

import re
cre = re.compile('unique\.name', re.IGNORECASE)
def process(mlist, msg, msgdata):
if mlist.internal_name <> 'abc-l':
return
if cre.search(msg.get('to', '')):
msgdata['approved'] = 1
# Used by the Emergency module
msgdata['adminapproved'] = 1

Of course, you adjust the regexp 'unique\.name' and the list name
'abc-l' to suit. The handler needs to be in the pipeline before
Moderate.
OK - I made a file called Foo.py and put it in /Mailman/Handlers.
I then inserted this module right before 'Moderate' in the pipeline (I
editted
Defaults.py for this - just as a temporary measure to see if it would
work).
I will remove this and add a line to mm_cfg.py later.

I then stopped/started the Mailman processes (not sure if that's
necessary, but
I did it anyway). Now the test email I sent is stuck in the shunt queue
and this
is in the errors log:

File "/Mailman/Handlers/Foo.py", line 2
cre = re.compile('unique\.name', re.IGNORECASE) def process(mlist,
msg, msgdata):
^
SyntaxError: invalid syntax


It didn't line up well in this email message, but the carat (^) is
positioned
under the 'f' in the "def".

I know diddly about Python (and not that much more about Mailman,
really) so I'm not
sure how to fix the problem. Any ideas? Thanks!

- jim -

------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #8  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 11-02-2009 , 05:23 PM



I also just noticed that the shunt queue started to fill up with
messages
for other lists as well, so I quickly removed the line I had inserted
into
Defaults.py, stopped/started the Mailman processes, and successfully
unshunted
everything. I was hoping the code would only affect the one list I am
messing
with, but I guess if there is a syntax error in it, it breaks the entire
pipeline (maybe).

------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #9  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 11-02-2009 , 05:35 PM



I also just noticed that all of the other handlers have an accompanying
..pyc file, but my Foo.py does not. Perhaps that 'c' stands for
"compiled"
and I was supposed to compile the code first? (probably seems obvious to
someone familiar with Mailman/Python).
------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #10  
Old   
Geoff Shang
 
Posts: n/a

Default Re: regexp help - 11-02-2009 , 05:44 PM



On Mon, 2 Nov 2009, Savoy, Jim wrote:

Quote:
I also just noticed that all of the other handlers have an accompanying
.pyc file, but my Foo.py does not. Perhaps that 'c' stands for
"compiled"
It does.

Quote:
and I was supposed to compile the code first? (probably seems obvious to
someone familiar with Mailman/Python).
No. The code is automatically compiled if there is no pyc file or the py
file is different.

Presumably there's no pyc file because of your syntax error. At a guess,
I'd say that the def statement should be on a new line, but I'm not a
Python expert.

Geoff.

------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.