Harbor Documentation

Harbor::Mailer

Attributes

  • mail_server [RW] (Not documented)

Public Class Methods

host()

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

host=(host)

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

layout()

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

layout=(layout)

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

new(*args)

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

Public Instance Methods

host()

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

send!()

      # File lib/harbor/mailer.rb, line 92
92:     def send!
93:       mail_server.deliver(self)
94:     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 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