Harbor::Mailer
Attributes
Public Class Methods
host()
# File lib/harbor/mailer.rb, line 26 26: def self.host 27: @@host rescue "www.example.com" 28: end
Public Instance Methods
tokenize_urls!(mail_server_url)
Tokenizes urls in the email body by replacing them with the mail_server_url provided. The message’s envelope_id and a base64 encoded version of the original url are passed to the URL provided.
mailer.html = 'Please visit <a href="http://example.com">our site</a> for details.'
mailer.tokenize_urls!("http://example.com/.m/%s?redirect=%s")
mailer.html # => "Please visit <a href=\"http://example.com/.m/%2AF%2Ch2Gtn.ny1poJnnvvCeSMZA?redirect=aHR0cDovL2V4YW1wbGUuY29t%0A\">our site</a> for details."
# File lib/harbor/mailer.rb, line 73 73: def tokenize_urls!(mail_server_url) 74: mail_server_url = "http://#{mail_server_url}" unless mail_server_url =~ /^http/ 75: 76: [:@html, :@text].each do |ivar| 77: if content = instance_variable_get(ivar) 78: new_content = content.to_s.gsub(/(https?:\/\/[^<"\s\n]+)(.{4}|$)/m) do |url| 79: # Don't tokenize the inner text of a link 80: if $2 == '</a>' 81: url 82: else 83: (mail_server_url % [CGI.escape(envelope_id), CGI.escape([$1].pack("m"))]) + $2 84: end 85: end 86: instance_variable_set(ivar, new_content) 87: end 88: end 89: end