Ejemplo n.º 1
0
    def macro(self, content, arguments, page_url, alternative):
        """
        Invocation: <<MailTo(user AT example DOT org, write me)>>
        where 2nd parameter is optional.
        """
        if arguments:
            arguments = arguments[0].split(',')
        try:
            assert len(arguments) > 0 and len(arguments) < 3
            email = arguments[0]
            assert len(email) >= 5
        except (AttributeError, AssertionError):
            raise ValueError(
                _("MailTo: invalid format, try: <<MailTo(user AT example DOT org, write me)>>"
                  ))

        try:
            text = arguments[1]
        except IndexError:
            text = u''

        if flaskg.user.valid:
            # decode address and generate mailto: link
            email = decodeSpamSafeEmail(email)
            result = moin_page.a(
                attrib={xlink.href: u'mailto:{0}'.format(email)},
                children=[text or email])
        else:
            # unknown user, maybe even a spambot, so just return text as given in macro args
            if text:
                text += " "
            result = moin_page.code(children=[text, "<{0}>".format(email)])

        return result
Ejemplo n.º 2
0
 def testDecodeSpamSafeMail(self):
     """mail.sendmail: decoding spam safe mail"""
     for coded, expected in self._tests:
         assert sendmail.decodeSpamSafeEmail(coded) == expected