1 """
2 MailTo macro
3
4 by Simon
5
6 Outputs an anchor mailto link munged to discourage spam robots.
7 Selected characters are replaced by numeric character references,
8 see http://www.w3.org/MarkUp/html3/latin1.html
9 Title attribute is provided for anchor.
10
11 [[MailTo(name, URL, description)]]
12
13
14 name email name
15 URL email URL
16 description description text in anchor, if not supplied name is used
17
18 Examples
19 [[MailTo(MyFriend, foo.bar)]]
20 [[MailTo(some.one, the.inter.net, Some One)]]
21
22 """
23 import string
24
25 def execute(macro, args):
26 ''' handle the MailTo macro, return a HTML mailto anchor
27 '''
28
29 if args==None:
30 args = ''
31 parseargs = string.split(args, ',')
32 if len(parseargs)<2:
33 return '<small><strong class="error">MailTo macro must have at least two arguments</strong></small>'
34 emailname, emailurl, emaildesc = parseargs[:3]
35 emailname = _munge_string(emailname)
36 emailurl = _munge_string(emailurl)
37 if emaildesc==None:
38 emaildesc =emailname
39 emailanchor ='<a href="mailto:%s@%s" title="Send an email to %s at %s">%s</a>'%(emailname, emailurl, emailname, emailurl, emaildesc)
40
41 return emailanchor
42
43 def _munge_string(argstring):
44 '''
45 '''
46 result=''
47
48 for character in argstring:
49 if character <> ' ':
50 if character == '.':
51 result=result+'.'
52 elif character == '-':
53 result=result+'-'
54 elif character == '_':
55 result=result+'_'
56 else:
57 result=result+character
58
59 return result
60 '''
61 Potential future enhancements
62 add class="external"
63 add parameter to request mail icon, generating code <img src="/wiki/img/moin-email.gif" width="14" border="0" alt="[EMAIL]" hspace="4" height="10">,
64 note, need to work out how to get path from moinmoin wiki.
65 figure out how to generate a line end so the next piece of HTML starts on a new line (to make viewing the HTML source nice)
66 add keyword arguement for keywords such as Subject, To, CC, BCC
67 '''