处理电子邮件 [英] Handling emails

查看:66
本文介绍了处理电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

***********************

您的邮件已被网关讯息安全设备扫描。

***********************

您好,


我会的想问一些线索进一步推进我的项目:-)

目的是收集所有电子邮件(本地和远程电子邮件)做一些

备份。

我试图通过阅读所有关于用python封装的模块来获取想法,

但电子邮件框架和邮箱都没有让我知道如何处理* one *

电子邮件完成有效载荷和附件(如果有的话)。

这个目的会让我有机会避免重复,我想要实现

等级制作maildir o mbox文件。

欢迎指向我有用的信息。当然,我不是要求现成的解决方案:-)。


BTW抱歉感受到了病毒扫描横幅的伤害。这不是由我生成的,而是由我的ISP生成的。我会尝试联系我的ISP并要求将其从电子邮件正文中移除




F

***********************
Your mail has been scanned by InterScan MSS.
***********************
Hello,

I''d like to ask some clue to move further on my project :-)
The purpose would be to gather all emails (local and remote ones) to do some
backup.
I''ve tried to get ideas by reading all about the modules enclose with python,
but neither email framework nor mailbox give me the idea how to handle *one*
email complete of payload and attachment (if any).
This purpose will give me chance to avoid duplicates and I suppose to achieve
the grade of making a maildir o mbox file.
It''s welcome to point me to useful information. Surely I''m not asking
ready-made solution :-).

BTW sorry to whom feel hurt by the "virus scan banner". That''s not generated
by me, but rather by my ISP. I''ll try to contact my ISP and ask to move it
off from the email body.

F

推荐答案



Fulvio写道:

Fulvio wrote:

>

你好,


我想问一些线索,以进一步推进我的项目:-)

目的是收集所有电子邮件(本地和远程的)做一些

备份。

我试图通过阅读所有关于python附带的模块来获取想法,

但电子邮件框架和邮箱都没有让我知道如何处理*一个*

电子邮件完成有效载荷和附件(如果有的话)。
>
Hello,

I''d like to ask some clue to move further on my project :-)
The purpose would be to gather all emails (local and remote ones) to do some
backup.
I''ve tried to get ideas by reading all about the modules enclose with python,
but neither email framework nor mailbox give me the idea how to handle *one*
email complete of payload and attachment (if any).



这里的''PopClient''课程可以帮到你:

http://gflanagan.net/site/python/pag...liacci.py.html


我使用的脚本在这里:

http://gflanagan.net/site/python/pag...opmail.py.html


有''可悲的缺乏评论,但希望你能搞清楚!

它将电子邮件与附件一起保存到文件系统。 (注意,

POP帐户密码以纯文本形式存储。)它检查邮件的

消息ID,如果已经有,则不会下载已下载。


hth


Gerard

The ''PopClient'' class here might help you:

http://gflanagan.net/site/python/pag...liacci.py.html

A script I use is here:

http://gflanagan.net/site/python/pag...opmail.py.html

There''s a woeful lack of comments but hopefully you can figure it out!
It saves emails to the filesystem along with attachments. (Note that
the POP account passwords are stored as plain text.) It checks a mail''s
message-id and doesn''t download if it already has been downloaded.

hth

Gerard


** *********************

您的邮件已被网关讯息安全设备扫描。

**** *******************

2006年10月24日星期二01:12,Dennis Lee Bieber写道:
***********************
Your mail has been scanned by InterScan MSS.
***********************
On Tuesday 24 October 2006 01:12, Dennis Lee Bieber wrote:

消息ID:

< 96 **************************** ********** @ emss01m1 2.us.lmco.com>


因为ID通常是在邮件提交给
$时创建的b $ b交付系统
Message-id:
<96**************************************@emss01m1 2.us.lmco.com>

as the ID is generally created when the message is submitted to the
delivery system



嗯,这就是我正在处理的事情,因为几个星期:-)确实。

有些可能没有,但Kmail应该已修复。

第二种方法是从mbox文件中获取整个电子邮件。我的

问题仍然存在,部分原因。我不确定以下程序是否会给我发电子邮件,包括多部分电子邮件。


8< -------- ----- 8< ------------- 8< ------------- 8< ------------- 8< -------------

#! / usr / bin / env python
来自__future__导入生成器的


导入电子邮件,重新

导入邮箱

导入email.Message


def getmbox(名称):

"""返回给定文件的mbox迭代器/ directory / folder name。""

fp = open(name," rb")

mbox = mailbox.PortableUnixMailbox(fp,get_message)

返回iter(mbox)

def get_message(obj):

"""返回电子邮件消息对象。 """


if isinstance(obj,email.Message.Message):

return obj

#创建电子邮件消息对象。

如果hasattr(obj,读取):

obj = obj.read()

尝试:

msg = email.message_from_string(obj)

除了email.Errors.MessageParseError:


obj = obj [len(headers) :]

msg = email.Message.Message()

返回消息


header_break_re = re.compile(r" \r?\ n(\ r?\ n)")

def extract_headers(text):

""" Very simple-minded header extraction""


m = header_break_re.search(text)

if m:

eol = m.start(1)

text = text [:eol]

if'':''not in text :

text =""

返回文字


if __name__ ==''__ main __'':

#simple试用本地mbox文件

import sys

试试:

file = sys.argv [1]

除了IOError:

print''必须给mbox文件程序/ path / to_mbox''

sys.exit()

k = getmbox(文件)

而1:

full_email = get_message(k.next())

print''%78s ''%full_email

answer = raw_input(''更多?是/否')

如果answer.lower()==''n'':休息


8< ------- ------ 8< ------------- 8< ------------- 8< ------------ -8< -------------

我承认并非所有代码都是我的真实设计,;-)其他一些程序

外推已完成。


F

Well, that''s what I''m dealing with, since a couple of weeks :-) indeed.
Some might not have one, but Kmail should had fixed.
The second will be the way to get the whole email from the mbox file. My
problem still remain, partially. I''m not sure if the below procedure will
give me the emails off including multipart ones.

8<-------------8<-------------8<-------------8<-------------8<-------------
#! /usr/bin/env python

from __future__ import generators

import email, re
import mailbox
import email.Message

def getmbox(name):
"""Return an mbox iterator given a file/directory/folder name."""
fp = open(name, "rb")
mbox = mailbox.PortableUnixMailbox(fp, get_message)
return iter(mbox)

def get_message(obj):
"""Return an email Message object."""

if isinstance(obj, email.Message.Message):
return obj
# Create an email Message object.
if hasattr(obj, "read"):
obj = obj.read()
try:
msg = email.message_from_string(obj)
except email.Errors.MessageParseError:

obj = obj[len(headers):]
msg = email.Message.Message()
return msg

header_break_re = re.compile(r"\r?\n(\r?\n)")

def extract_headers(text):
"""Very simple-minded header extraction"""

m = header_break_re.search(text)
if m:
eol = m.start(1)
text = text[:eol]
if '':'' not in text:
text = ""
return text

if __name__ == ''__main__'':
#simple trial with local mbox file
import sys
try:
file =sys.argv[1]
except IOError:
print ''Must give a mbox file program /path/to_mbox''
sys.exit()
k = getmbox(file)
while 1:
full_email = get_message(k.next())
print ''%78s'' %full_email
answer= raw_input(''More? Y/N'')
if answer.lower() == ''n'': break

8<-------------8<-------------8<-------------8<-------------8<-------------
I admit that not all code is my genuine design, ;-) some other programs
extrapolating have been done.

F


****************** *****

您的邮件已被网关讯息安全设备扫描。

******************** ***

2006年10月24日星期二03:07,Gerard Flanagan写道:
***********************
Your mail has been scanned by InterScan MSS.
***********************
On Tuesday 24 October 2006 03:07, Gerard Flanagan wrote:

这里的''PopClient''课程可能有帮助你:
The ''PopClient'' class here might help you:



谢谢你们的回复。

Gerard,

当然我会窥视在那个代码;-)收集更广泛的视角。一个小的

负面点是对于流行交易我已经取得了很大的成功:-)但是我不会放弃,也许是在那里''我会有一些好主意。

我对IMAP方面的问题更感兴趣,即使我可以避免我的

自己的目的。


最后,假设发布事物它将在哪里成为合适的网站?

目前我的程序可以对当地MUA进行过滤和混合

垃圾。 IMAP协议的小问题,但它可能适用于正则表达式过滤器选项上的POP3或IMAP4

。阿尔法测试人员(合作者)需要;-)


F

Thank you, both for the replies.
Gerard,
Surely I''ll peep on that code ;-) to gather a wider perspective. A small
negative point is that for pop deals I''ve gotten a good success :-) But I
don''t give up, perhaps it there''ll be some good idea.
I''m more interested for the IMAP side of the issue, even I might avoid for my
own purposes.

Last, suppose to publish the "thing" where will it be the appropriate site?
At the present my program can do filtering and sincronizing with local MUA
trash. Small problems with IMAP protocol, but it may work for POP3 or IMAP4
on regex filter options. Alfa testers (cooperators) needed ;-)

F


这篇关于处理电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆