immosquare-extensions 0.1.18 → 0.1.19
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7bde52f2f31bb043f3bc29531b12dc0bb941f459e78cb173ccf70bb7ce0c104
|
4
|
+
data.tar.gz: f609ddbfeea58e034b97766633f446033b4ee8a23ac3cb769e5e26dd2df3d617
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b34d2c9c0494ae39d6e7a2a3df4f41d59be2e0a3226791def1bb53681225977988571087083bed65a9f3cbb039b2b5c9eab12af6c047013963aa6415cb11d91c
|
7
|
+
data.tar.gz: 060c67baec1b1a3bbb691fa2595fab5700990b505294bb3ff5b3c98850e2095584dfdf7e2f00aa5379d251073658648cdc4ac125dd234fdad2cd2e10b2dfbc74
|
@@ -0,0 +1,207 @@
|
|
1
|
+
module ImmosquareExtensions
|
2
|
+
module MailHelper
|
3
|
+
##============================================================##
|
4
|
+
## Inspired by:
|
5
|
+
## https://github.com/rails/rails/blob/main/railties/lib/rails/templates/rails/mailers/email.html.erb
|
6
|
+
## -------------
|
7
|
+
## Here concact with "#{}" is not working, so used
|
8
|
+
## "data:application/octet-stream;charset=utf-8;base64,"+Base64.encode64(a.body.to_s)
|
9
|
+
##============================================================##
|
10
|
+
def display_email_header_infos(email)
|
11
|
+
ApplicationController.render(
|
12
|
+
:layout => false,
|
13
|
+
:locals => {
|
14
|
+
:email => email,
|
15
|
+
:formats => get_email_formats(email).map do |format|
|
16
|
+
name = format.split("/").last
|
17
|
+
{:name => name, :url => url_for(:part => name)}
|
18
|
+
end,
|
19
|
+
:locales => I18n.available_locales.map do |locale|
|
20
|
+
{:name => locale, :url => url_for(:mailer_locale => locale)}
|
21
|
+
end
|
22
|
+
},
|
23
|
+
:inline => <<~HTML
|
24
|
+
<header>
|
25
|
+
<table>
|
26
|
+
<% if email.respond_to?(:smtp_envelope_from) && Array(email.from) != Array(email.smtp_envelope_from) %>
|
27
|
+
<tr>
|
28
|
+
<th>SMTP-From:</th>
|
29
|
+
<td><%= email.smtp_envelope_from %></td>
|
30
|
+
</tr>
|
31
|
+
<% end %>
|
32
|
+
|
33
|
+
<% if email.respond_to?(:smtp_envelope_to) && email.to != email.smtp_envelope_to %>
|
34
|
+
<tr>
|
35
|
+
<th>SMTP-To:</th>
|
36
|
+
<td><%= email.smtp_envelope_to %></td>
|
37
|
+
</tr>
|
38
|
+
<% end %>
|
39
|
+
|
40
|
+
<tr>
|
41
|
+
<th>From:</th>
|
42
|
+
<td><%= email.header["from"] %></td>
|
43
|
+
</tr>
|
44
|
+
|
45
|
+
<% if email.reply_to %>
|
46
|
+
<tr>
|
47
|
+
<th>Reply-To:</th>
|
48
|
+
<td><%= email.header["reply-to"] %></td>
|
49
|
+
</tr>
|
50
|
+
<% end %>
|
51
|
+
|
52
|
+
<tr>
|
53
|
+
<th>To:</th>
|
54
|
+
<td><%= email.header["to"] %></td>
|
55
|
+
</tr>
|
56
|
+
|
57
|
+
<% if email.cc %>
|
58
|
+
<tr>
|
59
|
+
<th>CC:</th>
|
60
|
+
<td><%= email.header["cc"] %></td>
|
61
|
+
</tr>
|
62
|
+
<% end %>
|
63
|
+
|
64
|
+
<% if email.bcc %>
|
65
|
+
<tr>
|
66
|
+
<th>BCC:</th>
|
67
|
+
<td><%= email.header["bcc"] %></td>
|
68
|
+
</tr>
|
69
|
+
<% end %>
|
70
|
+
|
71
|
+
<tr>
|
72
|
+
<th>Date:</th>
|
73
|
+
<td><%= Time.current.rfc2822 %></td>
|
74
|
+
</tr>
|
75
|
+
|
76
|
+
<tr>
|
77
|
+
<th>Subject:</th>
|
78
|
+
<td><%= email.subject %></td>
|
79
|
+
</tr>
|
80
|
+
|
81
|
+
<tr>
|
82
|
+
<th>Formats:</th>
|
83
|
+
<td>
|
84
|
+
<% formats.each do |format| %>
|
85
|
+
<%= link_to(format[:name], format[:url]) %>
|
86
|
+
<%= content_tag(:span, " | ") unless format == formats.last %>
|
87
|
+
<% end %>
|
88
|
+
</td>
|
89
|
+
</tr>
|
90
|
+
|
91
|
+
<% if locales.size > 1 %>
|
92
|
+
<tr>
|
93
|
+
<th>Locale:</th>
|
94
|
+
<td>
|
95
|
+
<% locales.each do |locale| %>
|
96
|
+
<%= link_to(locale[:name], locale[:url]) %>
|
97
|
+
<% end %>
|
98
|
+
</td>
|
99
|
+
</tr>
|
100
|
+
<% end %>
|
101
|
+
|
102
|
+
<% if !(email.attachments.nil? || email.attachments.empty?) %>
|
103
|
+
<tr>
|
104
|
+
<th>Attachments:</th>
|
105
|
+
<td>
|
106
|
+
<% email.attachments.each do |a| %>
|
107
|
+
<% filename = a.respond_to?(:original_filename) ? a.original_filename : a.filename %>
|
108
|
+
<%= link_to filename, "data:application/octet-stream;charset=utf-8;base64,"+Base64.encode64(a.body.to_s), download: filename %>
|
109
|
+
<% end %>
|
110
|
+
</td>
|
111
|
+
</tr>
|
112
|
+
<% end %>
|
113
|
+
|
114
|
+
<% if !(email.header_fields.nil? || email.header_fields.empty?) %>
|
115
|
+
<tr>
|
116
|
+
<th class="align-top">Headers:</th>
|
117
|
+
<td>
|
118
|
+
<details>
|
119
|
+
<summary>Show all headers</summary>
|
120
|
+
<table>
|
121
|
+
<% email.header_fields.each do |field| %>
|
122
|
+
<tr>
|
123
|
+
<th><%= field.name %>:</th>
|
124
|
+
<td><%= field.value %></td>
|
125
|
+
</tr>
|
126
|
+
<% end %>
|
127
|
+
</table>
|
128
|
+
</details>
|
129
|
+
</td>
|
130
|
+
</tr>
|
131
|
+
<% end %>
|
132
|
+
</table>
|
133
|
+
</header>
|
134
|
+
HTML
|
135
|
+
)
|
136
|
+
end
|
137
|
+
|
138
|
+
def display_email_preview(email)
|
139
|
+
begin
|
140
|
+
availabe_formats = get_email_formats(email)
|
141
|
+
part_format = params[:part].present? ? availabe_formats.find {|format| format.end_with?(params[:part]) } : availabe_formats.first
|
142
|
+
part_format = availabe_formats.first if part_format.nil?
|
143
|
+
parts = get_email_parts(email)
|
144
|
+
parts.find {|part| part[:content_type] == part_format }[:body]
|
145
|
+
rescue StandardError => e
|
146
|
+
"Error displaying email: #{e.message}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
|
153
|
+
##============================================================##
|
154
|
+
## Return email formats
|
155
|
+
## ["text/plain", "text/html"]
|
156
|
+
## ["text/html"]
|
157
|
+
## ["text/plain"]
|
158
|
+
##============================================================##
|
159
|
+
def get_email_formats(email)
|
160
|
+
content_types = email.parts.map(&:content_type)
|
161
|
+
content_types_allowed = ["text/html", "text/plain"]
|
162
|
+
if !email.multipart? || content_types.empty?
|
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)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
##============================================================##
|
181
|
+
## Return email parts with content type and body
|
182
|
+
##============================================================##
|
183
|
+
def get_email_parts(email)
|
184
|
+
parts_type = email.parts.map(&:content_type)
|
185
|
+
if !email.multipart? || parts_type.empty?
|
186
|
+
if email.header_fields.nil? || email.header_fields.empty?
|
187
|
+
content_type = "text/plain"
|
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
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
@@ -3,6 +3,8 @@ require_relative "immosquare-extensions/array"
|
|
3
3
|
require_relative "immosquare-extensions/file"
|
4
4
|
require_relative "immosquare-extensions/hash"
|
5
5
|
require_relative "immosquare-extensions/string"
|
6
|
+
require_relative "immosquare-extensions/helpers/mail_helper"
|
7
|
+
require_relative "immosquare-extensions/railtie" if defined?(Rails)
|
6
8
|
|
7
9
|
module ImmosquareExtensions
|
8
10
|
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.19
|
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-
|
11
|
+
date: 2024-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode_utils
|
@@ -38,6 +38,8 @@ files:
|
|
38
38
|
- lib/immosquare-extensions/array.rb
|
39
39
|
- lib/immosquare-extensions/file.rb
|
40
40
|
- lib/immosquare-extensions/hash.rb
|
41
|
+
- lib/immosquare-extensions/helpers/mail_helper.rb
|
42
|
+
- lib/immosquare-extensions/railtie.rb
|
41
43
|
- lib/immosquare-extensions/shared_methods.rb
|
42
44
|
- lib/immosquare-extensions/string.rb
|
43
45
|
- lib/immosquare-extensions/version.rb
|
@@ -60,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
62
|
- !ruby/object:Gem::Version
|
61
63
|
version: '0'
|
62
64
|
requirements: []
|
63
|
-
rubygems_version: 3.
|
65
|
+
rubygems_version: 3.5.9
|
64
66
|
signing_key:
|
65
67
|
specification_version: 4
|
66
68
|
summary: Utility extensions for Ruby core classes
|