biff 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10baa1580d984257513cc494648360b858da4d2c
4
- data.tar.gz: 80e17475020465078acc4186394f08d401b2cabe
3
+ metadata.gz: 764dc7f862bfed11324c0de3ac43841347c6574e
4
+ data.tar.gz: 9583d5ea0182e7a32bf92ac40f60dbf681ef00f3
5
5
  SHA512:
6
- metadata.gz: 461e2fd31358b45231fcccd512338a43b63b53e60a6a2e117202221a433870c3f251c0b11fddc68e1140e9c07b8b41400257d68b37398db3547d6a4eb3de4294
7
- data.tar.gz: 205fa341d6cd04c01664e8d78cbae0333ce551a55951c320a5d92656b8d8e9f06723c3f105052bacb71e4d8d224a78110cf96eb34061cc10cd816d438ff16e91
6
+ metadata.gz: 8d26d37abc4b03c7e39edcd0983b92bd2c4657de5490f6f21d41c2ee1227939ed7bf13018756679fd2c92e0b1124c1bf154fd31a68a5442db15c6ade8e38bd2f
7
+ data.tar.gz: b4c08d4620cc717e8c2d5e5b0f3282a0d9f0dd2e3053492ae06cbd1b69ba933c3f33cf3b7d71545731a3cda0c08ffd2b7b685e0e52f3e780137196e63d3d8d3b
data/README.md CHANGED
@@ -4,27 +4,17 @@ Ruby Imap IDLE based biff utility.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'biff'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
7
  $ gem install biff
20
8
 
9
+ or the usual `bundler` incantations if you want to use the library in another app.
10
+
21
11
  ## Usage
22
12
 
23
- The gem provides two command-line scripts, `biffer` (to avoid conflict w/ system `biff` command) and `biff.5m.rb`. `biffer` uses `net/imap#listen` to wait for INBOX changes and print "{server name}:{unseen}/{all}".
13
+ The gem provides two command-line scripts, `biffer` (to avoid conflict w/ system `biff` command) and `biff.5m.rb`. `biffer` uses `net/imap#listen` to wait for INBOX changes and prints "{server name}:{unseen}/{all}". It will exit immediately with an error if the IMAP server does not have the IDLE capability.
24
14
 
25
- `biff.1m.rb` is a [BitBar](https://getbitbar.com) script, which will run every minute to update the menubar entry.
15
+ `biff.5m.rb` is a [BitBar](https://getbitbar.com) script, which will run every 5 minutes to update the menubar entry.
26
16
 
27
- Both scripts use (by default) the configuration in ~/.biff.yaml, which should be in the following format, multiple top-level keys (servers) are allowd. Note that one of either `password` or `passcmd` is required.
17
+ Both scripts use (by default) the configuration in ~/.biff.yaml, which should be in the following format, multiple top-level keys (servers) are allowed. Note that one of either `password` or `passcmd` is required.
28
18
 
29
19
  ```yaml
30
20
  Name:
@@ -34,8 +24,11 @@ Name:
34
24
  passcmd: shell_command_if_password_not_specified
35
25
  run: optional_command_to_run_after_inbox_changes
36
26
  cmd: optional_email_command_for_bitbar_menu_hot_link
27
+ debug: optional_set_net_imap_debug
37
28
  ```
38
29
 
30
+ Typically, `security find-internet-password -a {email-login} -w` is a good choice for `passcmd`. If your IMAP server is on Microsofit Office365, try `security find-internet-password -s 'mail.office365.com' -w` instead.
31
+
39
32
  Note that if you are using, e.g., `rbenv` to manage your ruby versions and gems, you can't use `biff.5m.rb` directly in your plugin directory. A shell script like the following will work:
40
33
 
41
34
  ``` zsh
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/bin/biffer CHANGED
@@ -3,8 +3,17 @@ require 'biff/cli'
3
3
 
4
4
  cli = Biff::CLI.new
5
5
 
6
- cli.update
7
- threads = cli.listen
6
+ def notify(status)
7
+ puts "#{status.name}:#{status.unseen}/#{status.all}"
8
+ end
9
+
10
+ cli.update do |server|
11
+ notify(server.status)
12
+ end
13
+
14
+ threads = cli.listen do |status|
15
+ notify(status)
16
+ end
8
17
 
9
18
  %w[TERM INT QUIT].each do |sig|
10
19
  Signal.trap(sig) do
data/lib/biff.rb CHANGED
@@ -2,7 +2,7 @@ require 'net/imap'
2
2
  require 'rfc2047'
3
3
  require 'version'
4
4
 
5
- Status = Struct.new(:name, :unseen, :all, :cmd)
5
+ Status = Struct.new(:name, :unseen, :all)
6
6
 
7
7
  class Biff
8
8
  is_versioned
@@ -43,11 +43,7 @@ class Biff
43
43
  idle # wait
44
44
 
45
45
  count
46
- if block_given?
47
- yield status
48
- else
49
- notify
50
- end
46
+ yield status
51
47
 
52
48
  run
53
49
  rescue ThreadError
@@ -73,11 +69,6 @@ class Biff
73
69
  [@unseen, @all]
74
70
  end
75
71
 
76
- def notify
77
- i = status
78
- puts "#{i.name}:#{i.unseen}/#{i.all}"
79
- end
80
-
81
72
  def cmd
82
73
  @config['cmd']
83
74
  end
@@ -97,6 +88,7 @@ class Biff
97
88
 
98
89
  def unseen_headers
99
90
  return unless @unseen
91
+
100
92
  @imap.fetch(@unseen, 'ENVELOPE').map { |e| e.attr['ENVELOPE'] }.map do |e|
101
93
  from = e.from[0]
102
94
  name = Rfc2047.decode(from.name || from.mailbox)
@@ -104,7 +96,7 @@ class Biff
104
96
  nl = name.length > NAME_MAX ? NAME_MAX - 1 : NAME_MAX
105
97
  sl = subject.length > SUBJ_MAX ? SUBJ_MAX - 1 : SUBJ_MAX
106
98
 
107
- # rubocop doesn't understand '*' width/precision
99
+ # rubocop doesn't understand '*.*' width.precision
108
100
  # rubocop:disable Lint/FormatParameterMismatch
109
101
  sprintf(
110
102
  '%*.*s%s: %-*.*s%s',
data/lib/biff/cli.rb CHANGED
@@ -12,9 +12,7 @@ class Biff::CLI
12
12
 
13
13
  options.config.each do |name, config|
14
14
  config['debug'] ||= options.debug
15
- config['verbose'] ||= options.verbose
16
15
  config['name'] = name
17
- $stderr.puts("INFO #{name}") if options.verbose
18
16
 
19
17
  b = @servers[name] = Biff.new(config)
20
18
  b.open
@@ -39,7 +37,9 @@ class Biff::CLI
39
37
 
40
38
  def update
41
39
  count
42
- map_servers(&:notify)
40
+ map_servers do |server|
41
+ yield server
42
+ end
43
43
  map_servers(&:run)
44
44
  end
45
45
 
data/lib/biff/options.rb CHANGED
@@ -3,7 +3,6 @@ require 'yaml'
3
3
 
4
4
  class Biff::Options
5
5
  ARGS = {
6
- verbose: 'Be noisy',
7
6
  debug: 'Debug IMAP connection',
8
7
  file: ['Config file', 'FILE', '~/.biff.yaml']
9
8
  }.freeze
@@ -30,6 +29,11 @@ class Biff::Options
30
29
  puts parser
31
30
  exit
32
31
  end
32
+
33
+ on(o, :version, "Print version (#{Biff::VERSION})") do
34
+ puts Biff::VERSION
35
+ exit
36
+ end
33
37
  end
34
38
 
35
39
  parser.parse!(ARGV)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Frankel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-07 00:00:00.000000000 Z
11
+ date: 2017-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: version