我在我的电子邮件中发送了打印机状态报告。我想下载它们并一一处理,并将所有信息放入某个数据库中以供进一步处理。我想在开始学习时使用 python3。我有这个代码:
import getpass
import poplib
server = poplib.POP3('pop3.mailserver.com' )
server.user('report@mailserver.com')
server.pass_('pswd')
numMessages = 1 #len(server.list()[1])
emails, total_bytes = server.stat()
print("{0} emails in the inbox, {1} bytes total".format(emails, total_bytes))
for i in range(numMessages):
for msg in server.retr(i+1)[1]:
print(msg)
我得到的是这种格式的整个电子邮件(带有标题和正文):
b'Return-Path: <"tever">'
b'Delivered-To: reportc@mailserver.com'
b'Received: (qmail 13193 invoked by uid 89); 23 May 2012 08:44:51 -0000'
b'Received: by simscan 1.2.0 ppid: 13156, pid: 13164, t: 0.1620s'
b' scanners: clamav: 0.97-exp/m:53 spam: 3.3.1'
b'X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mxavas16.ad.aruba.it'
b'X-Spam-Level: *'
b'X-Spam-Status: No, score=1.4 required=5.0 tests=FH_FROMEML_NOTLD,INVALID_MSGID,'
b'\tT_FILL_THIS_FORM_SHORT autolearn=disabled version=3.3.1'
b'Received: from unknown (HELO smtplq02.aruba.it) (62.149.158.35)'
b' by mxavas16.ad.aruba.it with SMTP; 23 May 2012 08:44:51 -0000'
b'Received: (qmail 30750 invoked by uid 89); 23 May 2012 08:44:51 -0000'
b'Received: from unknown (HELO smtp8.aruba.it) (62.149.158.228)'
b' by smtplq02.aruba.it with SMTP; 23 May 2012 08:44:51 -0000'
b'Received: (qmail 30979 invoked by uid 89); 23 May 2012 08:44:51 -0000'
b'Received: from unknown (HELO NM7ACD31) (email@server.it@83.xxx.xxx.xxx)'
b' by smtp8.ad.aruba.it with SMTP; 23 May 2012 08:44:51 -0000'
b'Date: Wed, 23 May 2012 10:46:34 +0200'
b'From: tever'
b'Subject: QEQ1313212'
b'To: report@mailserver.com'
b'Message-Id: <201205231046340001d806.TEVER>'
b'Mime-Version: 1.0'
b'Content-Type: text/plain; charset="utf-8"'
b'Content-Transfer-Encoding: base64'
b''
b'RXF1aXBtZW50IElEOiAgICAgICAgICAgICANCk1vZGVsIE5hbWU6ICAgICAgICAg'
b'ICAgICAgQ0RDIDE3MjVfRENDIDI3MjUNClNlcmlhbCBOdW1iZXI6ICAgICAgICAg'
b'ICAgUUVRMTMxMzIxMg0KTWV0ZXJEYXRlOiAgICAgICAgICAgICAgICBXZWQgMjMg'
b'TWF5IDIwMTIgMTA6NDY6MzQNCkNvdW50ZXJzIGJ5IEZ1bmN0aW9uDQogUHJpbnRl'
b'ZCBQYWdlcw0KICBDb3BpZXI6ICAgICAgICAgICAgICAgICAyMjE1ICAgIA0KICBQ'
b'cmludGVyOiAgICAgICAgICAgICAgICAxMTEyMDQgIA0KICBGQVg6ICAgICAgICAg'
b'ICAgICAgICAgICA5MzIgICAgIA0KICBUb3RhbDogICAgICAgICAgICAgICAgICAx'
b'MTQzNTEgIA0KIFNjYW5uZWQgUGFnZXMNCiAgQ29waWVyOiAgICAgICAgICAgICAg'
b'ICAgMTkxOSAgICANCiAgRkFYOiAgICAgICAgICAgICAgICAgICAgMjIwNyAgICAN'
b'CiAgT3RoZXI6ICAgICAgICAgICAgICAgICAgMTgyMiAgICANCiAgVG90YWw6ICAg'
b'ICAgICAgICAgICAgICAgNTk0OCAgICANCkNvdW50ZXJzIGJ5IFBhcGVyIFNpemUN'
b'Ck1vbm9jaHJvbWUNCiAgQTM6ICAgICAgICAgICAgICAgICAgICAgNDU0ICAgICAN'
b'CiAgQjQ6ICAgICAgICAgICAgICAgICAgICAgMCAgICAgICANCiAgQTQ6ICAgICAg'
b'ICAgICAgICAgICAgICAgMTA4MDQ4ICANCiAgQjU6ICAgICAgICAgICAgICAgICAg'
b'ICAgNDI3ICAgICANCiAgQTU6ICAgICAgICAgICAgICAgICAgICAgMCAgICAgICAN'
b'CiAgRm9saW86ICAgICAgICAgICAgICAgICAgMSAgICAgICANCiAgTGVkZ2VyOiAg'
b'ICAgICAgICAgICAgICAgMCAgICAgICANCiAgTGVnYWw6ICAgICAgICAgICAgICAg'
b'ICAgMCAgICAgICANCiAgTGV0dGVyOiAgICAgICAgICAgICAgICAgMCAgICAgICAN'
b'CiAgU3RhdGVtZW50OiAgICAgICAgICAgICAgMCAgICAgICANCiAgT3RoZXIxOiAg'
b'ICAgICAgICAgICAgICAgMCAgICAgICANCiAgT3RoZXIyOiAgICAgICAgICAgICAg'
b'ICAgMiAgICAgICANCk1vbm8gQ29sb3INCiAgQTM6ICAgICAgICAgICAgICAgICAg'
b'ICAgMCAgICAgICANCiAgQjQ6ICAgICAgICAgICAgICAgICAgICAgMCAgICAgICAN'
b'CiAgQTQ6ICAgICAgICAgICAgICAgICAgICAgMCAgICAgICANCiAgQjU6ICAgICAg'
b'IE90aGVyIEVycm9ycw0KDQo8V2VkIDIzIE1heSAyMDEyIDEwOjQxOjU0Pg0KICBb'
b'IF0gQWxsIE90aGVyIEVycm9ycw0KDQo8V2VkIDIzIE1heSAyMDEyIDEwOjQ1OjIx'
b'Pg0KICBbKl0gQWRkIFBhcGVyDQoNCi0tLS0tLS0tLS0tLS0tLS0tLS0NCkNEQyAx'
b'NzI1X0RDQyAyNzI1DQpbMDA6YzA6ZWU6N2E6Y2Q6MzFdDQotLS0tLS0tLS0tLS0t'
b'LS0tLS0t'
b'DQo='
b''
我需要的是逐行处理正文内容,如果匹配,我需要从服务器中删除它。
和提示怎么做?
非常感谢杰拉德