Custom footer based on sender's email
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
I need to figure out how to add a footer to an e-mail coming from a specific user. I just can't seem to figure this out. I have created a module to weed out the address, but now I need to munge the body of the message.
-Rob
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
You will need to do several things.
set OWNERS_CAN_ENABLE_PERSONALIZATION = Yes in mm_cfg.py so you can do
set the list's personalize option (in Non-digest options) to Yes so you will be sending separately to each recipient, then
see Mailman/Handlers/Decorate.py for the current code that adds personalized headers and footers. You either have to make your changes here or in Mailman/Handlers/SMTPDirect.py in the verpdeliver() function.
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Actually I just learned that not only do I need to add a footer, I have to remove the current footer of the incoming message. I got custom footer piece to work now, but now I actually need to edit the body of the message. What might be the best way of doing this?
-Rob
-----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Wednesday, May 03, 2006 6:18 PM To: Rob Jackson; mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Rob Jackson wrote:
You will need to do several things.
set OWNERS_CAN_ENABLE_PERSONALIZATION = Yes in mm_cfg.py so you can do
set the list's personalize option (in Non-digest options) to Yes so you will be sending separately to each recipient, then
see Mailman/Handlers/Decorate.py for the current code that adds personalized headers and footers. You either have to make your changes here or in Mailman/Handlers/SMTPDirect.py in the verpdeliver() function.
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/85e516d12e7b6c3f7b0dba64b53b17ba.jpg?s=120&d=mm&r=g)
On 5/4/06, Rob Jackson <robertj@linux4free.com> wrote:
Actually I just learned that not only do I need to add a footer, I have to remove the current footer of the incoming message.
The logic behind this might be difficult. How to know where the user's message starts and their footer begins?
--
- Patrick Bogen
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Was hoping to use some regular expression and just remove some lines. The lines I need to remove will always be the same.
-Rob
-----Original Message----- From: Patrick Bogen [mailto:pdbogen@gmail.com] Sent: Thursday, May 04, 2006 1:12 PM To: Rob Jackson Cc: mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
On 5/4/06, Rob Jackson <robertj@linux4free.com> wrote:
Actually I just learned that not only do I need to add a footer, I have to remove the current footer of the incoming message.
The logic behind this might be difficult. How to know where the user's message starts and their footer begins?
--
- Patrick Bogen
![](https://secure.gravatar.com/avatar/b273ab068bc220d17a3e4c710c401c4b.jpg?s=120&d=mm&r=g)
In a flurry of recycled electrons, Rob Jackson wrote:
Was hoping to use some regular expression and just remove some lines. The lines I need to remove will always be the same.
The problem is that it won't always the the same. As you see below, now the footer has "> " in front of each line. Another reply from a different MUA might add a different prefix and wrap a line or two. There isn't much you can count on here.
FWIW, my initial thought to the question was "user training".
z!
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
That is the thing, it will be the same everytime. It is a message automatically generated from a message board, unfortunatly, we are out-sourcing the message board and they are not capable to change the footer on a user level.
-----Original Message----- From: Carl Zwanzig [mailto:cpz@tuunq.com] Sent: Thursday, May 04, 2006 2:08 PM To: Rob Jackson Cc: mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
In a flurry of recycled electrons, Rob Jackson wrote:
Was hoping to use some regular expression and just remove some lines.
The lines I need to remove will always be the same.
The problem is that it won't always the the same. As you see below, now the footer has "> " in front of each line. Another reply from a different MUA might add a different prefix and wrap a line or two. There isn't much you can count on here.
FWIW, my initial thought to the question was "user training".
z!
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
You can delete the incoming footer in the same place you add the new one. You can do something like
pl = msg.get_payload(decode=True)
re.sub(pattern_matching_old_footer, replacement_footer, pl)
msg.set_payload(pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Ok, I have been trying to use this in several places without success. I have added to the Decorate.py and even tried to add it to my custom module used for a global incoming gateway. I replaced the re.sub line with:
re.sub('AZ', 'new text', pl)
In the message that I send, I only put AZ in the body of the message. I do not get any errors, but nothing happens to the message. The AZ does not get replaced.
Is there something else I need to do to get this working. I am about to use procmail to do this, which I really wanted to avoid, as it will add another step to the process.
-Rob
-----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Friday, May 05, 2006 10:20 AM To: Rob Jackson; mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
You can delete the incoming footer in the same place you add the new one. You can do something like
pl = msg.get_payload(decode=True)
re.sub(pattern_matching_old_footer, replacement_footer, pl)
msg.set_payload(pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
I need to see more context around what you are doing to understand what's failing. Something like a 'diff -u' between your modified Decorate.py and the base.
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
This is the diff on the Decorate.py I have also tried putting it other placed throught the script without success. There will be an if statement that will grap the senders e-mail address so this only happens to mail coming from my global gateway.
191,196d190 < #Testing to replace footer < pl = msg.get_payload(decode=True) < re.sub('AZ', 'new text', pl) < msg.set_payload(pl) < <
-----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Wednesday, May 10, 2006 11:27 AM To: Rob Jackson; mailman-users@python.org Subject: RE: [Mailman-Users] Custom footer based on sender's email
Rob Jackson wrote:
I need to see more context around what you are doing to understand what's failing. Something like a 'diff -u' between your modified Decorate.py and the base.
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Sorry about that. I could be going about this all wrong. Also, I am fairly new to python, I normally do perl, so learning how this softwar works has been just a little difficult. Here it is. +++ /u1/mailman/Mailman/Handlers/Decorate.py 2006-05-10 11:36:43.000000000 -0600 @@ -188,6 +188,12 @@ del msg['content-disposition'] msg['Content-Type'] = 'multipart/mixed' + #Testing to replace footer + pl = msg.get_payload(decode=True) + re.sub('AZ', 'new text', pl) + msg.set_payload(pl) + + def decorate(mlist, template, what, extradict={}): -----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Wednesday, May 10, 2006 12:42 PM To: Rob Jackson; mailman-users@python.org Subject: RE: [Mailman-Users] Custom footer based on sender's email Rob Jackson wrote:
Please either give me a unified context diff (diff -u) or at least tell me what Mailman version this is. -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
Elvis has left the building... I.e. putting the code there will only get those messages in which the mailman header/footer has been added as a separate mime part to a message not already multipart/mixed. Starting from the top of Decorate.process() we have several exits: # Escape hatch if both the footer and header are empty if not header and not footer: return If there is no defined msg_header or msg_footer, we leave. # If we couldn't add the header or footer in a less intrusive way, we can # at least do it by MIME encapsulation. We want to keep as much of the # outer chrome as possible. if not wrap: return If we have managed to add the header and/or footer to a text/plain message, or if the message was already multipart/mixed and we added the header and/or footer as separate mime parts, we are done and leave here. The only thing that gets beyond here is the case where we create a new multipart/mixed 'wrapper' with header and/or footer parts and the original message as a message/rfc822 part. You first have to see whether or not you have msg_header and or msg_footer for the list, and also what the structure of the incoming message is. In the simplest case of a single part text/plain message, you could add the three lines just prior to # Escape hatch if both the footer and header are empty if not header and not footer: return -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
I was aware of the if not header and not footer: return And made sure that wasn't a problem. But it seems I was probably exiting out someplace else. I used to be getting an error when I had it other places, and then when I moved it to the end, the error went away, well it is back now that I am actualy hitting the code before it exits. Here is my error. Thanks for helping out with my ignorance. "May 11 11:54:49 2006 (11951) Uncaught runner exception: global name 're' is not defined" What is the best way to define 're' I have tried looking at other examples throught the program and have been unable to determine how I need to do this. Thanks -Rob -----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Thursday, May 11, 2006 11:46 AM To: Rob Jackson; mailman-users@python.org Subject: RE: [Mailman-Users] Custom footer based on sender's email Rob Jackson wrote:
Elvis has left the building... I.e. putting the code there will only get those messages in which the mailman header/footer has been added as a separate mime part to a message not already multipart/mixed. Starting from the top of Decorate.process() we have several exits: # Escape hatch if both the footer and header are empty if not header and not footer: return If there is no defined msg_header or msg_footer, we leave. # If we couldn't add the header or footer in a less intrusive way, we can # at least do it by MIME encapsulation. We want to keep as much of the # outer chrome as possible. if not wrap: return If we have managed to add the header and/or footer to a text/plain message, or if the message was already multipart/mixed and we added the header and/or footer as separate mime parts, we are done and leave here. The only thing that gets beyond here is the case where we create a new multipart/mixed 'wrapper' with header and/or footer parts and the original message as a message/rfc822 part. You first have to see whether or not you have msg_header and or msg_footer for the list, and also what the structure of the incoming message is. In the simplest case of a single part text/plain message, you could add the three lines just prior to # Escape hatch if both the footer and header are empty if not header and not footer: return -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Ok, never mind on the problem with re, I don't know why I couldln't figure that out before, I just didn't look hard enough. Although it still doesn't work. Here is what I have now. --- /u1/mailman1/Mailman/Handlers/Decorate.py 2006-02-24 17:31:06.000000000 -0700 +++ Decorate.py 2006-05-11 12:14:22.000000000 -0600 @@ -20,6 +20,7 @@ from types import ListType from email.MIMEText import MIMEText +import re from Mailman import mm_cfg from Mailman import Utils from Mailman import Errors @@ -66,6 +67,15 @@ header = decorate(mlist, mlist.msg_header, 'non-digest header', d) footer = decorate(mlist, mlist.msg_footer, 'non-digest footer', d) # Escape hatch if both the footer and header are empty + + sender = msgdata.get('original_sender', msg.get_sender()) + if sender == '<email-address>': + footer = "THIS IS A GATEWAY MESSAGE" + + pl = msg.get_payload(decode=True) + re.sub('AZ', 'new text', pl) + msg.set_payload(pl) + if not header and not footer: return # Be MIME smart here. We only attach the header and footer by -----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Rob Jackson Sent: Thursday, May 11, 2006 12:07 PM To: 'Mark Sapiro'; mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email I was aware of the if not header and not footer: return And made sure that wasn't a problem. But it seems I was probably exiting out someplace else. I used to be getting an error when I had it other places, and then when I moved it to the end, the error went away, well it is back now that I am actualy hitting the code before it exits. Here is my error. Thanks for helping out with my ignorance. "May 11 11:54:49 2006 (11951) Uncaught runner exception: global name 're' is not defined" What is the best way to define 're' I have tried looking at other examples throught the program and have been unable to determine how I need to do this. Thanks -Rob -----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Thursday, May 11, 2006 11:46 AM To: Rob Jackson; mailman-users@python.org Subject: RE: [Mailman-Users] Custom footer based on sender's email Rob Jackson wrote:
Elvis has left the building... I.e. putting the code there will only get those messages in which the mailman header/footer has been added as a separate mime part to a message not already multipart/mixed. Starting from the top of Decorate.process() we have several exits: # Escape hatch if both the footer and header are empty if not header and not footer: return If there is no defined msg_header or msg_footer, we leave. # If we couldn't add the header or footer in a less intrusive way, we can # at least do it by MIME encapsulation. We want to keep as much of the # outer chrome as possible. if not wrap: return If we have managed to add the header and/or footer to a text/plain message, or if the message was already multipart/mixed and we added the header and/or footer as separate mime parts, we are done and leave here. The only thing that gets beyond here is the case where we create a new multipart/mixed 'wrapper' with header and/or footer parts and the original message as a message/rfc822 part. You first have to see whether or not you have msg_header and or msg_footer for the list, and also what the structure of the incoming message is. In the simplest case of a single part text/plain message, you could add the three lines just prior to # Escape hatch if both the footer and header are empty if not header and not footer: return -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan ------------------------------------------------------ Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
It looks OK to me. I assume by 'doesn't work' you mean there is no error in the log, but you don't get the desired result. What do the messages look like, both to and from the list? -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Mark Sapiro wrote:
Rob Jackson wrote:
<snip>
Actually, it's not OK. I overlooked the fact that Python strings are immutable and re.sub doesn't (can't) change them in place. Thus,
re.sub('AZ', 'new text', pl)
needs to be
pl = re.sub('AZ', 'new text', pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Ok, I got this piece kind of working, but there is a problem with this.
This is my search and replace string, and the search at this point doesn't matter.
pl = re.sub('lksjdfsdf', 'new text', pl)
Here is the last part of the body, it is all contained in one line:
"You received this e-mail because you are currently subscribed to this message board alert. To unsubscribe from this alert, or to change your settings to receive a digest version instead, please visit My Alerts."
After this message goes through mailman, this is how it comes out on the other side:
jZ;]yay%"hh?hjfzjCj?k-yM:4r^=JjgV'qbsOyDKijljw,&gZ,j }z?Ox^=by?m+m?y?+.n+a?Oy?zS?&~&jWZ zb -z+i?zoz"x?v^j??3 %zl
If I add, or remove a letter to the orginal footer, anywhere, or change any one of the punctuation marks to a letter, it will come through clean, and not garbled.
I am stumped!
-----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Mark Sapiro Sent: Thursday, May 11, 2006 3:53 PM To: mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Mark Sapiro wrote:
Rob Jackson wrote:
<snip>
Actually, it's not OK. I overlooked the fact that Python strings are immutable and re.sub doesn't (can't) change them in place. Thus,
re.sub('AZ', 'new text', pl)
needs to be
pl = re.sub('AZ', 'new text', pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m
Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
I found a fix the the problem. Charset is set to UTF-8, and I changed it to us-ascii, and it works great now.
-Rob
-----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Rob Jackson Sent: Monday, May 15, 2006 12:26 PM To: 'Mark Sapiro'; mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Ok, I got this piece kind of working, but there is a problem with this.
This is my search and replace string, and the search at this point doesn't matter.
pl = re.sub('lksjdfsdf', 'new text', pl)
Here is the last part of the body, it is all contained in one line:
"You received this e-mail because you are currently subscribed to this message board alert. To unsubscribe from this alert, or to change your settings to receive a digest version instead, please visit My Alerts."
After this message goes through mailman, this is how it comes out on the other side:
jZ;]yay%"hh?hjfzjCj?k-yM:4r^=JjgV'qbsOyDKijljw,&gZ,j }z?Ox^=by?m+m?y?+.n+a?Oy?zS?&~&jWZ zb -z+i?zoz"x?v^j??3 %zl
If I add, or remove a letter to the orginal footer, anywhere, or change any one of the punctuation marks to a letter, it will come through clean, and not garbled.
I am stumped!
-----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Mark Sapiro Sent: Thursday, May 11, 2006 3:53 PM To: mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Mark Sapiro wrote:
Rob Jackson wrote:
<snip>
Actually, it's not OK. I overlooked the fact that Python strings are immutable and re.sub doesn't (can't) change them in place. Thus,
re.sub('AZ', 'new text', pl)
needs to be
pl = re.sub('AZ', 'new text', pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m
Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m
Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Due to a change in the Message board, the messages come through as multipart/mixed.
If I try to run this in the multipart/mixed section of Decorate.py, I get:
TypeError: expected string or buffer.
What needs to be done to make this work properly?
Thanks -Rob
-----Original Message----- From: Rob Jackson [mailto:robertj@linux4free.com] Sent: Monday, May 15, 2006 2:49 PM To: 'Rob Jackson'; 'Mark Sapiro'; mailman-users@python.org Subject: RE: [Mailman-Users] Custom footer based on sender's email
I found a fix the the problem. Charset is set to UTF-8, and I changed it to us-ascii, and it works great now.
-Rob
-----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Rob Jackson Sent: Monday, May 15, 2006 12:26 PM To: 'Mark Sapiro'; mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Ok, I got this piece kind of working, but there is a problem with this.
This is my search and replace string, and the search at this point doesn't matter.
pl = re.sub('lksjdfsdf', 'new text', pl)
Here is the last part of the body, it is all contained in one line:
"You received this e-mail because you are currently subscribed to this message board alert. To unsubscribe from this alert, or to change your settings to receive a digest version instead, please visit My Alerts."
After this message goes through mailman, this is how it comes out on the other side:
jZ;]yay%"hh?hjfzjCj?k-yM:4r^=JjgV'qbsOyDKijljw,&gZ,j }z?Ox^=by?m+m?y?+.n+a?Oy?zS?&~&jWZ zb -z+i?zoz"x?v^j??3 %zl
If I add, or remove a letter to the orginal footer, anywhere, or change any one of the punctuation marks to a letter, it will come through clean, and not garbled.
I am stumped!
-----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Mark Sapiro Sent: Thursday, May 11, 2006 3:53 PM To: mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Mark Sapiro wrote:
Rob Jackson wrote:
<snip>
Actually, it's not OK. I overlooked the fact that Python strings are immutable and re.sub doesn't (can't) change them in place. Thus,
re.sub('AZ', 'new text', pl)
needs to be
pl = re.sub('AZ', 'new text', pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m
Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m
Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
Not surprising, since the payload of a multipart message is not the textual contents of the message; it is a list of message objects each of which is one of the sub-parts of the message.
What needs to be done to make this work properly?
It depends on what the incoming message looks like and what you want the result to be. Perhaps the description of the walk() method (and the other message methods) at <http://docs.python.org/lib/module-email.Message.html> will help.
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
I used to be getting an error when I had it other places, and then when I moved it to the end, the error went away,
Because you were no longer executing the code.
@@ -17,6 +17,7 @@ """Decorate a message by sticking the header and footer around it.""" +import re import logging from email.MIMEText import MIMEText -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
You will need to do several things.
set OWNERS_CAN_ENABLE_PERSONALIZATION = Yes in mm_cfg.py so you can do
set the list's personalize option (in Non-digest options) to Yes so you will be sending separately to each recipient, then
see Mailman/Handlers/Decorate.py for the current code that adds personalized headers and footers. You either have to make your changes here or in Mailman/Handlers/SMTPDirect.py in the verpdeliver() function.
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Actually I just learned that not only do I need to add a footer, I have to remove the current footer of the incoming message. I got custom footer piece to work now, but now I actually need to edit the body of the message. What might be the best way of doing this?
-Rob
-----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Wednesday, May 03, 2006 6:18 PM To: Rob Jackson; mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Rob Jackson wrote:
You will need to do several things.
set OWNERS_CAN_ENABLE_PERSONALIZATION = Yes in mm_cfg.py so you can do
set the list's personalize option (in Non-digest options) to Yes so you will be sending separately to each recipient, then
see Mailman/Handlers/Decorate.py for the current code that adds personalized headers and footers. You either have to make your changes here or in Mailman/Handlers/SMTPDirect.py in the verpdeliver() function.
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/85e516d12e7b6c3f7b0dba64b53b17ba.jpg?s=120&d=mm&r=g)
On 5/4/06, Rob Jackson <robertj@linux4free.com> wrote:
Actually I just learned that not only do I need to add a footer, I have to remove the current footer of the incoming message.
The logic behind this might be difficult. How to know where the user's message starts and their footer begins?
--
- Patrick Bogen
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Was hoping to use some regular expression and just remove some lines. The lines I need to remove will always be the same.
-Rob
-----Original Message----- From: Patrick Bogen [mailto:pdbogen@gmail.com] Sent: Thursday, May 04, 2006 1:12 PM To: Rob Jackson Cc: mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
On 5/4/06, Rob Jackson <robertj@linux4free.com> wrote:
Actually I just learned that not only do I need to add a footer, I have to remove the current footer of the incoming message.
The logic behind this might be difficult. How to know where the user's message starts and their footer begins?
--
- Patrick Bogen
![](https://secure.gravatar.com/avatar/b273ab068bc220d17a3e4c710c401c4b.jpg?s=120&d=mm&r=g)
In a flurry of recycled electrons, Rob Jackson wrote:
Was hoping to use some regular expression and just remove some lines. The lines I need to remove will always be the same.
The problem is that it won't always the the same. As you see below, now the footer has "> " in front of each line. Another reply from a different MUA might add a different prefix and wrap a line or two. There isn't much you can count on here.
FWIW, my initial thought to the question was "user training".
z!
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
That is the thing, it will be the same everytime. It is a message automatically generated from a message board, unfortunatly, we are out-sourcing the message board and they are not capable to change the footer on a user level.
-----Original Message----- From: Carl Zwanzig [mailto:cpz@tuunq.com] Sent: Thursday, May 04, 2006 2:08 PM To: Rob Jackson Cc: mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
In a flurry of recycled electrons, Rob Jackson wrote:
Was hoping to use some regular expression and just remove some lines.
The lines I need to remove will always be the same.
The problem is that it won't always the the same. As you see below, now the footer has "> " in front of each line. Another reply from a different MUA might add a different prefix and wrap a line or two. There isn't much you can count on here.
FWIW, my initial thought to the question was "user training".
z!
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
You can delete the incoming footer in the same place you add the new one. You can do something like
pl = msg.get_payload(decode=True)
re.sub(pattern_matching_old_footer, replacement_footer, pl)
msg.set_payload(pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Ok, I have been trying to use this in several places without success. I have added to the Decorate.py and even tried to add it to my custom module used for a global incoming gateway. I replaced the re.sub line with:
re.sub('AZ', 'new text', pl)
In the message that I send, I only put AZ in the body of the message. I do not get any errors, but nothing happens to the message. The AZ does not get replaced.
Is there something else I need to do to get this working. I am about to use procmail to do this, which I really wanted to avoid, as it will add another step to the process.
-Rob
-----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Friday, May 05, 2006 10:20 AM To: Rob Jackson; mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
You can delete the incoming footer in the same place you add the new one. You can do something like
pl = msg.get_payload(decode=True)
re.sub(pattern_matching_old_footer, replacement_footer, pl)
msg.set_payload(pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
I need to see more context around what you are doing to understand what's failing. Something like a 'diff -u' between your modified Decorate.py and the base.
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
This is the diff on the Decorate.py I have also tried putting it other placed throught the script without success. There will be an if statement that will grap the senders e-mail address so this only happens to mail coming from my global gateway.
191,196d190 < #Testing to replace footer < pl = msg.get_payload(decode=True) < re.sub('AZ', 'new text', pl) < msg.set_payload(pl) < <
-----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Wednesday, May 10, 2006 11:27 AM To: Rob Jackson; mailman-users@python.org Subject: RE: [Mailman-Users] Custom footer based on sender's email
Rob Jackson wrote:
I need to see more context around what you are doing to understand what's failing. Something like a 'diff -u' between your modified Decorate.py and the base.
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Sorry about that. I could be going about this all wrong. Also, I am fairly new to python, I normally do perl, so learning how this softwar works has been just a little difficult. Here it is. +++ /u1/mailman/Mailman/Handlers/Decorate.py 2006-05-10 11:36:43.000000000 -0600 @@ -188,6 +188,12 @@ del msg['content-disposition'] msg['Content-Type'] = 'multipart/mixed' + #Testing to replace footer + pl = msg.get_payload(decode=True) + re.sub('AZ', 'new text', pl) + msg.set_payload(pl) + + def decorate(mlist, template, what, extradict={}): -----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Wednesday, May 10, 2006 12:42 PM To: Rob Jackson; mailman-users@python.org Subject: RE: [Mailman-Users] Custom footer based on sender's email Rob Jackson wrote:
Please either give me a unified context diff (diff -u) or at least tell me what Mailman version this is. -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
Elvis has left the building... I.e. putting the code there will only get those messages in which the mailman header/footer has been added as a separate mime part to a message not already multipart/mixed. Starting from the top of Decorate.process() we have several exits: # Escape hatch if both the footer and header are empty if not header and not footer: return If there is no defined msg_header or msg_footer, we leave. # If we couldn't add the header or footer in a less intrusive way, we can # at least do it by MIME encapsulation. We want to keep as much of the # outer chrome as possible. if not wrap: return If we have managed to add the header and/or footer to a text/plain message, or if the message was already multipart/mixed and we added the header and/or footer as separate mime parts, we are done and leave here. The only thing that gets beyond here is the case where we create a new multipart/mixed 'wrapper' with header and/or footer parts and the original message as a message/rfc822 part. You first have to see whether or not you have msg_header and or msg_footer for the list, and also what the structure of the incoming message is. In the simplest case of a single part text/plain message, you could add the three lines just prior to # Escape hatch if both the footer and header are empty if not header and not footer: return -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
I was aware of the if not header and not footer: return And made sure that wasn't a problem. But it seems I was probably exiting out someplace else. I used to be getting an error when I had it other places, and then when I moved it to the end, the error went away, well it is back now that I am actualy hitting the code before it exits. Here is my error. Thanks for helping out with my ignorance. "May 11 11:54:49 2006 (11951) Uncaught runner exception: global name 're' is not defined" What is the best way to define 're' I have tried looking at other examples throught the program and have been unable to determine how I need to do this. Thanks -Rob -----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Thursday, May 11, 2006 11:46 AM To: Rob Jackson; mailman-users@python.org Subject: RE: [Mailman-Users] Custom footer based on sender's email Rob Jackson wrote:
Elvis has left the building... I.e. putting the code there will only get those messages in which the mailman header/footer has been added as a separate mime part to a message not already multipart/mixed. Starting from the top of Decorate.process() we have several exits: # Escape hatch if both the footer and header are empty if not header and not footer: return If there is no defined msg_header or msg_footer, we leave. # If we couldn't add the header or footer in a less intrusive way, we can # at least do it by MIME encapsulation. We want to keep as much of the # outer chrome as possible. if not wrap: return If we have managed to add the header and/or footer to a text/plain message, or if the message was already multipart/mixed and we added the header and/or footer as separate mime parts, we are done and leave here. The only thing that gets beyond here is the case where we create a new multipart/mixed 'wrapper' with header and/or footer parts and the original message as a message/rfc822 part. You first have to see whether or not you have msg_header and or msg_footer for the list, and also what the structure of the incoming message is. In the simplest case of a single part text/plain message, you could add the three lines just prior to # Escape hatch if both the footer and header are empty if not header and not footer: return -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Ok, never mind on the problem with re, I don't know why I couldln't figure that out before, I just didn't look hard enough. Although it still doesn't work. Here is what I have now. --- /u1/mailman1/Mailman/Handlers/Decorate.py 2006-02-24 17:31:06.000000000 -0700 +++ Decorate.py 2006-05-11 12:14:22.000000000 -0600 @@ -20,6 +20,7 @@ from types import ListType from email.MIMEText import MIMEText +import re from Mailman import mm_cfg from Mailman import Utils from Mailman import Errors @@ -66,6 +67,15 @@ header = decorate(mlist, mlist.msg_header, 'non-digest header', d) footer = decorate(mlist, mlist.msg_footer, 'non-digest footer', d) # Escape hatch if both the footer and header are empty + + sender = msgdata.get('original_sender', msg.get_sender()) + if sender == '<email-address>': + footer = "THIS IS A GATEWAY MESSAGE" + + pl = msg.get_payload(decode=True) + re.sub('AZ', 'new text', pl) + msg.set_payload(pl) + if not header and not footer: return # Be MIME smart here. We only attach the header and footer by -----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Rob Jackson Sent: Thursday, May 11, 2006 12:07 PM To: 'Mark Sapiro'; mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email I was aware of the if not header and not footer: return And made sure that wasn't a problem. But it seems I was probably exiting out someplace else. I used to be getting an error when I had it other places, and then when I moved it to the end, the error went away, well it is back now that I am actualy hitting the code before it exits. Here is my error. Thanks for helping out with my ignorance. "May 11 11:54:49 2006 (11951) Uncaught runner exception: global name 're' is not defined" What is the best way to define 're' I have tried looking at other examples throught the program and have been unable to determine how I need to do this. Thanks -Rob -----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Thursday, May 11, 2006 11:46 AM To: Rob Jackson; mailman-users@python.org Subject: RE: [Mailman-Users] Custom footer based on sender's email Rob Jackson wrote:
Elvis has left the building... I.e. putting the code there will only get those messages in which the mailman header/footer has been added as a separate mime part to a message not already multipart/mixed. Starting from the top of Decorate.process() we have several exits: # Escape hatch if both the footer and header are empty if not header and not footer: return If there is no defined msg_header or msg_footer, we leave. # If we couldn't add the header or footer in a less intrusive way, we can # at least do it by MIME encapsulation. We want to keep as much of the # outer chrome as possible. if not wrap: return If we have managed to add the header and/or footer to a text/plain message, or if the message was already multipart/mixed and we added the header and/or footer as separate mime parts, we are done and leave here. The only thing that gets beyond here is the case where we create a new multipart/mixed 'wrapper' with header and/or footer parts and the original message as a message/rfc822 part. You first have to see whether or not you have msg_header and or msg_footer for the list, and also what the structure of the incoming message is. In the simplest case of a single part text/plain message, you could add the three lines just prior to # Escape hatch if both the footer and header are empty if not header and not footer: return -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan ------------------------------------------------------ Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
It looks OK to me. I assume by 'doesn't work' you mean there is no error in the log, but you don't get the desired result. What do the messages look like, both to and from the list? -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Mark Sapiro wrote:
Rob Jackson wrote:
<snip>
Actually, it's not OK. I overlooked the fact that Python strings are immutable and re.sub doesn't (can't) change them in place. Thus,
re.sub('AZ', 'new text', pl)
needs to be
pl = re.sub('AZ', 'new text', pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Ok, I got this piece kind of working, but there is a problem with this.
This is my search and replace string, and the search at this point doesn't matter.
pl = re.sub('lksjdfsdf', 'new text', pl)
Here is the last part of the body, it is all contained in one line:
"You received this e-mail because you are currently subscribed to this message board alert. To unsubscribe from this alert, or to change your settings to receive a digest version instead, please visit My Alerts."
After this message goes through mailman, this is how it comes out on the other side:
jZ;]yay%"hh?hjfzjCj?k-yM:4r^=JjgV'qbsOyDKijljw,&gZ,j }z?Ox^=by?m+m?y?+.n+a?Oy?zS?&~&jWZ zb -z+i?zoz"x?v^j??3 %zl
If I add, or remove a letter to the orginal footer, anywhere, or change any one of the punctuation marks to a letter, it will come through clean, and not garbled.
I am stumped!
-----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Mark Sapiro Sent: Thursday, May 11, 2006 3:53 PM To: mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Mark Sapiro wrote:
Rob Jackson wrote:
<snip>
Actually, it's not OK. I overlooked the fact that Python strings are immutable and re.sub doesn't (can't) change them in place. Thus,
re.sub('AZ', 'new text', pl)
needs to be
pl = re.sub('AZ', 'new text', pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m
Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
I found a fix the the problem. Charset is set to UTF-8, and I changed it to us-ascii, and it works great now.
-Rob
-----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Rob Jackson Sent: Monday, May 15, 2006 12:26 PM To: 'Mark Sapiro'; mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Ok, I got this piece kind of working, but there is a problem with this.
This is my search and replace string, and the search at this point doesn't matter.
pl = re.sub('lksjdfsdf', 'new text', pl)
Here is the last part of the body, it is all contained in one line:
"You received this e-mail because you are currently subscribed to this message board alert. To unsubscribe from this alert, or to change your settings to receive a digest version instead, please visit My Alerts."
After this message goes through mailman, this is how it comes out on the other side:
jZ;]yay%"hh?hjfzjCj?k-yM:4r^=JjgV'qbsOyDKijljw,&gZ,j }z?Ox^=by?m+m?y?+.n+a?Oy?zS?&~&jWZ zb -z+i?zoz"x?v^j??3 %zl
If I add, or remove a letter to the orginal footer, anywhere, or change any one of the punctuation marks to a letter, it will come through clean, and not garbled.
I am stumped!
-----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Mark Sapiro Sent: Thursday, May 11, 2006 3:53 PM To: mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Mark Sapiro wrote:
Rob Jackson wrote:
<snip>
Actually, it's not OK. I overlooked the fact that Python strings are immutable and re.sub doesn't (can't) change them in place. Thus,
re.sub('AZ', 'new text', pl)
needs to be
pl = re.sub('AZ', 'new text', pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m
Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m
Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
![](https://secure.gravatar.com/avatar/e41a3670517dc8a2e69447fb08560553.jpg?s=120&d=mm&r=g)
Due to a change in the Message board, the messages come through as multipart/mixed.
If I try to run this in the multipart/mixed section of Decorate.py, I get:
TypeError: expected string or buffer.
What needs to be done to make this work properly?
Thanks -Rob
-----Original Message----- From: Rob Jackson [mailto:robertj@linux4free.com] Sent: Monday, May 15, 2006 2:49 PM To: 'Rob Jackson'; 'Mark Sapiro'; mailman-users@python.org Subject: RE: [Mailman-Users] Custom footer based on sender's email
I found a fix the the problem. Charset is set to UTF-8, and I changed it to us-ascii, and it works great now.
-Rob
-----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Rob Jackson Sent: Monday, May 15, 2006 12:26 PM To: 'Mark Sapiro'; mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Ok, I got this piece kind of working, but there is a problem with this.
This is my search and replace string, and the search at this point doesn't matter.
pl = re.sub('lksjdfsdf', 'new text', pl)
Here is the last part of the body, it is all contained in one line:
"You received this e-mail because you are currently subscribed to this message board alert. To unsubscribe from this alert, or to change your settings to receive a digest version instead, please visit My Alerts."
After this message goes through mailman, this is how it comes out on the other side:
jZ;]yay%"hh?hjfzjCj?k-yM:4r^=JjgV'qbsOyDKijljw,&gZ,j }z?Ox^=by?m+m?y?+.n+a?Oy?zS?&~&jWZ zb -z+i?zoz"x?v^j??3 %zl
If I add, or remove a letter to the orginal footer, anywhere, or change any one of the punctuation marks to a letter, it will come through clean, and not garbled.
I am stumped!
-----Original Message----- From: mailman-users-bounces+robertj=linux4free.com@python.org [mailto:mailman-users-bounces+robertj=linux4free.com@python.org] On Behalf Of Mark Sapiro Sent: Thursday, May 11, 2006 3:53 PM To: mailman-users@python.org Subject: Re: [Mailman-Users] Custom footer based on sender's email
Mark Sapiro wrote:
Rob Jackson wrote:
<snip>
Actually, it's not OK. I overlooked the fact that Python strings are immutable and re.sub doesn't (can't) change them in place. Thus,
re.sub('AZ', 'new text', pl)
needs to be
pl = re.sub('AZ', 'new text', pl)
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m
Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/robertj%40linux4free.co m
Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
Not surprising, since the payload of a multipart message is not the textual contents of the message; it is a list of message objects each of which is one of the sub-parts of the message.
What needs to be done to make this work properly?
It depends on what the incoming message looks like and what you want the result to be. Perhaps the description of the walk() method (and the other message methods) at <http://docs.python.org/lib/module-email.Message.html> will help.
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
![](https://secure.gravatar.com/avatar/746f7519ba02fb0d815e59f305c53fa2.jpg?s=120&d=mm&r=g)
Rob Jackson wrote:
I used to be getting an error when I had it other places, and then when I moved it to the end, the error went away,
Because you were no longer executing the code.
@@ -17,6 +17,7 @@ """Decorate a message by sticking the header and footer around it.""" +import re import logging from email.MIMEText import MIMEText -- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
participants (4)
-
cpz@tuunq.com
-
Mark Sapiro
-
Patrick Bogen
-
Rob Jackson