- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
关于 InboundMailHandler 的问题。
class MailHandle(InboundMailHandler):
def receive(self, mail_message):
mail_message.sender may contained "John Bolton <john78@mail.com>". How can i extract "john78@mail.com" from it?
最佳答案
我一直在使用这个正则表达式,效果很好。从理论上讲,设计一个无法通过此正则表达式的发件人是可能的,这就是我捕获异常并警告地址的原因。不过这还没有发生。
try:
sender = re.search('<?([^<>]+)>?$',mail.sender).group(1)
except AttributeError:
...
另一个答案与根据 RFC 2822 定义的官方电子邮件地址格式不兼容。
Normally, a mailbox is comprised of two parts: (1) an optional displayname that indicates the name of the recipient (which could be a personor a system) that could be displayed to the user of a mailapplication, and (2) an addr-spec address enclosed in angle brackets("<" and ">"). There is also an alternate simple form of a mailboxwhere the addr-spec address appears alone, without the recipient'sname or the angle brackets.
请注意,此片段提到了收件人,但如果您阅读规范,它也适用于发件人。
关于python - 如何从 InboundMailHandler 中提取仅电子邮件地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13319275/
我是一名优秀的程序员,十分优秀!