imap-filter 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: 2c399442d61849b86b6ab7f58a8d8e5e8e01566f
4
- data.tar.gz: d19e15efc6dc6fdd1ad25a547fd2abac18cc1d95
3
+ metadata.gz: a240cdefbc038f384351e9905758f500052df1d1
4
+ data.tar.gz: 768b6df466f6af225b9b82a31e6c5c8cbdff2694
5
5
  SHA512:
6
- metadata.gz: c8d3cc7800137f896ba21e5cb838b222379673a8d968060f1c530af56a572a2b75650bccba54336294725cefd6ddaeaa36dca1eebc694149ecc3877b43bf2bb4
7
- data.tar.gz: 76210364367885058ab7bb22adf455579383d60d580f598b53758b4b7e1ee11174c478034c1f6d18b91cfdd4ddad64ac6619e19f2436f5cafd8f06dff20a0afb
6
+ metadata.gz: a08b499e9f1b7a400bb12b5966694b74f4f79205215e237e51add5defdf8dcb5224eb7b0ca67d763fe45109ecbbbde509d7e9029302f6b94c7005a4295ebe5b3
7
+ data.tar.gz: ffcba35a649f15287f9163a261be2eaca6f825b63231639cc00806d679be537f83e74ec3a83f931cef7d431cd60bfcf76dc3ef57d551665cd2d30babcdd6c4ce
data/.semver CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 3
4
+ :patch: 4
5
5
  :special: ''
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.2.0
5
+ - 2.2.1
6
+ - 2.3.0
7
+ - 2.3.1
8
+ notifications:
9
+ irc: "irc.freenode.org#imap-filter"
data/Gemfile.lock CHANGED
@@ -28,9 +28,9 @@ GEM
28
28
  highline (1.7.8)
29
29
  interception (0.5)
30
30
  json (1.8.3)
31
- juwelier (2.1.2)
31
+ juwelier (2.1.3)
32
32
  builder
33
- bundler (>= 1.0)
33
+ bundler (>= 1.13)
34
34
  git (>= 1.2.5)
35
35
  github_api
36
36
  highline (>= 1.6.15)
@@ -44,16 +44,14 @@ GEM
44
44
  multi_json (1.12.1)
45
45
  multi_xml (0.5.5)
46
46
  multipart-post (2.0.0)
47
- nokogiri (1.6.8)
47
+ nokogiri (1.6.8.1)
48
48
  mini_portile2 (~> 2.1.0)
49
- pkg-config (~> 1.1.7)
50
49
  oauth2 (1.2.0)
51
50
  faraday (>= 0.8, < 0.10)
52
51
  jwt (~> 1.0)
53
52
  multi_json (~> 1.3)
54
53
  multi_xml (~> 0.5)
55
54
  rack (>= 1.2, < 3)
56
- pkg-config (1.1.7)
57
55
  pry (0.10.4)
58
56
  coderay (~> 1.1.0)
59
57
  method_source (~> 0.8.1)
@@ -121,4 +119,4 @@ DEPENDENCIES
121
119
  yard (~> 0)
122
120
 
123
121
  BUNDLED WITH
124
- 1.12.5
122
+ 1.13.6
data/README.org CHANGED
@@ -281,14 +281,17 @@
281
281
  *** Release Notes
282
282
  | Version | Breif | Description |
283
283
  |---------+------------------------+--------------------------------------------------------------------------------------------------------------------------------|
284
- | v0.0.2 | Initial Release | |
285
284
  | v0.0.3 | Fixed bug with timeout | On some lengthy remove copy/move operations, the source account can timeout. We do a simple NOOP to keep the connection alive. |
285
+ | v0.0.2 | Initial Release | |
286
286
 
287
287
  *** Known Issues
288
- | Date | Description |
289
- |------------+----------------------------------------------------------------|
290
- | 2016-09-25 | Remote copy / moves of HTML-based email does not work cleanly. |
291
- | | |
288
+ | Date | Description |
289
+ |------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
290
+ | 2016-09-25 | Remote copy / moves of HTML-based email does not work cleanly. |
291
+ | 2016-10-03 | Getting "Too many errors" ByeResponseError -- most likely from the errors of duplicate mailboxes (which is OK but some servers hate that). So I will have to check for the existence of the mailbox first before trying to create it. |
292
+ | | Timeout errors still persist in some cases. |
293
+ | | Need to capture all errors and provide human-readable responses, unless a certail verbosity level has been set. |
294
+ | | |
292
295
 
293
296
  ** Contributing to imap-filter
294
297
 
data/imap-filter.gemspec CHANGED
@@ -2,19 +2,19 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: imap-filter 0.0.3 ruby lib
5
+ # stub: imap-filter 0.0.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "imap-filter"
9
- s.version = "0.0.3"
8
+ s.name = "imap-filter".freeze
9
+ s.version = "0.0.4"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Fred Mitchell"]
14
- s.date = "2016-10-01"
15
- s.description = "\n imap-filter is a Ruby implementation of an IMAP filtering application.\n it can handle multiple IMAP accounts, and create IMAP folders automatically\n where none exists.\n\n The imap-filter DSL makes it easy to filter. You can also do \"dry-runs\"\n to make sure what happens is what is expected."
16
- s.email = "fred.mitchell@gmx.de"
17
- s.executables = ["imap-filter"]
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Fred Mitchell".freeze]
14
+ s.date = "2016-11-05"
15
+ s.description = "\n imap-filter is a Ruby implementation of an IMAP filtering application.\n it can handle multiple IMAP accounts, and create IMAP folders automatically\n where none exists.\n\n The imap-filter DSL makes it easy to filter. You can also do \"dry-runs\"\n to make sure what happens is what is expected.".freeze
16
+ s.email = "fred.mitchell@gmx.de".freeze
17
+ s.executables = ["imap-filter".freeze]
18
18
  s.extra_rdoc_files = [
19
19
  "LICENSE.txt",
20
20
  "README.org"
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  ".rspec",
25
25
  ".ruby-version",
26
26
  ".semver",
27
+ ".travis.yml",
27
28
  "Gemfile",
28
29
  "Gemfile.lock",
29
30
  "LICENSE.txt",
@@ -41,73 +42,73 @@ Gem::Specification.new do |s|
41
42
  "spec/imap-filter_spec.rb",
42
43
  "spec/spec_helper.rb"
43
44
  ]
44
- s.homepage = "http://github.com/flajann2/imap-filter"
45
- s.licenses = ["MIT"]
46
- s.required_ruby_version = Gem::Requirement.new(">= 2.2")
47
- s.rubygems_version = "2.5.1"
48
- s.summary = "IMAP Scriptable filter for one or multiple Email accounts."
45
+ s.homepage = "http://github.com/flajann2/imap-filter".freeze
46
+ s.licenses = ["MIT".freeze]
47
+ s.required_ruby_version = Gem::Requirement.new(">= 2.2".freeze)
48
+ s.rubygems_version = "2.6.7".freeze
49
+ s.summary = "IMAP Scriptable filter for one or multiple Email accounts.".freeze
49
50
 
50
51
  if s.respond_to? :specification_version then
51
52
  s.specification_version = 4
52
53
 
53
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
- s.add_runtime_dependency(%q<semver>, ["~> 1"])
55
- s.add_runtime_dependency(%q<awesome_print>, ["~> 1"])
56
- s.add_runtime_dependency(%q<text-table>, ["~> 1"])
57
- s.add_runtime_dependency(%q<thor>, ["~> 0"])
58
- s.add_runtime_dependency(%q<colorize>, ["~> 0"])
59
- s.add_runtime_dependency(%q<aspector>, ["~> 0"])
60
- s.add_development_dependency(%q<rspec>, ["~> 2"])
61
- s.add_development_dependency(%q<yard>, ["~> 0"])
62
- s.add_development_dependency(%q<rdoc>, ["~> 3"])
63
- s.add_development_dependency(%q<bundler>, ["~> 1"])
64
- s.add_development_dependency(%q<juwelier>, ["~> 2"])
65
- s.add_development_dependency(%q<simplecov>, ["~> 0"])
66
- s.add_development_dependency(%q<pry>, ["~> 0"])
67
- s.add_development_dependency(%q<pry-byebug>, ["~> 3"])
68
- s.add_development_dependency(%q<pry-doc>, ["~> 0"])
69
- s.add_development_dependency(%q<pry-remote>, ["~> 0"])
70
- s.add_development_dependency(%q<pry-rescue>, ["~> 1"])
71
- s.add_development_dependency(%q<pry-stack_explorer>, ["~> 0"])
55
+ s.add_runtime_dependency(%q<semver>.freeze, ["~> 1"])
56
+ s.add_runtime_dependency(%q<awesome_print>.freeze, ["~> 1"])
57
+ s.add_runtime_dependency(%q<text-table>.freeze, ["~> 1"])
58
+ s.add_runtime_dependency(%q<thor>.freeze, ["~> 0"])
59
+ s.add_runtime_dependency(%q<colorize>.freeze, ["~> 0"])
60
+ s.add_runtime_dependency(%q<aspector>.freeze, ["~> 0"])
61
+ s.add_development_dependency(%q<rspec>.freeze, ["~> 2"])
62
+ s.add_development_dependency(%q<yard>.freeze, ["~> 0"])
63
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 3"])
64
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 1"])
65
+ s.add_development_dependency(%q<juwelier>.freeze, ["~> 2"])
66
+ s.add_development_dependency(%q<simplecov>.freeze, ["~> 0"])
67
+ s.add_development_dependency(%q<pry>.freeze, ["~> 0"])
68
+ s.add_development_dependency(%q<pry-byebug>.freeze, ["~> 3"])
69
+ s.add_development_dependency(%q<pry-doc>.freeze, ["~> 0"])
70
+ s.add_development_dependency(%q<pry-remote>.freeze, ["~> 0"])
71
+ s.add_development_dependency(%q<pry-rescue>.freeze, ["~> 1"])
72
+ s.add_development_dependency(%q<pry-stack_explorer>.freeze, ["~> 0"])
72
73
  else
73
- s.add_dependency(%q<semver>, ["~> 1"])
74
- s.add_dependency(%q<awesome_print>, ["~> 1"])
75
- s.add_dependency(%q<text-table>, ["~> 1"])
76
- s.add_dependency(%q<thor>, ["~> 0"])
77
- s.add_dependency(%q<colorize>, ["~> 0"])
78
- s.add_dependency(%q<aspector>, ["~> 0"])
79
- s.add_dependency(%q<rspec>, ["~> 2"])
80
- s.add_dependency(%q<yard>, ["~> 0"])
81
- s.add_dependency(%q<rdoc>, ["~> 3"])
82
- s.add_dependency(%q<bundler>, ["~> 1"])
83
- s.add_dependency(%q<juwelier>, ["~> 2"])
84
- s.add_dependency(%q<simplecov>, ["~> 0"])
85
- s.add_dependency(%q<pry>, ["~> 0"])
86
- s.add_dependency(%q<pry-byebug>, ["~> 3"])
87
- s.add_dependency(%q<pry-doc>, ["~> 0"])
88
- s.add_dependency(%q<pry-remote>, ["~> 0"])
89
- s.add_dependency(%q<pry-rescue>, ["~> 1"])
90
- s.add_dependency(%q<pry-stack_explorer>, ["~> 0"])
74
+ s.add_dependency(%q<semver>.freeze, ["~> 1"])
75
+ s.add_dependency(%q<awesome_print>.freeze, ["~> 1"])
76
+ s.add_dependency(%q<text-table>.freeze, ["~> 1"])
77
+ s.add_dependency(%q<thor>.freeze, ["~> 0"])
78
+ s.add_dependency(%q<colorize>.freeze, ["~> 0"])
79
+ s.add_dependency(%q<aspector>.freeze, ["~> 0"])
80
+ s.add_dependency(%q<rspec>.freeze, ["~> 2"])
81
+ s.add_dependency(%q<yard>.freeze, ["~> 0"])
82
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3"])
83
+ s.add_dependency(%q<bundler>.freeze, ["~> 1"])
84
+ s.add_dependency(%q<juwelier>.freeze, ["~> 2"])
85
+ s.add_dependency(%q<simplecov>.freeze, ["~> 0"])
86
+ s.add_dependency(%q<pry>.freeze, ["~> 0"])
87
+ s.add_dependency(%q<pry-byebug>.freeze, ["~> 3"])
88
+ s.add_dependency(%q<pry-doc>.freeze, ["~> 0"])
89
+ s.add_dependency(%q<pry-remote>.freeze, ["~> 0"])
90
+ s.add_dependency(%q<pry-rescue>.freeze, ["~> 1"])
91
+ s.add_dependency(%q<pry-stack_explorer>.freeze, ["~> 0"])
91
92
  end
92
93
  else
93
- s.add_dependency(%q<semver>, ["~> 1"])
94
- s.add_dependency(%q<awesome_print>, ["~> 1"])
95
- s.add_dependency(%q<text-table>, ["~> 1"])
96
- s.add_dependency(%q<thor>, ["~> 0"])
97
- s.add_dependency(%q<colorize>, ["~> 0"])
98
- s.add_dependency(%q<aspector>, ["~> 0"])
99
- s.add_dependency(%q<rspec>, ["~> 2"])
100
- s.add_dependency(%q<yard>, ["~> 0"])
101
- s.add_dependency(%q<rdoc>, ["~> 3"])
102
- s.add_dependency(%q<bundler>, ["~> 1"])
103
- s.add_dependency(%q<juwelier>, ["~> 2"])
104
- s.add_dependency(%q<simplecov>, ["~> 0"])
105
- s.add_dependency(%q<pry>, ["~> 0"])
106
- s.add_dependency(%q<pry-byebug>, ["~> 3"])
107
- s.add_dependency(%q<pry-doc>, ["~> 0"])
108
- s.add_dependency(%q<pry-remote>, ["~> 0"])
109
- s.add_dependency(%q<pry-rescue>, ["~> 1"])
110
- s.add_dependency(%q<pry-stack_explorer>, ["~> 0"])
94
+ s.add_dependency(%q<semver>.freeze, ["~> 1"])
95
+ s.add_dependency(%q<awesome_print>.freeze, ["~> 1"])
96
+ s.add_dependency(%q<text-table>.freeze, ["~> 1"])
97
+ s.add_dependency(%q<thor>.freeze, ["~> 0"])
98
+ s.add_dependency(%q<colorize>.freeze, ["~> 0"])
99
+ s.add_dependency(%q<aspector>.freeze, ["~> 0"])
100
+ s.add_dependency(%q<rspec>.freeze, ["~> 2"])
101
+ s.add_dependency(%q<yard>.freeze, ["~> 0"])
102
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3"])
103
+ s.add_dependency(%q<bundler>.freeze, ["~> 1"])
104
+ s.add_dependency(%q<juwelier>.freeze, ["~> 2"])
105
+ s.add_dependency(%q<simplecov>.freeze, ["~> 0"])
106
+ s.add_dependency(%q<pry>.freeze, ["~> 0"])
107
+ s.add_dependency(%q<pry-byebug>.freeze, ["~> 3"])
108
+ s.add_dependency(%q<pry-doc>.freeze, ["~> 0"])
109
+ s.add_dependency(%q<pry-remote>.freeze, ["~> 0"])
110
+ s.add_dependency(%q<pry-rescue>.freeze, ["~> 1"])
111
+ s.add_dependency(%q<pry-stack_explorer>.freeze, ["~> 0"])
111
112
  end
112
113
  end
113
114
 
@@ -19,6 +19,9 @@ module ImapFilter
19
19
  puts "script %s " % [script] if _options[:verbose] >= 1
20
20
  load script, true
21
21
  end
22
+
23
+ def list
24
+ end
22
25
  end
23
26
  end
24
27
  end
@@ -62,7 +62,7 @@ module ImapFilter
62
62
  super
63
63
  @name = name
64
64
  instance_eval( &block )
65
- _accounts[name] = self
65
+ _accounts[name] = self
66
66
  end
67
67
 
68
68
  def to_s
@@ -81,7 +81,7 @@ module ImapFilter
81
81
 
82
82
  print "\n *** auth #{userid} pass #{pass}...".light_cyan unless _options[:verbose] < 2
83
83
  imap.authenticate(auth_type, userid, pass)
84
- @delim = imap.list('', '').first.delim
84
+ @delim = imap.list('', '').first.delim
85
85
  end
86
86
 
87
87
  def _close_connection
@@ -3,7 +3,55 @@ module ImapFilter
3
3
  module Functionality
4
4
  include Forwardable
5
5
  include ImapFilter::DSL
6
+ @@facc_list = nil
7
+
8
+ def self._functional_accounts
9
+ @@facc_list ||= _accounts.map { |name, acc|
10
+ [name, FunctAccount.new( acc )]
11
+ }.to_h
12
+ end
13
+
14
+ class FunctAccount
15
+ extend Forwardable
16
+
17
+ attr :dacc
18
+
19
+ def_delegators :@dacc, :name, :userid, :pass,
20
+ :fqdn, :use_ssl, :use_port,
21
+ :auth_type, :imap, :delim, :to_s,
22
+ :_open_connection, :_close_connection
6
23
 
24
+ def initialize acc
25
+ @dacc = acc
26
+ end
27
+
28
+ def mbox_list
29
+ @mbox_list ||= @dacc.imap.list('', '*')
30
+ .map { |m| [m['name'], m['attr']] }
31
+ .map { |mbox, attr|
32
+ begin
33
+ [mbox,
34
+ [@dacc.imap.status(mbox, STATUS.values)
35
+ .map{ |k, v| "#{ISTAT[k]}:#{v}" }
36
+ .join(' '),
37
+ attr]]
38
+ rescue
39
+ nil
40
+ end }.compact.to_h
41
+ end
42
+
43
+ def member? mbox
44
+ mbox_list.member? mbox
45
+ end
46
+
47
+ def ensure_mailbox mbox
48
+ unless member? mbox
49
+ @dacc.imap.create mbox
50
+ @mbox_list[mbox] = [:new_mailbox, :new_mailbox]
51
+ end
52
+ end
53
+ end
54
+
7
55
  FULL ='(UID RFC822.SIZE ENVELOPE BODY.PEEK[TEXT])'
8
56
  BODYTEXT = 'BODY[TEXT]'
9
57
  SUBJECTPEEKLIST = '(UID RFC822.SIZE BODY.PEEK[HEADER.FIELDS (SUBJECT)])'
@@ -27,7 +75,7 @@ module ImapFilter
27
75
  a, b = ambox.split ':'
28
76
  a, b = [nil, a] if b.nil?
29
77
  a = nil if a == ''
30
- acc = a.nil? ? default_account : _accounts[a.to_sym]
78
+ acc = FunctAccount.new( a.nil? ? default_account : _accounts[a.to_sym] )
31
79
  mbox = b
32
80
  [acc, mbox]
33
81
  end
@@ -40,9 +88,8 @@ module ImapFilter
40
88
 
41
89
  def ensure_mailbox account, mailbox
42
90
  begin
43
- account.imap.create mailbox
91
+ account.ensure_mailbox mailbox
44
92
  rescue Net::IMAP::NoResponseError => e
45
- # we ignore this because it -- probably -- means the mailbox already exists.
46
93
  puts " *** ignored mailbox error: #{e}".red unless _options[:verbose] < 1
47
94
  end
48
95
  end
@@ -24,30 +24,16 @@ module ImapFilter
24
24
  end
25
25
 
26
26
  # List all mboxes of given account and their statuses
27
- def self.list_mboxes account
28
- account.imap.list('', '*')
29
- .map { |m| [m['name'], m['attr']] }
30
- .map { |mbox, attr|
31
- begin
32
- [mbox,
33
- account.imap.status(mbox, STATUS.values)
34
- .map{ |k, v| "#{ISTAT[k]}:#{v}" }
35
- .join(' '),
36
- attr]
37
- rescue
38
- nil
39
- end }
40
- .compact
41
- end
42
27
 
43
28
  def self.login_imap_accounts test: false
44
29
  puts "====== #{test ? 'Test' : 'Login'} Accounts".light_yellow
45
- _accounts.each do |name, account|
30
+ _functional_accounts.each do |name, account|
46
31
  print " #{name}...".light_white
47
32
  begin
48
33
  account._open_connection
49
- puts "SUCCESS, delim #{account.delim}".light_green
50
- list_mboxes(account).each do |mbox, stat, attr|
34
+ puts "SUCCESS, delim #{account.delim}".light_green
35
+
36
+ account.mbox_list.each do |mbox, (stat, attr)|
51
37
  print " #{mbox}".light_blue
52
38
  print " #{stat}".light_red
53
39
  puts " #{attr}".light_cyan
@@ -46,4 +46,3 @@ end
46
46
  class IMAPHooks < Aspector::Base
47
47
  default private_methods: true
48
48
  end
49
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Mitchell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-01 00:00:00.000000000 Z
11
+ date: 2016-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semver
@@ -282,6 +282,7 @@ files:
282
282
  - ".rspec"
283
283
  - ".ruby-version"
284
284
  - ".semver"
285
+ - ".travis.yml"
285
286
  - Gemfile
286
287
  - Gemfile.lock
287
288
  - LICENSE.txt
@@ -318,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
318
319
  version: '0'
319
320
  requirements: []
320
321
  rubyforge_project:
321
- rubygems_version: 2.5.1
322
+ rubygems_version: 2.6.7
322
323
  signing_key:
323
324
  specification_version: 4
324
325
  summary: IMAP Scriptable filter for one or multiple Email accounts.