Attachment 'EmailScript.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - Email Address Insertion macro
   4 
   5     EmailScript(name=my.name, dom=the.domain.com)
   6 
   7     Inserts a JavaScript snippet such that the user sees an html mailto link
   8     but browsers such as spambots, that don't generally run JS, dont.
   9     Note that it matters how the lines containing script and /script are
  10     formatted.
  11 
  12     Copyright (c) 2007 by Ruth Ivimey-Cook
  13     
  14 """
  15 
  16 
  17 import os
  18 
  19 def execute(macro, args):
  20     request=macro.request
  21 
  22     data = u''
  23     if args:
  24         # Arguments are comma delimited key=value pairs
  25         sargs = args.split(',')
  26 	params = {}
  27         for item in sargs:
  28             sitem = item.split('=')
  29         
  30             if len(sitem) == 2:
  31                 key, value = sitem[0], sitem[1]
  32                 params[key.strip()] = value.strip()
  33 
  34 	name = params.get('name', 'user')
  35 	dom = params.get('dom', 'host')
  36         
  37 	data =        u'<script language="JavaScript"><!--\n'
  38 	data = data + u'var n = "%s"; var d = "%s";\n'  % (name, dom)
  39 	data = data + u'document.write(\'<a href=\"mailto:\' + n + \'@\' + d + \'\\\">\');\n'
  40 	data = data + u'document.write(n + \'@\' + d + \'</a>\');\n'
  41 	data = data + u'// --></script>\n'
  42 
  43     return data

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2007-05-05 23:00:26, 1.2 KB) [[attachment:EmailScript.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.