2006年07月04日 星期二 09:56
大家好! 我现需要解决这样一个问题:自动收取POP3邮件,将From、To、主题、信件内容保存到数据库中,将附件保存到文件中,请问如何实现最方便? 我的初步思路是,尽量使用现有的软件,如在Linux下,收meil有fetchmail,收到的mail存放在mbox邮箱中,如何解析每一封邮件就是我要实现的最关键问题了。在windows下,我发现Thundbird邮件客户端的邮箱也是mbox格式的,所以可以用Thundbird自动收邮件,但如何自动解析邮件也是关键所在。 现在的邮件客户端都需要手工来查看邮件内容、另存附件等操作,不能满足我的自动解析邮件内容的需求。 我查看了Python的mailbox、email等模块,发现是可以解析mbox邮箱的,但没有搞明白到底如何实现。请教python-chinese的朋友们,是否能够帮助我解决一下这个问题呢? 非常感谢! -- ---------------------------------------- Lei zhenlin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060704/a6cd47cb/attachment.htm
2006年07月04日 星期二 10:45
An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060704/c6252d9e/attachment.htm
2006年07月04日 星期二 10:47
正责.给你参考.我在写一个基于数据库的新闻组..你有兴趣吗?
你的需求我很早以前做过..因为硬盘坏了,例子没了..你可以去网上找找我的贴子.
def parseArticle(self,data):
"""
From: "NEO" <openunix at 163.com>
Newsgroups: cn.test
Subject: test
Date: Fri, 30 Jun 2006 17:14:17 +0800
Lines: 3
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
"""
#[a-zA-z0-9]+@[a-zA-z0-9]+.[a-zA-z]+
matchs = (
('From', r'From: (".+" <.+>)\r\n'),
('Newsgroups', r'Newsgroups: (.+)\r\n'),
('Subject', r'Subject: (.+)\r\n'),
('Date', r'Date: (.+)\r\n'),
('Lines', r'Lines: (.+)\r\n'),
('X-Priority', r'X-Priority: (.+)\r\n'),
('X-MSMail-Priority', r'X-MSMail-Priority: (.+)\r\n'),
('X-Newsreader', r'X-Newsreader: (.+)\r\n'),
('X-MimeOLE', r'X-MimeOLE: (.+)\r\n'),
('X-RFC2646', r'X-RFC2646: (.+)\r\n'),
('Xref', r'Xref: (.+)\r\n'),
('Body', r'\r\n\r\n(.+)\r\n\r\n\r\n')
)
parse = {}
for head, value in matchs:
digs = re.compile(value,re.IGNORECASE)
for test in digs.findall(data):
parse[head] = test
# print parse
return parse
----- Original Message -----
From: lei zhenlin
To: python-chinese at lists.python.cn
Sent: Tuesday, July 04, 2006 9:56 AM
Subject: [python-chinese] 请教读取email的办法
大家好!
我现需要解决这样一个问题:自动收取POP3邮件,将From、To、主题、信件内容保存到数据库中,将附件保存到文件中,请问如何实现最方便?
我的初步思路是,尽量使用现有的软件,如在Linux下,收meil有fetchmail,收到的mail存放在mbox邮箱中,如何解析每一封邮件就是我要实现的最关键问题了。在windows下,我发现Thundbird邮件客户端的邮箱也是mbox格式的,所以可以用Thundbird自动收邮件,但如何自动解析邮件也是关键所在。
现在的邮件客户端都需要手工来查看邮件内容、另存附件等操作,不能满足我的自动解析邮件内容的需求。
我查看了Python的mailbox、email等模块,发现是可以解析mbox邮箱的,但没有搞明白到底如何实现。请教python-chinese的朋友们,是否能够帮助我解决一下这个问题呢? 非常感谢!
--
----------------------------------------
Lei zhenlin
------------------------------------------------------------------------------
_______________________________________________
python-chinese
Post: send python-chinese at lists.python.cn
Subscribe: send subscribe to python-chinese-request at lists.python.cn
Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060704/f43202f6/attachment-0001.html
2006年07月04日 星期二 13:49
非常感谢,我试试看 On 7/4/06, sun baole <sun_able at kinca.cn> wrote: > > lei zhenlin 写道: > > 大家好! > > 我现需要解决这样一个问题:自动收取POP3邮件,将From、To、主题、信件内容保存到数据库中,将附件保存到文件中,请问如何实现最方便? > > 我的初步思路是,尽量使用现有的软件,如在Linux下,收meil有fetchmail,收到的mail存放在mbox邮箱中,如何解析每一封邮件就是 > 我要实现的最关键问题了。在windows下,我发现Thundbird邮件客户端的邮箱也是mbox格式的,所以可以用Thundbird自动收邮件, > 但如何自动解析邮件也是关键所在。 > > > 现在的邮件客户端都需要手工来查看邮件内容、另存附件等操作,不能满足我的自动解析邮件内容的需求。 > > 我查看了Python的mailbox、email等模块,发现是可以解析mbox邮箱的,但没有搞明白到底如何实现。请教python-chinese > 的朋友们,是否能够帮助我解决一下这个问题呢? 非常感谢! > > -- > ---------------------------------------- > Lei zhenlin > > ------------------------------ > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > 可以先看看这个 > http://bbs.chinaunix.net/archiver/?tid-575710.html > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -- ---------------------------------------- Lei zhenlin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060704/cd12eac7/attachment.htm
2006年07月08日 星期六 00:18
用不着怎么Thundbird,直接通过pop3client读取,然后用mimetools,rfc822之类的处理就行
Programming Pythoh 里有一段代码抄给你
import poplib, getpass, sys, mailconfig
mailserver = mailconfig.popservername # ex: 'pop.rmi.net'
mailuser = mailconfig.popusername # ex: 'lutz'
mailpasswd = getpass.getpass('Password for %s?' % mailserver)
print 'Connecting...'
server = poplib.POP3(mailserver)
server.user(mailuser) # connect, login to mail server
server.pass_(mailpasswd) # pass is a reserved word
try:
print server.getwelcome() # print returned greeting message
msgCount, msgBytes = server.stat()
print 'There are', msgCount, 'mail messages in', msgBytes, 'bytes'
print server.list()
print '-'*80
if sys.platform[:3] == 'win': raw_input() # windows getpass is odd
raw_input('[Press Enter key]')
for i in range(msgCount):
hdr, message, octets = server.retr(i+1) # octets is byte count
for line in message: print line # retrieve, print all
mail
print '-'*80 # mail box locked till
quit
if i < msgCount - 1:
raw_input('[Press Enter key]')
finally: # make sure we unlock
mbox
server.quit() # else locked till
timeout
print 'Bye.'
2006/7/4, lei zhenlin <ray8866 at gmail.com>:
>
> 大家好!
>
> 我现需要解决这样一个问题:自动收取POP3邮件,将From、To、主题、信件内容保存到数据库中,将附件保存到文件中,请问如何实现最方便?
>
> 我的初步思路是,尽量使用现有的软件,如在Linux下,收meil有fetchmail,收到的mail存放在mbox邮箱中,如何解析每一封邮件就是我要实现的最关键问题了。在windows下,我发现Thundbird邮件客户端的邮箱也是mbox格式的,所以可以用Thundbird自动收邮件,但如何自动解析邮件也是关键所在。
>
>
> 现在的邮件客户端都需要手工来查看邮件内容、另存附件等操作,不能满足我的自动解析邮件内容的需求。
>
> 我查看了Python的mailbox、email等模块,发现是可以解析mbox邮箱的,但没有搞明白到底如何实现。请教python-chinese的朋友们,是否能够帮助我解决一下这个问题呢?
> 非常感谢!
>
> --
> ----------------------------------------
>
> Lei zhenlin
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060708/3370c679/attachment.html
Zeuux © 2025
京ICP备05028076号