Skip to content

Commit f14196e

Browse files
committed
alert for spam mails
1 parent 3819c93 commit f14196e

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

lib/helpers.rb

+5
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ def surround_urls_with_a_tag(text, urls)
128128
result + h(text)
129129
end
130130

131+
def spam?(mail)
132+
spam = [*mail.header['X-Spam']]
133+
spam.any? {|v| v.value.upcase == 'YES' }
134+
end
135+
131136
def virus_detected?(mail)
132137
virus = [*mail.header['X-Virus']]
133138
return if virus.empty?

public/css/style.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ div.footer{
5252
padding:2pt;
5353
}
5454

55-
.mail-virus {
55+
.mail-alert {
5656
background-color: #dc3545;
5757
color: #ffffff;
5858
}

views/mail.rhtml

+21-13
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
mail <%= h(mailnum) %> was not found.
44
<% else %>
55
<% if virus = virus_detected?(mail) %>
6-
<div class='mail-virus'>
7-
このメールにはウイルスが検出されています: <%= h(virus) %>
8-
</div>
6+
<div class='mail-virus mail-alert'>このメールにはウイルスが検出されています: <%= h(virus) %></div>
7+
<% end %>
8+
<% if spam = spam?(mail) %>
9+
<div class='mail-spam mail-alert'>このメールはスパムメールと判定されています</div>
910
<% end %>
1011
<div class='mail-actions'>
1112
<% if remote_user %>
@@ -20,7 +21,7 @@
2021
</div>
2122
<pre><%= h(get_header mail) %></pre>
2223
<hr>
23-
<pre><%= render_mail_body(mail) %></pre>
24+
<pre class='mail-body'><%= render_mail_body(mail) %></pre>
2425
<% if !mail.attachments.empty? %>
2526
<hr>
2627
<pre>添付ファイル:</pre>
@@ -32,15 +33,22 @@
3233
</a></li>
3334
<% end %>
3435
</ul>
35-
<% if virus %>
36-
<script>
37-
for(const link of document.querySelectorAll('.mail-attachments a')) {
38-
link.addEventListener('click', function(e) {
39-
if(!confirm('この添付ファイルは危険な可能性があります。本当にダウンロードしますか?')) e.preventDefault();
40-
})
41-
}
42-
</script>
43-
<% end %>
36+
<% end %>
37+
38+
<% if virus || spam %>
39+
<script>
40+
for(const link of document.querySelectorAll('.mail-body a')) {
41+
link.addEventListener('click', function(e) {
42+
if(!confirm('このリンクは危険な可能性があります。本当に開きますか?')) e.preventDefault();
43+
})
44+
}
45+
46+
for(const link of document.querySelectorAll('.mail-attachments a')) {
47+
link.addEventListener('click', function(e) {
48+
if(!confirm('この添付ファイルは危険な可能性があります。本当にダウンロードしますか?')) e.preventDefault();
49+
})
50+
}
51+
</script>
4452
<% end %>
4553
<% end %>
4654
</div>

0 commit comments

Comments
 (0)