bootstrap-email 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbb329e67fb8b535a16ee1215af017f799873acbaf4282971555bdb546e5138b
4
- data.tar.gz: 14a664c9e97bfcb6846866ffdfa99809cc007646361e9db733aaffaaf53dee45
3
+ metadata.gz: 0af8d16392d189b851cad1448686b2fda2a322b61c0b98553090394a598d0b32
4
+ data.tar.gz: '009e81f356b5f8519113b32f44b1c82cac62692b1bf035b2449da4dea46e60a0'
5
5
  SHA512:
6
- metadata.gz: 35bfed648f7f86be0eb2bcbd5dba531d785f0c2b1bc82af1100806896f2480e1816a9275fd9678fcb86700cc4ae9c4052be7ebb33e614300a8ffcf005178cb53
7
- data.tar.gz: d409bb910231e9e157ff375c379bc059e573a2ca44c860af183a72851b8ce825c3f52c193ade74d61551575dfa1bbfa4dadb6b7890ef8bfe3fe9dbcd530dcff1
6
+ metadata.gz: 2f2f9702d22b020da0968896dd7e3134a716c450492569fd3597676e4ad8305c340ba7abc26bd93b6d0b78b5f60de70a0d7bca2b0f310ccd15c73763e0bc3ca2
7
+ data.tar.gz: fd7db09c66be97a4082768c8b66025f714932dc356bac007033bb7f7a333d722d45caac63818cfca54344c23cf74bbd882045fc8cfeb11e2fef50217799a34a3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.3.1
@@ -3,39 +3,50 @@
3
3
  module BootstrapEmail
4
4
  module Rails
5
5
  class MailBuilder
6
- attr_reader :mail, :bootstrap_email
6
+ attr_reader :message, :bootstrap_email
7
7
 
8
8
  def self.perform(mail)
9
- new(mail) if mail
9
+ new(mail).perform if mail
10
10
  end
11
11
 
12
- private
13
-
14
12
  def initialize(mail)
15
- @mail = mail
16
- @bootstrap_email = BootstrapEmail::Compiler.new(html_part, type: :string)
17
- perform
13
+ @message = mail
14
+ @bootstrap_email = BootstrapEmail::Compiler.new(html_part.decoded, type: :string)
18
15
  end
19
16
 
20
17
  def perform
21
- add_mail_parts
22
- mail
18
+ replace_html_part(generate_html_part_replacement)
19
+ message
23
20
  end
24
21
 
25
- def html_part
26
- (mail.html_part || mail).body.raw_source
22
+ private
23
+
24
+ # Much of this files derives from: https://github.com/fphilipe/premailer-rails/blob/2870060f9740de1c3f7a1da0acfc7b88e3181077/lib/premailer/rails/hook.rb
25
+
26
+ def message_contains_html?
27
+ html_part.present?
28
+ end
29
+
30
+ # Returns true if the message itself has a content type of text/html, thus
31
+ # it does not contain other parts such as alternatives and attachments.
32
+ def pure_html_message?
33
+ message.content_type&.include?('text/html')
27
34
  end
28
35
 
29
- def add_mail_parts
30
- if BootstrapEmail.static_config.generate_rails_text_part
31
- mail.parts << build_alternative_part
36
+ def generate_html_part_replacement
37
+ if generate_text_part?
38
+ generate_alternative_part
32
39
  else
33
- html = bootstrap_email.perform_full_compile
34
- mail.parts << build_html_part(html)
40
+ html = bootstrap_email.perform_html_compile
41
+ build_html_part(html)
35
42
  end
36
43
  end
37
44
 
38
- def build_alternative_part
45
+ def generate_text_part?
46
+ BootstrapEmail.static_config.generate_rails_text_part && !message.text_part
47
+ end
48
+
49
+ def generate_alternative_part
39
50
  compiled = bootstrap_email.perform_multipart_compile
40
51
 
41
52
  part = Mail::Part.new(content_type: 'multipart/alternative')
@@ -47,7 +58,7 @@ module BootstrapEmail
47
58
 
48
59
  def build_html_part(html)
49
60
  Mail::Part.new do
50
- content_type "text/html; charset=#{html.encoding}"
61
+ content_type 'text/html; charset=UTF-8'
51
62
  body html
52
63
  end
53
64
  end
@@ -58,6 +69,47 @@ module BootstrapEmail
58
69
  body text
59
70
  end
60
71
  end
72
+
73
+ def html_part
74
+ if pure_html_message?
75
+ message
76
+ else
77
+ message.html_part
78
+ end
79
+ end
80
+
81
+ def replace_html_part(new_part)
82
+ if pure_html_message?
83
+ replace_in_pure_html_message(new_part)
84
+ else
85
+ replace_part_in_list(message.parts, html_part, new_part)
86
+ end
87
+ end
88
+
89
+ # If the new part is a pure text/html part, the body and its content type
90
+ # are used for the message. If the new part is
91
+ def replace_in_pure_html_message(new_part)
92
+ if new_part.content_type.include?('text/html')
93
+ message.body = new_part.decoded
94
+ message.content_type = new_part.content_type
95
+ else
96
+ message.body = nil
97
+ message.content_type = new_part.content_type
98
+ new_part.parts.each do |part|
99
+ message.add_part(part)
100
+ end
101
+ end
102
+ end
103
+
104
+ def replace_part_in_list(parts_list, old_part, new_part)
105
+ if (index = parts_list.index(old_part))
106
+ parts_list[index] = new_part
107
+ else
108
+ parts_list.any? do |part|
109
+ replace_part_in_list(part.parts, old_part, new_part) if part.respond_to?(:parts)
110
+ end
111
+ end
112
+ end
61
113
  end
62
114
  end
63
115
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-email
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Yamartino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-03 00:00:00.000000000 Z
11
+ date: 2022-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlbeautifier