imap_mogura 0.3.1 → 0.4.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/lib/imap_mogura/cli.rb +10 -0
- data/lib/imap_mogura/debug_util.rb +15 -0
- data/lib/imap_mogura/rules_parser/rule_elements.rb +49 -21
- data/lib/imap_mogura/version.rb +1 -1
- data/lib/imap_mogura.rb +1 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3889ab4ffaf619e936cb0a0dcf3aa0dd8eb7b5613866028c75ccc10c274f933e
|
4
|
+
data.tar.gz: e3c626aba3ffab681a53e9ccb8b8f436ba86ee3d790c373ba486b81e26daf6c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4c0fe1d4db3a23912e681cbd17a1bf13ba8b02f961a04ce44497659ec672b22b166a737bb6a258e5c6c10c7d067810064833e595063b56ba1aea25967da9378
|
7
|
+
data.tar.gz: 30a8d4e087f2c3d0aba2ca58237afba9c9fc1e6da17fef7006822dbbecce1c80164cbf7c3f02b0b95d451303e0e8003346c93bc33bf5989bb5ceee5765986302
|
data/lib/imap_mogura/cli.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require "thor"
|
4
4
|
require "base64"
|
5
5
|
|
6
|
+
require_relative "debug_util"
|
7
|
+
|
6
8
|
module ImapMogura
|
7
9
|
class CustomOptionError < Thor::Error
|
8
10
|
def initialize(msg = "Custom option error message")
|
@@ -29,6 +31,7 @@ module ImapMogura
|
|
29
31
|
option :filter_unseen, type: :boolean, default: true
|
30
32
|
option :create_directory, type: :boolean, default: true
|
31
33
|
option :dry_run, type: :boolean, default: false
|
34
|
+
option :debug, type: :boolean, default: false
|
32
35
|
def start(host)
|
33
36
|
port = options[:port]
|
34
37
|
starttls = options[:starttls]
|
@@ -41,6 +44,9 @@ module ImapMogura
|
|
41
44
|
filter_unseen = options[:filter_unseen]
|
42
45
|
create_directory = options[:create_directory]
|
43
46
|
dry_run = options[:dry_run]
|
47
|
+
debug = options[:debug]
|
48
|
+
|
49
|
+
DebugUtil.enable_debug if debug
|
44
50
|
|
45
51
|
search_keys = ["RECENT", *(["UNSEEN"] if filter_unseen)]
|
46
52
|
|
@@ -77,6 +83,7 @@ module ImapMogura
|
|
77
83
|
option :filter_only_unseen, type: :boolean, default: false
|
78
84
|
option :create_directory, type: :boolean, default: true
|
79
85
|
option :dry_run, type: :boolean, default: false
|
86
|
+
option :debug, type: :boolean, default: false
|
80
87
|
def filter(host)
|
81
88
|
port = options[:port]
|
82
89
|
starttls = options[:starttls]
|
@@ -91,9 +98,12 @@ module ImapMogura
|
|
91
98
|
filter_only_unseen = options[:filter_only_unseen]
|
92
99
|
create_directory = options[:create_directory]
|
93
100
|
dry_run = options[:dry_run]
|
101
|
+
debug = options[:debug]
|
94
102
|
|
95
103
|
raise CustomOptionError, "--all-mailbox (-a) or --target-mailbox (-b) is required" if !all_mailbox && target_mailbox.nil?
|
96
104
|
|
105
|
+
DebugUtil.enable_debug if debug
|
106
|
+
|
97
107
|
search_keys = if filter_only_unseen
|
98
108
|
["UNSEEN"]
|
99
109
|
else
|
@@ -1,10 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "../debug_util"
|
4
|
+
|
3
5
|
module ImapMogura
|
4
6
|
class RuleElement
|
5
7
|
def match?(mail)
|
6
8
|
raise NotImplementedError
|
7
9
|
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def debug_out_before_trying_rule(msg)
|
14
|
+
DebugUtil.debug "## checking if it matches the rule: #{msg}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def debug_out_if_it_matches_rule(match_result)
|
18
|
+
if match_result
|
19
|
+
DebugUtil.debug "## it matches the rule"
|
20
|
+
else
|
21
|
+
DebugUtil.debug "## it doesn't match"
|
22
|
+
end
|
23
|
+
end
|
8
24
|
end
|
9
25
|
|
10
26
|
class LogicalOperator < RuleElement
|
@@ -47,46 +63,57 @@ module ImapMogura
|
|
47
63
|
|
48
64
|
class FromMatcher < SpecialFieldMatcher
|
49
65
|
def match?(mail)
|
50
|
-
|
51
|
-
|
52
|
-
mail.from
|
53
|
-
|
54
|
-
|
55
|
-
|
66
|
+
debug_out_before_trying_rule("From #{mail.from.inspect} matches the regexp #{@regexp}")
|
67
|
+
debug_out_if_it_matches_rule(
|
68
|
+
case mail.from
|
69
|
+
when Enumerable
|
70
|
+
mail.from.any? { |address| address&.match?(@regexp) }
|
71
|
+
else
|
72
|
+
mail.from&.match?(@regexp)
|
73
|
+
end
|
74
|
+
)
|
56
75
|
end
|
57
76
|
end
|
58
77
|
|
59
78
|
class SenderMatcher < SpecialFieldMatcher
|
60
79
|
def match?(mail)
|
61
|
-
mail.sender
|
80
|
+
debug_out_before_trying_rule("Sender #{mail.sender.inspect} matches the regexp #{@regexp}")
|
81
|
+
debug_out_if_it_matches_rule(mail.sender&.match?(@regexp))
|
62
82
|
end
|
63
83
|
end
|
64
84
|
|
65
85
|
class ToMatcher < SpecialFieldMatcher
|
66
86
|
def match?(mail)
|
67
|
-
|
68
|
-
|
69
|
-
mail.to
|
70
|
-
|
71
|
-
|
72
|
-
|
87
|
+
debug_out_before_trying_rule("To #{mail.to.inspect} matches the regexp #{@regexp}")
|
88
|
+
debug_out_if_it_matches_rule(
|
89
|
+
case mail.to
|
90
|
+
when Enumerable
|
91
|
+
mail.to.any? { |address| address&.match?(@regexp) }
|
92
|
+
else
|
93
|
+
mail.to&.match?(@regexp)
|
94
|
+
end
|
95
|
+
)
|
73
96
|
end
|
74
97
|
end
|
75
98
|
|
76
99
|
class CcMatcher < SpecialFieldMatcher
|
77
100
|
def match?(mail)
|
78
|
-
|
79
|
-
|
80
|
-
mail.cc
|
81
|
-
|
82
|
-
|
83
|
-
|
101
|
+
debug_out_before_trying_rule("Cc #{mail.cc.inspect} matches the regexp #{@regexp}")
|
102
|
+
debug_out_if_it_matches_rule(
|
103
|
+
case mail.cc
|
104
|
+
when Enumerable
|
105
|
+
mail.cc.any? { |address| address&.match?(@regexp) }
|
106
|
+
else
|
107
|
+
mail.cc&.match?(@regexp)
|
108
|
+
end
|
109
|
+
)
|
84
110
|
end
|
85
111
|
end
|
86
112
|
|
87
113
|
class SubjectMatcher < SpecialFieldMatcher
|
88
114
|
def match?(mail)
|
89
|
-
mail.subject
|
115
|
+
debug_out_before_trying_rule("Subject \"#{mail.subject}\" matches the regexp #{@regexp}")
|
116
|
+
debug_out_if_it_matches_rule(mail.subject&.match?(@regexp))
|
90
117
|
end
|
91
118
|
end
|
92
119
|
|
@@ -105,7 +132,8 @@ module ImapMogura
|
|
105
132
|
end
|
106
133
|
|
107
134
|
def match?(mail)
|
108
|
-
mail.headers[@field_name]&.value
|
135
|
+
debug_out_before_trying_rule("header field \"#{@field_name}\" with value \"#{mail.headers[@field_name]&.value}\" matches the regexp #{@regexp}")
|
136
|
+
debug_out_if_it_matches_rule(mail.headers[@field_name]&.value&.match?(@regexp))
|
109
137
|
end
|
110
138
|
end
|
111
139
|
end
|
data/lib/imap_mogura/version.rb
CHANGED
data/lib/imap_mogura.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imap_mogura
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ysk
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/imap_mogura/cli.rb
|
85
85
|
- lib/imap_mogura/config_parser.rb
|
86
86
|
- lib/imap_mogura/config_parser/errors.rb
|
87
|
+
- lib/imap_mogura/debug_util.rb
|
87
88
|
- lib/imap_mogura/imap_handler.rb
|
88
89
|
- lib/imap_mogura/rules_parser.rb
|
89
90
|
- lib/imap_mogura/rules_parser/errors.rb
|
@@ -97,7 +98,7 @@ licenses:
|
|
97
98
|
metadata:
|
98
99
|
homepage_uri: https://github.com/yskuniv/imap_mogura
|
99
100
|
source_code_uri: https://github.com/yskuniv/mogura
|
100
|
-
post_install_message:
|
101
|
+
post_install_message:
|
101
102
|
rdoc_options: []
|
102
103
|
require_paths:
|
103
104
|
- lib
|
@@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
114
|
version: '0'
|
114
115
|
requirements: []
|
115
116
|
rubygems_version: 3.5.22
|
116
|
-
signing_key:
|
117
|
+
signing_key:
|
117
118
|
specification_version: 4
|
118
119
|
summary: A mail filtering tool for IMAP.
|
119
120
|
test_files: []
|