Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60498

Flattening an email message

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <mailinglists@xgm.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'messages.': 0.05; 'msg': 0.09; 'received:localnet': 0.09; 'rfc': 0.09; 'def': 0.12; '2822': 0.16; 'stuff.': 0.16; 'throw': 0.16; 'have:': 0.19; "python's": 0.19; 'machine': 0.22; 'header:User-Agent:1': 0.23; 'skip:e 30': 0.24; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'layer': 0.31; 'stuff': 0.32; 'thanks!': 0.32; 'text': 0.33; 'could': 0.34; 'knows': 0.35; 'anybody': 0.35; 'etc.)': 0.35; 'step': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'first': 0.61; 'kind': 0.63; 'florian': 0.84; 'wish.': 0.84
From Florian Lindner <mailinglists@xgm.de>
To python-list@python.org
Subject Flattening an email message
Date Tue, 26 Nov 2013 11:51:48 +0100
User-Agent KMail/4.11.3 (Linux/3.12.1-1-ARCH; KDE/4.11.3; x86_64; ; )
MIME-Version 1.0
Content-Transfer-Encoding 7Bit
Content-Type text/plain; charset="utf-8"
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3225.1385463445.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1385463445 news.xs4all.nl 15980 [2001:888:2000:d::a6]:34895
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60498

Show key headers only | View raw


Hello,

I want to use some machine learning stuff on mail messages. First step is get 
some flattened text from a mail message, python's email package does not work 
as automatically as I wish. Right now I have:

> def mail_preprocessor(str):
>     msg = email.message_from_string(str)
>     msg_body = ""
>     
>     for part in msg.walk():
>         if part.get_content_type() == "text/plain":
>             msg_body += part.get_payload(decode=True)
>     
>     msg_body = msg_body.lower()
>     msg_body = msg_body.replace("\n", " ")
>     msg_body = msg_body.replace("\t", " ")
>     return msg_body

For getting a text from html I could use BeautifulSoup. Right now I'm still a 
layer down (encapsulation etc.) at RFC 2822 stuff. 

Does anybody knows about some package or code I can throw an email message at 
and get some kind of text from it? Attachments being discarded, HTML I can 
take care of...

Thanks!

Florian

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Flattening an email message Florian Lindner <mailinglists@xgm.de> - 2013-11-26 11:51 +0100

csiph-web