osa 0.2.2 → 0.2.3
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/Gemfile.lock +1 -1
- data/lib/osa/scripts/dashboard_server.rb +2 -1
- data/lib/osa/scripts/scan_junk_folder.rb +22 -8
- data/lib/osa/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: aa725966ad372fd1be8d324225544fe3d41075433fc2c6f5832f915600774b0d
|
4
|
+
data.tar.gz: 1ecdbe1fc443c62db5d611cbcceacb5c88e9c0777df2e0ae17a1b720f07bce18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38eef44a8c56008bc86611994979f717b6dd029f03df021f9720ae6769a3d8be48bd6f2330d1f273867c8c295aa30fcd534949f1f0424a09082ec662ea942ebf
|
7
|
+
data.tar.gz: 0ea2067bb74bdea9220adc2fe8c0e7c53399b2e3340a5342b7ee463a6a3eaabb4c5f87a5397ca4da95182c47fa76e5bd450ea613a688321d64f0b3f5cb784009
|
data/Gemfile.lock
CHANGED
@@ -45,7 +45,8 @@ class DashboardServer < Sinatra::Base
|
|
45
45
|
week_reported = reports.where('reported_at > ?', week).count
|
46
46
|
month = DateTime.now - 30.days
|
47
47
|
month_reported = reports.where('reported_at > ?', month).count
|
48
|
-
domains = reports.select(:sender).distinct.map { |e| e.sender.split('@', 2)[1] }
|
48
|
+
domains = reports.select(:sender).distinct.map { |e| e.sender.split('@', 2)[1] }
|
49
|
+
domains.uniq!
|
49
50
|
|
50
51
|
json total_reported: total_reported,
|
51
52
|
today_reported: today_reported,
|
@@ -25,7 +25,7 @@ def extract_email_address(mail)
|
|
25
25
|
email_address = mail['sender']['emailAddress']['address']
|
26
26
|
return email_address unless email_address.nil?
|
27
27
|
|
28
|
-
#
|
28
|
+
# The SMTP From header might be misformatted and the email address is
|
29
29
|
# parsed as part of the name by Outlook. Try to extract the email address
|
30
30
|
# from the name.
|
31
31
|
sender_name = mail['sender']['emailAddress']['name']
|
@@ -34,6 +34,13 @@ def extract_email_address(mail)
|
|
34
34
|
sender_name.scan(/<(.+@.+)>/).first&.first
|
35
35
|
end
|
36
36
|
|
37
|
+
def report(mail, context, email_address)
|
38
|
+
puts "forwarding spam from #{email_address}"
|
39
|
+
context.graph_client.forward_mail_as_attachment(mail['id'], context.config.spamcop_report_email)
|
40
|
+
puts "deleting spam from #{email_address}"
|
41
|
+
context.graph_client.delete_mail(mail['id'])
|
42
|
+
end
|
43
|
+
|
37
44
|
while continue
|
38
45
|
mails = context.graph_client.mails(context.config.junk_folder_id)
|
39
46
|
continue = false
|
@@ -41,10 +48,21 @@ while continue
|
|
41
48
|
break if mails.nil?
|
42
49
|
mails['value'].each do |mail|
|
43
50
|
email_address = extract_email_address(mail)
|
51
|
+
flagged = mail['flag']['flagStatus'] == 'flagged'
|
52
|
+
|
53
|
+
# Emails without a proper email address are not properly
|
54
|
+
# handled down below. Just report the mail and skip other
|
55
|
+
# procedures.
|
56
|
+
if flagged && email_address.nil?
|
57
|
+
report(mail, context, email_address)
|
58
|
+
continue = true
|
59
|
+
next
|
60
|
+
end
|
61
|
+
|
44
62
|
next if email_address.nil?
|
63
|
+
|
45
64
|
domain = PublicSuffix.domain(email_address.split('@', 2)[1])
|
46
65
|
|
47
|
-
flagged = mail['flag']['flagStatus'] == 'flagged'
|
48
66
|
blacklist = (resolve_blacklist(mail['id'], email_address, domain, context, dns_blacklists) unless flagged)
|
49
67
|
|
50
68
|
if flagged
|
@@ -56,13 +74,9 @@ while continue
|
|
56
74
|
next
|
57
75
|
end
|
58
76
|
|
77
|
+
report(mail, context, email_address)
|
59
78
|
continue = true
|
60
79
|
|
61
|
-
puts "forwarding spam from #{email_address}"
|
62
|
-
context.graph_client.forward_mail_as_attachment(mail['id'], context.config.spamcop_report_email)
|
63
|
-
puts "deleting spam from #{email_address}"
|
64
|
-
context.graph_client.delete_mail(mail['id'])
|
65
|
-
|
66
80
|
OSA::Report.create!(sender: email_address,
|
67
81
|
sender_domain: domain,
|
68
82
|
subject: mail['subject'],
|
@@ -71,7 +85,7 @@ while continue
|
|
71
85
|
received_at: Time.iso8601(mail['receivedDateTime']),
|
72
86
|
reported_at: Time.now)
|
73
87
|
|
74
|
-
# Do not add to the blacklist if
|
88
|
+
# Do not add to the blacklist if it's blacklisted by the db (it's already present)
|
75
89
|
# or blacklisted by DNSBLs (these blacklists are only supposed to be temporary).
|
76
90
|
if flagged
|
77
91
|
is_free_provider = OSA::EmailProvider.where(value: domain).exists?
|
data/lib/osa/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moray Baruh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|