我正在编写一个Python脚本来处理从Procmail返回的电子邮件.正如question中所建议的那样,我使用的是以下Procmail配置:
:0:
|$HOME/process_mail.py
我的process_mail.py脚本通过stdin接收电子邮件,如下所示:
From hostname Tue Jun 15 21:43:30 2010
Received: (qmail 8580 invoked from network); 15 Jun 2010 21:43:22 -0400
Received: from mail-fx0-f44.google.com (209.85.161.44)
by ip-73-187-35-131.ip.secureserver.net with SMTP; 15 Jun 2010 21:43:22 -0400
Received: by fxm19 with SMTP id 19so170709fxm.3
for ; Tue, 15 Jun 2010 18:47:33 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.103.84.1 with SMTP id m1mr2774225mul.26.1276652853684; Tue, 15
Jun 2010 18:47:33 -0700 (PDT)
Received: by 10.123.143.4 with HTTP; Tue, 15 Jun 2010 18:47:33 -0700 (PDT)
Date: Tue, 15 Jun 2010 20:47:33 -0500
Message-ID:
Subject: TEST 12
From: Full Name
To: username@domain.com
Content-Type: text/plain; charset=ISO-8859-1
ONE
TWO
THREE
我试图以这种方式解析消息:
>>> import email
>>> msg = email.message_from_string(full_message)
我想获取“From”,“To”和“Subject”等消息字段.但是,消息对象不包含任何这些字段.
我究竟做错了什么?