simple_mailing_list 0.2.0 → 0.3.0
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/example/config_example.ja.yaml +19 -0
- data/example/config_example.yaml +12 -0
- data/lib/simple_mailing_list/configfile.rb +4 -0
- data/lib/simple_mailing_list/main.rb +49 -18
- data/lib/simple_mailing_list/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d8f533e87e480112035f53b5d344db916d0321a
|
4
|
+
data.tar.gz: 97dbe991ad2ce2ec4658d17f648b9784857d1554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89dc8c260cceee29e6b83f697e8c7f9b2b1ba392ba3a0570c9795442a99cb25b0092b2462294d02f69dedde9d6f4e6e000a7cfe979293b31070c5e4e4dbdf3a2
|
7
|
+
data.tar.gz: 1bfed8edcbaea036b2ce9dfe438738d9c90d95af95d6b67957d397ec397abc946ed0193329b6390ed715c05e0595d383c137c76f3c40d5a840d8d104e82c2a3f
|
@@ -125,3 +125,22 @@ forward:
|
|
125
125
|
# forward@mail.example.com に送ると登録者全員に、
|
126
126
|
# forward(数値)@mail.example.com に送ると
|
127
127
|
# 該当学年の登録者のみにメールを転送する。
|
128
|
+
|
129
|
+
# メール転送に失敗/成功した際に送る報告メール。
|
130
|
+
# 省略した場合は、報告メールを送らない。
|
131
|
+
forward_fail_subject: メール配信の認証に失敗しました
|
132
|
+
forward_fail_body: |
|
133
|
+
「{{subject}}」
|
134
|
+
のメール配信認証に失敗しました。
|
135
|
+
次のような原因が考えられます:
|
136
|
+
・配信が許可されていないメールアドレスから配信しようとした。
|
137
|
+
・認証コードが必要な設定にもかかわらず認証コードが入力されていない。
|
138
|
+
・危険性のあるファイルを添付している。
|
139
|
+
forward_success_subject: メール配信が完了しました
|
140
|
+
forward_success_body: |
|
141
|
+
「{{subject}}」
|
142
|
+
のメール配信が終了しました。
|
143
|
+
全部で{{count}}通のメールが配信されました。
|
144
|
+
|
145
|
+
# 転送メールの「reply_to」欄に設定するメールアドレス。
|
146
|
+
reply_to_address: noreply_smltest@mail.nodai-2-h.ed.jp
|
data/example/config_example.yaml
CHANGED
@@ -87,3 +87,15 @@ forward:
|
|
87
87
|
options: { grade: 2 }
|
88
88
|
- address: forward3@mail.example.com
|
89
89
|
options: { grade: 3 }
|
90
|
+
|
91
|
+
forward_fail_subject: "Mail forwarding Error!"
|
92
|
+
forward_fail_body: |
|
93
|
+
failed forwarding mail
|
94
|
+
"{{subject}}"
|
95
|
+
forward_success_subject: "Mail forwarding successed."
|
96
|
+
forward_success_body: |
|
97
|
+
successed forwarding mail
|
98
|
+
"{{subject}}"
|
99
|
+
{{count}} mails have been sent.
|
100
|
+
|
101
|
+
reply_to_address: noreply_smltest@mail.nodai-2-h.ed.jp
|
@@ -56,6 +56,10 @@ module SimpleMailingList
|
|
56
56
|
@delete_success_body = config["delete_success_body"] || ""
|
57
57
|
|
58
58
|
@forward = config["forward"] || []
|
59
|
+
@forward_fail_subject = config["forward_fail_subject"]
|
60
|
+
@forward_fail_body = config["forward_fail_body"]
|
61
|
+
@forward_success_subject = config["forward_success_subject"]
|
62
|
+
@forward_success_body = config["forward_success_body"]
|
59
63
|
@reply_to_address = config["reply_to_address"]
|
60
64
|
|
61
65
|
# database
|
@@ -62,7 +62,7 @@ module SimpleMailingList
|
|
62
62
|
mode: "register",
|
63
63
|
options: JSON.generate(regisiter_options)
|
64
64
|
).save!
|
65
|
-
|
65
|
+
|
66
66
|
mail = create_mail(
|
67
67
|
to: address,
|
68
68
|
subject: @register_confirm_subject,
|
@@ -90,7 +90,7 @@ module SimpleMailingList
|
|
90
90
|
mode: "delete",
|
91
91
|
options: "{}"
|
92
92
|
).save!
|
93
|
-
|
93
|
+
|
94
94
|
mail = create_mail(
|
95
95
|
to: address,
|
96
96
|
subject: @delete_confirm_subject,
|
@@ -110,11 +110,11 @@ module SimpleMailingList
|
|
110
110
|
subject = mail.subject.to_s
|
111
111
|
body = mail.body ? mail.body.decoded : ""
|
112
112
|
body += mail.text_part.decoded.to_s if mail.text_part
|
113
|
-
|
113
|
+
|
114
114
|
Confirmation.where(mail_address: address).each do |confirmation|
|
115
115
|
check_code = confirmation.check_code
|
116
116
|
next unless subject.index(check_code) || body.index(check_code)
|
117
|
-
|
117
|
+
|
118
118
|
confirm_options = {}
|
119
119
|
subject_text, body_text = case confirmation.mode
|
120
120
|
when "register"
|
@@ -129,7 +129,7 @@ module SimpleMailingList
|
|
129
129
|
else
|
130
130
|
next
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
create_mail(
|
134
134
|
to: address,
|
135
135
|
subject: subject_text,
|
@@ -143,7 +143,7 @@ module SimpleMailingList
|
|
143
143
|
confirmation.destroy
|
144
144
|
return true
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
return false
|
148
148
|
end
|
149
149
|
|
@@ -178,12 +178,14 @@ module SimpleMailingList
|
|
178
178
|
if @permitted_users
|
179
179
|
permitted_user = @permitted_users.find do |user|
|
180
180
|
(!user["address"] || user["address"] == address) &&
|
181
|
-
(!user["check_code"] || subject.index(["check_code"]))
|
181
|
+
(!user["check_code"] || subject.encode("utf-8").index(user["check_code"]))
|
182
|
+
end
|
183
|
+
return forward_mail_failed(mail, filename) unless permitted_user
|
184
|
+
if permitted_user["check_code"]
|
185
|
+
subject = subject.encode("utf-8").sub(permitted_user["check_code"], "")
|
182
186
|
end
|
183
|
-
return true unless permitted_user
|
184
|
-
subject.sub!(permitted_user["check_code"], "") if permitted_user["check_code"]
|
185
187
|
elsif @registered_user_only
|
186
|
-
return
|
188
|
+
return forward_mail_failed(mail, filename) unless User.find_by(mail_address: address)
|
187
189
|
end
|
188
190
|
danger_ext = /\.(exe|com|bat|cmd|vbs|vbe|js|jse|wsf|wsh|msc|jar|hta|scr|cpl|lnk)$/i
|
189
191
|
if mail.has_attachments?
|
@@ -192,20 +194,21 @@ module SimpleMailingList
|
|
192
194
|
end
|
193
195
|
if attachment
|
194
196
|
@log.warn("Contains danger attachment![#{attachment}@#{File.basename(filename)}]")
|
195
|
-
return
|
197
|
+
return forward_mail_failed(mail, filename)
|
196
198
|
end
|
197
199
|
end
|
198
|
-
|
200
|
+
|
199
201
|
sendmail = create_forward_mail(mail, subject)
|
200
|
-
|
202
|
+
|
201
203
|
users = User.where(enabled: 1).to_a.select do |user|
|
202
204
|
user_options = JSON.parse(user.options)
|
203
205
|
!forward_options.keys.any?{ |key| forward_options[key] != user_options[key] }
|
204
206
|
end
|
205
207
|
users.map! { |user| user.mail_address }
|
208
|
+
users.unshift(address)
|
206
209
|
users.uniq!
|
207
|
-
|
208
|
-
|
210
|
+
|
211
|
+
@log.info "Sending start."
|
209
212
|
domains = { "???" => [] }
|
210
213
|
users.each do |user|
|
211
214
|
domain = user.match(/@([^@]+)$/) ? $1 : "???"
|
@@ -213,8 +216,7 @@ module SimpleMailingList
|
|
213
216
|
domains[domain].push(user)
|
214
217
|
end
|
215
218
|
max = domains.values.map(&:size).max
|
216
|
-
|
217
|
-
0.upto(max) do |i|
|
219
|
+
max.times do |i|
|
218
220
|
time = Time.now
|
219
221
|
domains.each_value do |address_array|
|
220
222
|
mail_address = address_array[i]
|
@@ -237,7 +239,36 @@ module SimpleMailingList
|
|
237
239
|
next if Time.now - time > @sleep_time2 || i+1 == max
|
238
240
|
sleep time - Time.now + @sleep_time2
|
239
241
|
end
|
240
|
-
|
242
|
+
|
243
|
+
@log.info "Forward mails to #{users.size} user#{users.size > 0 ? 's' : ''}."
|
244
|
+
if @forward_success_subject && @forward_success_body
|
245
|
+
options = {
|
246
|
+
"subject" => subject.encode("utf-8"),
|
247
|
+
"count" => users.size
|
248
|
+
}
|
249
|
+
reportmail = create_mail(
|
250
|
+
to: address,
|
251
|
+
subject: @forward_success_subject,
|
252
|
+
body: @forward_success_body,
|
253
|
+
options: options
|
254
|
+
).deliver
|
255
|
+
end
|
256
|
+
move_mail_file(filename, "forward")
|
257
|
+
return true
|
258
|
+
end
|
259
|
+
|
260
|
+
def forward_mail_failed(mail, filename)
|
261
|
+
return true unless @forward_fail_subject && @forward_fail_body
|
262
|
+
|
263
|
+
options = {
|
264
|
+
"subject" => mail.subject.to_s.encode("utf-8")
|
265
|
+
}
|
266
|
+
sendmail = create_mail(
|
267
|
+
to: Array(mail.from).first.to_s,
|
268
|
+
subject: @forward_fail_subject,
|
269
|
+
body: @forward_fail_body,
|
270
|
+
options: options
|
271
|
+
).deliver
|
241
272
|
move_mail_file(filename, "forward")
|
242
273
|
return true
|
243
274
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_mailing_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nodai2hITC
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04
|
11
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|