imap_mogura 0.2.2.pre.dev → 0.3.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: e8ab3a83b682da8cfeeb55ea96c1e1bd3b046246da28923196d33fe7cd3d7f26
4
- data.tar.gz: 3d0fd5fa039f632ed3c63e2467e3eb31703cb4ec9aca2aa8a0a15d2592b04124
3
+ metadata.gz: e14cd28606dbecabfd04544f634f81cf8378412f64a4af268b97300e754d9c55
4
+ data.tar.gz: 3b3f86b413c84f8d4bfc6a889bf197a54793210b212d9db794a5a40717f6ba1a
5
5
  SHA512:
6
- metadata.gz: 05230b9da5a38e8abc1b398d0939528fed9dcccf1f01dae327844d63e26f25dfa009083c3ee5b84d070fc164cce22ce18c23a52edb3fcbbef34926f908fd256f
7
- data.tar.gz: c81ee3bc93144669f170ea3d139aac88bbfc2c660d6fa3e15a2f653b7fde2ff8b2f69bb7dbcef69fed73ff51845aa6ce08f005d1b4326e2ed0798fe397cf3249
6
+ metadata.gz: 717b2e6eee24de47f2219cc6331a0bcf78476505b45ee28f7b2b8ff453bc8c63792e14926e7530563dea2f8b1c8240b30342e08b30beb9457ab71cb47d74a957
7
+ data.tar.gz: f5ef0e70a29a0d5c10277a153ee1989614b1b697418deda0a9d4fa9bee6a9f75a331cdd892dcd4d88f3c83cc78f63c91f73a50aa2ed2966b69a49d9c70a955d7
data/README.md CHANGED
@@ -7,11 +7,9 @@ A mail filtering tool for IMAP.
7
7
  To install this gem, just run as following. You can get the gem from [RubyGems.org](https://rubygems.org/).
8
8
 
9
9
  ```console
10
- $ gem install imap_mogura --pre
10
+ $ gem install imap_mogura
11
11
  ```
12
12
 
13
- (This branch is `develop`, that means this is a pre-release version. You can install this version by specifying `--pre` option.)
14
-
15
13
  ## Usage
16
14
 
17
15
  Create `rules.yml` and write rules like following.
@@ -53,9 +53,11 @@ module ImapMogura
53
53
  monitor_recents_on_mailbox(imap_handler, target_mailbox) do
54
54
  # find mails with search keys on the target mailbox and handle them
55
55
  imap_handler.find_and_handle_mails(target_mailbox, search_keys) do |message_id|
56
- warn "mail (id = #{message_id} on \"#{target_mailbox}\") is recent"
56
+ warn "a mail is recent on \"#{target_mailbox}\""
57
57
 
58
58
  filter_mail(imap_handler, rules, target_mailbox, message_id, dry_run: dry_run)
59
+
60
+ imap_handler.close_operation_for_mailbox(target_mailbox)
59
61
  end
60
62
  end
61
63
  end
@@ -219,7 +221,7 @@ module ImapMogura
219
221
  handle_mail_fetch_error_and_preprocess_retrying(e, retry_count)
220
222
 
221
223
  # retry monitor recents on mailbox itself with retry count to be incremented
222
- warn "retry monitoring mails on #{e.mailbox}..."
224
+ warn "retry monitoring mails on \"#{e.mailbox}\"..."
223
225
 
224
226
  monitor_recents_on_mailbox(imap_handler, mailbox, retry_count + 1)
225
227
  end
@@ -228,43 +230,32 @@ module ImapMogura
228
230
  imap_handler.find_and_handle_mails(mailbox, search_keys) do |message_id|
229
231
  filter_mail(imap_handler, rules, mailbox, message_id, dry_run: dry_run)
230
232
  end
233
+
234
+ imap_handler.close_operation_for_mailbox(mailbox)
231
235
  rescue IMAPHandler::MailFetchError => e
232
236
  handle_mail_fetch_error_and_preprocess_retrying(e, retry_count)
233
237
 
234
238
  # retry filter all mails itself with retry count to be incremented
235
- warn "retry filtering all mails on #{e.mailbox}"
239
+ warn "retry filtering all mails on \"#{e.mailbox}\""
236
240
 
237
241
  filter_mails(imap_handler, rules, mailbox, search_keys, retry_count + 1, dry_run: dry_run)
238
242
  end
239
243
 
240
- def handle_mail_fetch_error_and_preprocess_retrying(error, retry_count)
241
- warn "failed to fetch mail (id = #{error.message_id} on mailbox #{error.mailbox}): #{error.bad_response_error_message}"
242
-
243
- # if retry_count is over the threshold, abort processing
244
- raise Thor::Error, "retry count is over the threshold, stop processing" unless retry_count < 3
245
-
246
- warn "wait a moment..."
247
-
248
- sleep 10
249
- end
250
-
251
244
  def filter_mail(imap_handler, rules, mailbox, message_id, dry_run: false)
252
245
  mail = imap_handler.fetch_header(mailbox, message_id)
253
246
 
254
247
  warn "# filtering mail on \"#{mailbox}\" of subject \"#{mail.subject}\"..."
255
248
 
256
249
  rules.each do |rule_set|
257
- try_to_filter_mail_for_rule_set(imap_handler, rule_set, mailbox, message_id, mail, dry_run: dry_run)
250
+ break if try_to_filter_mail_for_rule_set(imap_handler, rule_set, mailbox, message_id, mail, dry_run: dry_run)
258
251
  end
259
-
260
- imap_handler.close_operation_for_mailbox(mailbox)
261
252
  end
262
253
 
263
254
  def try_to_filter_mail_for_rule_set(imap_handler, rule_set, mailbox, message_id, mail, dry_run: false)
264
255
  dst_mailbox = rule_set.destination
265
256
  rule = rule_set.rule
266
257
 
267
- return unless rule.match?(mail)
258
+ return nil unless rule.match?(mail)
268
259
 
269
260
  warn "the mail matches for the rule of the destination \"#{dst_mailbox}\""
270
261
  warn "moving the mail..."
@@ -279,6 +270,19 @@ module ImapMogura
279
270
  warn "moving skipped because the destination is the same with the current mailbox \"#{mailbox}\""
280
271
  end
281
272
  end
273
+
274
+ dst_mailbox
275
+ end
276
+
277
+ def handle_mail_fetch_error_and_preprocess_retrying(error, retry_count)
278
+ warn "failed to fetch the mail on \"#{error.mailbox}\": #{error.bad_response_error_message}"
279
+
280
+ # if retry_count is over the threshold, abort processing
281
+ raise Thor::Error, "retry count is over the threshold, stop processing" unless retry_count < 3
282
+
283
+ warn "wait a moment..."
284
+
285
+ sleep 10
282
286
  end
283
287
  end
284
288
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ImapMogura
4
- VERSION = "0.2.2.pre.dev"
4
+ VERSION = "0.3.1"
5
5
  end
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.2.2.pre.dev
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ysk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-25 00:00:00.000000000 Z
11
+ date: 2024-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64