FAQ
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

Search Discussions

  • Mark Sapiro at May 4, 2006 at 12:18 am

    Rob Jackson wrote:
    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.

    You will need to do several things.

    1) set OWNERS_CAN_ENABLE_PERSONALIZATION = Yes in mm_cfg.py so you can
    do

    2) set the list's personalize option (in Non-digest options) to Yes so
    you will be sending separately to each recipient, then

    3) 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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Rob Jackson at May 4, 2006 at 4:03 pm
    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 at value.net]
    Sent: Wednesday, May 03, 2006 6:18 PM
    To: Rob Jackson; mailman-users at python.org
    Subject: Re: [Mailman-Users] Custom footer based on sender's email

    Rob Jackson wrote:
    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.

    You will need to do several things.

    1) set OWNERS_CAN_ENABLE_PERSONALIZATION = Yes in mm_cfg.py so you can do

    2) set the list's personalize option (in Non-digest options) to Yes so you
    will be sending separately to each recipient, then

    3) 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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Patrick Bogen at May 4, 2006 at 7:12 pm

    On 5/4/06, Rob Jackson 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
  • Rob Jackson at May 4, 2006 at 7:20 pm
    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 at gmail.com]
    Sent: Thursday, May 04, 2006 1:12 PM
    To: Rob Jackson
    Cc: mailman-users at python.org
    Subject: Re: [Mailman-Users] Custom footer based on sender's email
    On 5/4/06, Rob Jackson 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
  • Carl Zwanzig at May 4, 2006 at 8:07 pm

    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!
  • Rob Jackson at May 5, 2006 at 4:07 pm
    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 at tuunq.com]
    Sent: Thursday, May 04, 2006 2:08 PM
    To: Rob Jackson
    Cc: mailman-users at 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!
  • Mark Sapiro at May 5, 2006 at 4:20 pm

    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.
    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Rob Jackson at May 10, 2006 at 4:30 pm
    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 at value.net]
    Sent: Friday, May 05, 2006 10:20 AM
    To: Rob Jackson; mailman-users at python.org
    Subject: Re: [Mailman-Users] Custom footer based on sender's email
    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.
    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Mark Sapiro at May 10, 2006 at 5:27 pm

    Rob Jackson wrote:
    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.

    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Rob Jackson at May 10, 2006 at 5:52 pm
    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 at value.net]
    Sent: Wednesday, May 10, 2006 11:27 AM
    To: Rob Jackson; mailman-users at python.org
    Subject: RE: [Mailman-Users] Custom footer based on sender's email

    Rob Jackson wrote:
    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.

    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Mark Sapiro at May 10, 2006 at 6:42 pm

    Rob Jackson wrote:
    This is the diff on the Decorate.py

    191,196d190
    < #Testing to replace footer
    < pl = msg.get_payload(decode=True)
    < re.sub('AZ', 'new text', pl)
    < msg.set_payload(pl)
    <
    <
    Please either give me a unified context diff (diff -u) or at least tell
    me what Mailman version this is.

    --
    Mark Sapiro <msapiro at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Rob Jackson at May 11, 2006 at 5:13 pm
    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 at value.net]
    Sent: Wednesday, May 10, 2006 12:42 PM
    To: Rob Jackson; mailman-users at python.org
    Subject: RE: [Mailman-Users] Custom footer based on sender's email

    Rob Jackson wrote:
    This is the diff on the Decorate.py

    191,196d190
    < #Testing to replace footer
    < pl = msg.get_payload(decode=True)
    < re.sub('AZ', 'new text', pl)
    < msg.set_payload(pl)
    <
    <
    Please either give me a unified context diff (diff -u) or at least tell me
    what Mailman version this is.

    --
    Mark Sapiro <msapiro at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Mark Sapiro at May 11, 2006 at 5:46 pm

    Rob Jackson wrote:
    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={}):

    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Rob Jackson at May 11, 2006 at 6:07 pm
    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 at value.net]
    Sent: Thursday, May 11, 2006 11:46 AM
    To: Rob Jackson; mailman-users at python.org
    Subject: RE: [Mailman-Users] Custom footer based on sender's email

    Rob Jackson wrote:
    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={}):

    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Rob Jackson at May 11, 2006 at 6:25 pm
    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 at python.org
    [mailto:mailman-users-bounces+robertj=linux4free.com at python.org] On Behalf
    Of Rob Jackson
    Sent: Thursday, May 11, 2006 12:07 PM
    To: 'Mark Sapiro'; mailman-users at 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 at value.net]
    Sent: Thursday, May 11, 2006 11:46 AM
    To: Rob Jackson; mailman-users at python.org
    Subject: RE: [Mailman-Users] Custom footer based on sender's email

    Rob Jackson wrote:
    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={}):

    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan

    ------------------------------------------------------
    Mailman-Users mailing list
    Mailman-Users at 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&amp;file=faq01.027.htp
  • Mark Sapiro at May 11, 2006 at 6:47 pm

    Rob Jackson wrote:
    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

    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Mark Sapiro at May 11, 2006 at 9:53 pm

    Mark Sapiro wrote:
    Rob Jackson wrote:
    <snip>
    + pl = msg.get_payload(decode=True)
    + re.sub('AZ', 'new text', pl)
    + msg.set_payload(pl)
    <snip>
    It looks OK to me.
    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Rob Jackson at May 15, 2006 at 6:25 pm
    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 at python.org
    [mailto:mailman-users-bounces+robertj=linux4free.com at python.org] On Behalf
    Of Mark Sapiro
    Sent: Thursday, May 11, 2006 3:53 PM
    To: mailman-users at python.org
    Subject: Re: [Mailman-Users] Custom footer based on sender's email

    Mark Sapiro wrote:
    Rob Jackson wrote:
    <snip>
    + pl = msg.get_payload(decode=True)
    + re.sub('AZ', 'new text', pl)
    + msg.set_payload(pl)
    <snip>
    It looks OK to me.
    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan

    ------------------------------------------------------
    Mailman-Users mailing list
    Mailman-Users at 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&amp;file=faq01.027.htp
  • Rob Jackson at May 15, 2006 at 8:49 pm
    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 at python.org
    [mailto:mailman-users-bounces+robertj=linux4free.com at python.org] On Behalf
    Of Rob Jackson
    Sent: Monday, May 15, 2006 12:26 PM
    To: 'Mark Sapiro'; mailman-users at 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 at python.org
    [mailto:mailman-users-bounces+robertj=linux4free.com at python.org] On Behalf
    Of Mark Sapiro
    Sent: Thursday, May 11, 2006 3:53 PM
    To: mailman-users at python.org
    Subject: Re: [Mailman-Users] Custom footer based on sender's email

    Mark Sapiro wrote:
    Rob Jackson wrote:
    <snip>
    + pl = msg.get_payload(decode=True)
    + re.sub('AZ', 'new text', pl)
    + msg.set_payload(pl)
    <snip>
    It looks OK to me.
    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan

    ------------------------------------------------------
    Mailman-Users mailing list
    Mailman-Users at 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&amp;file=faq01.027.htp

    ------------------------------------------------------
    Mailman-Users mailing list
    Mailman-Users at 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&amp;file=faq01.027.htp
  • Rob Jackson at Jun 29, 2006 at 11:06 pm
    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 at linux4free.com]
    Sent: Monday, May 15, 2006 2:49 PM
    To: 'Rob Jackson'; 'Mark Sapiro'; mailman-users at 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 at python.org
    [mailto:mailman-users-bounces+robertj=linux4free.com at python.org] On Behalf
    Of Rob Jackson
    Sent: Monday, May 15, 2006 12:26 PM
    To: 'Mark Sapiro'; mailman-users at 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 at python.org
    [mailto:mailman-users-bounces+robertj=linux4free.com at python.org] On Behalf
    Of Mark Sapiro
    Sent: Thursday, May 11, 2006 3:53 PM
    To: mailman-users at python.org
    Subject: Re: [Mailman-Users] Custom footer based on sender's email

    Mark Sapiro wrote:
    Rob Jackson wrote:
    <snip>
    + pl = msg.get_payload(decode=True)
    + re.sub('AZ', 'new text', pl)
    + msg.set_payload(pl)
    <snip>
    It looks OK to me.
    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan

    ------------------------------------------------------
    Mailman-Users mailing list
    Mailman-Users at 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&amp;file=faq01.027.htp

    ------------------------------------------------------
    Mailman-Users mailing list
    Mailman-Users at 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&amp;file=faq01.027.htp
  • Mark Sapiro at Jun 30, 2006 at 12:13 am

    Rob Jackson wrote:
    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.

    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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan
  • Mark Sapiro at May 11, 2006 at 6:25 pm

    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.

    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'

    @@ -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 at value.net> The highway is for gamblers,
    San Francisco Bay Area, California better use your sense - B. Dylan

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmailman-users @
categoriespython
postedMay 3, '06 at 7:44p
activeJun 30, '06 at 12:13a
posts23
users4
websitelist.org

People

Translate

site design / logo © 2022 Grokbase