old_contents: from django import template
  from django.template.defaultfilters import stringfilter
  from django.utils.safestring import mark_safe
  
  register = template.Library()
  
  
  def obfuscate_string(value):
      return ''.join(['&#{0:s};'.format(str(ord(char))) for char in value])
  
  
  @register.filter
  @stringfilter
  def obfuscate(value):
      return mark_safe(obfuscate_string(value))
  
  
  @register.filter
  @stringfilter
  def obfuscate_mailto(value, text=False):
      mail = obfuscate_string(value)
  
      if text:
          link_text = text
      else:
          link_text = mail
  
      return mark_safe('<a href="{0:s}{1:s}">{2:s}</a>'.format(
          obfuscate_string('mailto:'), mail, link_text))
  
new_contents: from django import template
  from django.template.defaultfilters import stringfilter
  from django.utils.safestring import mark_safe
  
  register = template.Library()
  
  def obfuscate_string(value):
      return ''.join(['&#{0:s};'.format(str(ord(char))) for char in value])
  
  @register.filter
  @stringfilter
  def obfuscate(value):
      return mark_safe(obfuscate_string(value))
  
  @register.filter
  @stringfilter
  def obfuscate_mailto(value, text=False):
      mail = obfuscate_string(value)
      if text:
          link_text = text
          # Detect subject lines
          if ';' in text:
              args = text.split(';')
              link_text = args[0]
              subject = args[1]
              mail = mail + '?subject=' + subject
      else:
          link_text = mail
      return mark_safe('<a href="{0:s}{1:s}">{2:s}</a>'.format(
          obfuscate_string('mailto:'), mail, link_text))
  
subject: Allow subject lines