Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to modify the content of an email

Reply
Thread Tools

How to modify the content of an email

 
 
alejandro.valdez@gmail.com
Guest
Posts: n/a
 
      01-25-2008
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.

 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      01-27-2008
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
how to modify row content of file in python? holmes86 Python 3 10-27-2009 01:12 PM
AspectJ modify property field content or add and/or change methodbody in a runtime instance Jimmy Java 11 08-09-2009 07:03 PM
Sorting a directory content by last modify date J_Zanetti Java 4 01-29-2007 02:38 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57