imap_mogura 0.3.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e14cd28606dbecabfd04544f634f81cf8378412f64a4af268b97300e754d9c55
4
- data.tar.gz: 3b3f86b413c84f8d4bfc6a889bf197a54793210b212d9db794a5a40717f6ba1a
3
+ metadata.gz: 1098d9f2efbc9c5217d93bb2cc3577f90cd64884ccea587163166abfb5160275
4
+ data.tar.gz: 1a9c668019cb0da2093aab3ff88e03956bf43b83c359947085808c10ee2735c8
5
5
  SHA512:
6
- metadata.gz: 717b2e6eee24de47f2219cc6331a0bcf78476505b45ee28f7b2b8ff453bc8c63792e14926e7530563dea2f8b1c8240b30342e08b30beb9457ab71cb47d74a957
7
- data.tar.gz: f5ef0e70a29a0d5c10277a153ee1989614b1b697418deda0a9d4fa9bee6a9f75a331cdd892dcd4d88f3c83cc78f63c91f73a50aa2ed2966b69a49d9c70a955d7
6
+ metadata.gz: 0fcf8a3ba59e7d38d88be956308697b278d5db988bfb26544ffaf35f7ccd70292fc1665b6746d763980a1e281c225edbd557d41870d33514d28cad20e90e3100
7
+ data.tar.gz: cf92e40b912996ec5a395ad9722a12f8f303b569354a87911b855d44308cdf69fada23fabbd655eacf65ac3bcc04edb8505e4f86a148b31cd8467b401ed5e376
@@ -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
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImapMogura
4
+ module DebugUtil
5
+ class << self
6
+ def enable_debug
7
+ $DEBUG = true
8
+ end
9
+
10
+ def debug(msg)
11
+ warn msg if $DEBUG
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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
@@ -23,13 +39,15 @@ module ImapMogura
23
39
 
24
40
  class AndOperator < LogicalOperator
25
41
  def match?(mail)
26
- @operands.all? { |elm| elm.match?(mail) }
42
+ debug_out_before_trying_rule("All of the operands match the rule")
43
+ debug_out_if_it_matches_rule(@operands.all? { |elm| elm.match?(mail) })
27
44
  end
28
45
  end
29
46
 
30
47
  class OrOperator < LogicalOperator
31
48
  def match?(mail)
32
- @operands.any? { |elm| elm.match?(mail) }
49
+ debug_out_before_trying_rule("Any of the operands matches the rule")
50
+ debug_out_if_it_matches_rule(@operands.any? { |elm| elm.match?(mail) })
33
51
  end
34
52
  end
35
53
 
@@ -47,46 +65,57 @@ module ImapMogura
47
65
 
48
66
  class FromMatcher < SpecialFieldMatcher
49
67
  def match?(mail)
50
- case mail.from
51
- when Enumerable
52
- mail.from.any? { |address| address&.match?(@regexp) }
53
- else
54
- mail.from&.match?(@regexp)
55
- end
68
+ debug_out_before_trying_rule("From #{mail.from.inspect} matches the regexp #{@regexp}")
69
+ debug_out_if_it_matches_rule(
70
+ case mail.from
71
+ when Enumerable
72
+ mail.from.any? { |address| address&.match?(@regexp) }
73
+ else
74
+ mail.from&.match?(@regexp)
75
+ end
76
+ )
56
77
  end
57
78
  end
58
79
 
59
80
  class SenderMatcher < SpecialFieldMatcher
60
81
  def match?(mail)
61
- mail.sender&.match?(@regexp)
82
+ debug_out_before_trying_rule("Sender #{mail.sender.inspect} matches the regexp #{@regexp}")
83
+ debug_out_if_it_matches_rule(mail.sender&.match?(@regexp))
62
84
  end
63
85
  end
64
86
 
65
87
  class ToMatcher < SpecialFieldMatcher
66
88
  def match?(mail)
67
- case mail.to
68
- when Enumerable
69
- mail.to.any? { |address| address&.match?(@regexp) }
70
- else
71
- mail.to&.match?(@regexp)
72
- end
89
+ debug_out_before_trying_rule("To #{mail.to.inspect} matches the regexp #{@regexp}")
90
+ debug_out_if_it_matches_rule(
91
+ case mail.to
92
+ when Enumerable
93
+ mail.to.any? { |address| address&.match?(@regexp) }
94
+ else
95
+ mail.to&.match?(@regexp)
96
+ end
97
+ )
73
98
  end
74
99
  end
75
100
 
76
101
  class CcMatcher < SpecialFieldMatcher
77
102
  def match?(mail)
78
- case mail.cc
79
- when Enumerable
80
- mail.cc.any? { |address| address&.match?(@regexp) }
81
- else
82
- mail.cc&.match?(@regexp)
83
- end
103
+ debug_out_before_trying_rule("Cc #{mail.cc.inspect} matches the regexp #{@regexp}")
104
+ debug_out_if_it_matches_rule(
105
+ case mail.cc
106
+ when Enumerable
107
+ mail.cc.any? { |address| address&.match?(@regexp) }
108
+ else
109
+ mail.cc&.match?(@regexp)
110
+ end
111
+ )
84
112
  end
85
113
  end
86
114
 
87
115
  class SubjectMatcher < SpecialFieldMatcher
88
116
  def match?(mail)
89
- mail.subject&.match?(@regexp)
117
+ debug_out_before_trying_rule("Subject \"#{mail.subject}\" matches the regexp #{@regexp}")
118
+ debug_out_if_it_matches_rule(mail.subject&.match?(@regexp))
90
119
  end
91
120
  end
92
121
 
@@ -105,7 +134,8 @@ module ImapMogura
105
134
  end
106
135
 
107
136
  def match?(mail)
108
- mail.headers[@field_name]&.value&.match?(@regexp)
137
+ debug_out_before_trying_rule("header field \"#{@field_name}\" with value \"#{mail.headers[@field_name]&.value}\" matches the regexp #{@regexp}")
138
+ debug_out_if_it_matches_rule(mail.headers[@field_name]&.value&.match?(@regexp))
109
139
  end
110
140
  end
111
141
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ImapMogura
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.1"
5
5
  end
data/lib/imap_mogura.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "imap_mogura/debug_util"
3
4
  require_relative "imap_mogura/config_parser"
4
5
  require_relative "imap_mogura/imap_handler"
5
6
  require_relative "imap_mogura/rules_parser"
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.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ysk
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-29 00:00:00.000000000 Z
11
+ date: 2025-01-07 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: []