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


Python Gmail.get_message方法代码示例

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


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

示例1: __init__

# 需要导入模块: from gmail import Gmail [as 别名]
# 或者: from gmail.Gmail import get_message [as 别名]
 def __init__(self, username, password):
     g = Gmail(username, password)
     
     graph_out = csv.writer(open('email_graph.csv', 'wb'))
     
     viewed_messages = []
     for folder in g.list_folders(): # iterate through all folders in the account
         # print "%s: %s" % (folder, g.get_message_ids(folder)) # NOTE: uncomment this to see which ids are in each folder
         for message_id in g.get_message_ids(folder): # iterate through message IDs
             if message_id not in viewed_messages: # ...but don't repeat messages
                 # print "Processing %s" % message_id
                 msg = g.get_message(message_id)
                 
                 for line in msg.split('\n'): # grab the from and to lines
                     line = line.strip()
                     if line[0:5] == "From:":
                         msg_from = line[5:].strip()
                     elif line[0:3] == "To:":
                         msg_to = line[3:].strip()
                     
                 try:
                     # print "%s, %s" % (msg_from, msg_to) # DEBUG
                     graph_out.writerow([msg_from, msg_to]) # output the from and to
                 except UnboundLocalError: # ignore if we can't read the headers
                     pass
开发者ID:Mondego,项目名称:pyreco,代码行数:27,代码来源:allPythonContent.py


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