当前位置: 首页>>代码示例>>Python>>正文


Python Message.getaddrlist方法代码示例

本文整理汇总了Python中mimetools.Message.getaddrlist方法的典型用法代码示例。如果您正苦于以下问题:Python Message.getaddrlist方法的具体用法?Python Message.getaddrlist怎么用?Python Message.getaddrlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mimetools.Message的用法示例。


在下文中一共展示了Message.getaddrlist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_archive

# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import getaddrlist [as 别名]
        def process_archive(self, peer, sender, mail_options, recips, rcptopts, data):

            """Archives email meta data using a Backend"""
            LOG(E_INFO, "%s: Sender is <%s> - Recipients (Envelope): %s" % (self.type, sender, ",".join(recips)))

            size = len(data)
            if size < MINSIZE:
                return self.do_exit(550, "Invalid Mail")

            if not data.endswith(NL):
                data = data + NL

            args = {}
            aid = None
            mid = None
            stream = StringIO(data)
            msg = Message(stream)

            if sender == "":
                LOG(E_INFO, "%s: Null return path mail, not archived" % (self.type))
                return self.sendmail("<>", mail_options, recips, rcptopts, data, aid)

            ## Check if I have msgid in my cache
            mid = msg.get("message-id", self.new_mid())
            hash = hash_headers(msg.get)
            if self.hashdb.has_key(hash):
                LOG(E_TRACE, "%s: Message-id: %s" % (self.type, mid))
                aid = self.hashdb[hash]
                LOG(E_TRACE, "%s: Message already has year/pid pair, only adding header" % self.type)
                return self.sendmail(sender, mail_options, recips, rcptopts, self.add_aid(data, msg, aid), aid, hash)
            args["m_mid"] = mid
            args["hash"] = hash

            ## Check for duplicate headers
            dupe = dupe_check(msg.headers)
            if dupe is not None:
                LOG(E_ERR, "%s: Duplicate header %s" % (self.type, dupe))
                return self.do_exit(552, "Duplicate header %s" % dupe)

            ## Extraction of From field
            m_from = msg.getaddrlist("From")
            if len(m_from) == 1:
                m_from = safe_parseaddr(m_from[0][1])
            else:
                m_from = None

            ## Empty or invalid 'From' field, try to use sender
            if m_from is None:
                LOG(E_ERR, "%s: no From header in mail using sender" % self.type)
                m_from = safe_parseaddr(sender)

            ## No luck
            if m_from is None:
                return self.do_exit(552, "Mail has not suitable From/Sender")

            args["m_from"] = m_from

            ## Extract 'To' field
            m_to = []
            for h in msg.getaddrlist("To"):
                rec = safe_parseaddr(h[1])
                if rec is None:
                    continue
                m_to.append(rec)

            ## Empty 'To' field use recipients
            if len(m_to) == 0:
                LOG(E_ERR, "%s: no To header in mail using recipients" % self.type)
                for recipient in recips:
                    rec = safe_parseaddr(recipient)
                    if rec is None:
                        continue
                    m_to.append(rec)
                if len(m_to) == 0:
                    return self.do_exit(552, "Mail has not suitable To/Recipient")

            ## Extract 'Cc' field
            for h in msg.getaddrlist("Cc"):
                rec = safe_parseaddr(h[1])
                if rec is None:
                    continue
                m_to.append(rec)

            ## Cleanup: remove duplicates
            recs = []
            for rec in m_to:
                if rec not in recs:
                    recs.append(rec)
            args["m_rec"] = recs

            ## Extract 'Subject' field
            m_sub = mime_decode_header(msg.get("Subject", "No Subject"))
            if subjpattern is not None and m_sub.find(subjpattern) != -1:
                LOG(E_INFO, "%s: Subject pattern matched, not archived" % self.type)
                return self.sendmail(sender, mail_options, recips, rcptopts, self.remove_aid(data, msg))
            args["m_sub"] = m_sub

            ## Whitelist check: From, To and Sender (envelope)
            checklist = [m_from] + m_to
            ss = safe_parseaddr(sender)
#.........这里部分代码省略.........
开发者ID:sherpya,项目名称:archiver,代码行数:103,代码来源:archiver.py

示例2: Message

# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import getaddrlist [as 别名]
#!/usr/bin/env python
from mimetools import Message
m = Message(open("bug1.eml"))

print m.getaddrlist('From')
开发者ID:netconstructor,项目名称:archiver,代码行数:7,代码来源:bug1.py


注:本文中的mimetools.Message.getaddrlist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。