summaryrefslogtreecommitdiffstats
path: root/unfinished/openprompt/mail.py
diff options
context:
space:
mode:
authort.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-04-20 16:34:19 +0200
committert.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-04-20 16:34:19 +0200
commita485cfb180094f14b3fe27ea218d2890033768a3 (patch)
tree8cf4b2f08fb79271a9dc30a0f8843c5561c5d9c9 /unfinished/openprompt/mail.py
parentora.sh (diff)
downloadgpt4free-a485cfb180094f14b3fe27ea218d2890033768a3.tar
gpt4free-a485cfb180094f14b3fe27ea218d2890033768a3.tar.gz
gpt4free-a485cfb180094f14b3fe27ea218d2890033768a3.tar.bz2
gpt4free-a485cfb180094f14b3fe27ea218d2890033768a3.tar.lz
gpt4free-a485cfb180094f14b3fe27ea218d2890033768a3.tar.xz
gpt4free-a485cfb180094f14b3fe27ea218d2890033768a3.tar.zst
gpt4free-a485cfb180094f14b3fe27ea218d2890033768a3.zip
Diffstat (limited to 'unfinished/openprompt/mail.py')
-rw-r--r--unfinished/openprompt/mail.py109
1 files changed, 109 insertions, 0 deletions
diff --git a/unfinished/openprompt/mail.py b/unfinished/openprompt/mail.py
new file mode 100644
index 00000000..082ac9fb
--- /dev/null
+++ b/unfinished/openprompt/mail.py
@@ -0,0 +1,109 @@
+import requests
+import email
+
+class MailClient:
+
+ def __init__(self):
+ self.username = None
+ self.token = None
+ self.raw = None
+ self.mailids = None
+ self.mails = None
+ self.mail = None
+
+ def create(self, force=False):
+ headers = {
+ 'accept': 'application/json',
+ }
+
+ if self.username:
+ pass
+ else:
+ self.response = requests.put(
+ 'https://www.developermail.com/api/v1/mailbox', headers=headers)
+ self.response = self.response.json()
+ self.username = self.response['result']['name']
+ self.token = self.response['result']['token']
+
+ return {'username': self.username, 'token': self.token}
+
+ def destroy(self):
+ headers = {
+ 'accept': 'application/json',
+ 'X-MailboxToken': self.token,
+ }
+ self.response = requests.delete(
+ f'https://www.developermail.com/api/v1/mailbox/{self.username}', headers=headers)
+ self.response = self.response.json()
+ self.username = None
+ self.token = None
+ return self.response
+
+ def newtoken(self):
+ headers = {
+ 'accept': 'application/json',
+ 'X-MailboxToken': self.token,
+ }
+ self.response = requests.put(
+ f'https://www.developermail.com/api/v1/mailbox/{self.username}/token', headers=headers)
+ self.response = self.response.json()
+ self.token = self.response['result']['token']
+ return {'username': self.username, 'token': self.token}
+
+ def getmailids(self):
+ headers = {
+ 'accept': 'application/json',
+ 'X-MailboxToken': self.token,
+ }
+
+ self.response = requests.get(
+ f'https://www.developermail.com/api/v1/mailbox/{self.username}', headers=headers)
+ self.response = self.response.json()
+ self.mailids = self.response['result']
+ return self.mailids
+
+ def getmails(self, mailids: list = None):
+ headers = {
+ 'accept': 'application/json',
+ 'X-MailboxToken': self.token,
+ 'Content-Type': 'application/json',
+ }
+
+ if mailids is None:
+ mailids = self.mailids
+
+ data = str(mailids)
+
+ self.response = requests.post(
+ f'https://www.developermail.com/api/v1/mailbox/{self.username}/messages', headers=headers, data=data)
+ self.response = self.response.json()
+ self.mails = self.response['result']
+ return self.mails
+
+ def getmail(self, mailid: str, raw=False):
+ headers = {
+ 'accept': 'application/json',
+ 'X-MailboxToken': self.token,
+ }
+ self.response = requests.get(
+ f'https://www.developermail.com/api/v1/mailbox/{self.username}/messages/{mailid}', headers=headers)
+ self.response = self.response.json()
+ self.mail = self.response['result']
+ if raw is False:
+ self.mail = email.message_from_string(self.mail)
+ return self.mail
+
+ def delmail(self, mailid: str):
+ headers = {
+ 'accept': 'application/json',
+ 'X-MailboxToken': self.token,
+ }
+ self.response = requests.delete(
+ f'https://www.developermail.com/api/v1/mailbox/{self.username}/messages/{mailid}', headers=headers)
+ self.response = self.response.json()
+ return self.response
+
+
+client = MailClient()
+client.newtoken()
+print(client.getmails()) \ No newline at end of file