vmail 0.4.6 → 0.4.7

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.
data/README.markdown CHANGED
@@ -130,7 +130,7 @@ top of the list that looks something like this:
130
130
 
131
131
  Put the cursor on this line and press ENTER to load more of these messages.
132
132
 
133
- Unread messages are marked with a `[+]` symbol.
133
+ Unread messages are marked with a `+` symbol.
134
134
 
135
135
  To view the raw RFC822 version of a message, type `,R` while viewing the message.
136
136
 
@@ -138,7 +138,7 @@ To view the raw RFC822 version of a message, type `,R` while viewing the message
138
138
 
139
139
  To star a message, put the cursor on it and type `,*`. (Note that the comma
140
140
  before the * is part of the key sequence.) Starring a message copies it to the
141
- `starred` mailbox. Starred messages are marked with a `[*]` symbol and
141
+ `starred` mailbox. Starred messages are marked with a `*` symbol and
142
142
  color-highlighted.
143
143
 
144
144
  To delete a message, put the cursor on it and type `,#`. Deleting a message
@@ -419,6 +419,17 @@ Then you can create an SSH tunnel, e.g.
419
419
 
420
420
  [davebolton]:https://github.com/lightningdb
421
421
 
422
+
423
+ ## Customizing colors
424
+
425
+ By default, vmail highlights starred messages in bold green against a black
426
+ background. You can customize this setting by adding a line to your ~/.vimrc
427
+ file like so:
428
+
429
+ let g:vmail_flagged_color = "ctermfg=yellow ctermbg=black cterm=bold"
430
+
431
+ Type `:help highlight-args` in Vim for more details.
432
+
422
433
  ## Bug reports, feature requests
423
434
 
424
435
  Please file bug reports and feature requests in the [vmail github issue tracker][tracker].
data/lib/vmail.vim CHANGED
@@ -1,3 +1,6 @@
1
+ if !exists("g:vmail_flagged_color")
2
+ let g:vmail_flagged_color = "ctermfg=green ctermbg=black"
3
+ endif
1
4
  let s:mailbox = $VMAIL_MAILBOX
2
5
  let s:query = $VMAIL_QUERY
3
6
  let s:browser_command = $VMAIL_BROWSER
@@ -67,14 +70,15 @@ endfunction
67
70
 
68
71
  function! s:show_message()
69
72
  let line = getline(line("."))
70
- if match(line, '^> Load') != -1
73
+ if match(line, '^> Load') != -1
71
74
  setlocal modifiable
72
75
  delete
73
76
  call s:more_messages()
74
77
  return
75
78
  endif
76
- " remove the unread flag [+]
77
- let newline = substitute(line, "\\[+\]\\s*", "", '')
79
+ " remove the unread flag +
80
+ " TODO!
81
+ let newline = substitute(line, '^**+', ' ', '')
78
82
  setlocal modifiable
79
83
  call setline(line('.'), newline)
80
84
  setlocal nomodifiable
@@ -156,8 +160,9 @@ function! s:focus_list_window()
156
160
  " set up syntax highlighting
157
161
  if has("syntax")
158
162
  syn clear
159
- syn match BufferFlagged /^.*[*].*$/hs=s
160
- hi def BufferFlagged ctermfg=red
163
+ " colorize whole line
164
+ syn match VmailBufferFlagged /^*.*/hs=s
165
+ exec "hi def VmailBufferFlagged " . g:vmail_flagged_color
161
166
  endif
162
167
  " vertically center the cursor line
163
168
  " normal z.
@@ -199,32 +204,46 @@ endfunction
199
204
 
200
205
  function! s:toggle_star() range
201
206
  let uid_set = (a:firstline - 2) . '..' . (a:lastline - 2)
202
- let flag_symbol = "[*]"
207
+ let nummsgs = (a:lastline - a:firstline + 1)
208
+ let flag_symbol = "^*"
203
209
  " check if starred already
204
210
  let action = " +FLAGS"
205
211
  if (match(getline(a:firstline), flag_symbol) != -1)
206
212
  let action = " -FLAGS"
207
213
  endif
208
214
  let command = s:flag_command . uid_set . action . " Flagged"
209
- if (a:lastline - a:firstline + 1) == 1
215
+ if nummsgs == 1
210
216
  echom "toggling flag on message"
211
217
  else
212
- echom "toggling flags on " . (a:lastline - a:firstline + 1) . " messages"
218
+ echom "toggling flags on " . nummsgs . " messages"
213
219
  endif
214
- " toggle [*] on lines; TODO: do this all in vimscript and do the starring
215
- " in a thread in imap_client
220
+ " toggle * on lines
216
221
  let res = system(command)
217
222
  setlocal modifiable
218
- exec a:firstline . "," . a:lastline . "delete"
219
- exec (a:firstline - 1). "put =res"
223
+ let lnum = a:firstline
224
+ while lnum <= a:lastline
225
+ let line = getline(lnum)
226
+ if action == " +FLAGS"
227
+ let newline = substitute(line, '^ ', '*', '')
228
+ let newline = substitute(newline, '^+ ', '*+', '')
229
+ else
230
+ let newline = substitute(line, '^*+', '+ ', '')
231
+ let newline = substitute(newline, '^* ', ' ', '')
232
+ endif
233
+ call setline(lnum, newline)
234
+ let lnum += 1
235
+ endwhile
220
236
  setlocal nomodifiable
221
237
  write
222
- " if more than 2 lines change, vim forces us to look at a message.
223
- " dismiss it.
224
- if len(split(res, "\n")) > 2
225
- call feedkeys("\<cr>")
238
+ if nummsgs > 2
239
+ " call feedkeys("\<cr>")
240
+ endif
241
+ redraw
242
+ if nummsgs == 1
243
+ echom "toggled flag on message"
244
+ else
245
+ echom "toggled flags on " . nummsgs . " messages"
226
246
  endif
227
- echom "done"
228
247
  endfunction
229
248
 
230
249
  " flag can be Deleted or [Gmail]/Spam
@@ -442,6 +461,7 @@ function! s:select_mailbox()
442
461
  setlocal nomodifiable
443
462
  write
444
463
  normal z.
464
+ echom "done"
445
465
  endfunction
446
466
 
447
467
  func! s:search_query()
@@ -478,15 +498,14 @@ function! s:do_search()
478
498
  1,$delete
479
499
  put! =res
480
500
  execute "normal Gdd\<c-y>"
481
- normal z.
482
501
  setlocal nomodifiable
483
502
  write
503
+ normal z.
484
504
  endfunction
485
505
 
486
506
  function! s:more_messages()
487
507
  let line = getline(line('.'))
488
- let uid = matchstr(line, '^\d\+')
489
- let command = s:more_messages_command . uid
508
+ let command = s:more_messages_command
490
509
  echo "fetching more messages. please wait..."
491
510
  let res = system(command)
492
511
  setlocal modifiable
@@ -743,5 +762,3 @@ autocmd bufreadpost *.txt call <SID>turn_into_compose_window()
743
762
  call system(s:select_mailbox_command . shellescape(s:mailbox))
744
763
  call s:do_search()
745
764
 
746
-
747
-
@@ -120,7 +120,6 @@ module Vmail
120
120
  if id_set.is_a?(String)
121
121
  id_set = id_set.split(',')
122
122
  end
123
- max_id = id_set.to_a[-1]
124
123
  if id_set.to_a.empty?
125
124
  log "empty set"
126
125
  return ""
@@ -137,7 +136,7 @@ module Vmail
137
136
  log(error) && raise(error)
138
137
  end
139
138
  log "extracting headers"
140
- new_message_rows = results.map {|x| extract_row_data(x, max_id) }
139
+ new_message_rows = results.map {|x| extract_row_data(x) }
141
140
  if are_uids
142
141
  # replace old row_text values
143
142
  new_message_rows.each {|new_row_data|
@@ -156,7 +155,7 @@ module Vmail
156
155
  end
157
156
 
158
157
  # TODO extract this to another class or module and write unit tests
159
- def extract_row_data(fetch_data, max_id=nil)
158
+ def extract_row_data(fetch_data)
160
159
  seqno = fetch_data.seqno
161
160
  uid = fetch_data.attr['UID']
162
161
  # log "fetched seqno #{seqno} uid #{uid}"
@@ -194,21 +193,18 @@ module Vmail
194
193
  subject = envelope.subject || ''
195
194
  subject = Mail::Encodings.unquote_and_convert_to(subject, 'UTF-8')
196
195
  flags = format_flags(flags)
197
- first_col_width = max_id.to_s.length
198
- mid_width = @width - (first_col_width + 33)
196
+ mid_width = @width - 38
199
197
  address_col_width = (mid_width * 0.3).ceil
200
198
  subject_col_width = (mid_width * 0.7).floor
201
- row_text = [ seqno.to_s.col(first_col_width),
202
- (date_formatted || '').col(14),
203
- address.col(address_col_width),
204
- subject.col(subject_col_width),
205
- number_to_human_size(size).rcol(6),
206
- flags.rcol(7)
207
- ].join(' ')
199
+ row_text = [ flags.col(2),
200
+ (date_formatted || '').col(14),
201
+ address.col(address_col_width),
202
+ subject.col(subject_col_width),
203
+ number_to_human_size(size).rcol(6) ].join(' ')
208
204
  {:uid => uid, :seqno => seqno, :row_text => row_text}
209
205
  rescue
210
206
  log "error extracting header for uid #{uid} seqno #{seqno}: #$!"
211
- row_text =i "#{seqno.to_s} : error extracting this header"
207
+ row_text = "#{seqno.to_s} : error extracting this header"
212
208
  {:uid => uid, :seqno => seqno, :row_text => row_text}
213
209
  end
214
210
 
@@ -224,16 +220,16 @@ module Vmail
224
220
  exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit
225
221
  number /= 1024 ** exponent
226
222
  unit = UNITS[exponent]
227
- "#{number} #{unit}"
223
+ "#{number}#{unit}"
228
224
  end
229
225
  end
230
226
 
231
- FLAGMAP = {:Flagged => '[*]'}
227
+ FLAGMAP = {:Flagged => '*'}
232
228
  # flags is an array like [:Flagged, :Seen]
233
229
  def format_flags(flags)
234
230
  flags = flags.map {|flag| FLAGMAP[flag] || flag}
235
231
  if flags.delete(:Seen).nil?
236
- flags << '[+]' # unread
232
+ flags << '+' # unread
237
233
  end
238
234
  flags.join('')
239
235
  end
@@ -294,7 +290,8 @@ module Vmail
294
290
  end
295
291
 
296
292
  # gets 100 messages prior to id
297
- def more_messages(message_id, limit=100)
293
+ def more_messages(limit=100)
294
+ message_id = @message_list[0][:seqno]
298
295
  log "more_messages: message_id #{message_id}"
299
296
  message_id = message_id.to_i
300
297
  if @all_search
@@ -329,7 +326,7 @@ module Vmail
329
326
  return res
330
327
  end
331
328
  log "remaining messages: #{remaining}"
332
- "> Load #{[100, remaining].min} more messages. #{remaining} remaining.\n" + res
329
+ "> Load #{[100, remaining].min} more messages. #{remaining} remaining.\n" + res
333
330
  end
334
331
 
335
332
  def show_message(index, raw=false)
@@ -352,7 +349,7 @@ module Vmail
352
349
  out = formatter.process_body
353
350
  size = fetch_data.attr["RFC822.SIZE"]
354
351
  @current_message = <<-EOF
355
- #{@mailbox} #{index} #{number_to_human_size size} #{format_parts_info(formatter.list_parts)}
352
+ #{@mailbox} seqno:#{index} uid:#{uid} #{number_to_human_size size} #{format_parts_info(formatter.list_parts)}
356
353
  ---------------------------------------
357
354
  #{format_headers(formatter.extract_headers)}
358
355
 
@@ -397,9 +394,10 @@ EOF
397
394
  "#{id} deleted"
398
395
  else
399
396
  log "Flagging index_range: #{index_range.inspect}; uid_set: #{uid_set.inspect}"
400
- res = @imap.uid_store(uid_set, action, [flg.to_sym])
401
- log res.inspect
402
- fetch_envelopes(uid_set, true).tap {|x| log x}
397
+ Thread.new do
398
+ res = @imap.uid_store(uid_set, action, [flg.to_sym])
399
+ log res.inspect
400
+ end
403
401
  end
404
402
  end
405
403
 
data/lib/vmail/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vmail
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 6
9
- version: 0.4.6
8
+ - 7
9
+ version: 0.4.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Choi