This commit is contained in:
Wang Zhiyu 2022-05-25 05:00:18 +00:00 committed by GitHub
parent bbf3a4eb6a
commit 9171ad584a
3 changed files with 19 additions and 11 deletions

View File

@ -8,6 +8,7 @@
### 单目录 (root)
|名称|路径|介绍|语言|
|:---|:---|----|----|
|README|README.md|自述文件|Markdown|
|LAN++|./lanpp|一个跨平台的简易局域网文件传输工具|Python|
|Plane Fighting|./plane_fighting|一个跨平台的简易"飞机大战"小游戏|Python|
|Python HTTPS Server|./python_https_server|一个 HTTPS 网络服务器程序|Python|
@ -15,6 +16,7 @@
### 单文件 (onefile)
|文件名|介绍|语言|
|----|----|----|
|README|README.md|自述文件|Markdown|
|file_reader.cpp|输出文件内容至终端|C++|
|pause.cpp|按任意键继续|C++|
|fastmaillib.py|开箱即用的 Python 邮件封装|Python|

View File

@ -1,11 +1,17 @@
# fastmaillib.py
# LICENSE: MIT
# VERSION: v0.2
# VERSION: v0.2.1
"""
说明:
更加方便地使用 Python 收邮件
部分基于 Liao Xuefeng 的代码, 并进行了封装操作
此代码为 Python 3.x 而设计, 但理论上兼容 Python 2.x(2.7)
"""
"""
日志:
v0.2.3:
修复 Get.get 函数中 num 参数不可用问题
"""
import email, smtplib
from email.mime.text import MIMEText
@ -23,33 +29,33 @@ class Get:
obj.pass_(password)
return obj
except Exception as e:
return False
return e
def num(obj):
"""Get the number of messages on hand"""
try:
resp, mails, octets = obj.list()
return len(mails)
except Exception as e:
return False
return e
def get(obj, num):
"""Get mail's content"""
try:
resp, mails, octets = obj.list()
index = len(mails)
resp, lines, octets = obj.retr(index - 1) #
resp, lines, octets = obj.retr(num)
message_content = b'\r\n'.join(lines).decode('utf-8')
message = Parser().parsestr(message_content)
info = Get.print_info(message)
return info
except Exception as e:
return False
return e
def quit(obj):
"""Break connection"""
try:
obj.quit()
return True
except Exception as e:
return False
return e
def print_info(msg, indent=0):
"""Convert mail object to content"""
total = {}
@ -64,9 +70,9 @@ class Get:
hdr, addr = parseaddr(value)
name = Get.decode_str(hdr)
value = u'%s <%s>' % (name, addr)
total["name"] = name
total["addr"] = addr
# print(value)
if not("name" in total):
total["name"] = name
total["addr"] = addr
if msg.is_multipart():
parts = msg.get_payload()
for n, part in enumerate(parts):
@ -94,4 +100,4 @@ class Get:
pos = content_type.find('charset=')
if pos >= 0:
charset = content_type[pos + 8:].strip()
return charset
return charset

View File

@ -1,5 +1,5 @@
// file_reader.cpp
// LICENSE: MIT
// LICENSE: Nothing(do what ever you want!)
#include <iostream>
using namespace std;