How to modify the content of an email

Discussion in 'Python' started by alejandro.valdez@gmail.com, Jan 25, 2008.

  1. Guest

    Hello, I'm trying to make a python script that take an email in (raw)
    text format, and add a footer to the text (or html) body of the email.

    I'm aware of the email and email.mime modules, but I can't figure out
    how to identify 'the main text (or html) content' from the email, and
    how to be sure that I don't incorrectly identify a txt (or html)
    attach as the main content of the email.

    By 'main text (or html) content' I mean the text (or html) that is
    showed by a Mail User Agent when it display the email to the
    recipient.

    Thanks in advance.
     
    , Jan 25, 2008
    #1
    1. Advertising

  2. En Fri, 25 Jan 2008 20:59:41 -0200, <> escribi�:

    > Hello, I'm trying to make a python script that take an email in (raw)
    > text format, and add a footer to the text (or html) body of the email.
    >
    > I'm aware of the email and email.mime modules, but I can't figure out
    > how to identify 'the main text (or html) content' from the email, and
    > how to be sure that I don't incorrectly identify a txt (or html)
    > attach as the main content of the email.
    > By 'main text (or html) content' I mean the text (or html) that is
    > showed by a Mail User Agent when it display the email to the
    > recipient.


    I suggest you read or overview the MIME specification (RFC 2045 and a few
    others), or some introductory text, in order to understand the terminology
    and what the email package does.
    Simple messages have is_multipart()==False and get_payload() gives you the
    message text.
    Multipart messages (e.g. having attachments, or an html/plaintext
    alternative) have is_multipart()==False and get_payload() returns a list
    of its parts. The parts may be Messages too, and can be multipart also.
    HTML messages usually have Content-Type: multipart/alternative, coming
    first the text part and later the HTML part. You probably will have to
    modify both, because it's up to the MUA to decide which part to show.
    When you modify an existing part you have to *remove* some headers like
    Content-Transfer-Encoding if you don't honor them in the replaced part. By
    example, the original may have been encoded in base64 or quoted-printable
    (but you didn't notice that because Python decoded the part for you).

    --
    Gabriel Genellina
     
    Gabriel Genellina, Jan 27, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hazz
    Replies:
    6
    Views:
    49,671
    SkyUCHC
    Jun 9, 2010
  2. J_Zanetti
    Replies:
    4
    Views:
    579
    Patricia Shanahan
    Jan 29, 2007
  3. Jimmy
    Replies:
    11
    Views:
    1,917
    Arne Vajhøj
    Aug 9, 2009
  4. holmes86
    Replies:
    3
    Views:
    1,399
    Simon Hibbs
    Oct 27, 2009
  5. NickH
    Replies:
    9
    Views:
    177
    Randy Webb
    Jan 22, 2004
Loading...

Share This Page