├── .gitignore
├── LICENSE.txt
├── MANIFEST.in
├── README.md
├── email_obfuscator
├── __init__.py
└── templatetags
│ ├── __init__.py
│ └── email_obfuscator.py
└── setup.py
/.gitignore:
--------------------------------------------------------------------------------
1 | *.py[co]
2 |
3 | # Packages
4 | *.egg
5 | *.egg-info
6 | dist
7 | build
8 | eggs
9 | parts
10 | bin
11 | var
12 | sdist
13 | develop-eggs
14 | .installed.cfg
15 |
16 | # Installer logs
17 | pip-log.txt
18 |
19 | # Unit test / coverage reports
20 | .coverage
21 | .tox
22 |
23 | #Translations
24 | *.mo
25 |
26 | #Mr Developer
27 | .mr.developer.cfg
28 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) 2012 Joseph Mornin
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include email_obfuscator/templatetags/__init__.py
2 | include email_obfuscator/templatetags/email_obfuscator.py
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | django-email-obfuscator
2 | =======================
3 |
4 | A Django template filter to protect email addresses from crawlers.
5 |
6 | Installation
7 | ------------
8 |
9 | Install from the Python package index:
10 |
11 | $ pip install django-email-obfuscator
12 |
13 | Add `email_obfuscator` to `INSTALLED_APPS` in `settings.py`:
14 |
15 | ```python
16 | INSTALLED_APPS = (
17 | # ...
18 | 'email_obfuscator',
19 | )
20 | ```
21 |
22 | Usage
23 | -----
24 |
25 | In your templates, you can protect email addresses with the `obfuscate`
26 | filter:
27 |
28 | ```python
29 | {% load email_obfuscator %}
30 | {{ 'your@email.com'|obfuscate }}
31 | ```
32 |
33 | The email address will be encoded with ASCII character entities, protecting it
34 | from spambots but rendering it readably in web browsers.
35 |
36 | You can also use the filter to create clickable `mailto` links:
37 |
38 | ```python
39 | {% load email_obfuscator %}
40 | {{ 'your@email.com'|obfuscate_mailto }}
41 | # returns 'your@email.com' as an encoded string like
42 | # your@email.com
43 | ```
44 |
45 | And if you want to add a custom link text, use this filter:
46 |
47 | ```python
48 | {% load email_obfuscator %}
49 | {{ 'your@email.com'|obfuscate_mailto:"my custom text" }}
50 | # returns 'my custom text' as an encoded string like
51 | # my custom text
52 | ```
53 |
54 | To add a subject line, separate it with a semicolon from the link text:
55 |
56 |
57 | ```python
58 | {% load email_obfuscator %}
59 | {{ 'your@email.com'|obfuscate_mailto:"my custom text" }}
60 | # returns 'my custom text' as an encoded string like
61 | # my custom text
62 | ```
63 |
64 | Credits
65 | -------
66 |
67 | [Joseph Mornin](http://www.mornin.org/) is the main author. Thanks to
68 | [Benjamin Banduhn](http://www.banduhn.com/) for optimizations and additions.
69 |
--------------------------------------------------------------------------------
/email_obfuscator/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/morninj/django-email-obfuscator/a7c576dc0f6d091764be923f45052862f6ed2e81/email_obfuscator/__init__.py
--------------------------------------------------------------------------------
/email_obfuscator/templatetags/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/morninj/django-email-obfuscator/a7c576dc0f6d091764be923f45052862f6ed2e81/email_obfuscator/templatetags/__init__.py
--------------------------------------------------------------------------------
/email_obfuscator/templatetags/email_obfuscator.py:
--------------------------------------------------------------------------------
1 | from django import template
2 | from django.template.defaultfilters import stringfilter
3 | from django.utils.safestring import mark_safe
4 |
5 | register = template.Library()
6 |
7 | def obfuscate_string(value):
8 | return ''.join(['{0:s};'.format(str(ord(char))) for char in value])
9 |
10 | @register.filter
11 | @stringfilter
12 | def obfuscate(value):
13 | return mark_safe(obfuscate_string(value))
14 |
15 | @register.filter
16 | @stringfilter
17 | def obfuscate_mailto(value, text=False):
18 | mail = obfuscate_string(value)
19 | if text:
20 | link_text = text
21 | # Detect subject lines
22 | if ';' in text:
23 | args = text.split(';')
24 | link_text = args[0]
25 | subject = args[1]
26 | mail = mail + '?subject=' + subject
27 | else:
28 | link_text = mail
29 | return mark_safe('{2:s}'.format(
30 | obfuscate_string('mailto:'), mail, link_text))
31 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | from distutils.core import setup
2 |
3 | setup(name='django-email-obfuscator',
4 | version='0.1.5',
5 | description='A Django template filter to protect email addresses from \
6 | crawlers.',
7 | author='Joseph Mornin',
8 | author_email='joseph@mornin.org',
9 | url='https://github.com/morninj/django-email-obfuscator',
10 | license='MIT',
11 | classifiers=[
12 | 'Development Status :: 4 - Beta',
13 | 'Environment :: Web Environment',
14 | 'Intended Audience :: Developers',
15 | 'License :: OSI Approved :: MIT License',
16 | 'Operating System :: OS Independent',
17 | 'Programming Language :: Python',
18 | 'Programming Language :: Python :: 3',
19 | 'Framework :: Django',
20 | ],
21 | packages=['email_obfuscator'],
22 | package_data = {
23 | 'email_obfuscator': [
24 | 'templatetags/*',
25 | ],
26 | },
27 | )
28 |
--------------------------------------------------------------------------------