mail_jack 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,38 @@
1
1
  module MailJack
2
2
  class Interceptor
3
3
  def self.delivering_email(message)
4
- body = message.body.to_s
5
- hrefs = body.scan(/href=\"(.*?)\"/).flatten
6
- hrefs = hrefs.grep(MailJack.config.href_filter)
7
- hrefs = hrefs.uniq
4
+ querystr = generate_query_string(message)
5
+
6
+ if message.multipart?
7
+ message.parts.each do |part|
8
+ unless part.attachment?
9
+ part.body = append_links(part.body, querystr)
10
+ end
11
+ end
12
+ else
13
+ message.body = append_links(message.body, querystr)
14
+ end
15
+ end
8
16
 
17
+ def self.generate_query_string(message)
9
18
  querystr = MailJack.trackables.keys.inject({}) {|hash, a| hash[a] = message.send(a); hash}.to_query
10
19
  if MailJack.config.enable_encoding?
11
20
  querystr = "#{MailJack.config.encode_to}=#{Base64.encode64(querystr)}"
12
21
  end
22
+ return querystr
23
+ end
24
+
25
+ def self.append_links(text, querystr)
26
+ str = text.to_s
27
+ hrefs = str.scan(/href=\"(.*?)\"/).flatten
28
+ hrefs = hrefs.grep(MailJack.config.href_filter)
29
+ hrefs = hrefs.uniq
30
+
13
31
  hrefs.each do |h|
14
32
  q = h.include?("?") ? "&#{querystr}" : "?#{querystr}"
15
- body.gsub!(h, "#{h}#{q}")
33
+ str.gsub!(h, "#{h}#{q}")
16
34
  end
17
- message.body = body
35
+ return str
18
36
  end
19
37
  end
20
38
  end
@@ -1,4 +1,4 @@
1
1
  module MailJack
2
2
  # The version of the gem
3
- VERSION = '0.2.3'.freeze unless defined?(::MailJack::VERSION)
3
+ VERSION = '0.2.4'.freeze unless defined?(::MailJack::VERSION)
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail_jack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-11 00:00:00.000000000 Z
12
+ date: 2013-06-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Autogenerate query parameters to links in emails to track click throughs
15
15
  email: