    # File lib/vmail/imap_client.rb, line 509
        def flag(uid_set, action, flg)
          log "flag #{uid_set} #{flg} #{action}"
          uid_set = uid_set.split(',').map(&:to_i)
          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
        end