summaryrefslogtreecommitdiffstats
path: root/gpt4free/usesless/utils/__init__.py
blob: 818c605d2d82680f2014ba8f1a3bb66d0ae741b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import requests
import random
import string
import time
import sys
import re
import os


def check_email(mail, logging: bool = False):
    username = mail.split("@")[0]
    domain = mail.split("@")[1]
    reqLink = f"https://www.1secmail.com/api/v1/?action=getMessages&login={username}&domain={domain}"
    req = requests.get(reqLink)
    req.encoding = req.apparent_encoding
    req = req.json()

    length = len(req)

    if logging:
        os.system("cls" if os.name == "nt" else "clear")
        time.sleep(1)
        print("Your temporary mail:", mail)

    if logging and length == 0:
        print(
            "Mailbox is empty. Hold tight. Mailbox is refreshed automatically every 5 seconds.",
        )
    else:
        messages = []
        id_list = []

        for i in req:
            for k, v in i.items():
                if k == "id":
                    id_list.append(v)

        x = "mails" if length > 1 else "mail"

        if logging:
            print(
                f"Mailbox has {length} {x}. (Mailbox is refreshed automatically every 5 seconds.)"
            )

        for i in id_list:
            msgRead = f"https://www.1secmail.com/api/v1/?action=readMessage&login={username}&domain={domain}&id={i}"
            req = requests.get(msgRead)
            req.encoding = req.apparent_encoding
            req = req.json()

            for k, v in req.items():
                if k == "from":
                    sender = v
                if k == "subject":
                    subject = v
                if k == "date":
                    date = v
                if k == "textBody":
                    content = v

            if logging:
                print(
                    "Sender:",
                    sender,
                    "\nTo:",
                    mail,
                    "\nSubject:",
                    subject,
                    "\nDate:",
                    date,
                    "\nContent:",
                    content,
                    "\n",
                )
            messages.append(
                {
                    "sender": sender,
                    "to": mail,
                    "subject": subject,
                    "date": date,
                    "content": content,
                }
            )

        if logging:
            os.system("cls" if os.name == "nt" else "clear")
        return messages


def create_email(custom_domain: bool = False, logging: bool = False):
    domainList = ["1secmail.com", "1secmail.net", "1secmail.org"]
    domain = random.choice(domainList)
    try:
        if custom_domain:
            custom_domain = input(
                "\nIf you enter 'my-test-email' as your domain name, mail address will look like this: 'my-test-email@1secmail.com'"
                "\nEnter the name that you wish to use as your domain name: "
            )

            newMail = f"https://www.1secmail.com/api/v1/?login={custom_domain}&domain={domain}"
            reqMail = requests.get(newMail)
            reqMail.encoding = reqMail.apparent_encoding

            username = re.search(r"login=(.*)&", newMail).group(1)
            domain = re.search(r"domain=(.*)", newMail).group(1)
            mail = f"{username}@{domain}"

            if logging:
                print("\nYour temporary email was created successfully:", mail)
            return mail

        else:
            name = string.ascii_lowercase + string.digits
            random_username = "".join(random.choice(name) for i in range(10))
            newMail = f"https://www.1secmail.com/api/v1/?login={random_username}&domain={domain}"

            reqMail = requests.get(newMail)
            reqMail.encoding = reqMail.apparent_encoding

            username = re.search(r"login=(.*)&", newMail).group(1)
            domain = re.search(r"domain=(.*)", newMail).group(1)
            mail = f"{username}@{domain}"

            if logging:
                print("\nYour temporary email was created successfully:", mail)
            return mail

    except KeyboardInterrupt:
        requests.post(
            "https://www.1secmail.com/mailbox",
            data={
                "action": "deleteMailbox",
                "login": f"{username}",
                "domain": f"{domain}",
            },
        )
        if logging:
            print("\nKeyboard Interrupt Detected! \nTemporary mail was disposed!")
            os.system("cls" if os.name == "nt" else "clear")