imap_easybox package
imap_easybox.server module
- class imap_easybox.server.ImapEasyBox(host: str, port=993, user: str | None = None, password: str | None = None, ssl: bool = True, **kwargs)
基类:
object
登录imap服务器,对邮箱内的文件夹进行操作
- 参数:
host (str) -- 服务器域名
port (int, default 993) -- 服务器端口,默认为993
user (str, default None) -- 用户名,也可以稍后在调用
login
方法时指定password (str, default None) -- 密码,也可以稍后在调用
login
方法时指定ssl (bool, default True) -- 为
True
, 则内部使用imaplib.IMAP4
,否则使用imaplib.IMAP4_SSL
创建实例kwargs -- 任意关键字参数,会透传给
imaplib.IMAP4
或imaplib.IMAP4_SSL
构造函数
示例
可以传入用户名,密码,登录时候无须再次输入
>>> box = ImapEasyBox(host='mail.imap.com', port=993, user='username', password='password') >>> box.login()
也可以延迟输入用户名密码:
>>> box = ImapEasyBox(host='mail.imap.com', port=993) >>> box.login(user='username', password='password')
调用
quit
方法退出:>>> box.quit()
可以使用上下文管理器:
>>> with ImapEasyBox(host='mail.imap.com', port=993, user='username', password='password') as box: ... pass
- property folders: FolderList
返回邮箱当前所有文件夹
示例
>>> folders = box.folders >>> folders [Folder<inbox>, Folder<垃圾箱>, ...]
返回
FolderList
实例,FolderList
可通过整数或者文件夹名称选择文件夹- Type:
- quit()
退出登录
- update_folders()
更新文件夹列表
获取当前所有文件夹,更新内部
_folders
属性,_folders
是一个字典,键是解析后的文件夹名称, 值是文件夹的原始名称
imap_easybox.folder module
- class imap_easybox.folder.Folder(folder_name: str, box: ImapEasyBox)
基类:
object
对应邮箱中的文件夹
- delete()
删除当前文件夹
删除以后,实例的
folder_name
,box
,server
属性都被设置为None
。
- class imap_easybox.folder.FolderList(initlist=None)
基类:
UserList
覆盖了
collections.UserList
的__getitem__
方法,可通过整数或者文件夹名称选择文件夹,在内部会调用ImapEasyBox.select()
方法选定该文件夹示例
>>> folders [Folder<inbox>, Folder<垃圾箱>, ...] >>> inbox = folders[0] >>> inbox Folder<inbox> >>> inbox = folders['inbox'] >>> inbox Folder<inbox>
imap_easybox.email module
- class imap_easybox.email.Mail(mail_id: int | str, folder: Folder)
基类:
object
- property content: dict
返回邮件所有内容构成的字典,结构如下:
content = { "text_body": ..., "html_body": ..., "html_encoding": ..., "attachments": [...], "images": [...] }
- save_attachments(save_path: str = '.')
保存所有附件,返回附件路径组成的列表
- 参数:
save_path (str, default '.') -- 附件保存目录,默认为当前目录
imap_easybox.utils module
- imap_easybox.utils.decode_mail_header(header)
解析邮件元数据