Skip to main content

Django Mailprotector

CI Version Licence PyPI Downloads

A reusable Django app that protects email addresses and phone numbers, in various ways. Django 1.8+, no further dependencies.

Installation

To get the latest stable release from PyPi

pip install django-mailprotector

Add mailprotector to your INSTALLED_APPS

INSTALLED_APPS = (
    ...,
    'mailprotector',
)

If you want to use the mailprotector_textblock tag, you'll need to have beautifulsoup4 installed.

Usage

Before your tags/filters are available in your templates, load them by using

{% load mailprotector_tags %}

Then either email address after email address:

{% mailprotector 'your@domain.com' link_text='link text' css_class='stylish' %}

Or as text block, for example from a rich text editor:

{% mailprotector_textblock object.richtext css_class='stylish' %}

Settings

MAILPROTECTOR_MODE = 'munger|munger_link_only'

This settings defines the protection algorithm used. Each has benefits and drawbacks...

  • munger: basic "munging" algo, replacing a mailto/tel link with a span, that gets filled with a new link. drawbacks: mailto are in dom, after a page is fully rendered with js (for example, with phantomjs). the link text can only be basic text, no html is possible. existing attributes (in textblock mode) will be removed (including class!) .

  • munger_link_only: "munging", but only with the href. benefits: all link attributes as well as link text including html is conserved drawbacks: for safety, emails and phone numbers (not yet) are protected in a basic way: @ = ' (at) ', . = ' . '

    email_pattern = r'\b[-.\w]+@[-.\w]+.[a-z]{2,6}\b' phone_pattern = r'\d{3} \d{3} \d{2} \d{2}'

    MAILPROTECTOR_EMAIL_PATTERN = re.compile(r'(' + email_pattern + r')') MAILPROTECTOR_PHONE_PATTERN = re.compile(r'(' + phone_pattern + r')')

For the mailprotector_textblock tag, you can yourself define the used regexes. Following are the defaults. If any of these are None, it is omitted during protection. WARNING: The default phone pattern is going to change to a more international default!

Development

  • there is test app, available with ./manage.py runserver.
  • to run tests: ./manage.py test
  • to run tests with django 1.8 / 1.9 / 1.10: tox

Contribute

If you want to contribute to this project, please perform the following steps

# Fork this repository
# Clone your fork
mkvirtualenv -p python2.7 django-mailprotector
pip install -r test_requirements.txt
git checkout -b feature_branch
# Implement your feature and tests
git add . && git commit
git push -u origin feature_branch
# Send us a pull request for your feature branch

geckodriver install

  • visit https://github.com/mozilla/geckodriver/releases
  • download the latest version of "geckodriver-vX.XX.X-linux64.tar.gz"
  • unarchive the tarball (tar -xvzf geckodriver-vX.XX.X-linux64.tar.gz)
  • give executable permissions to geckodriver (chmod +x geckodriver)
  • move the geckodriver binary to /usr/local/bin or any location on your system PATH.

Metadata

Release files for django-mailprotector 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-mailprotector 0.3.1
File Size Uploaded
django-mailprotector-0.3.1.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-mailprotector 0.3.1
File Interpreter ABI Platform
django_mailprotector-0.3.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 41.9 kB

Release files / django-mailprotector-0.3.1.tar.gz

Download URL django-mailprotector-0.3.1.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
25e1f7ec37ec2809a09f593f24ed203eb5151650cdd4d8bf5d0b060a99977880
BLAKE2b-256 checksum
How to use checksums
7425da72c45a50f554df29dc6553debcacd58b32a5493b3e9b94e501291fdf8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release files / django_mailprotector-0.3.1-py2.py3-none-any.whl

Download URL django_mailprotector-0.3.1-py2.py3-none-any.whl
Size 28.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6c0ab4d819eb20ef19d56cb484dab2b7d545b6399b3ec164f5652b5e825c3cfe
BLAKE2b-256 checksum
How to use checksums
d8c36c8adff58c84f4724f28ddaa4a2bc2e15da1802d336a31755fe51a060be9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page