vmail 2.3.8 → 2.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -198,11 +198,17 @@ To save you keystrokes, Vmail provides alternative key mappings for
198
198
 
199
199
  These save you from having to press the SHIFT key in each case.
200
200
 
201
- ## Checking for new messages
201
+ ## Checking for new messages, INBOX polling
202
202
 
203
203
  To check for new messages in the current mailbox, press `u` in normal
204
204
  mode if you're in the message list window or `,u` if you are in the
205
205
  message window. Watch the status line.
206
+
207
+ If you have `notify-send` (Linux) or `growlnotify` (OS X) installed on
208
+ your system, Vmail will also poll your INBOX every 30 seconds for new
209
+ messages. If it detects a new message, it will alert you through your
210
+ notification program. **NOTE**: You will still have to press `u` in the
211
+ Vmail interface to force the new messages to display.
206
212
 
207
213
  ## Switching mailboxes, moving messages, copying messages to another mailbox
208
214
 
@@ -3,6 +3,7 @@ require 'vmail/options'
3
3
  require 'vmail/imap_client'
4
4
  require 'vmail/query'
5
5
  require 'vmail/message_formatter'
6
+ require 'vmail/inbox_poller'
6
7
  require 'iconv'
7
8
 
8
9
  module Vmail
@@ -55,6 +56,12 @@ module Vmail
55
56
 
56
57
  puts "Starting vmail imap client for #{config['username']}"
57
58
 
59
+ # start inbox poller
60
+ inbox_poller = Vmail::InboxPoller.start config
61
+ Thread.new do
62
+ inbox_poller.start_polling
63
+ end
64
+
58
65
  drb_uri = begin
59
66
  Vmail::ImapClient.daemon config
60
67
  rescue
@@ -195,11 +195,11 @@ module Vmail
195
195
  end
196
196
 
197
197
  def check_for_new_messages
198
+ log "Checking for new messages"
198
199
  if search_query?
199
200
  log "Update aborted because query is search query: #{@query.inspect}"
200
201
  return ""
201
202
  end
202
- prime_connection
203
203
  old_num_messages = @num_messages
204
204
  # we need to re-select the mailbox to get the new highest id
205
205
  reload_mailbox
@@ -218,8 +218,8 @@ module Vmail
218
218
  new_ids
219
219
  end
220
220
 
221
- # TODO why not just reload the current page?
222
221
  def update
222
+ prime_connection
223
223
  new_ids = check_for_new_messages
224
224
  if !new_ids.empty?
225
225
  self.max_seqno = new_ids[-1]
@@ -490,7 +490,7 @@ EOF
490
490
  end
491
491
 
492
492
  def self.start(config)
493
- imap_client = Vmail::ImapClient.new config
493
+ imap_client = self.new config
494
494
  imap_client.open
495
495
  imap_client
496
496
  end
@@ -0,0 +1,68 @@
1
+ module Vmail
2
+ class InboxPoller < ImapClient
3
+
4
+ # This is a second IMAP client operating in a separate process
5
+
6
+ def start_polling
7
+ n = [`which notify-send`.chomp, `which growlnotify`.chomp].detect {|c| c != ''}
8
+ if n
9
+ log "Using notify tool: #{n}"
10
+ @notifier = case n
11
+ when /notify-send/
12
+ Proc.new {|t, m| `#{n} '#{t}' '#{m}'` }
13
+ when /growlnotify/
14
+ Proc.new {|t, m| `#{n} -t '#{t}' -m '#{m}'` }
15
+ end
16
+ else
17
+ log "No notification tool detected. INBOX polling aborted."
18
+ return
19
+ end
20
+
21
+ log "INBOX POLLER: started polling"
22
+ @mailboxes.unshift "INBOX"
23
+ select_mailbox "INBOX"
24
+ search "ALL"
25
+ loop do
26
+ log "INBOX POLLER: checking inbox"
27
+ update
28
+ sleep 30
29
+ end
30
+ end
31
+
32
+ def update
33
+ new_ids = check_for_new_messages
34
+ if !new_ids.empty?
35
+ self.max_seqno = new_ids[-1]
36
+ @ids = @ids + new_ids
37
+ message_ids = fetch_and_cache_headers(new_ids)
38
+ res = get_message_headers(message_ids)
39
+ @notifier.call "Vmail: new email", "from #{res}"
40
+ end
41
+ rescue
42
+ log "VMAIL_ERROR: #{[$!.message, $!.backtrace].join("\n")}"
43
+ end
44
+
45
+ def get_message_headers(message_ids)
46
+ messages = message_ids.map {|message_id|
47
+ m = Message[message_id]
48
+ if m.nil?
49
+ raise "Message #{message_id} not found"
50
+ end
51
+ m
52
+ }
53
+ res = messages.map {|m| m.sender }.join(", ")
54
+ res
55
+ end
56
+
57
+ def log(string)
58
+ if string.is_a?(::Net::IMAP::TaggedResponse)
59
+ string = string.raw_data
60
+ end
61
+ @logger.debug "[INBOX POLLER]: #{string}"
62
+ end
63
+
64
+
65
+ end
66
+ end
67
+
68
+
@@ -2,6 +2,7 @@ module Vmail
2
2
  module Searching
3
3
  # The main function called by the client to retrieve messages
4
4
  def search(query)
5
+ log "#search: #{query.inspect}"
5
6
  @query = Vmail::Query.parse(query)
6
7
  # customizable @limit is Deprecated
7
8
  @limit = 100
@@ -1,3 +1,3 @@
1
1
  module Vmail
2
- VERSION = '2.3.8'
2
+ VERSION = '2.3.9'
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 3
8
- - 8
9
- version: 2.3.8
8
+ - 9
9
+ version: 2.3.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Choi
@@ -108,6 +108,7 @@ files:
108
108
  - lib/vmail/flagging_and_moving.rb
109
109
  - lib/vmail/helpers.rb
110
110
  - lib/vmail/imap_client.rb
111
+ - lib/vmail/inbox_poller.rb
111
112
  - lib/vmail/message_formatter.rb
112
113
  - lib/vmail/options.rb
113
114
  - lib/vmail/query.rb