Exemple #1
0
    def macro(self, content, arguments, page_url, alternative):
        # TODO new arg parsing is not compatible, splits at blanks
        try:
            email = arguments[0]
        except IndexError:
            raise ValueError("You need to give an (obfuscated) email address")

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

        from MoinMoin.mail.sendmail import decodeSpamSafeEmail

        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
Exemple #2
0
    def macro_MailTo(self, email=unicode, text=u''):
        if not email:
            raise ValueError("You need to give an (obfuscated) email address")

        from MoinMoin.mail.sendmail import decodeSpamSafeEmail

        if self.request.user.valid:
            # decode address and generate mailto: link
            email = decodeSpamSafeEmail(email)
            result = (self.formatter.url(1, 'mailto:' + email, css='mailto') +
                      self.formatter.text(text or email) +
                      self.formatter.url(0))
        else:
            # unknown user, maybe even a spambot, so
            # just return text as given in macro args

            if text:
                result = self.formatter.text(text + " ")
            else:
                result = ''

            result += (self.formatter.code(1) +
                       self.formatter.text("<%s>" % email) +
                       self.formatter.code(0))

        return result
Exemple #3
0
    def macro_MailTo(self, email=unicode, text=u""):
        if not email:
            raise ValueError("You need to give an (obfuscated) email address")

        from MoinMoin.mail.sendmail import decodeSpamSafeEmail

        if self.request.user.valid:
            # decode address and generate mailto: link
            email = decodeSpamSafeEmail(email)
            result = (
                self.formatter.url(1, "mailto:" + email, css="mailto")
                + self.formatter.text(text or email)
                + self.formatter.url(0)
            )
        else:
            # unknown user, maybe even a spambot, so
            # just return text as given in macro args

            if text:
                result = self.formatter.text(text + " ")
            else:
                result = ""

            result += self.formatter.code(1) + self.formatter.text("<%s>" % email) + self.formatter.code(0)

        return result
Exemple #4
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
 def testDecodeSpamSafeMail(self):
     """mail.sendmail: decoding spam safe mail"""
     for coded, expected in self._tests:
         assert sendmail.decodeSpamSafeEmail(coded) == expected
 def testDecodeSpamSafeMail(self):
     """mail.sendmail: decoding spam safe mail"""
     for coded, expected in self._tests:
         assert sendmail.decodeSpamSafeEmail(coded) == expected