bcbiff 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +3 -10
  3. data/Gemfile.lock +18 -17
  4. data/Rakefile +1 -65
  5. data/bcbiff.gemspec +29 -51
  6. data/lib/bcbiff.rb +53 -7
  7. metadata +72 -97
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile CHANGED
@@ -1,11 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "mail"
4
-
5
- # Add dependencies to develop your gem here.
6
- # Include everything needed to run rake, tests, features, etc.
7
- group :development do
8
- gem "bundler", "~> 1.0.0"
9
- gem "jeweler", "~> 1.6.4"
10
- gem "rcov", ">= 0"
11
- end
3
+ # Specify your gem's dependencies in bcbiff.gemspec
4
+ gemspec
@@ -1,21 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bcbiff (0.3.0)
5
+ mail
6
+
1
7
  GEM
2
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
3
9
  specs:
4
- git (1.2.5)
5
- i18n (0.6.0)
6
- jeweler (1.6.4)
7
- bundler (~> 1.0)
8
- git (>= 1.2.5)
9
- rake
10
- mail (2.3.0)
10
+ i18n (0.6.1)
11
+ json (1.7.7)
12
+ mail (2.5.3)
11
13
  i18n (>= 0.4.0)
12
14
  mime-types (~> 1.16)
13
15
  treetop (~> 1.4.8)
14
- mime-types (1.16)
15
- polyglot (0.3.2)
16
- rake (0.9.2)
17
- rcov (0.9.10)
18
- treetop (1.4.10)
16
+ mime-types (1.21)
17
+ polyglot (0.3.3)
18
+ rdoc (3.12.1)
19
+ json (~> 1.4)
20
+ treetop (1.4.12)
19
21
  polyglot
20
22
  polyglot (>= 0.3.1)
21
23
 
@@ -23,7 +25,6 @@ PLATFORMS
23
25
  ruby
24
26
 
25
27
  DEPENDENCIES
26
- bundler (~> 1.0.0)
27
- jeweler (~> 1.6.4)
28
- mail
29
- rcov
28
+ bcbiff!
29
+ bundler (>= 1.2)
30
+ rdoc (> 2.4.2)
data/Rakefile CHANGED
@@ -1,65 +1 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- eval File.read('./lib/bcbiff.rb').lines.find { |line|
17
- /BCBIFF_VERSION/ =~ line
18
- } if !defined?(BCBIFF_VERSION)
19
-
20
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
21
- gem.name = "bcbiff"
22
- gem.homepage = "http://github.com/knu/bcbiff"
23
- gem.license = "2-clause BSDL"
24
- gem.summary = %Q{bcbiff(1) - Boxcar based IMAP biff}
25
- gem.description = <<-'EOS'
26
- Bcbiff checks the Inbox folder on an IMAP server for unread mails and
27
- sends a notification for each. Ideal for enabling push notification
28
- for your Gmail account using Boxcar.
29
- EOS
30
- gem.email = "knu@idaemons.org"
31
- gem.authors = ["Akinori MUSHA"]
32
- gem.executables = ["bcbiff"]
33
- gem.version = BCBIFF_VERSION
34
-
35
- gem.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
36
- # dependencies defined in Gemfile
37
- end
38
- Jeweler::RubygemsDotOrgTasks.new
39
-
40
- require 'rake/testtask'
41
- Rake::TestTask.new(:test) do |test|
42
- test.libs << 'lib' << 'test'
43
- test.pattern = 'test/**/test_*.rb'
44
- test.verbose = true
45
- end
46
-
47
- require 'rcov/rcovtask'
48
- Rcov::RcovTask.new do |test|
49
- test.libs << 'test'
50
- test.pattern = 'test/**/test_*.rb'
51
- test.verbose = true
52
- test.rcov_opts << '--exclude "gems/*"'
53
- end
54
-
55
- task :default => :test
56
-
57
- require 'rake/rdoctask'
58
- Rake::RDocTask.new do |rdoc|
59
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
60
-
61
- rdoc.rdoc_dir = 'rdoc'
62
- rdoc.title = "bcbiff #{version}"
63
- rdoc.rdoc_files.include('README*')
64
- rdoc.rdoc_files.include('lib/**/*.rb')
65
- end
1
+ require 'bundler/gem_tasks'
@@ -1,59 +1,37 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ eval File.read(
5
+ File.expand_path('../lib/bcbiff.rb', __FILE__)
6
+ ).lines.find { |line|
7
+ /BCBIFF_VERSION/ =~ line
8
+ } if !defined?(BCBIFF_VERSION)
5
9
 
6
- Gem::Specification.new do |s|
7
- s.name = "bcbiff"
8
- s.version = "0.2.1"
10
+ Gem::Specification.new do |gem|
11
+ gem.name = "bcbiff"
12
+ gem.version = BCBIFF_VERSION
13
+ gem.authors = ["Akinori MUSHA"]
14
+ gem.email = ["knu@idaemons.org"]
15
+ gem.homepage = "https://github.com/knu/bcbiff"
16
+ gem.licenses = ["2-clause BSDL"]
17
+ gem.description = <<'EOS'
18
+ Bcbiff checks the Inbox folder on an IMAP server for unread mails and
19
+ sends a notification for each. Ideal for enabling push notification
20
+ for your Gmail account using Boxcar.
21
+ EOS
22
+ gem.summary = %q{bcbiff(1) - Boxcar based IMAP biff}
9
23
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Akinori MUSHA"]
12
- s.date = "2011-09-26"
13
- s.description = "Bcbiff checks the Inbox folder on an IMAP server for unread mails and\nsends a notification for each. Ideal for enabling push notification\nfor your Gmail account using Boxcar.\n"
14
- s.email = "knu@idaemons.org"
15
- s.executables = ["bcbiff"]
16
- s.extra_rdoc_files = [
24
+ gem.files = `git ls-files`.split($/)
25
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
26
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
27
+ gem.require_paths = ["lib"]
28
+
29
+ gem.extra_rdoc_files = [
17
30
  "LICENSE.txt",
18
31
  "README.md"
19
32
  ]
20
- s.files = [
21
- ".document",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "LICENSE.txt",
25
- "README.md",
26
- "Rakefile",
27
- "bcbiff.gemspec",
28
- "bin/bcbiff",
29
- "lib/bcbiff.rb"
30
- ]
31
- s.homepage = "http://github.com/knu/bcbiff"
32
- s.licenses = ["2-clause BSDL"]
33
- s.require_paths = ["lib"]
34
- s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
35
- s.rubygems_version = "1.8.10"
36
- s.summary = "bcbiff(1) - Boxcar based IMAP biff"
37
33
 
38
- if s.respond_to? :specification_version then
39
- s.specification_version = 3
40
-
41
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_runtime_dependency(%q<mail>, [">= 0"])
43
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
44
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
45
- s.add_development_dependency(%q<rcov>, [">= 0"])
46
- else
47
- s.add_dependency(%q<mail>, [">= 0"])
48
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
49
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
50
- s.add_dependency(%q<rcov>, [">= 0"])
51
- end
52
- else
53
- s.add_dependency(%q<mail>, [">= 0"])
54
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
56
- s.add_dependency(%q<rcov>, [">= 0"])
57
- end
34
+ gem.add_runtime_dependency("mail", [">= 0"])
35
+ gem.add_development_dependency("rdoc", ["> 2.4.2"])
36
+ gem.add_development_dependency("bundler", [">= 1.2"])
58
37
  end
59
-
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # bcbiff(1) - Boxcar based IMAP biff
5
5
  #
6
- # Copyright (c) 2011 Akinori MUSHA
6
+ # Copyright (c) 2011, 2012 Akinori MUSHA
7
7
  #
8
8
  # All rights reserved.
9
9
  #
@@ -28,13 +28,19 @@
28
28
  # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
29
  # SUCH DAMAGE.
30
30
 
31
+ if defined?(Encoding)
32
+ Encoding.default_external = Encoding::UTF_8
33
+ else
34
+ $KCODE = 'u'
35
+ end
36
+
31
37
  require 'rubygems'
32
38
  require 'net/imap'
33
39
  require 'yaml'
34
40
  require 'mail'
35
41
  require 'shellwords'
36
42
 
37
- BCBIFF_VERSION = '0.2.1'
43
+ BCBIFF_VERSION = '0.3.0'
38
44
 
39
45
  CERTS_PATHS = [
40
46
  '/etc/ssl/cert.pem', # FreeBSD
@@ -47,6 +53,7 @@ CERTS_PATH = CERTS_PATHS.find { |f| File.exist?(f) }
47
53
  IDCACHE_FILE = '~/Maildir/idcache.%s.yml'
48
54
  IDCACHE_SIZE = 100
49
55
  BCBIFF_FILE = '~/.bcbiff'
56
+ ADDRESSES_FILE = '~/.addresses'
50
57
 
51
58
  def main(argv)
52
59
  accounts = config[:accounts]
@@ -79,6 +86,8 @@ Then add `:certs_path: /path/to/pem` to #{BCBIFF_FILE}.
79
86
  exit 1
80
87
  end
81
88
 
89
+ read_addresses
90
+
82
91
  accounts.each { |options|
83
92
  check_mails(options)
84
93
  }
@@ -121,6 +130,34 @@ def certs_path
121
130
  $certs_path ||= config[:certs_path] || CERTS_PATH
122
131
  end
123
132
 
133
+ def read_addresses
134
+ $display_address = {}
135
+
136
+ begin
137
+ content = File.read(ADDRESSES_FILE)
138
+ rescue
139
+ return
140
+ end
141
+
142
+ content.each_line { |line|
143
+ line.chomp!
144
+ address, nickname, fullname = line.split("\t").map { |field|
145
+ if m = field.match(/\A"(.*)"\z/)
146
+ m[1].gsub(/\\(.)/, "\\1")
147
+ else
148
+ field
149
+ end
150
+ }
151
+ begin
152
+ addr = Mail::Address.new(address)
153
+ addr.display_name = nickname
154
+ $display_address[address.downcase] = addr.to_s
155
+ rescue
156
+ end
157
+ }
158
+ rescue
159
+ end
160
+
124
161
  def check_mails(options)
125
162
  #Net::IMAP.debug = true
126
163
  mailto = options[:mailto]
@@ -146,8 +183,8 @@ def check_mails(options)
146
183
  next if msgids.include?(msgid)
147
184
  msgids << msgid
148
185
 
149
- (header = mail.header).fields.each { |field|
150
- case name = field.name
186
+ (header = mail.header).fields.map(&:name).each { |name|
187
+ case name
151
188
  when /\A(From|Subject|Date)\z/i
152
189
  # preserve
153
190
  else
@@ -155,9 +192,18 @@ def check_mails(options)
155
192
  end
156
193
  }
157
194
 
158
- open("| sendmail #{mailto.shellescape}", 'w') { |sendmail|
159
- sendmail.print mail.encoded
160
- }
195
+ mail.from = mail[:from].field.addrs.map { |addr|
196
+ $display_address[addr.address.downcase] || addr.to_s
197
+ }.join(', ')
198
+
199
+ begin
200
+ encoded = mail.encoded
201
+ open("| sendmail #{mailto.shellescape}", 'w') { |sendmail|
202
+ sendmail.print encoded
203
+ }
204
+ rescue => e
205
+ STDERR.puts "%s: %s" % [msgid, e.message]
206
+ end
161
207
  }
162
208
  }
163
209
  msgids.slice!(0...-IDCACHE_SIZE) if msgids.size > IDCACHE_SIZE
metadata CHANGED
@@ -1,97 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bcbiff
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Akinori MUSHA
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-26 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- requirement: &id001 !ruby/object:Gem::Requirement
22
- none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- hash: 3
27
- segments:
28
- - 0
29
- version: "0"
30
- version_requirements: *id001
12
+ date: 2013-02-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
31
15
  name: mail
32
- prerelease: false
33
- type: :runtime
34
- - !ruby/object:Gem::Dependency
35
- requirement: &id002 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
36
17
  none: false
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- hash: 23
41
- segments:
42
- - 1
43
- - 0
44
- - 0
45
- version: 1.0.0
46
- version_requirements: *id002
47
- name: bundler
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
48
23
  prerelease: false
49
- type: :development
50
- - !ruby/object:Gem::Dependency
51
- requirement: &id003 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
52
25
  none: false
53
- requirements:
54
- - - ~>
55
- - !ruby/object:Gem::Version
56
- hash: 7
57
- segments:
58
- - 1
59
- - 6
60
- - 4
61
- version: 1.6.4
62
- version_requirements: *id003
63
- name: jeweler
64
- prerelease: false
65
- type: :development
66
- - !ruby/object:Gem::Dependency
67
- requirement: &id004 !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
68
33
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
76
- version_requirements: *id004
77
- name: rcov
34
+ requirements:
35
+ - - ! '>'
36
+ - !ruby/object:Gem::Version
37
+ version: 2.4.2
38
+ type: :development
78
39
  prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>'
44
+ - !ruby/object:Gem::Version
45
+ version: 2.4.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '1.2'
79
54
  type: :development
80
- description: |
81
- Bcbiff checks the Inbox folder on an IMAP server for unread mails and
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ description: ! 'Bcbiff checks the Inbox folder on an IMAP server for unread mails
63
+ and
64
+
82
65
  sends a notification for each. Ideal for enabling push notification
66
+
83
67
  for your Gmail account using Boxcar.
84
68
 
85
- email: knu@idaemons.org
86
- executables:
69
+ '
70
+ email:
71
+ - knu@idaemons.org
72
+ executables:
87
73
  - bcbiff
88
74
  extensions: []
89
-
90
- extra_rdoc_files:
75
+ extra_rdoc_files:
91
76
  - LICENSE.txt
92
77
  - README.md
93
- files:
78
+ files:
94
79
  - .document
80
+ - .gitignore
95
81
  - Gemfile
96
82
  - Gemfile.lock
97
83
  - LICENSE.txt
@@ -100,40 +86,29 @@ files:
100
86
  - bcbiff.gemspec
101
87
  - bin/bcbiff
102
88
  - lib/bcbiff.rb
103
- homepage: http://github.com/knu/bcbiff
104
- licenses:
89
+ homepage: https://github.com/knu/bcbiff
90
+ licenses:
105
91
  - 2-clause BSDL
106
92
  post_install_message:
107
93
  rdoc_options: []
108
-
109
- require_paths:
94
+ require_paths:
110
95
  - lib
111
- required_ruby_version: !ruby/object:Gem::Requirement
96
+ required_ruby_version: !ruby/object:Gem::Requirement
112
97
  none: false
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 57
117
- segments:
118
- - 1
119
- - 8
120
- - 7
121
- version: 1.8.7
122
- required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
103
  none: false
124
- requirements:
125
- - - ">="
126
- - !ruby/object:Gem::Version
127
- hash: 3
128
- segments:
129
- - 0
130
- version: "0"
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
131
108
  requirements: []
132
-
133
109
  rubyforge_project:
134
- rubygems_version: 1.8.10
110
+ rubygems_version: 1.8.24
135
111
  signing_key:
136
112
  specification_version: 3
137
113
  summary: bcbiff(1) - Boxcar based IMAP biff
138
114
  test_files: []
139
-