Module: Awestruct::Extensions::Obfuscate

Defined in:
lib/awestruct/extensions/obfuscate.rb

Instance Method Summary collapse

Instance Method Details

#mail_to(email, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/awestruct/extensions/obfuscate.rb', line 5

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
    , domain = [ email[0...index], email[index..-1] ]
    content = "#{hex()}<!--\nmailto:[email protected]\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