imap_mogura 0.2.0 → 0.2.2.pre.dev
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/imap_mogura/cli.rb +29 -19
- data/lib/imap_mogura/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8ab3a83b682da8cfeeb55ea96c1e1bd3b046246da28923196d33fe7cd3d7f26
|
4
|
+
data.tar.gz: 3d0fd5fa039f632ed3c63e2467e3eb31703cb4ec9aca2aa8a0a15d2592b04124
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05230b9da5a38e8abc1b398d0939528fed9dcccf1f01dae327844d63e26f25dfa009083c3ee5b84d070fc164cce22ce18c23a52edb3fcbbef34926f908fd256f
|
7
|
+
data.tar.gz: c81ee3bc93144669f170ea3d139aac88bbfc2c660d6fa3e15a2f653b7fde2ff8b2f69bb7dbcef69fed73ff51845aa6ce08f005d1b4326e2ed0798fe397cf3249
|
data/README.md
CHANGED
@@ -7,9 +7,11 @@ 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
|
10
|
+
$ gem install imap_mogura --pre
|
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
|
+
|
13
15
|
## Usage
|
14
16
|
|
15
17
|
Create `rules.yml` and write rules like following.
|
data/lib/imap_mogura/cli.rb
CHANGED
@@ -51,6 +51,7 @@ module ImapMogura
|
|
51
51
|
warn "* start monitoring recent mails in \"#{target_mailbox}\""
|
52
52
|
|
53
53
|
monitor_recents_on_mailbox(imap_handler, target_mailbox) do
|
54
|
+
# find mails with search keys on the target mailbox and handle them
|
54
55
|
imap_handler.find_and_handle_mails(target_mailbox, search_keys) do |message_id|
|
55
56
|
warn "mail (id = #{message_id} on \"#{target_mailbox}\") is recent"
|
56
57
|
|
@@ -105,7 +106,10 @@ module ImapMogura
|
|
105
106
|
if all_mailbox
|
106
107
|
excluded_mailboxes = options[:excluded_mailboxes]
|
107
108
|
|
108
|
-
|
109
|
+
# figure out target mailboxes
|
110
|
+
target_mailboxes = imap_handler.all_mailbox_list.reject { |mailbox| excluded_mailboxes.include?(mailbox) }
|
111
|
+
|
112
|
+
target_mailboxes.each do |mailbox|
|
109
113
|
filter_mails(imap_handler, rules, mailbox, search_keys, dry_run: dry_run)
|
110
114
|
end
|
111
115
|
else
|
@@ -133,6 +137,7 @@ module ImapMogura
|
|
133
137
|
starttls: starttls, usessl: use_ssl, certs: nil, verify: true,
|
134
138
|
auth_info: { auth_type: auth_type, user: user, password: password })
|
135
139
|
|
140
|
+
# output all mailbox list
|
136
141
|
puts imap_handler.all_mailbox_list
|
137
142
|
|
138
143
|
imap_handler.close
|
@@ -172,10 +177,12 @@ module ImapMogura
|
|
172
177
|
# exit
|
173
178
|
# end
|
174
179
|
|
180
|
+
# create directories specified as destination
|
175
181
|
touch_all_mailboxes_in_rules(imap_handler, rules, dry_run: dry_run) if create_directory
|
176
182
|
|
177
183
|
options = { excluded_mailboxes: excluded_mailboxes }
|
178
184
|
|
185
|
+
# call the given block
|
179
186
|
block[imap_handler, rules, options]
|
180
187
|
|
181
188
|
imap_handler.close
|
@@ -211,9 +218,9 @@ module ImapMogura
|
|
211
218
|
rescue IMAPHandler::MailFetchError => e
|
212
219
|
handle_mail_fetch_error_and_preprocess_retrying(e, retry_count)
|
213
220
|
|
221
|
+
# retry monitor recents on mailbox itself with retry count to be incremented
|
214
222
|
warn "retry monitoring mails on #{e.mailbox}..."
|
215
223
|
|
216
|
-
# retry monitor recents on mailbox itself with retry count to be incremented
|
217
224
|
monitor_recents_on_mailbox(imap_handler, mailbox, retry_count + 1)
|
218
225
|
end
|
219
226
|
|
@@ -224,9 +231,9 @@ module ImapMogura
|
|
224
231
|
rescue IMAPHandler::MailFetchError => e
|
225
232
|
handle_mail_fetch_error_and_preprocess_retrying(e, retry_count)
|
226
233
|
|
234
|
+
# retry filter all mails itself with retry count to be incremented
|
227
235
|
warn "retry filtering all mails on #{e.mailbox}"
|
228
236
|
|
229
|
-
# retry filter all mails itself with retry count to be incremented
|
230
237
|
filter_mails(imap_handler, rules, mailbox, search_keys, retry_count + 1, dry_run: dry_run)
|
231
238
|
end
|
232
239
|
|
@@ -238,7 +245,6 @@ module ImapMogura
|
|
238
245
|
|
239
246
|
warn "wait a moment..."
|
240
247
|
|
241
|
-
# wait a moment...
|
242
248
|
sleep 10
|
243
249
|
end
|
244
250
|
|
@@ -248,27 +254,31 @@ module ImapMogura
|
|
248
254
|
warn "# filtering mail on \"#{mailbox}\" of subject \"#{mail.subject}\"..."
|
249
255
|
|
250
256
|
rules.each do |rule_set|
|
251
|
-
|
252
|
-
|
257
|
+
try_to_filter_mail_for_rule_set(imap_handler, rule_set, mailbox, message_id, mail, dry_run: dry_run)
|
258
|
+
end
|
253
259
|
|
254
|
-
|
260
|
+
imap_handler.close_operation_for_mailbox(mailbox)
|
261
|
+
end
|
255
262
|
|
256
|
-
|
257
|
-
|
263
|
+
def try_to_filter_mail_for_rule_set(imap_handler, rule_set, mailbox, message_id, mail, dry_run: false)
|
264
|
+
dst_mailbox = rule_set.destination
|
265
|
+
rule = rule_set.rule
|
258
266
|
|
259
|
-
|
260
|
-
|
267
|
+
return unless rule.match?(mail)
|
268
|
+
|
269
|
+
warn "the mail matches for the rule of the destination \"#{dst_mailbox}\""
|
270
|
+
warn "moving the mail..."
|
271
|
+
|
272
|
+
if dry_run
|
273
|
+
warn "moving skipped because this is dry run"
|
274
|
+
else
|
275
|
+
result = imap_handler.move(mailbox, message_id, dst_mailbox)
|
276
|
+
if result
|
277
|
+
warn "moving done"
|
261
278
|
else
|
262
|
-
|
263
|
-
if result
|
264
|
-
warn "moving done"
|
265
|
-
else
|
266
|
-
warn "moving skipped because the destination is the same with the current mailbox \"#{mailbox}\""
|
267
|
-
end
|
279
|
+
warn "moving skipped because the destination is the same with the current mailbox \"#{mailbox}\""
|
268
280
|
end
|
269
281
|
end
|
270
|
-
|
271
|
-
imap_handler.close_operation_for_mailbox(mailbox)
|
272
282
|
end
|
273
283
|
end
|
274
284
|
end
|
data/lib/imap_mogura/version.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.2.
|
4
|
+
version: 0.2.2.pre.dev
|
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-
|
11
|
+
date: 2024-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|