public Method

BlueCloth.encode_email_address( addr )

Transform a copy of the given email addr into an escaped version safer for posting publicly.

Source Code

# File bluecloth.rb, line 634
def encode_email_address( addr )

        rval = ''
        ("mailto:" + addr).each_byte {|b|
                case b
                when ?:
                        rval += ":"
                when ?@
                        rval += Encoders[ rand(2) ][ b ]
                else
                        r = rand(100)
                        rval += (
                                r > 90 ? Encoders[2][ b ] :
                                r < 45 ? Encoders[1][ b ] :
                                                 Encoders[0][ b ]
                        )
                end
        }

        return %{<a href="%s">%s</a>} % [ rval, rval.sub(/.+?:/, '') ]
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.