immosquare-extensions 0.1.20 → 0.1.21
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.
- checksums.yaml +4 -4
- data/lib/immosquare-extensions/helpers/mail_helper.rb +55 -55
- data/lib/immosquare-extensions/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca3fb89d5fc5c6222302e98796ed714a90dc9fdebf1f06e35b1637527134c03f
|
4
|
+
data.tar.gz: 7e71e05406df6ab3926b70de55b75d98ec31587e7711ec003202b9289db60578
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8a1217ca2660fd80f2bf94397012aaf14b37d5a460722b816d473db7ae75ae39a6fe72d44491ab3f1133aaca4d470707ca0c1be155b44e40ba9940d025d4783
|
7
|
+
data.tar.gz: f2da86452dba12cf84763701dd25f6ed198a5bc13f0a8361ca1960caf7044a7fd2c9b1a4643d832cab29f4ec24dba7002db511e1d79d862b6c5da1fb70774600
|
@@ -12,12 +12,13 @@ module ImmosquareExtensions
|
|
12
12
|
:layout => false,
|
13
13
|
:locals => {
|
14
14
|
:email => email,
|
15
|
-
:formats => get_email_formats(email)
|
16
|
-
name = format.split("/").last
|
17
|
-
{:name => name, :url => url_for(:part => name)}
|
18
|
-
end,
|
15
|
+
:formats => get_email_formats(email),
|
19
16
|
:locales => I18n.available_locales.map do |locale|
|
20
|
-
{
|
17
|
+
{
|
18
|
+
:name => locale,
|
19
|
+
:url => url_for(:mailer_locale => locale, :part => params[:part].presence),
|
20
|
+
:css_class => (params[:mailer_locale].present? && params[:mailer_locale] == locale.to_s) || (params[:mailer_locale].blank? && I18n.locale == locale) ? "" : "text-body"
|
21
|
+
}
|
21
22
|
end
|
22
23
|
},
|
23
24
|
:inline => <<~HTML
|
@@ -82,7 +83,7 @@ module ImmosquareExtensions
|
|
82
83
|
<th>Formats:</th>
|
83
84
|
<td>
|
84
85
|
<% formats.each do |format| %>
|
85
|
-
<%= link_to(format[:name], format[:url]) %>
|
86
|
+
<%= link_to(format[:name], format[:url], :class => "text-decoration-none hover-primary" + " " + format[:css_class]) %>
|
86
87
|
<%= content_tag(:span, " | ") unless format == formats.last %>
|
87
88
|
<% end %>
|
88
89
|
</td>
|
@@ -93,7 +94,8 @@ module ImmosquareExtensions
|
|
93
94
|
<th>Locale:</th>
|
94
95
|
<td>
|
95
96
|
<% locales.each do |locale| %>
|
96
|
-
<%= link_to(locale[:name], locale[:url]) %>
|
97
|
+
<%= link_to(locale[:name], locale[:url], :class => "text-decoration-none hover-primary" + " " + locale[:css_class]) %>
|
98
|
+
<%= content_tag(:span, " | ") unless locale == locales.last %>
|
97
99
|
<% end %>
|
98
100
|
</td>
|
99
101
|
</tr>
|
@@ -137,11 +139,14 @@ module ImmosquareExtensions
|
|
137
139
|
|
138
140
|
def display_email_preview(email)
|
139
141
|
begin
|
140
|
-
|
141
|
-
part_format
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
formats = get_email_formats(email)
|
143
|
+
part_format = formats.find {|f| f[:selected] }
|
144
|
+
part_type = Mime::Type.lookup(part_format[:content_type])
|
145
|
+
|
146
|
+
raise("No email part found for content type: #{part_format[:content_type]}") if !(part = find_part(email, part_type))
|
147
|
+
|
148
|
+
body = part.respond_to?(:decoded) ? part.decoded : part
|
149
|
+
part_format[:name] == "html" ? body.html_safe : simple_format(body)
|
145
150
|
rescue StandardError => e
|
146
151
|
"Error displaying email: #{e.message}"
|
147
152
|
end
|
@@ -151,57 +156,52 @@ module ImmosquareExtensions
|
|
151
156
|
|
152
157
|
|
153
158
|
##============================================================##
|
154
|
-
##
|
155
|
-
##
|
156
|
-
##
|
157
|
-
##
|
159
|
+
## find_first_mime_type is a method from the Mail gem for module
|
160
|
+
## Mail Message
|
161
|
+
## ----------------
|
162
|
+
## https://github.com/mikel/mail/blob/master/lib/mail/message.rb#L1938
|
158
163
|
##============================================================##
|
159
|
-
def
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
if email.header_fields.nil? || email.header_fields.empty?
|
164
|
-
["text/plain"]
|
165
|
-
else
|
166
|
-
header = email.header_fields.find {|header| header.name == "Content-Type" }
|
167
|
-
[header.nil? || !content_types_allowed.include?(header.value) ? "text/plain" : header.value]
|
168
|
-
end
|
169
|
-
else
|
170
|
-
content_types.map do |content_type|
|
171
|
-
content_type = content_type.split(";").first
|
172
|
-
content_types_allowed.include?(content_type) ? content_type : nil
|
173
|
-
end
|
174
|
-
.compact.sort_by do |content_type|
|
175
|
-
content_types_allowed.index(content_type)
|
164
|
+
def find_preferred_part(email, *formats)
|
165
|
+
formats.each do |format|
|
166
|
+
if (part = email.find_first_mime_type(format))
|
167
|
+
return part
|
176
168
|
end
|
177
169
|
end
|
170
|
+
|
171
|
+
email if formats.any? {|f| email.mime_type == f }
|
178
172
|
end
|
179
173
|
|
180
174
|
##============================================================##
|
181
|
-
##
|
175
|
+
## find_part use the find_first_mime_type method from the Mail
|
176
|
+
## gem for module Mail Message
|
182
177
|
##============================================================##
|
183
|
-
def
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
else
|
189
|
-
header = email.header_fields.find {|header| header.name == "Content-Type" }
|
190
|
-
content_type = header.nil? ? "text/plain" : header.value
|
191
|
-
end
|
192
|
-
[{
|
193
|
-
:content_type => content_type,
|
194
|
-
:body => content_type == "text/plain" ? simple_format(email.body.decoded) : email.body.decoded
|
195
|
-
}]
|
196
|
-
else
|
197
|
-
email.parts.map do |part|
|
198
|
-
content_type = part.content_type.split(";").first
|
199
|
-
{
|
200
|
-
:content_type => content_type,
|
201
|
-
:body => content_type == "text/plain" ? simple_format(part.body.decoded) : part.body.decoded
|
202
|
-
}
|
203
|
-
end
|
178
|
+
def find_part(email, format)
|
179
|
+
if (part = email.find_first_mime_type(format))
|
180
|
+
part
|
181
|
+
elsif email.mime_type == format
|
182
|
+
email
|
204
183
|
end
|
205
184
|
end
|
185
|
+
|
186
|
+
##============================================================##
|
187
|
+
## Return email formats
|
188
|
+
##============================================================##
|
189
|
+
def get_email_formats(email)
|
190
|
+
part = find_preferred_part(email, Mime[:html], Mime[:text])
|
191
|
+
formats = []
|
192
|
+
formats =
|
193
|
+
if email.html_part && email.text_part
|
194
|
+
selected = params[:part].present? && params[:part] == "text" ? "text" : "html"
|
195
|
+
[
|
196
|
+
{:name => "html", :content_type => "text/html", :url => url_for(:part => "html", :mailer_locale => params[:mailer_locale].presence), :selected => selected == "html", :css_class => selected == "html" ? "" : "text-body"},
|
197
|
+
{:name => "text", :content_type => "text/plain", :url => url_for(:part => "text", :mailer_locale => params[:mailer_locale].presence), :selected => selected == "text", :css_class => selected == "text" ? "" : "text-body"}
|
198
|
+
]
|
199
|
+
elsif part
|
200
|
+
data = part.content_type.split(";").first.split("/").last
|
201
|
+
[
|
202
|
+
{:name => data, :content_type => "text/#{data}", :url => url_for(:part => data, :mailer_locale => params[:mailer_locale].presence), :selected => true, :css_class => ""}
|
203
|
+
]
|
204
|
+
end
|
205
|
+
end
|
206
206
|
end
|
207
207
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: immosquare-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IMMO SQUARE
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode_utils
|