一个没有密码的Python客户端

protonmail的Python项目详细描述


原型邮件

使用pgpy、bcrypt和atom的python的非正式的protonmail客户机。

它可以使用sync或async,目前支持twisted和tornado Python2.7及更高版本。

目前,它支持向protonmail用户读取和发送消息,以及 外部用户。尚不支持发送和接收附件。

用法

为给定用户创建一个客户端,并将密码传递给login方法。

fromgetpassimportgetpassfromprotonmail.clientimportClient# Loginclient=Client(Username="someuser",blocking=True)# It's async by default# If using different keys for login and mailbox you must unlock separately                client.api.login(getpass())

一旦通过身份验证并解锁,就可以使用点执行api请求 表示法或用路径调用请求。

# Use dot notation client.api.conversations.count()# Or use request and the pathclient.api.request('api/conversations/count')# Can also pass method, body, headers, and cookiesclient.api.messages.read(method='PUT',body={'IDs':['msid1...==','...']})# Poll for updatesclient.api.events()

使用webclient查看可用的api。

阅读对话
fromprotonmailresponsesimportConversationsResponse,ConversationResponse# First get the list of messagesr=client.api.conversations(response=ConversationsResponse)# Open the first conversationconversation=r.Conversations[0]r=client.api.conversations(conversation.ID,response=ConversationResponse)# Open and read the first message from the conversationr=client.read_message(r.Messages[0].ID)# Now decrypt and read the messagem=client.read_message(m)print(m.DecryptedBody)

检查消息

# Poll to see if any events occurred# this passes the clients EventID by defaultc.api.events()

发送消息
fromprotonmail.modelsimportEmailAddress# Create a draftr=client.create_draft()draft=r.Messagedraft.Subject="Hello from python!"draft.DecryptedBody="JS got you down huh?"draft.ToList=[EmailAddress(Address="user@example.com",Name="User"),EmailAddress(Address="user@protonmail.com"),]# Save the draft if neededr=client.save_draft(draft)# Now send itr=client.send_message(draft)ifr.Code!=1000:print(r.Error)

还有一个快捷方式client.send_simple可以完成上面的所有操作。

一旦完成,一定要注销。

# Logoutc.api.logout()

评论和许可

许可证现在是GPL。有关备用许可证,请与我联系(猜猜我的电子邮件)。

这是基于web客户端编写的。请审核代码并报告错误。

请给我买杯咖啡。

谢谢你!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
迭代值时的java HashMap线程安全性   java Android:从sqlite数据库检索数据   java OpeNni:颜色坐标到深度坐标   替换Java将所有逗号替换为分号,引号内的逗号除外   java如何获取数据库中的图像,并将其设置为特定行的表的“tooltipText()   java如何使用“没有休息吗?   java Spring引导与Gradle版本的Gradle问题   java无法更新oracle中的clob字段   用Java创建一个简单的银行账户   java openfire服务器是否实现了地雷功能?   java Android获取支持的区域设置列表   用sqlite安卓实现java简单数学计算   JavaAEMServlet获取请求头值   在java中生成随机16位数字   有类似dotnetkicks的东西吗。com for Java   xml@xmlanyement不会解组为特定的Java类型,而是在JAXBElement处停止   尝试反序列化对象时发生java错误   java如何将JSON对象从POSTMAN发送到Restful Web服务   com的java性能。太阳网httpserver。HttpServer和HttpURLConnection?