osa 0.1.1 → 0.1.2
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/README.md +9 -14
- data/exe/osa +1 -3
- data/lib/osa/clients/ms_graph_client.rb +2 -2
- data/lib/osa/scripts/scan_junk_folder.rb +7 -2
- data/lib/osa/services/setup_service.rb +1 -2
- data/lib/osa/version.rb +1 -1
- metadata +2 -3
- data/lib/osa/scripts/scan_report_folder.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 257c4fb16627c69c705da1ca2c95fe5b120f7706cbbacec3cb5b54cec8aa4e97
|
4
|
+
data.tar.gz: 003041712c82eeb6d9e686de02a36372517dfda89c5d1b4ca58920efc1a06cfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 904c9b9e2db9f64c0bdab038a3fce8cb5f294ed7c38f1a25ad50f4df769456880ac7e3a17df7dcf6a101f332c836f821edf7e992a07a6ce1ec4b6c1604862407
|
7
|
+
data.tar.gz: 8ee576b4dcb8c7e78742328fbc3921ac7f17a7d56b85bf2474feb251cdcc8d6a5deda969d2219a40815d8f14075d4fdae5fcd9c400abbcc1b0974ee8ba7eb782
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,17 +4,18 @@
|
|
4
4
|
|
5
5
|
### Basics
|
6
6
|
|
7
|
-
OSA
|
8
|
-
|
9
|
-
folder.
|
7
|
+
OSA asks you to choose your junk folder on first configuration. After the folder is selected, the `scan-junk` command
|
8
|
+
allows you to scan the folder to report and delete any unwanted spam. It's important to chose the actual junk folder
|
9
|
+
so your Outlook spam filters does not get broken. However, OSA will work with any folder. The processing for each email
|
10
|
+
uses the following rules:
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
1. If the email is flagged, the email is reported to Spamcop, then deleted and the sender is blacklisted.
|
13
|
+
2. If the email's sender is blacklisted, the email is reported to Spamcop, then deleted.
|
14
|
+
3. Otherwise, the email is left untouched.
|
14
15
|
|
15
|
-
*OSA will not touch any folder beside
|
16
|
+
*OSA will not touch any folder beside the folder you've chosen.*
|
16
17
|
|
17
|
-
*It's the user's responsibility to move junk mails to the
|
18
|
+
*It's the user's responsibility to move junk mails to the junk folder and flag them to build up the blacklist.*
|
18
19
|
|
19
20
|
### The blacklist
|
20
21
|
|
@@ -58,12 +59,6 @@ osa setup
|
|
58
59
|
|
59
60
|
Each time you run this command, your previous configuration will be erased, except for your blacklist.
|
60
61
|
|
61
|
-
Process your report folder:
|
62
|
-
|
63
|
-
```sh
|
64
|
-
osa scan-report
|
65
|
-
```
|
66
|
-
|
67
62
|
Process your junk folder:
|
68
63
|
|
69
64
|
```sh
|
data/exe/osa
CHANGED
@@ -12,9 +12,7 @@ when 'login'
|
|
12
12
|
OSA::AuthService.login(OSA::Config.first || OSA::Config.new)
|
13
13
|
when 'scan-junk'
|
14
14
|
require 'osa/scripts/scan_junk_folder'
|
15
|
-
when 'scan-report'
|
16
|
-
require 'osa/scripts/scan_report_folder'
|
17
15
|
else
|
18
|
-
$stderr.puts "Usage: #{File.basename($0)} [setup|login|scan-junk
|
16
|
+
$stderr.puts "Usage: #{File.basename($0)} [setup|login|scan-junk]"
|
19
17
|
exit 1
|
20
18
|
end
|
@@ -33,11 +33,11 @@ module OSA
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def folders
|
36
|
-
Paginated.new(@authenticated.get('/v1.0/me/mailFolders'),
|
36
|
+
Paginated.new(@authenticated.get('/v1.0/me/mailFolders'), @authenticated)
|
37
37
|
end
|
38
38
|
|
39
39
|
def mails(folder_id)
|
40
|
-
Paginated.new(@authenticated.get("/v1.0/me/mailFolders/#{folder_id}/messages"),
|
40
|
+
Paginated.new(@authenticated.get("/v1.0/me/mailFolders/#{folder_id}/messages"), @authenticated)
|
41
41
|
end
|
42
42
|
|
43
43
|
def raw_mail(mail_id)
|
@@ -18,8 +18,13 @@ while continue
|
|
18
18
|
next if email_address.nil?
|
19
19
|
domain = PublicSuffix.domain(email_address.split('@', 2)[1])
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
flagged = mail['flag']['flagStatus'] == 'flagged'
|
22
|
+
blacklisted = nil
|
23
|
+
blacklisted = OSA::Blacklist.where(value: email_address).or(OSA::Blacklist.where(value: domain)).exists? unless flagged
|
24
|
+
|
25
|
+
if flagged
|
26
|
+
puts "Email from #{email_address} is flagged, reporting and deleting"
|
27
|
+
elsif blacklisted
|
23
28
|
puts "#{email_address} is blacklisted, reporting and deleting"
|
24
29
|
else
|
25
30
|
puts "Skipping mail from #{email_address}, its not blacklisted"
|
@@ -18,10 +18,9 @@ module OSA
|
|
18
18
|
}.to_h
|
19
19
|
prompt = TTY::Prompt.new
|
20
20
|
junk_folder_id = prompt.select('Select junk folder:', choices)
|
21
|
-
report_folder_id = prompt.select('Select report folder:', choices)
|
22
21
|
spamcop_email = prompt.ask('Spamcop report email:') { |q| q.validate :email }
|
23
22
|
|
24
|
-
config.update! junk_folder_id: junk_folder_id,
|
23
|
+
config.update! junk_folder_id: junk_folder_id, spamcop_report_email: spamcop_email
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moray Baruh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -110,7 +110,6 @@ files:
|
|
110
110
|
- lib/osa/migrations/00003_create_config.rb
|
111
111
|
- lib/osa/migrations/free-email-providers.txt
|
112
112
|
- lib/osa/scripts/scan_junk_folder.rb
|
113
|
-
- lib/osa/scripts/scan_report_folder.rb
|
114
113
|
- lib/osa/services/auth_service.rb
|
115
114
|
- lib/osa/services/setup_service.rb
|
116
115
|
- lib/osa/util/constants.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'uri'
|
3
|
-
require 'public_suffix'
|
4
|
-
require 'osa/util/db'
|
5
|
-
require 'osa/util/context'
|
6
|
-
|
7
|
-
context = OSA::Context.new
|
8
|
-
|
9
|
-
loop do
|
10
|
-
mails = context.graph_client.mails(context.config.report_folder_id)
|
11
|
-
break if mails['value'].empty?
|
12
|
-
mails['value'].each do |mail|
|
13
|
-
email_address = mail['sender']['emailAddress']['address']
|
14
|
-
|
15
|
-
puts "forwarding spam from #{email_address}"
|
16
|
-
context.graph_client.forward_mail_as_attachment(mail['id'], context.config.spamcop_report_email)
|
17
|
-
puts "deleting spam from #{email_address}"
|
18
|
-
context.graph_client.delete_mail(mail['id'])
|
19
|
-
|
20
|
-
next if email_address.nil?
|
21
|
-
domain = PublicSuffix.domain(email_address.split('@', 2)[1])
|
22
|
-
|
23
|
-
is_free_provider = OSA::EmailProvider.where(value: domain).exists?
|
24
|
-
if is_free_provider
|
25
|
-
puts "#{email_address} is using a free provider, blacklisting full address"
|
26
|
-
OSA::Blacklist.find_or_create_by(value: email_address).save!
|
27
|
-
else
|
28
|
-
puts "Adding #{domain} to blacklist"
|
29
|
-
OSA::Blacklist.find_or_create_by(value: domain).save!
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|