vmail 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  if !exists("g:vmail_flagged_color")
2
- let g:vmail_flagged_color = "ctermfg=green ctermbg=black"
2
+ let g:vmail_flagged_color = "ctermfg=green ctermbg=black guifg=green guibg=grey"
3
3
  endif
4
4
  let s:mailbox = $VMAIL_MAILBOX
5
5
  let s:query = $VMAIL_QUERY
@@ -25,7 +25,6 @@ let s:new_message_template_command = s:client_script . "new_message_template "
25
25
  let s:reply_template_command = s:client_script . "reply_template "
26
26
  let s:forward_template_command = s:client_script . "forward_template "
27
27
  let s:deliver_command = s:client_script . "deliver "
28
- let s:save_draft_command = s:client_script . "save_draft "
29
28
  let s:save_attachments_command = s:client_script . "save_attachments "
30
29
  let s:open_html_part_command = s:client_script . "open_html_part "
31
30
  let s:show_help_command = s:client_script . "show_help"
@@ -606,17 +605,6 @@ function! s:send_message()
606
605
  redraw
607
606
  endfunction
608
607
 
609
- func! s:save_draft()
610
- let mail = join(getline(1,'$'), "\n")
611
- echo "saving draft"
612
- call system(s:save_draft_command, mail)
613
- redraw
614
- call s:focus_list_window()
615
- wincmd p
616
- close!
617
- echo "draft saved"
618
- endfunc
619
-
620
608
  " --------------------------------------------------------------------------------
621
609
 
622
610
  " call from inside message window with <Leader>h
@@ -737,7 +725,6 @@ func! s:global_mappings()
737
725
  " NOTE send_message is a global mapping, so user can load a saved
738
726
  " message from a file and send it
739
727
  nnoremap <silent> <leader>vs :call <SID>send_message()<CR>
740
- nnoremap <silent> <leader>vd :call <SID>save_draft()<CR>
741
728
  noremap <silent> <leader>o :call <SID>open_href()<cr>
742
729
  noremap <silent> <leader>? :call <SID>show_help()<cr>
743
730
  endfunc
@@ -91,7 +91,8 @@ module Vmail
91
91
  log "priming connection for delivering"
92
92
  res = @imap.fetch(@ids[-1], ["ENVELOPE"])
93
93
  if res.nil?
94
- raise IOError, "IMAP connection seems broken"
94
+ # just go ahead, just log
95
+ log "priming connection didn't work, connection seems broken, but still going ahead..."
95
96
  end
96
97
  end
97
98
  end
@@ -283,9 +284,11 @@ module Vmail
283
284
  @imap.search(update_query.join(' '))
284
285
  }
285
286
  # TODO change this. will throw error now
286
- new_ids = ids.select {|x| x > @ids.max}
287
+ max_seqno = @message_list[-1][:seqno]
288
+ log "lookind for seqnos > #{max_seqno}"
289
+ new_ids = ids.select {|seqno| seqno > max_seqno}
287
290
  @ids = @ids + new_ids
288
- log "UPDATE: NEW UIDS: #{new_ids.inspect}"
291
+ log "update: new uids: #{new_ids.inspect}"
289
292
  if !new_ids.empty?
290
293
  res = fetch_envelopes(new_ids)
291
294
  res
@@ -380,17 +383,22 @@ EOF
380
383
  # for delete, do in a separate thread because deletions are slow
381
384
  Thread.new do
382
385
  unless @mailbox == '[Gmail]/Trash'
383
- @imap.uid_copy(uid_set, "[Gmail]/Trash")
386
+ log "@imap.uid_copy #{uid_set.inspect} to trash"
387
+ log @imap.uid_copy(uid_set, "[Gmail]/Trash")
384
388
  end
385
- res = @imap.uid_store(uid_set, action, [flg.to_sym])
389
+ log "@imap.uid_store #{uid_set.inspect} #{action} [#{flg.to_sym}]"
390
+ log @imap.uid_store(uid_set, action, [flg.to_sym])
386
391
  remove_uid_set_from_cached_lists(uid_set)
387
392
  reload_mailbox
388
393
  end
394
+
389
395
  elsif flg == '[Gmail]/Spam'
390
396
  log "Marking as spam index_range: #{index_range.inspect}; uid_set: #{uid_set.inspect}"
391
397
  Thread.new do
392
- @imap.uid_copy(uid_set, "[Gmail]/Spam")
393
- res = @imap.uid_store(uid_set, action, [:Deleted])
398
+ log "@imap.uid_copy #{uid_set.inspect} to spam"
399
+ log @imap.uid_copy(uid_set, "[Gmail]/Spam")
400
+ log "@imap.uid_store #{uid_set.inspect} #{action} [:Deleted]"
401
+ log @imap.uid_store(uid_set, action, [:Deleted])
394
402
  remove_uid_set_from_cached_lists(uid_set)
395
403
  reload_mailbox
396
404
  end
@@ -398,8 +406,8 @@ EOF
398
406
  else
399
407
  log "Flagging index_range: #{index_range.inspect}; uid_set: #{uid_set.inspect}"
400
408
  Thread.new do
401
- res = @imap.uid_store(uid_set, action, [flg.to_sym])
402
- log res.inspect
409
+ log "@imap.uid_store #{uid_set.inspect} #{action} [#{flg.to_sym}]"
410
+ log @imap.uid_store(uid_set, action, [flg.to_sym])
403
411
  end
404
412
  end
405
413
  end
@@ -415,18 +423,36 @@ EOF
415
423
 
416
424
  def remove_uid_set_from_cached_lists(uid_set)
417
425
  # delete from cached @ids and @message_list
426
+ seqnos_to_delete = []
418
427
  uid_set.each {|uid|
419
- @message_list.
420
- select {|row| row[:uid] == uid}.
421
- each {|row|
422
- seqno = row[:seqno]
423
- log "deleting seqno #{seqno} from @ids"
424
- @ids.delete seqno
425
- log "deleting msg uid #{row[:uid]} from @message_list"
426
- @message_list.delete(row)
427
- }
428
+ row = @message_list.detect {|row| row[:uid] == uid}
429
+ seqno = row[:seqno]
430
+ log "deleting seqno #{seqno} from @ids"
431
+ @ids.delete seqno
432
+ seqnos_to_delete << seqno
428
433
  }
429
-
434
+ log "seqnos_to_delete: #{seqnos_to_delete.inspect}"
435
+ seqnos_to_delete.reverse.each do |seqno|
436
+ startsize = @message_list.size
437
+ log "deleting row with seqno #{seqno}"
438
+ @message_list = @message_list.delete_if {|x| x[:seqno] == seqno}
439
+ endsize = @message_list.size
440
+ log "deleted #{startsize - endsize} rows"
441
+ end
442
+ # now we need to decrement all the higher sequence numbers!
443
+ basenum = seqnos_to_delete.min # this is the lowested seqno deleted
444
+ diff = seqnos_to_delete.size # substract this from all seqnos >= basenum
445
+ changes = []
446
+ @message_list.each do |row|
447
+ if row[:seqno] >= basenum
448
+ changes << "#{row[:seqno]}->#{row[:seqno] - diff}"
449
+ row[:seqno] -= diff
450
+ end
451
+ end
452
+ log "seqno decremented: #{changes.join(";")}"
453
+ rescue
454
+ log "error removing uid set from cached lists"
455
+ log $!
430
456
  end
431
457
 
432
458
  def move_to(id_set, mailbox)
@@ -444,6 +470,7 @@ EOF
444
470
  Thread.new do
445
471
  log @imap.uid_copy(uid_set, mailbox)
446
472
  log @imap.uid_store(uid_set, '+FLAGS', [:Deleted])
473
+ remove_uid_set_from_cached_lists(uid_set)
447
474
  reload_mailbox
448
475
  log "moved uid_set #{uid_set.inspect} to #{mailbox}"
449
476
  end
@@ -468,7 +495,8 @@ EOF
468
495
  log "current mailboxes: #{current_mailboxes.inspect}"
469
496
  log "creating mailbox #{mailbox}"
470
497
  log @imap.create(mailbox)
471
- mailboxes = nil # force reload next fime list_mailboxes() called
498
+ @mailboxes = nil # force reload ...
499
+ list_mailboxes
472
500
  end
473
501
  end
474
502
 
@@ -537,15 +565,6 @@ EOF
537
565
  "message '#{mail.subject}' sent"
538
566
  end
539
567
 
540
- def save_draft(text)
541
- mail = new_mail_from_input(text)
542
- log "saving draft"
543
- reconnect_if_necessary do
544
- log "saving draft"
545
- log @imap.append("[Gmail]/Drafts", text.gsub(/\n/, "\r\n"), [:Seen], Time.now)
546
- end
547
- end
548
-
549
568
  # TODO
550
569
  def resume_draft
551
570
  # chop off top three lines (this is hackey, fix later)
@@ -664,8 +683,11 @@ EOF
664
683
  log "error: #{$!}"
665
684
  log "attempting to reconnect"
666
685
  log(revive_connection)
667
- # try just once
668
- block.call
686
+ # hope this isn't an endless loop
687
+ reconnect_if_necessary do
688
+ close
689
+ block.call
690
+ end
669
691
  rescue
670
692
  log "error: #{$!}"
671
693
  raise
@@ -1,3 +1,3 @@
1
1
  module Vmail
2
- VERSION = "0.5.7"
2
+ VERSION = "0.5.8"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 7
9
- version: 0.5.7
8
+ - 8
9
+ version: 0.5.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Choi