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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3bc9c2b204260bd0cecd1650fdbfca0676c53e6e44c59aef8926caf9a5f0246
4
- data.tar.gz: f32d6566bc6195847fc12fe680f8c22e6cbfe91f587bc7a35937efb1582eaccc
3
+ metadata.gz: aa725966ad372fd1be8d324225544fe3d41075433fc2c6f5832f915600774b0d
4
+ data.tar.gz: 1ecdbe1fc443c62db5d611cbcceacb5c88e9c0777df2e0ae17a1b720f07bce18
5
5
  SHA512:
6
- metadata.gz: 76462c72b811ecb6b2224725ec954aa3ff3c6d2fc99a4cc91ae66698d72de709c740683ce6c4690095853199c7ef67c836ddc0bf6c0d3c4eb33751ee0fec3058
7
- data.tar.gz: f4e79f61caa68f2c1ecd646ffa3d127070addf334f827bb33066bfdefc1e44f8b2986b6983c120c94867fa907e65184fd679ef73ad0eaa6b1b34f49956d5393d
6
+ metadata.gz: 38eef44a8c56008bc86611994979f717b6dd029f03df021f9720ae6769a3d8be48bd6f2330d1f273867c8c295aa30fcd534949f1f0424a09082ec662ea942ebf
7
+ data.tar.gz: 0ea2067bb74bdea9220adc2fe8c0e7c53399b2e3340a5342b7ee463a6a3eaabb4c5f87a5397ca4da95182c47fa76e5bd450ea613a688321d64f0b3f5cb784009
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- osa (0.2.2)
4
+ osa (0.2.3)
5
5
  activerecord (~> 6.0)
6
6
  faraday (~> 1.1)
7
7
  mail (~> 2.7.1)
@@ -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] }.uniq
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
- # Sometimes the SMTP From header is misformatted and the email address is
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 the it's blacklisted by the db (it's already present)
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module OSA
3
- VERSION = '0.2.2'
3
+ VERSION = '0.2.3'
4
4
  end
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.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: 2021-03-22 00:00:00.000000000 Z
11
+ date: 2022-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord