diff --git a/lib/fakeMail.py b/lib/fakeMail.py new file mode 100644 index 00000000..4e0ae738 --- /dev/null +++ b/lib/fakeMail.py @@ -0,0 +1,131 @@ +import random +import string +import time + +from core import httptools, support +from platformcode import platformtools, config, logger + + +class Mailbox: + def __init__(self): + self.address = self.new() + if '@' in self.address: + self.user, self.domain = self.address.split('@') + else: + self.user = None + self.domain = None + + def new(self): + return 'test@ciao.it' + + def inbox(self): + pass + + def readLast(self): + pass + + def waitForMail(self, timeout=50): + info = 'verifica tramite mail richiesta dal sito, sono in attesa di nuove mail sulla casella ' + self.address + info += '\nTimeout tra ' + str(timeout) + ' secondi' + dialog = platformtools.dialog_progress(config.get_localized_string(20000), info) + secs = 0 + while secs < timeout: + msg = self.readLast() + logger.debug('Checked mail ' + self.address) + if msg: + dialog.close() + logger.debug(msg) + return msg + else: + time.sleep(1) + secs += 1 + dialog.update(0, info + '\nTimeout tra ' + str(timeout-secs) + ' secondi') + if dialog.iscanceled(): + break + logger.debug('No mail found, timeout reached or dialog canceled') + return None + + +class Email: + def __init__(self, subject='', body='', sender='', date=''): + self.subject = subject + self.body = body + self.sender = sender + self.date = date + + def __repr__(self): + r = "Date: " + self.date + '\n' + r += "Subject: " + self.subject + '\n' + r += "Sender: " + self.sender + '\n\n' + r += self.body + return r + + +class OneSecMailbox(Mailbox): + def __init__(self): + self.defDomain = '1secmail.com' + self.baseUrl = 'https://www.1secmail.com/api/v1/' + + Mailbox.__init__(self) + if not self.domain: + self.domain = self.defDomain + self.user = self.address + + def inbox(self): + """ + :param user: user@1secmail.com + :return: json containing inbox id and subjects + """ + apiUrl = self.baseUrl + '?action=getMessages&login=' + self.user + '&domain=' + self.domain + return httptools.downloadpage(apiUrl).json + + def readLast(self): + try: + id = self.inbox()[0]['id'] + except: + return None + apiUrl = self.baseUrl + '?action=readMessage&login=' + self.user + '&domain=' + self.domain + '&id=' + str(id) + j = httptools.downloadpage(apiUrl).json + + return Email(j['subject'], j['htmlBody'], j['from'], j['date']) + + def new(self, len=10): + letters = string.ascii_lowercase + return ''.join(random.choice(letters) for i in range(len)) + '@' + self.defDomain + + +class Gmailnator(Mailbox): + def __init__(self, domains=('.gmail',)): + self.baseUrl = 'https://gmailnator.com/' + self.genDomains = { + 'gmailnator': 1, + '+gmail': 2, + '.gmail': 3 + } + self.data = [self.genDomains[d] for d in domains] + Mailbox.__init__(self) + + def new(self): + self.csrf = support.match(self.baseUrl, patron='csrf-token" content="([a-z0-9]+)').match + logger.debug(self.csrf) + e = httptools.downloadpage(self.baseUrl + 'index/indexquery', post={'csrf_gmailnator_token': self.csrf, 'action': 'GenerateEmail', 'data[]': self.data}) + if e.success: + return e.data + else: + platformtools.dialog_ok(config.get_localized_string(20000), 'Impossibile ottenere una mail temporanea') + + def inbox(self): + #[{"content":"\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t
dsds<\/td>\n\t\t\t\t\t\t\t\tbody<\/td>\n\t\t\t\t\t\t\t\tone minute ago<\/td>\n\t\t\t\t\t\t\t<\/tr>\n\t\t\t\t\t\t<\/tbody>\n\t\t\t\t\t<\/table>\n\t\t\t\t<\/a>"}] + return httptools.downloadpage(self.baseUrl + 'mailbox/mailboxquery', post={'csrf_gmailnator_token': self.csrf, 'action': 'LoadMailList', 'Email_address': self.address}).json + + def readLast(self): + inbox = self.inbox() + if inbox: + self.user, id = support.match(inbox[0]['content'], patron='([^\/]+)\/messageid\/#([a-z0-9]+)').match + #subject
2 minutes ago

body
+ html = httptools.downloadpage(self.baseUrl + 'mailbox/get_single_message/', post={'csrf_gmailnator_token': self.csrf, 'action': 'get_message', 'message_id': id, 'email': self.user}).data + m = Email() + m.subject, m.date, m.body = support.match(html, patron='([^<]+)<\/b>
([^<]+)<\/div>
(.*)').match + + return m + return inbox diff --git a/lib/onesecmail.py b/lib/onesecmail.py deleted file mode 100644 index 7fe81993..00000000 --- a/lib/onesecmail.py +++ /dev/null @@ -1,56 +0,0 @@ -import random -import string -import time - -from core import httptools -from platformcode import platformtools, config - -baseUrl = 'https://www.1secmail.com/api/v1/' -defDomain = '1secmail.com' - -def splitMail(mail): - if '@' in mail: - user, domain = mail.split('@') - else: - user = mail - domain = defDomain - return user, domain - -def getMessages(mail): - """ - :param user: user@1secmail.com - :return: json containing inbox id and subjects - """ - user, domain = splitMail(mail) - apiUrl = baseUrl + '?action=getMessages&login=' + user + '&domain=' + domain - return httptools.downloadpage(apiUrl).json - - -def readLastMessage(mail): - user, domain = splitMail(mail) - try: - id = getMessages(mail)[0]['id'] - except: - return None - apiUrl = baseUrl + '?action=readMessage&login=' + user + '&domain=' + domain + '&id=' + str(id) - return httptools.downloadpage(apiUrl).json - - -def waitForMail(mail, timeout=50): - dialog = platformtools.dialog_progress(config.get_localized_string(20000), 'verifica tramite mail richiesta dal sito, sono in attesa di nuove mail sulla casella ' + mail) - secs = 0 - while secs < timeout: - msg = readLastMessage(mail) - if msg: - dialog.close() - return msg - else: - time.sleep(1) - secs += 1 - if dialog.iscanceled(): - break - return None - -def getRandom(len=10): - letters = string.ascii_lowercase - return ''.join(random.choice(letters) for i in range(len)) + '@' + defDomain \ No newline at end of file diff --git a/platformcode/platformtools.py b/platformcode/platformtools.py index a1a9ac23..5d019d12 100644 --- a/platformcode/platformtools.py +++ b/platformcode/platformtools.py @@ -136,7 +136,7 @@ def render_items(itemlist, parent_item): logger.info('START render_items') thumb_type = config.get_setting('video_thumbnail_type') from platformcode import shortcuts - from core import httptools + # from core import httptools _handle = int(sys.argv[1]) default_fanart = config.get_fanart() def_context_commands = shortcuts.context()