Sha256: 917987a537e61fbcb52f0038e68cf13a63c61d193320092429b4029712ffb134

Contents?: true

Size: 1.07 KB

Versions: 29

Compression:

Stored size: 1.07 KB

Contents

module Awestruct
  module Extensions
    module Obfuscate

      def mail_to(email, options={})
        index = email.index('@') or raise "email needs to contain one @"
        index += 3

        headers = [ :subject, :body, :bcc, :cc ] & options.keys
        parameters = "?" + headers.map { |k| "#{k}=#{percent(options[k])}" }.join('&') if headers.length > 0

        if options[:title]
          content = options[:title]
        else
          account, domain = [ email[0...index], email[index..-1] ]
          content = "#{hex(account)}<!--\nmailto:abuse@hotmail.com\n</a>\n-->#{hex(domain)}"
        end

        "<a target='_blank' class='#{options[:class]}\nhref=\"mailto:x@y\"\n'\nhref\n =  '#{hex('mailto:' + email)}#{parameters}\n'>#{content}</a>"
      end

      private

      def hex(s)
        result = ''
        s.each_codepoint do |cp|
          result << "&#x%x;" % [cp]
        end
        result
      end

      def percent(s)
        result = ''
        s.each_codepoint do |cp|
          result << "%%%x" % [cp]
        end
        result
      end

    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
awestruct-0.6.7 lib/awestruct/extensions/obfuscate.rb
awestruct-0.6.6 lib/awestruct/extensions/obfuscate.rb
awestruct-0.6.5 lib/awestruct/extensions/obfuscate.rb
awestruct-0.6.4 lib/awestruct/extensions/obfuscate.rb
awestruct-0.6.3 lib/awestruct/extensions/obfuscate.rb
awestruct-0.6.2 lib/awestruct/extensions/obfuscate.rb
awestruct-0.6.1 lib/awestruct/extensions/obfuscate.rb
awestruct-0.6.0 lib/awestruct/extensions/obfuscate.rb
awestruct-0.6.0.RC1 lib/awestruct/extensions/obfuscate.rb
awestruct-0.6.0.alpha4 lib/awestruct/extensions/obfuscate.rb
awestruct-0.6.0.alpha3 lib/awestruct/extensions/obfuscate.rb
awestruct-0.6.0.alpha1 lib/awestruct/extensions/obfuscate.rb
awestruct-0.5.7 lib/awestruct/extensions/obfuscate.rb
awestruct-0.5.7.RC2 lib/awestruct/extensions/obfuscate.rb
awestruct-0.5.7.RC1 lib/awestruct/extensions/obfuscate.rb
awestruct-0.5.6 lib/awestruct/extensions/obfuscate.rb
awestruct-0.5.6.beta9 lib/awestruct/extensions/obfuscate.rb
awestruct-0.5.6.beta8 lib/awestruct/extensions/obfuscate.rb
awestruct-0.5.6.beta7 lib/awestruct/extensions/obfuscate.rb
awestruct-0.5.6.beta6 lib/awestruct/extensions/obfuscate.rb