new messages module: guerrillamail
This commit is contained in:
parent
8e9db151ed
commit
407774937d
5 changed files with 217 additions and 0 deletions
24
modules/guerrillamail/__init__.py
Normal file
24
modules/guerrillamail/__init__.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2013 Vincent A
|
||||||
|
#
|
||||||
|
# This file is part of weboob.
|
||||||
|
#
|
||||||
|
# weboob is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# weboob is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from .backend import GuerrillamailBackend
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['GuerrillamailBackend']
|
||||||
86
modules/guerrillamail/backend.py
Normal file
86
modules/guerrillamail/backend.py
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2013 Vincent A
|
||||||
|
#
|
||||||
|
# This file is part of weboob.
|
||||||
|
#
|
||||||
|
# weboob is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# weboob is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||||
|
from weboob.capabilities.messages import ICapMessages, ICapMessagesPost, Thread, Message
|
||||||
|
from weboob.tools.value import Value
|
||||||
|
|
||||||
|
from .browser import GuerrillamailBrowser
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['GuerrillamailBackend']
|
||||||
|
|
||||||
|
|
||||||
|
class GuerrillamailBackend(BaseBackend, ICapMessages, ICapMessagesPost):
|
||||||
|
NAME = 'guerrillamail'
|
||||||
|
DESCRIPTION = u'GuerrillaMail temp mailbox'
|
||||||
|
MAINTAINER = u'Vincent A'
|
||||||
|
EMAIL = 'dev@indigo.re'
|
||||||
|
LICENSE = 'AGPLv3+'
|
||||||
|
VERSION = '0.i'
|
||||||
|
|
||||||
|
BROWSER = GuerrillamailBrowser
|
||||||
|
|
||||||
|
CONFIG = BackendConfig(Value('inbox', label='Inbox', default=''))
|
||||||
|
|
||||||
|
def iter_threads(self):
|
||||||
|
inbox = self.config['inbox'].get()
|
||||||
|
if not inbox:
|
||||||
|
raise NotImplementedError()
|
||||||
|
else:
|
||||||
|
return [self.get_thread(inbox)]
|
||||||
|
|
||||||
|
def get_thread(self, _id):
|
||||||
|
t = Thread(_id)
|
||||||
|
t.title = 'Mail for %s' % _id
|
||||||
|
t.flags = t.IS_DISCUSSION
|
||||||
|
|
||||||
|
first = True
|
||||||
|
for d in self.browser.get_mails(_id):
|
||||||
|
m = self.make_message(d, t)
|
||||||
|
|
||||||
|
if not m.content:
|
||||||
|
m.content = self.browser.get_mail_content(m.id)
|
||||||
|
|
||||||
|
if first:
|
||||||
|
first = False
|
||||||
|
t.root = m
|
||||||
|
else:
|
||||||
|
m.parent = t.root
|
||||||
|
m.parent.children.append(m)
|
||||||
|
|
||||||
|
return t
|
||||||
|
|
||||||
|
def post_message(self, m):
|
||||||
|
raise NotImplementedError()
|
||||||
|
for receiver in m.receivers:
|
||||||
|
self.browser.send_mail(m.sender, receiver, m.title, m.content)
|
||||||
|
|
||||||
|
def make_message(self, d, thread):
|
||||||
|
m = Message(thread, d['id'])
|
||||||
|
m.children = []
|
||||||
|
m.sender = d['from']
|
||||||
|
m.flags = 0
|
||||||
|
if not d.get('read', True):
|
||||||
|
m.flags = m.IS_UNREAD
|
||||||
|
m.title = d['subject']
|
||||||
|
m.date = d['datetime']
|
||||||
|
m.receivers = [d['to']]
|
||||||
|
return m
|
||||||
70
modules/guerrillamail/browser.py
Normal file
70
modules/guerrillamail/browser.py
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2013 Vincent A
|
||||||
|
#
|
||||||
|
# This file is part of weboob.
|
||||||
|
#
|
||||||
|
# weboob is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# weboob is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from weboob.tools.browser import BaseBrowser
|
||||||
|
from weboob.tools.date import datetime
|
||||||
|
from weboob.tools.parsers.jsonparser import json
|
||||||
|
from urllib import urlencode
|
||||||
|
|
||||||
|
#from .pages import Page1, Page2
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['GuerrillamailBrowser']
|
||||||
|
|
||||||
|
|
||||||
|
class GuerrillamailBrowser(BaseBrowser):
|
||||||
|
PROTOCOL = 'https'
|
||||||
|
DOMAIN = 'www.guerrillamail.com'
|
||||||
|
ENCODING = 'utf-8'
|
||||||
|
|
||||||
|
def __init__(self, *args, **kw):
|
||||||
|
kw['parser'] = 'raw'
|
||||||
|
BaseBrowser.__init__(self, *args, **kw)
|
||||||
|
|
||||||
|
def _get_unicode(self, url, *a):
|
||||||
|
return self.get_document(self.openurl(url, *a)).decode(self.ENCODING, 'replace')
|
||||||
|
|
||||||
|
def _get_json(self, url, *a):
|
||||||
|
j = json.loads(self._get_unicode(url, *a))
|
||||||
|
return j
|
||||||
|
|
||||||
|
def get_mails(self, boxid):
|
||||||
|
params = {'email_user': boxid, 'lang': 'en', 'domain': 'guerrillamail.com'}
|
||||||
|
d = self._get_json('https://www.guerrillamail.com/ajax.php?f=set_email_user', urlencode(params))
|
||||||
|
|
||||||
|
d = self._get_json('https://www.guerrillamail.com/ajax.php?f=get_email_list&offset=0&domain=guerrillamail.com')
|
||||||
|
for m in d['list']:
|
||||||
|
info = {}
|
||||||
|
info['id'] = m['mail_id']
|
||||||
|
info['from'] = m['mail_from']
|
||||||
|
# info['to'] = m['mail_recipient']
|
||||||
|
info['to'] = '%s@guerrillamail.com' % boxid
|
||||||
|
info['subject'] = m['mail_subject']
|
||||||
|
info['datetime'] = datetime.fromtimestamp(int(m['mail_timestamp']))
|
||||||
|
info['read'] = bool(int(m['mail_read']))
|
||||||
|
yield info
|
||||||
|
|
||||||
|
def get_mail_content(self, mailid):
|
||||||
|
d = self._get_json('https://www.guerrillamail.com/ajax.php?f=fetch_email&email_id=mr_%s&domain=guerrillamail.com' % mailid)
|
||||||
|
return d['mail_body']
|
||||||
|
|
||||||
|
def send_mail(self, from_, to, subject, body):
|
||||||
|
params = {'from': from_, 'to': to, 'subject': subject, 'body': body, 'attach': '', 'domain': 'guerrillamail.com'}
|
||||||
|
self._get_json('https://www.guerrillamail.com/ajax.php?f=send_email', urlencode(params))
|
||||||
BIN
modules/guerrillamail/favicon.png
Normal file
BIN
modules/guerrillamail/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
37
modules/guerrillamail/test.py
Normal file
37
modules/guerrillamail/test.py
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2013 Vincent A
|
||||||
|
#
|
||||||
|
# This file is part of weboob.
|
||||||
|
#
|
||||||
|
# weboob is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# weboob is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from weboob.tools.test import BackendTest
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
|
||||||
|
class GuerrillamailTest(BackendTest):
|
||||||
|
BACKEND = 'guerrillamail'
|
||||||
|
|
||||||
|
def test_guerrillamail(self):
|
||||||
|
box = uuid4()
|
||||||
|
thread = self.backend.get_thread(box)
|
||||||
|
self.assertTrue(thread)
|
||||||
|
message = thread.root
|
||||||
|
self.assertTrue(message)
|
||||||
|
self.assertTrue(message.sender)
|
||||||
|
self.assertTrue(message.title)
|
||||||
|
self.assertTrue(message.date)
|
||||||
|
self.assertTrue(message.receivers)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue