Python 的email
模块非常适合解析标头。但是,To:
标头可以有多个收件人,并且可能有多个To:
标头。那么如何拆分每个电子邮件地址呢?我不能用逗号分开,因为可以引用逗号。有没有办法做到这一点?
演示代码:
msg="""To: user1@company1.com, "User Two" <user2@company2.com", "Three, User <user3@company3.com>
From: anotheruser@user.com
Subject: This is a subject
This is the message.
"""
import email
msg822 = email.message_from_string(msg)
for to in msg822.get_all("To"):
print("To:",to)
电流输出:
$ python x.py
To: user1@company1.com, "User Two" <user2@company2.com", "Three, User <user3@company3.com>
$