imap_mogura 0.2.2 → 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: 993c63cfc198ecb1bf303676897fe03825ebd959b84b80f543c3e9268dd418de
4
- data.tar.gz: a67fa16f14228240da1eecdf806bd9208d9019dfa98bcd13a20d3ed1aeaeacf5
3
+ metadata.gz: e14cd28606dbecabfd04544f634f81cf8378412f64a4af268b97300e754d9c55
4
+ data.tar.gz: 3b3f86b413c84f8d4bfc6a889bf197a54793210b212d9db794a5a40717f6ba1a
5
5
  SHA512:
6
- metadata.gz: 8530a54d7aa22e3267f31eec06f7f5c125b1d908b1b6a2677fa7a6699f3ec3c343fdc0bc5003d7f7be26a05ddcadc0bf5c947c0d38e445faee86e3a90081dc64
7
- data.tar.gz: 50cce8e16ee1f23bd198da3fcb984c33d537800a84bc0d41a48a0a3b0c252d738051b140cb22646d5f7344c3ac1d87bffaa51895cae542e58cfc2c5d1138b170
6
+ metadata.gz: 717b2e6eee24de47f2219cc6331a0bcf78476505b45ee28f7b2b8ff453bc8c63792e14926e7530563dea2f8b1c8240b30342e08b30beb9457ab71cb47d74a957
7
+ data.tar.gz: f5ef0e70a29a0d5c10277a153ee1989614b1b697418deda0a9d4fa9bee6a9f75a331cdd892dcd4d88f3c83cc78f63c91f73a50aa2ed2966b69a49d9c70a955d7
@@ -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"
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
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