File size: 14,929 Bytes
308cf3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
from .SharedTools import *

from email import policy, parser

import requests
import time

DEFINE_PARSE_10MINUTEMAIL_INBOX_FUNCTION = """function parse_10minutemail_inbox() {

    updatemailbox()

    let mails = Array.from(document.getElementsByTagName('tr')).slice(1)

    let inbox = []

    for(let i=0; i < mails.length; i++) {

        let id = mails[i].children[0].children[0].href

        let from = mails[i].children[0].innerText

        let subject = mails[i].children[1].innerText

        inbox.push([id, from, subject]) }

    return inbox }"""
PARSE_GUERRILLAMAIL_INBOX = """

var email_list = document.getElementById('email_list').children

var inbox = []

for(var i=0; i < email_list.length-1; i++) {

    var mail = email_list[i].children

    var from = mail[1].innerText

    var subject = mail[2].innerText

    var mail_id = mail[0].children[0].value

    inbox.push([mail_id, from, subject])

}

return inbox

"""
GET_GUERRILLAMAIL_DOMAINS = """

var domains_options = document.getElementById('gm-host-select').options

var domains = [] 

for(var i=0; i < domains_options.length-1; i++) {

    domains.push(domains_options[i].value)

}

return domains

"""
PARSE_MAILTICKING_INBOX = """function MailTickingParse() {

    var inbox = []

    var mlist = document.getElementById("message-list").children

    for(i=0; i<mlist.length-1; i++) {

        var mfields = mlist[i].children

        var mail_id = mfields[0].children[0].href

        var from = mfields[0].innerText

        var subject = mfields[1].innerText

        inbox.push([mail_id, from, subject])

    }

    return inbox;

}

return MailTickingParse()"""
PARSE_FAKEMAIL_INBOX = """

let raw_inbox = Array.from(document.getElementById('schranka').children).slice(0, -3)

let inbox = []

for(let i=0; i < raw_inbox.length; i++) {

    let id = raw_inbox[i].dataset.href

    let from = raw_inbox[i].children[0].children[1].tagName.toLowerCase()

    let subject = raw_inbox[i].children[1].innerText.trim()

    inbox.push([id, from, subject])

}

return inbox

"""
PARSE_1SECMAILPRO_INBOX = """

let iframes = document.getElementsByTagName('iframe')

let message_iframes = []

for (let i = 0; i < iframes.length; i++) {

    if (iframes[i].className.search('flex') !== -1)

        message_iframes.push(iframes[i])

}



let messages = []

let mailbox = document.getElementsByClassName('list')[0].children[1].children

for(let i = 0; i < mailbox.length; i++) {

    let temp = mailbox[i].innerText.split('\n')

    messages.push([temp[1].trim(), temp[2].trim(), message_iframes[i].srcdoc])

}

return messages

"""
PARSE_INCOGNITOMAIL_INBOX = """

let li_elements = document.getElementsByTagName('li')

let messages_header = []

for (let i = 0; i < li_elements.length; i++) {

    let headers = li_elements[i].querySelectorAll('p')

    try {

        if (headers[0].title != '' && headers[1].title != '')

            messages_header.push([headers[0], headers[0].title, headers[1].title])

    } catch (error) { }

}

return messages_header

"""

class OneSecEmailAPI:
    def __init__(self):
        self.class_name = '1secmail'
        self.__login = None
        self.__domain = None
        self.email = None
        self.__api = 'https://www.1secmail.com/api/v1/'
        
    def init(self):
        url = f'{self.__api}?action=genRandomMailbox&count=1'
        try:
            r = requests.get(url)
        except:
            raise RuntimeError('SecEmailAPI: API access error!')
        if r.status_code != 200:
            raise RuntimeError('SecEmailAPI: API access error!')
        self.__login, self.__domain = str(r.content, 'utf-8')[2:-2].split('@')
        self.email = self.__login+'@'+self.__domain
    
    def login(self, login, domain):
        self.__login = login
        self.__domain = domain
    
    def read_email(self):
        url = f'{self.__api}?action=getMessages&login={self.__login}&domain={self.__domain}'
        print(url)
        try:
            r = requests.get(url)
        except:
            raise RuntimeError('SecEmailAPI: API access error!')
        if r.status_code != 200:
            raise RuntimeError('SecEmailAPI: API access error!')
        return r.json()
    
    def get_message(self, message_id):
        url = f'{self.__api}?action=readMessage&login={self.__login}&domain={self.__domain}&id={message_id}'
        print(url)
        try:
            r = requests.get(url)
        except:
            raise RuntimeError('SecEmailAPI: API access error!')
        if r.status_code != 200:
            raise RuntimeError('SecEmailAPI: API access error!')
        return r.json()

class DeveloperMailAPI:
    def __init__(self):
        self.class_name = 'developermail'
        self.email = None
        self.email_name = ''
        self.headers = {}
        self.api_url = 'https://www.developermail.com/api/v1'
    
    def init(self):
        r = requests.put(f'{self.api_url}/mailbox')
        self.email_name, token = list(r.json()['result'].values())
        self.email = self.email_name+'@developermail.com'
        self.headers = {'X-MailboxToken': token}

    def __parse_message(self, raw_message_body):
        message_bytes = raw_message_body.encode('utf-8')
        msg = parser.BytesParser(policy=policy.default).parsebytes(message_bytes)
        message_subject = msg['subject']
        message_from = msg['from']
        message_body = str(msg.get_payload(decode=True).decode(msg.get_content_charset())) # decoding MIME-Type to html
        return {'subject':message_subject, 'from':message_from, 'body':message_body}

    def get_messages(self):
        # get message IDs
        r = requests.get(
            f'{self.api_url}/mailbox/{self.email_name}',
            headers=self.headers
        )
        message_ids = r.json()['result']
        if message_ids == []:
            return None
        # parse messages
        messages = []
        for message_id in message_ids:
            try:
                r = requests.get(f'{self.api_url}/mailbox/{self.email_name}/messages/{message_id}', headers=self.headers)
                raw_message_body = r.json()['result']
                messages.append(self.__parse_message(raw_message_body))
            except:
                continue
        if messages == []:
            messages = None
        return messages
    
class GuerRillaMailAPI:
    def __init__(self, driver: Chrome):
        self.class_name = 'guerrillamail'
        self.driver = driver
        self.email = None
        self.window_handle = None

    def init(self):     
        self.driver.get('https://www.guerrillamail.com/')
        self.window_handle = self.driver.current_window_handle
        untilConditionExecute(self.driver, f'return {GET_EBID}("email-widget") != null')
        self.email = self.driver.execute_script(f'return {GET_EBID}("email-widget").innerText')
        # change to random available domain
        self.email = self.email.split('@')[0]+'@'+random.choice(self.driver.execute_script(GET_GUERRILLAMAIL_DOMAINS))
    
    def parse_inbox(self):
        self.driver.switch_to.window(self.window_handle)
        self.driver.get('https://www.guerrillamail.com/')
        inbox = self.driver.execute_script(PARSE_GUERRILLAMAIL_INBOX)
        return inbox

    def open_mail(self, id):
        self.driver.switch_to.window(self.window_handle)
        self.driver.get(f'https://www.guerrillamail.com/inbox?mail_id={id}')

class MailTickingAPI:
    def __init__(self, driver: Chrome):
        self.class_name = 'mailticking'
        self.driver = driver
        self.email = None
        self.window_handle = None

    def init(self):
        try:
            self.driver.get('https://www.mailticking.com')
            self.window_handle = self.driver.current_window_handle
            untilConditionExecute(self.driver, f'return {CLICK_WITH_BOOL}({GET_EBCN}("modal-footer text-center")[1].children[0])')
            untilConditionExecute(self.driver, f'return {GET_EBID}("active-mail") != null')
            time.sleep(3)
            self.email = self.driver.execute_script(f'return {GET_EBID}("active-mail").value')
            return True
        except:
            raise RuntimeError("MailTickingAPI.init Error!")
    
    def parse_inbox(self):
        self.driver.switch_to.window(self.window_handle)
        self.driver.get('https://www.mailticking.com')
        try:
            self.driver.execute_script(f'return {GET_EBID}("refresh-button")').click()
            time.sleep(1)
            inbox = self.driver.execute_script(PARSE_MAILTICKING_INBOX)
        except:
            inbox = []
        return inbox

    def open_mail(self, id):
        self.driver.switch_to.window(self.window_handle)
        self.driver.get(id)

class FakeMailAPI:
    def __init__(self, driver: Chrome):
        self.class_name = 'fakemail'
        self.driver = driver
        self.email = None
        self.window_handle = None

    def init(self):     
        self.driver.get('https://www.fakemail.net')
        self.window_handle = self.driver.current_window_handle
        untilConditionExecute(self.driver, f'return {GET_EBID}("email").innerText != null')
        self.email = self.driver.execute_script(f'return {GET_EBID}("email").innerText')
    
    def parse_inbox(self):
        self.driver.switch_to.window(self.window_handle)
        self.driver.get('https://www.fakemail.net')
        inbox = self.driver.execute_script(PARSE_FAKEMAIL_INBOX)
        return inbox

    def open_mail(self, id):
        self.driver.switch_to.window(self.window_handle)
        self.driver.get(f'https://www.fakemail.net/email/id/{id}')

class InboxesAPI:
    def __init__(self, driver: Chrome):
        self.class_name = 'inboxes'
        self.driver = driver
        self.email = None
        self.window_handle = None
    
    def init(self):
        self.driver.get('https://inboxes.com')
        self.window_handle = self.driver.current_window_handle
        button = None
        for _ in range(DEFAULT_MAX_ITER):
            try:
                button = self.driver.find_element('xpath', '//button[contains(text(), "Get my first inbox!")]')
                break
            except:
                pass
            time.sleep(DEFAULT_DELAY)
        if button is not None:
            button.click()
            time.sleep(1)
            for button in self.driver.execute_script(f'return {GET_EBTN}("button")'):
                if button.text.strip().lower() == 'choose for me':
                    button.click()
                    break
            time.sleep(2)
            for element in self.driver.execute_script(f'return {GET_EBTN}("span")'):
                new_email = ''.join(element.text.split())
                if new_email is not None:
                    new_email = re.match(r'[-a-z0-9+.]+@[a-z]+(\.[a-z]+)+', new_email)
                    if new_email is not None:
                        self.email = new_email.group()
                        break
    
    def get_messages(self):
        r = requests.get(f'https://inboxes.com/api/v2/inbox/{self.email}')
        raw_inbox = r.json()['msgs']
        messages = []
        for message in raw_inbox:
            r = requests.get(f'https://inboxes.com/api/v2/message/{message["uid"]}').json()
            messages.append({
                'from': r['ff'][0]['address'],
                'subject': message['s'],
                'body': r['html']
            })
        return messages

"""class OneSecMailProAPI:

    def __init__(self, driver: Chrome):

        self.class_name = '1secmailpro'

        self.driver = driver

        self.email = None

        self.window_handle = None

    

    def init(self):

        self.driver.get("https://1secmail.pro")

        self.window_handle = self.driver.current_window_handle

        untilConditionExecute(self.driver, f"return {CLICK_WITH_BOOL}(document.querySelectorAll('input.block')[3])")

        for _ in range(5):

            if self.driver.page_source.lower().find('you have reached daily limit of maximum 5 temp mail addresses') != -1:

                console_log('[1secmailpro]: Daily limit reached!', ERROR)

                return False

            time.sleep(DEFAULT_DELAY)

        untilConditionExecute(self.driver, f"return {GET_EBID}('email_id').innerText != ''", delay=0.5, max_iter=20)

        self.email = self.driver.execute_script(f"return {GET_EBID}('email_id').innerText")



    def get_messages(self):

        self.driver.switch_to.window(self.window_handle)

        self.driver.get("https://1secmail.pro/mailbox")

        for _ in range(5):

            try:

                messages_list = self.driver.execute_script(PARSE_1SECMAILPRO_INBOX)

                print(messages_list)

                if messages_list is not None:

                    messages = []

                    for message in messages_list:

                        messages.append({

                            'from': message[0],

                            'subject': message[1],

                            'body': message[2]

                        })

                    return messages

            except Exception as E:

                pass

            time.sleep(DEFAULT_DELAY)"""

class IncognitoMailAPI:
    def __init__(self, driver: Chrome):
        self.class_name = 'incognitomail'
        self.driver = driver
        self.email = None
        self.window_handle = None
    
    def init(self):
        self.driver.get("https://incognitomail.co/")
        self.window_handle = self.driver.current_window_handle
        untilConditionExecute(self.driver, f"return {GET_EBAV}('button', 'aria-label', 'Email dropdown').textContent != 'Creating...'")
        self.email = self.driver.execute_script(f"return {GET_EBAV}('button', 'aria-label', 'Email dropdown').textContent")

    def parse_inbox(self):
        self.driver.switch_to.window(self.window_handle)
        self.driver.get("https://incognitomail.co")
        for _ in range(3):
            try:
                inbox_headers = self.driver.execute_script(PARSE_INCOGNITOMAIL_INBOX)
                if inbox_headers != [] and inbox_headers is not None:
                    return inbox_headers
            except Exception as E:
                pass
            time.sleep(DEFAULT_DELAY)
        return []

    def open_mail(self, web_element):
        self.driver.switch_to.window(self.window_handle)
        web_element.click()


class CustomEmailAPI:
    def __init__(self):
        self.class_name = 'custom'
        self.email = None

WEB_WRAPPER_EMAIL_APIS_CLASSES = (GuerRillaMailAPI, MailTickingAPI, FakeMailAPI, InboxesAPI, IncognitoMailAPI)