一个没有密码的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)
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客户端编写的。请审核代码并报告错误。
请给我买杯咖啡。
谢谢你!