vmail 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/NOTES CHANGED
@@ -480,17 +480,15 @@ DONE
480
480
  - sending an attachment
481
481
  - can specify a directory, then all the items in the directory get
482
482
  attached and sent
483
+ - extract and append text of all selected messages into file (append)
483
484
 
484
485
  next:
485
- - forwarding with attachments
486
- - could be "attach: [uid] attachments to signal"
486
+ - tweak contacts list script (plus instruction for how to use)
487
487
  - help doc: just return readme file, or a vim version of it (vim filetype later)
488
488
  - follow mysql and use -u and -p flags on startup of server?
489
489
  - omitting -p flag forces prompt
490
- - print all selected messages into file (append)
491
490
  - ,s s confusion? Star vs search
492
- - enhance contacts auto fix with more advanced vim script
493
- - sort contacts by frequency, then take first 10 or so of any match
491
+ - note dependence on lynx in README
494
492
 
495
493
  later:
496
494
  - mvim - starred messages not syntax colored
@@ -504,8 +502,11 @@ later:
504
502
  - need to bundle macvim
505
503
  - if move to unknown mailbox, create the mailbox, then do the move
506
504
  - some lingering encoding issues
505
+ - forwarding with attachments
506
+ - could be "attach: [uid] attachments to signal"
507
507
  - something is wrong with cursorline sometimes
508
508
  - try flashing progress in echo line
509
+ - sort contacts by frequency, then take first 10 or so of any match
509
510
  - straight to switch mailbox, etc from message window
510
511
  - allow deliver command from any buffer or window, as long as headers are at top
511
512
  - range selection from : prompt
@@ -519,6 +520,8 @@ later:
519
520
  - tempname()
520
521
  - system() allows a parameters that is written to tmp file and passed
521
522
  to stdin
523
+ - enhance contacts auto fix with more advanced vim script
524
+ - create contacts database on first startup
522
525
 
523
526
 
524
527
 
data/lib/vmail.rb CHANGED
@@ -29,7 +29,7 @@ module Vmail
29
29
  buffer_file = "vmailbuffer.txt"
30
30
  puts "using buffer file: #{buffer_file}"
31
31
  File.open(buffer_file, "w") do |file|
32
- file.puts "just a moment..."
32
+ file.puts "fetching messages. please wait..."
33
33
  end
34
34
 
35
35
  # invoke vim
data/lib/vmail.vim CHANGED
@@ -1,5 +1,6 @@
1
1
  let s:mailbox = $VMAIL_MAILBOX
2
2
  let s:query = $VMAIL_QUERY
3
+ let s:append_file = ''
3
4
 
4
5
  let s:drb_uri = $DRB_URI
5
6
 
@@ -13,6 +14,7 @@ let s:select_mailbox_command = s:client_script . "select_mailbox "
13
14
  let s:search_command = s:client_script . "search "
14
15
  let s:more_messages_command = s:client_script . "more_messages "
15
16
  let s:flag_command = s:client_script . "flag "
17
+ let s:append_to_file_command = s:client_script . "append_to_file "
16
18
  let s:move_to_command = s:client_script . "move_to "
17
19
  let s:new_message_template_command = s:client_script . "new_message_template "
18
20
  let s:reply_template_command = s:client_script . "reply_template "
@@ -180,6 +182,7 @@ function! s:update()
180
182
  let line = line('$')
181
183
  $put =res
182
184
  setlocal nomodifiable
185
+ write
183
186
  let num = len(split(res, '\n', ''))
184
187
  redraw
185
188
  call cursor(line + 1, 0)
@@ -221,6 +224,7 @@ function! s:toggle_star() range
221
224
  exec a:firstline . "," . a:lastline . "delete"
222
225
  exec (a:firstline - 1). "put =res"
223
226
  setlocal nomodifiable
227
+ write
224
228
  " if more than 2 lines change, vim forces us to look at a message.
225
229
  " dismiss it.
226
230
  if len(split(res, "\n")) > 2
@@ -246,6 +250,7 @@ func! s:delete_messages(flag) range
246
250
  setlocal modifiable
247
251
  exec a:firstline . "," . a:lastline . "delete"
248
252
  setlocal nomodifiable
253
+ write
249
254
  " if more than 2 lines change, vim forces us to look at a message.
250
255
  " dismiss it.
251
256
  if len(uids) > 2
@@ -253,6 +258,27 @@ func! s:delete_messages(flag) range
253
258
  endif
254
259
  endfunc
255
260
 
261
+ " --------------------------------------------------------------------------------
262
+ " append text bodies of a set of messages to a file
263
+ func! s:append_messages_to_file() range
264
+ let lnum = a:firstline
265
+ let n = 0
266
+ let uids = []
267
+ while lnum <= a:lastline
268
+ let line = getline(lnum)
269
+ let message_uid = matchstr(line, '^\d\+')
270
+ call add(uids, message_uid)
271
+ let lnum = lnum + 1
272
+ endwhile
273
+ let uid_set = join(uids, ",")
274
+ let s:append_file = input("print messages to file: ", s:append_file)
275
+ let command = s:append_to_file_command . s:append_file . ' ' . uid_set
276
+ echo "appending " . len(uids) . " message" . (len(uids) == 1 ? '' : 's') . " to " s:append_file
277
+ let res = system(command)
278
+ echo res
279
+ redraw
280
+ endfunc
281
+
256
282
  " --------------------------------------------------------------------------------
257
283
  " move to another mailbox
258
284
  function! s:move_to_mailbox() range
@@ -465,7 +491,6 @@ function! s:compose_reply(all)
465
491
  endfunction
466
492
 
467
493
  function! s:compose_message()
468
- write
469
494
  let command = s:new_message_template_command
470
495
  call s:open_compose_window(command)
471
496
  " position cursor after to:
@@ -475,7 +500,6 @@ function! s:compose_message()
475
500
  endfunction
476
501
 
477
502
  function! s:compose_forward()
478
- write
479
503
  let command = s:forward_template_command . s:current_uid
480
504
  call s:open_compose_window(command)
481
505
  call search("^to:")
@@ -487,10 +511,12 @@ func! s:open_compose_window(command)
487
511
  redraw
488
512
  echo a:command
489
513
  let res = system(a:command)
490
- split ComposeMessage
491
- wincmd p
492
- close
514
+ split compose-message
515
+ setlocal buftype=nofile
516
+ setlocal noswapfile
493
517
  setlocal modifiable
518
+ wincmd p
519
+ close!
494
520
  1,$delete
495
521
  put! =res
496
522
  normal 1G
@@ -526,23 +552,22 @@ function! s:cancel_compose()
526
552
  endfunction
527
553
 
528
554
  function! s:send_message()
529
- write
530
555
  let mail = join(getline(1,'$'), "\n")
531
- exec ":!" . s:deliver_command . " < ComposeMessage"
556
+ echo "sending message"
557
+ call system(s:deliver_command, mail)
532
558
  redraw
533
- call s:focus_list_window()
534
- wincmd p
535
- close!
559
+ echo "sent! press q to go back to message list"
536
560
  endfunction
537
561
 
538
562
  func! s:save_draft()
539
- write
540
563
  let mail = join(getline(1,'$'), "\n")
541
- exec ":!" . s:save_draft_command . " < ComposeMessage"
564
+ echo "saving draft"
565
+ call system(s:save_draft_command, mail)
542
566
  redraw
543
567
  call s:focus_list_window()
544
568
  wincmd p
545
569
  close!
570
+ echo "draft saved"
546
571
  endfunc
547
572
 
548
573
  " --------------------------------------------------------------------------------
@@ -616,6 +641,7 @@ func! s:message_list_window_mappings()
616
641
  noremap <silent> <buffer> <leader>! :call <SID>delete_messages("[Gmail]/Spam")<CR>
617
642
  "open a link browser (os x)
618
643
  "autocmd CursorMoved <buffer> call <SID>show_message()
644
+ noremap <silent> <buffer> <leader>vp :call <SID>append_messages_to_file()<CR>
619
645
  noremap <silent> <buffer> u :call <SID>update()<CR>
620
646
  noremap <silent> <buffer> <Leader>s :call <SID>search_query()<CR>
621
647
  noremap <silent> <buffer> <Leader>m :call <SID>mailbox_window()<CR>
@@ -224,8 +224,11 @@ module Vmail
224
224
 
225
225
  def show_message(uid, raw=false, forwarded=false)
226
226
  uid = uid.to_i
227
+ if forwarded
228
+ return @current_message.split(/\n-{20,}\n/, 2)[1]
229
+ end
227
230
  return @current_mail.to_s if raw
228
- return @current_message if uid == @current_uid
231
+ return @current_message if uid == @current_uid
229
232
  log "fetching #{uid.inspect}"
230
233
  fetch_data = reconnect_if_necessary do
231
234
  @imap.uid_fetch(uid, ["FLAGS", "RFC822", "RFC822.SIZE"])[0]
@@ -240,8 +243,8 @@ module Vmail
240
243
  out = formatter.process_body
241
244
  size = fetch_data.attr["RFC822.SIZE"]
242
245
  @current_message = <<-EOF
243
- #{@mailbox} #{uid} #{number_to_human_size size} #{forwarded ? nil : format_parts_info(formatter.list_parts)}
244
- ----------------------------------------
246
+ #{@mailbox} #{uid} #{number_to_human_size size} #{format_parts_info(formatter.list_parts)}
247
+ ---------------------------------------
245
248
  #{format_headers(formatter.extract_headers)}
246
249
 
247
250
  #{out}
@@ -295,7 +298,20 @@ EOF
295
298
  log @imap.uid_store(uid_set, '+FLAGS', [:Deleted])
296
299
  end
297
300
 
298
- # TODO mark spam
301
+ def append_to_file(file, uid_set)
302
+ if uid_set.is_a?(String)
303
+ uid_set = uid_set.split(",").map(&:to_i)
304
+ end
305
+ log "append messages to file: #{file}"
306
+ uid_set.each do |uid|
307
+ message = show_message(uid)
308
+ divider = "#{'=' * 39}\n"
309
+ File.open(file, 'a') {|f| f.puts(divider + message + "\n\n")}
310
+ log "appended uid #{uid}"
311
+ end
312
+ "printed #{uid_set.size} message#{uid_set.size == 1 ? '' : 's'} to #{file.strip}"
313
+ end
314
+
299
315
 
300
316
  def new_message_template
301
317
  headers = {'from' => "#{@name} <#{@username}>",
@@ -349,7 +365,6 @@ EOF
349
365
  "\n\n#@signature"
350
366
  end
351
367
 
352
- # TODO, forward with attachments
353
368
  def forward_template(uid)
354
369
  original_body = show_message(uid, false, true)
355
370
  new_message_template +
@@ -397,7 +412,7 @@ EOF
397
412
  if (attachments = raw_body.split(/\n\s*\n/, 2)[0]) =~ /^attach(ment|ments)*:/
398
413
  # TODO
399
414
  files = YAML::load(attachments).values.flatten
400
- log "attachments: #{files}"
415
+ log "attach: #{files}"
401
416
  files.each do |file|
402
417
  if File.directory?(file)
403
418
  Dir.glob("#{file}/*").each {|f| mail.add_file(f) if File.size?(f)}
@@ -408,6 +423,7 @@ EOF
408
423
  mail.text_part do
409
424
  body raw_body.split(/\n\s*\n/, 2)[1]
410
425
  end
426
+
411
427
  else
412
428
  mail.text_part do
413
429
  body raw_body
data/lib/vmail/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vmail
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Choi