• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

python打包你的整个Gmail邮箱

PHP 水墨上仙 1414次浏览

使用python打包你的整个Gmail邮箱,需要Gmail打开IMAP服务

#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
""" GMail archiver 1.1
This program will download and archive all you emails from GMail.
Simply enter your login and password, and all your emails will 
be downloaded from GMail and stored in a standard mbox file.
This inclues inbox, archived and sent mails, whatever label you applied.
Spam is not downloaded.
This mbox files can later on be opened with almost any email client (eg. Evolution).
Author:
    Sébastien SAUVAGE - sebsauvage at sebsauvage dot net
    Webmaster for http://sebsauvage.net/
License:
    This program is distributed under the OSI-certified zlib/libpnglicense .
    http://www.opensource.org/licenses/zlib-license.php
    This software is provided 'as-is', without any express or implied warranty.
    In no event will the authors be held liable for any damages arising from
    the use of this software.
    Permission is granted to anyone to use this software for any purpose,
    including commercial applications, and to alter it and redistribute it freely,
    subject to the following restrictions:
        1. The origin of this software must not be misrepresented; you must not
           claim that you wrote the original software. If you use this software
           in a product, an acknowledgment in the product documentation would be
           appreciated but is not required.
        2. Altered source versions must be plainly marked as such, and must not
           be misrepresented as being the original software.
        3. This notice may not be removed or altered from any source distribution.
Requirements:
    - a GMail account with IMAP enabled in settings.
    - GMail settings in english
    - Python 2.5
"""
import imaplib,getpass,os
print "GMail archiver 1.0"
user = raw_input("Enter your GMail username:")
pwd = getpass.getpass("Enter your password: ")
m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login(user,pwd)
m.select("[Gmail]/All Mail")
resp, items = m.search(None, "ALL")
items = items[0].split()
print "Found %d emails." % len(items)
count = len(items)
for emailid in items:
    print "Downloading email %s (%d remaining)" % (emailid,count)
    resp, data = m.fetch(emailid, "(RFC822)")
    email_body = data[0][1]
    # We duplicate the From: line to the beginning of the email because mbox format requires it.
    from_line = "from:unknown@unknown"
    try:
        from_line = [line for line in email_body[:16384].split('\n') if line.lower().startswith('from:')][0].strip()
    except IndexError:
        print "  'from:' unreadable."
    email_body = "From %s\n%s" % (from_line[5:].strip(),email_body)
    file = open("%s.mbox"%user,"a")
    file.write(email_body)
    file.write("\n")
    file.close()
    count -= 1
print "All done."


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明python打包你的整个Gmail邮箱
喜欢 (0)
加载中……