Method: Vmail::FlaggingAndMoving#flag

Defined in:
lib/vmail/flagging_and_moving.rb

#flag(message_ids, action, flg) ⇒ Object

uid_set is a string comming from the vim client action is -FLAGS or +FLAGS



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vmail/flagging_and_moving.rb', line 13

def flag(message_ids, action, flg)
  uid_set = convert_to_message_ids(message_ids)
  log "Flag #{uid_set} #{flg} #{action}"
  if flg == 'Deleted'
    log "Deleting uid_set: #{uid_set.inspect}"
    decrement_max_seqno(uid_set.size)
    # for delete, do in a separate thread because deletions are slow
    spawn_thread_if_tty do 
      unless @mailbox == mailbox_aliases['trash']
        log "imap.uid_copy #{uid_set.inspect} to #{mailbox_aliases['trash']}"
        log @imap.uid_copy(uid_set, mailbox_aliases['trash'])
      end
      log "imap.uid_store #{uid_set.inspect} #{action} [#{flg.to_sym}]"
      log @imap.uid_store(uid_set, action, [flg.to_sym])
      reload_mailbox
      clear_cached_message
    end
  elsif flg == 'spam' || flg == mailbox_aliases['spam'] 
    log "Marking as spam uid_set: #{uid_set.inspect}"
    decrement_max_seqno(uid_set.size)
    spawn_thread_if_tty do 
      log "imap.uid_copy #{uid_set.inspect} to #{mailbox_aliases['spam']}"
      log @imap.uid_copy(uid_set, mailbox_aliases['spam']) 
      log "imap.uid_store #{uid_set.inspect} #{action} [:Deleted]"
      log @imap.uid_store(uid_set, action, [:Deleted])
      reload_mailbox
      clear_cached_message
    end
  else
    log "Flagging uid_set: #{uid_set.inspect}"
    spawn_thread_if_tty do
      log "imap.uid_store #{uid_set.inspect} #{action} [#{flg.to_sym}]"
      log @imap.uid_store(uid_set, action, [flg.to_sym])
    end
  end
rescue
  log $!
end