Harbor::Mailer
Attributes
Public Class Methods
host()
# File lib/harbor/mailer.rb, line 27 27: def self.host 28: @@host rescue "www.example.com" 29: 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 74 74: def tokenize_urls!(mail_server_url) 75: mail_server_url = "http://#{mail_server_url}" unless mail_server_url =~ /^http/ 76: 77: [:@html, :@text].each do |ivar| 78: if content = instance_variable_get(ivar) 79: new_content = content.to_s.gsub(/(https?:\/\/[^<"\s\n]+)(.{4}|$)/m) do |url| 80: # Don't tokenize the inner text of a link 81: if $2 == '</a>' 82: url 83: else 84: (mail_server_url % [CGI.escape(envelope_id), CGI.escape([$1].pack("m"))]) + $2 85: end 86: end 87: instance_variable_set(ivar, new_content) 88: end 89: end 90: end