Harbor Documentation

Harbor::Mailer

Attributes

  • mail_server [RW] (Not documented)

Public Class Methods

host()

      # File lib/harbor/mailer.rb, line 26
26:     def self.host
27:       @@host rescue "www.example.com"
28:     end

host=(host)

      # File lib/harbor/mailer.rb, line 22
22:     def self.host=(host)
23:       @@host = host
24:     end

layout()

      # File lib/harbor/mailer.rb, line 18
18:     def self.layout
19:       @@layout rescue nil
20:     end

layout=(layout)

      # File lib/harbor/mailer.rb, line 14
14:     def self.layout=(layout)
15:       @@layout = layout
16:     end

new(*args)

      # File lib/harbor/mailer.rb, line 32
32:     def initialize(*args)
33:       super
34: 
35:       @layout = self.class.layout
36:       @host = self.class.host
37:     end

Public Instance Methods

host()

      # File lib/harbor/mailer.rb, line 60
60:     def host
61:       @host
62:     end

send!()

      # File lib/harbor/mailer.rb, line 91
91:     def send!
92:       mail_server.deliver(self)
93:     end

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