├── pip-selfcheck.json
├── bin
├── python2.7
├── flask
├── pip
├── pip2
├── pip2.7
├── wheel
├── chardetect
├── easy_install
├── easy_install-2.7
├── activate.csh
├── activate_this.py
├── activate
├── activate.fish
└── python-config
├── test.py
├── __pycache__
└── tempmail.cpython-36.pyc
├── base.html
├── app.py
├── LICENSE
├── README.md
├── throwaway.py
└── tempmail.py
/pip-selfcheck.json:
--------------------------------------------------------------------------------
1 | {"last_check":"2018-08-17T22:07:48Z","pypi_version":"18.0"}
--------------------------------------------------------------------------------
/bin/python2.7:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samysspace/Throwaway/HEAD/bin/python2.7
--------------------------------------------------------------------------------
/test.py:
--------------------------------------------------------------------------------
1 | from tempmail import TempMail
2 |
3 | tm = TempMail()
4 | email = tm.get_email_address()
5 | print(email)
--------------------------------------------------------------------------------
/__pycache__/tempmail.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samysspace/Throwaway/HEAD/__pycache__/tempmail.cpython-36.pyc
--------------------------------------------------------------------------------
/base.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/bin/flask:
--------------------------------------------------------------------------------
1 | #!/Users/scherfaoui/CS170/throwaway/bin/python2.7
2 |
3 | # -*- coding: utf-8 -*-
4 | import re
5 | import sys
6 |
7 | from flask.cli import main
8 |
9 | if __name__ == '__main__':
10 | sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 | sys.exit(main())
12 |
--------------------------------------------------------------------------------
/bin/pip:
--------------------------------------------------------------------------------
1 | #!/Users/scherfaoui/CS170/throwaway/bin/python2.7
2 |
3 | # -*- coding: utf-8 -*-
4 | import re
5 | import sys
6 |
7 | from pip._internal import main
8 |
9 | if __name__ == '__main__':
10 | sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 | sys.exit(main())
12 |
--------------------------------------------------------------------------------
/bin/pip2:
--------------------------------------------------------------------------------
1 | #!/Users/scherfaoui/CS170/throwaway/bin/python2.7
2 |
3 | # -*- coding: utf-8 -*-
4 | import re
5 | import sys
6 |
7 | from pip._internal import main
8 |
9 | if __name__ == '__main__':
10 | sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 | sys.exit(main())
12 |
--------------------------------------------------------------------------------
/bin/pip2.7:
--------------------------------------------------------------------------------
1 | #!/Users/scherfaoui/CS170/throwaway/bin/python2.7
2 |
3 | # -*- coding: utf-8 -*-
4 | import re
5 | import sys
6 |
7 | from pip._internal import main
8 |
9 | if __name__ == '__main__':
10 | sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 | sys.exit(main())
12 |
--------------------------------------------------------------------------------
/bin/wheel:
--------------------------------------------------------------------------------
1 | #!/Users/scherfaoui/CS170/throwaway/bin/python2.7
2 |
3 | # -*- coding: utf-8 -*-
4 | import re
5 | import sys
6 |
7 | from wheel.tool import main
8 |
9 | if __name__ == '__main__':
10 | sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 | sys.exit(main())
12 |
--------------------------------------------------------------------------------
/bin/chardetect:
--------------------------------------------------------------------------------
1 | #!/Users/scherfaoui/CS170/throwaway/bin/python2.7
2 |
3 | # -*- coding: utf-8 -*-
4 | import re
5 | import sys
6 |
7 | from chardet.cli.chardetect import main
8 |
9 | if __name__ == '__main__':
10 | sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 | sys.exit(main())
12 |
--------------------------------------------------------------------------------
/bin/easy_install:
--------------------------------------------------------------------------------
1 | #!/Users/scherfaoui/CS170/throwaway/bin/python2.7
2 |
3 | # -*- coding: utf-8 -*-
4 | import re
5 | import sys
6 |
7 | from setuptools.command.easy_install import main
8 |
9 | if __name__ == '__main__':
10 | sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 | sys.exit(main())
12 |
--------------------------------------------------------------------------------
/bin/easy_install-2.7:
--------------------------------------------------------------------------------
1 | #!/Users/scherfaoui/CS170/throwaway/bin/python2.7
2 |
3 | # -*- coding: utf-8 -*-
4 | import re
5 | import sys
6 |
7 | from setuptools.command.easy_install import main
8 |
9 | if __name__ == '__main__':
10 | sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 | sys.exit(main())
12 |
--------------------------------------------------------------------------------
/app.py:
--------------------------------------------------------------------------------
1 | from tempmail import Throwaway
2 | from flask import Flask, render_template, request
3 |
4 | app = Flask(__name__)
5 |
6 | user = Throwaway()
7 | email = user.get_email_address()
8 | #email = "test"
9 |
10 | @app.route("/")
11 | def index():
12 | return """""".format(email=email)
13 |
14 | @app.route('/', methods=['POST'])
15 | def form_data():
16 | emails = user.get_mailbox(email)
17 | #emails = ["hi", "bye"]
18 | return """Your emails are: {test}
""".format(test=emails)
19 |
20 |
21 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Samy Cherfaoui
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/bin/activate.csh:
--------------------------------------------------------------------------------
1 | # This file must be used with "source bin/activate.csh" *from csh*.
2 | # You cannot run it directly.
3 | # Created by Davide Di Blasi .
4 |
5 | alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate && unalias pydoc'
6 |
7 | # Unset irrelevant variables.
8 | deactivate nondestructive
9 |
10 | setenv VIRTUAL_ENV "/Users/scherfaoui/CS170/throwaway"
11 |
12 | set _OLD_VIRTUAL_PATH="$PATH"
13 | setenv PATH "$VIRTUAL_ENV/bin:$PATH"
14 |
15 |
16 |
17 | if ("" != "") then
18 | set env_name = ""
19 | else
20 | set env_name = `basename "$VIRTUAL_ENV"`
21 | endif
22 |
23 | # Could be in a non-interactive environment,
24 | # in which case, $prompt is undefined and we wouldn't
25 | # care about the prompt anyway.
26 | if ( $?prompt ) then
27 | set _OLD_VIRTUAL_PROMPT="$prompt"
28 | set prompt = "[$env_name] $prompt"
29 | endif
30 |
31 | unset env_name
32 |
33 | alias pydoc python -m pydoc
34 |
35 | rehash
36 |
37 |
--------------------------------------------------------------------------------
/bin/activate_this.py:
--------------------------------------------------------------------------------
1 | """By using execfile(this_file, dict(__file__=this_file)) you will
2 | activate this virtualenv environment.
3 |
4 | This can be used when you must use an existing Python interpreter, not
5 | the virtualenv bin/python
6 | """
7 |
8 | try:
9 | __file__
10 | except NameError:
11 | raise AssertionError(
12 | "You must run this like execfile('path/to/activate_this.py', dict(__file__='path/to/activate_this.py'))")
13 | import sys
14 | import os
15 |
16 | old_os_path = os.environ.get('PATH', '')
17 | os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + os.pathsep + old_os_path
18 | base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19 | if sys.platform == 'win32':
20 | site_packages = os.path.join(base, 'Lib', 'site-packages')
21 | else:
22 | site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages')
23 | prev_sys_path = list(sys.path)
24 | import site
25 | site.addsitedir(site_packages)
26 | sys.real_prefix = sys.prefix
27 | sys.prefix = base
28 | # Move the added items to the front of the path:
29 | new_sys_path = []
30 | for item in list(sys.path):
31 | if item not in prev_sys_path:
32 | new_sys_path.append(item)
33 | sys.path.remove(item)
34 | sys.path[:0] = new_sys_path
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Throwaway
2 | > 📧A disposable email client built with Flask
3 |
4 | This simple Flask web app will assign a user a temporary email address which they can use as they wish to sign up for accounts, get rewards etc. I built a Python API wrapper for the Temp Mail API and a simple and flexible web interface to see the emails.
5 |
6 | ### Why should I use this over literally anything else?
7 |
8 | It's a no fuss, localized disposable email client. You can create emails on the go straight from your local Flask server. No bells and whistles, just get your email and go!
9 |
10 | # Install
11 |
12 | Make sure you have the most recent version of Flask installed. You will also need to get a key from MashApe which can be found here: https://market.mashape.com/Privatix/temp-mail. If you are creating a local instance and using less than 100 API calls per day, it should be a free subscription. After you clone the repository or download the files, replace the 12 in this line in tempmail.py with your MashApe key. Be aware that there are two instances in the code where you need to replace the key.
13 |
14 | ```python
15 | http = urllib.request.urlopen(url, "X-Mashape-Key": 12,
16 | "Accept": "application/json"})
17 | ```
18 | Beyond this, you will need to install urllib.request as follows:
19 | ```shell
20 | pip install urllib.request
21 | ```
22 | You are now good to go as soon as you run this command in your terminal or command prompt:
23 | ```shell
24 | FLASK_APP=app.py flask run
25 | ```
26 | Have fun!
27 |
28 | ### License
29 |
30 | Graciously licensed with ❤️ by MIT.
31 |
--------------------------------------------------------------------------------
/bin/activate:
--------------------------------------------------------------------------------
1 | # This file must be used with "source bin/activate" *from bash*
2 | # you cannot run it directly
3 |
4 | deactivate () {
5 | unset -f pydoc >/dev/null 2>&1
6 |
7 | # reset old environment variables
8 | # ! [ -z ${VAR+_} ] returns true if VAR is declared at all
9 | if ! [ -z "${_OLD_VIRTUAL_PATH+_}" ] ; then
10 | PATH="$_OLD_VIRTUAL_PATH"
11 | export PATH
12 | unset _OLD_VIRTUAL_PATH
13 | fi
14 | if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+_}" ] ; then
15 | PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
16 | export PYTHONHOME
17 | unset _OLD_VIRTUAL_PYTHONHOME
18 | fi
19 |
20 | # This should detect bash and zsh, which have a hash command that must
21 | # be called to get it to forget past commands. Without forgetting
22 | # past commands the $PATH changes we made may not be respected
23 | if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
24 | hash -r 2>/dev/null
25 | fi
26 |
27 | if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then
28 | PS1="$_OLD_VIRTUAL_PS1"
29 | export PS1
30 | unset _OLD_VIRTUAL_PS1
31 | fi
32 |
33 | unset VIRTUAL_ENV
34 | if [ ! "${1-}" = "nondestructive" ] ; then
35 | # Self destruct!
36 | unset -f deactivate
37 | fi
38 | }
39 |
40 | # unset irrelevant variables
41 | deactivate nondestructive
42 |
43 | VIRTUAL_ENV="/Users/scherfaoui/CS170/throwaway"
44 | export VIRTUAL_ENV
45 |
46 | _OLD_VIRTUAL_PATH="$PATH"
47 | PATH="$VIRTUAL_ENV/bin:$PATH"
48 | export PATH
49 |
50 | # unset PYTHONHOME if set
51 | if ! [ -z "${PYTHONHOME+_}" ] ; then
52 | _OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
53 | unset PYTHONHOME
54 | fi
55 |
56 | if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
57 | _OLD_VIRTUAL_PS1="$PS1"
58 | if [ "x" != x ] ; then
59 | PS1="$PS1"
60 | else
61 | PS1="(`basename \"$VIRTUAL_ENV\"`) $PS1"
62 | fi
63 | export PS1
64 | fi
65 |
66 | # Make sure to unalias pydoc if it's already there
67 | alias pydoc 2>/dev/null >/dev/null && unalias pydoc
68 |
69 | pydoc () {
70 | python -m pydoc "$@"
71 | }
72 |
73 | # This should detect bash and zsh, which have a hash command that must
74 | # be called to get it to forget past commands. Without forgetting
75 | # past commands the $PATH changes we made may not be respected
76 | if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
77 | hash -r 2>/dev/null
78 | fi
79 |
--------------------------------------------------------------------------------
/bin/activate.fish:
--------------------------------------------------------------------------------
1 | # This file must be used using `. bin/activate.fish` *within a running fish ( http://fishshell.com ) session*.
2 | # Do not run it directly.
3 |
4 | function deactivate -d 'Exit virtualenv mode and return to the normal environment.'
5 | # reset old environment variables
6 | if test -n "$_OLD_VIRTUAL_PATH"
7 | set -gx PATH $_OLD_VIRTUAL_PATH
8 | set -e _OLD_VIRTUAL_PATH
9 | end
10 |
11 | if test -n "$_OLD_VIRTUAL_PYTHONHOME"
12 | set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
13 | set -e _OLD_VIRTUAL_PYTHONHOME
14 | end
15 |
16 | if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
17 | # Set an empty local `$fish_function_path` to allow the removal of `fish_prompt` using `functions -e`.
18 | set -l fish_function_path
19 |
20 | # Erase virtualenv's `fish_prompt` and restore the original.
21 | functions -e fish_prompt
22 | functions -c _old_fish_prompt fish_prompt
23 | functions -e _old_fish_prompt
24 | set -e _OLD_FISH_PROMPT_OVERRIDE
25 | end
26 |
27 | set -e VIRTUAL_ENV
28 |
29 | if test "$argv[1]" != 'nondestructive'
30 | # Self-destruct!
31 | functions -e pydoc
32 | functions -e deactivate
33 | end
34 | end
35 |
36 | # Unset irrelevant variables.
37 | deactivate nondestructive
38 |
39 | set -gx VIRTUAL_ENV "/Users/scherfaoui/CS170/throwaway"
40 |
41 | set -gx _OLD_VIRTUAL_PATH $PATH
42 | set -gx PATH "$VIRTUAL_ENV/bin" $PATH
43 |
44 | # Unset `$PYTHONHOME` if set.
45 | if set -q PYTHONHOME
46 | set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
47 | set -e PYTHONHOME
48 | end
49 |
50 | function pydoc
51 | python -m pydoc $argv
52 | end
53 |
54 | if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
55 | # Copy the current `fish_prompt` function as `_old_fish_prompt`.
56 | functions -c fish_prompt _old_fish_prompt
57 |
58 | function fish_prompt
59 | # Save the current $status, for fish_prompts that display it.
60 | set -l old_status $status
61 |
62 | # Prompt override provided?
63 | # If not, just prepend the environment name.
64 | if test -n ""
65 | printf '%s%s' "" (set_color normal)
66 | else
67 | printf '%s(%s) ' (set_color normal) (basename "$VIRTUAL_ENV")
68 | end
69 |
70 | # Restore the original $status
71 | echo "exit $old_status" | source
72 | _old_fish_prompt
73 | end
74 |
75 | set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
76 | end
77 |
--------------------------------------------------------------------------------
/bin/python-config:
--------------------------------------------------------------------------------
1 | #!/Users/scherfaoui/CS170/throwaway/bin/python
2 |
3 | import sys
4 | import getopt
5 | import sysconfig
6 |
7 | valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
8 | 'ldflags', 'help']
9 |
10 | if sys.version_info >= (3, 2):
11 | valid_opts.insert(-1, 'extension-suffix')
12 | valid_opts.append('abiflags')
13 | if sys.version_info >= (3, 3):
14 | valid_opts.append('configdir')
15 |
16 |
17 | def exit_with_usage(code=1):
18 | sys.stderr.write("Usage: {0} [{1}]\n".format(
19 | sys.argv[0], '|'.join('--'+opt for opt in valid_opts)))
20 | sys.exit(code)
21 |
22 | try:
23 | opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
24 | except getopt.error:
25 | exit_with_usage()
26 |
27 | if not opts:
28 | exit_with_usage()
29 |
30 | pyver = sysconfig.get_config_var('VERSION')
31 | getvar = sysconfig.get_config_var
32 |
33 | opt_flags = [flag for (flag, val) in opts]
34 |
35 | if '--help' in opt_flags:
36 | exit_with_usage(code=0)
37 |
38 | for opt in opt_flags:
39 | if opt == '--prefix':
40 | print(sysconfig.get_config_var('prefix'))
41 |
42 | elif opt == '--exec-prefix':
43 | print(sysconfig.get_config_var('exec_prefix'))
44 |
45 | elif opt in ('--includes', '--cflags'):
46 | flags = ['-I' + sysconfig.get_path('include'),
47 | '-I' + sysconfig.get_path('platinclude')]
48 | if opt == '--cflags':
49 | flags.extend(getvar('CFLAGS').split())
50 | print(' '.join(flags))
51 |
52 | elif opt in ('--libs', '--ldflags'):
53 | abiflags = getattr(sys, 'abiflags', '')
54 | libs = ['-lpython' + pyver + abiflags]
55 | libs += getvar('LIBS').split()
56 | libs += getvar('SYSLIBS').split()
57 | # add the prefix/lib/pythonX.Y/config dir, but only if there is no
58 | # shared library in prefix/lib/.
59 | if opt == '--ldflags':
60 | if not getvar('Py_ENABLE_SHARED'):
61 | libs.insert(0, '-L' + getvar('LIBPL'))
62 | if not getvar('PYTHONFRAMEWORK'):
63 | libs.extend(getvar('LINKFORSHARED').split())
64 | print(' '.join(libs))
65 |
66 | elif opt == '--extension-suffix':
67 | ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
68 | if ext_suffix is None:
69 | ext_suffix = sysconfig.get_config_var('SO')
70 | print(ext_suffix)
71 |
72 | elif opt == '--abiflags':
73 | if not getattr(sys, 'abiflags', None):
74 | exit_with_usage()
75 | print(sys.abiflags)
76 |
77 | elif opt == '--configdir':
78 | print(sysconfig.get_config_var('LIBPL'))
79 |
--------------------------------------------------------------------------------
/throwaway.py:
--------------------------------------------------------------------------------
1 | import urllib.request
2 | import string
3 | import random
4 | from hashlib import md5
5 |
6 |
7 | class Throwaway(object):
8 | """
9 | API Wrapper for service which provides temporary email address.
10 | :param login: (optional) login for email address.
11 | :param domain: (optional) domain (from current available)
12 | for email address.
13 | :param api_domain: (optional) domain for temp-mail api.
14 | Default value is ``api.temp-mail.ru``.
15 | """
16 |
17 | def __init__(self, login=None, domain=None, api_domain='api.temp-mail.ru'):
18 | self.login = login
19 | self.domain = domain
20 | self.api_domain = api_domain
21 |
22 | def __repr__(self):
23 | return u''.format(self.get_email_address())
24 |
25 | @property
26 | def available_domains(self):
27 | """
28 | Return list of available domains for use in email address.
29 | """
30 | if not hasattr(self, '_available_domains'):
31 | url = 'http://{0}/request/domains/format/json/'.format(
32 | self.api_domain)
33 | http = urllib.request.urlopen(url)
34 | domains = http.json()
35 | setattr(self, '_available_domains', domains)
36 | return self._available_domains
37 |
38 | def generate_login(self, min_length=6, max_length=10, digits=True):
39 | """
40 | Generate string for email address login with defined length and
41 | alphabet.
42 | :param min_length: (optional) min login length.
43 | Default value is ``6``.
44 | :param max_length: (optional) max login length.
45 | Default value is ``10``.
46 | :param digits: (optional) use digits in login generation.
47 | Default value is ``True``.
48 | """
49 | chars = string.ascii_lowercase
50 | if digits:
51 | chars += string.digits
52 | length = random.randint(min_length, max_length)
53 | return ''.join(random.choice(chars) for x in range(length))
54 |
55 | def get_email_address(self):
56 | """
57 | Return full email address from login and domain from params in class
58 | initialization or generate new.
59 | """
60 | if self.login is None:
61 | self.login = self.generate_login()
62 |
63 | available_domains = self.available_domains
64 | if self.domain is None:
65 | self.domain = random.choice(available_domains)
66 | elif self.domain not in available_domains:
67 | raise ValueError('Domain not found in available domains!')
68 | return u'{0}{1}'.format(self.login, self.domain)
69 |
70 | def get_hash(self, email):
71 | """
72 | Return md5 hash for given email address.
73 | :param email: email address for generate md5 hash.
74 | """
75 | return md5(email).hexdigest()
76 |
77 | def get_mailbox(self, email=None, email_hash=None):
78 | """
79 | Return list of emails in given email address
80 | or dict with `error` key if mail box is empty.
81 | :param email: (optional) email address.
82 | :param email_hash: (optional) md5 hash from email address.
83 | """
84 | if email is None:
85 | email = self.get_email_address()
86 | if email_hash is None:
87 | email_hash = self.get_hash(email)
88 |
89 | url = 'http://{0}/request/mail/id/{1}/format/json/'.format(
90 | self.api_domain, email_hash)
91 | req = requests.get(url)
92 | return req.json()
--------------------------------------------------------------------------------
/tempmail.py:
--------------------------------------------------------------------------------
1 | import urllib.request
2 | import string
3 | import random
4 | from hashlib import md5
5 |
6 |
7 | class Throwaway(object):
8 | """
9 | API Wrapper for service which provides temporary email address.
10 | :param login: (optional) login for email address.
11 | :param domain: (optional) domain (from current available)
12 | for email address.
13 | :param api_domain: (optional) domain for temp-mail api.
14 | Default value is ``privatix-temp-mail-v1.p.mashape.com``.
15 | """
16 |
17 | def __init__(self, login=None, domain=None, api_domain='https://privatix-temp-mail-v1.p.mashape.com'):
18 | self.login = login
19 | self.domain = domain
20 | self.api_domain = api_domain
21 |
22 | def __repr__(self):
23 | return u''.format(self.get_email_address())
24 |
25 | @property
26 | def available_domains(self):
27 | """
28 | Return list of available domains for use in email address.
29 | """
30 | if not hasattr(self, '_available_domains'):
31 | url = 'https://{0}/request/domains/'.format(
32 | self.api_domain)
33 | http = urllib.request.urlopen(url, {
34 | "X-Mashape-Key": 12,
35 | "Accept": "application/json"})
36 | domains = http.json()
37 | setattr(self, '_available_domains', domains)
38 | return self._available_domains
39 |
40 | def generate_login(self, min_length=6, max_length=10, digits=True):
41 | """
42 | Generate string for email address login with defined length and
43 | alphabet.
44 | :param min_length: (optional) min login length.
45 | Default value is ``6``.
46 | :param max_length: (optional) max login length.
47 | Default value is ``10``.
48 | :param digits: (optional) use digits in login generation.
49 | Default value is ``True``.
50 | """
51 | chars = string.ascii_lowercase
52 | if digits:
53 | chars += string.digits
54 | length = random.randint(min_length, max_length)
55 | return ''.join(random.choice(chars) for x in range(length))
56 |
57 | def get_email_address(self):
58 | """
59 | Return full email address from login and domain from params in class
60 | initialization or generate new.
61 | """
62 | if self.login is None:
63 | self.login = self.generate_login()
64 |
65 | available_domains = self.available_domains
66 | if self.domain is None:
67 | self.domain = random.choice(available_domains)
68 | elif self.domain not in available_domains:
69 | raise ValueError('Domain not found in available domains!')
70 | return u'{0}{1}'.format(self.login, self.domain)
71 |
72 | def get_hash(self, email):
73 | """
74 | Return md5 hash for given email address.
75 | :param email: email address for generate md5 hash.
76 | """
77 | return md5(email).hexdigest()
78 |
79 | def get_mailbox(self, email=None, email_hash=None):
80 | """
81 | Return list of emails in given email address
82 | or dict with `error` key if mail box is empty.
83 | :param email: (optional) email address.
84 | :param email_hash: (optional) md5 hash from email address.
85 | """
86 | if email is None:
87 | email = self.get_email_address()
88 | if email_hash is None:
89 | email_hash = self.get_hash(email)
90 |
91 | url = 'https://{0}/request/mail/id/{md5}/'.format(self.api_domain, email_hash)
92 | req = urllib.request.urlopen(url, {"X-Mashape-Key": 12,
93 | "Accept": "application/json"})
94 | return req.json()
95 |
--------------------------------------------------------------------------------