FAQ
Hi,

I've been trying to get personalization working inside the body of the original
email instead of using header and footer.
I did manage to get it working in plain text and html format, by doing some
tweaking in the Decorate.py file.
However, the code I added to get it working for multipart/alternative does not
seem to work. See below:

sMsgToFormat=""
msgtype = msg.get_content_type()

if not msg.is_multipart():
sMsgToFormat=msg.get_payload()

elif msgtype == 'multipart/alternative':
sBoundary=msg.get_boundary()
part=msg.get_payload()
for val in part:
sPart=sBoundary+'\n'+val.as_string()
sMsgToFormat+=sPart
sMsgToFormat+='\n'

#now replace substitute var that are formmated as [[variable]]
for key, val in d.iteritems():
sMsgToFormat=string.replace(sMsgToFormat,'[['+key+']]',val)

#set the original message with the new content
msg.set_payload(sMsgToFormat)

The output generated seems ok when I look at the mail source on any client, but
the message does not show up at all.

Fred.

Search Discussions

  • Mark Sapiro at Mar 28, 2006 at 4:52 pm

    fmpage at free.fr wrote:
    I've been trying to get personalization working inside the body of the original
    email instead of using header and footer.
    I did manage to get it working in plain text and html format, by doing some
    tweaking in the Decorate.py file.
    However, the code I added to get it working for multipart/alternative does not
    seem to work. See below:

    sMsgToFormat=""
    msgtype = msg.get_content_type()

    if not msg.is_multipart():
    sMsgToFormat=msg.get_payload()

    elif msgtype == 'multipart/alternative':
    sBoundary=msg.get_boundary()
    part=msg.get_payload()
    for val in part:
    sPart=sBoundary+'\n'+val.as_string()
    sMsgToFormat+=sPart
    sMsgToFormat+='\n'

    #now replace substitute var that are formmated as [[variable]]
    for key, val in d.iteritems():
    sMsgToFormat=string.replace(sMsgToFormat,'[['+key+']]',val)

    #set the original message with the new content
    msg.set_payload(sMsgToFormat)

    The output generated seems ok when I look at the mail source on any client, but
    the message does not show up at all.

    First, this is probably OT for mailman-users. I suggest you take any
    follow ups to mailman-developers.

    You have probably broken the MIME structure in some way. It is not
    clear to me exactly how, but you are manipulating MIME parts outside
    of the standard methods for doing so, so it's not surprising. Why not
    just to something like:

    for part in msg.walk():
    if part.get_content_maintype() == 'text':
    del part['content-transfer-encoding']
    part.set_payload(DoReplacements(
    part.get_payload(decode=True)))

    --
    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 Mar 28, 2006 at 5:00 pm

    Mark Sapiro wrote:
    for part in msg.walk():
    if part.get_content_maintype() == 'text':
    del part['content-transfer-encoding']
    part.set_payload(DoReplacements(
    part.get_payload(decode=True)))

    That probably won't work. How about

    for part in msg.walk():
    if part.get_content_maintype() == 'text':
    sMsgToFormat = part.get_payload(decode=True)
    del part['content-transfer-encoding']
    part.set_payload(DoReplacements(sMsgToFormat))

    --
    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
postedMar 28, '06 at 10:29a
activeMar 28, '06 at 5:00p
posts3
users2
websitelist.org

2 users in discussion

Mark Sapiro: 2 posts Fmpage: 1 post

People

Translate

site design / logo © 2022 Grokbase