anchor.diff:  %% @equiv step(State, Cmd) if there is a command the queue
   -spec step(#state{}) ->
       #state{}.
  -step(#state{active=none, cmds=Cmds} = State) ->
  +step(#state{active=none, cmds=Cmds, socket=Socket, tag=Tag} = State) ->
       case queue:out(Cmds) of
           {empty, Cmds} ->
               State;
  -        {{value, Cmd}, Cmds2} ->
  -            send_cmd(State#state{cmds=Cmds2}, Cmd)
  +        {{value, {cmd, _, InternalCmd} = Cmd}, Cmds2} ->
  +            CTag = <<$C, (integer_to_binary(Tag))/binary>>,
  +            ?LOG_DEBUG("SENDING: ~p", [cmd_to_data(InternalCmd)]),
  +            ok = ssl:send(Socket, [CTag, " " | cmd_to_data(InternalCmd)]),
  +            State#state{cmds=Cmds2, tag=Tag+1, active={CTag, Cmd}}
       end.
   
   
  -%% @doc tag and send the cmd
  --spec send_cmd(#state{}, internal_cmd()) ->
  -    #state{}.
  -send_cmd(#state{} = State, {cmd, _, {login, {plain, Username, Password}}} = Cmd) ->
  -    send_cmd(State, Cmd, intersperse(" ", ["LOGIN", Username, Password, "\r\n"])).
  -
  --spec send_cmd(#state{}, internal_cmd(), iodata()) ->
  -    #state{}.
  -send_cmd(#state{socket=Socket, tag=Tag} = State, Cmd, Data) ->
  -    CTag = <<$C, (integer_to_binary(Tag))/binary>>,
  -    ?LOG_DEBUG("SENDING: ~p", [Data]),
  -    ok = ssl:send(Socket, [CTag, " " | Data]),
  -    State#state{tag=Tag+1, active={CTag, Cmd}}.
  +%% @doc return a command as iodata() ready to be sent to the IMAP server
  +-spec cmd_to_data(internal_cmd()) ->
  +    iodata().
  +cmd_to_data(InternalCmd) ->
  +    %% XXX -- ineffecient end append
  +    intersperse(" ", cmd_to_list(InternalCmd)) ++ ["\r\n"].
  +
  +
  +%% @doc return the list of command tokens
  +-spec cmd_to_list(internal_cmd()) ->
  +    iodata().
  +cmd_to_list({login, {plain, Username, Password}}) ->
  +    ["LOGIN", Username, Password];
  +cmd_to_list(list) ->
  +    ["LIST"].
   
   
   %% @doc intersperses the separator between list elements
  --spec intersperse(Sep :: iodata(), Xs :: iodata()) ->
  -    iodata().
  +-spec intersperse(Sep, [Sep | A]) ->
  +    [A] when Sep :: _, A :: _.
   intersperse(_, []) ->
     [];
   intersperse(_, [X]) ->
  
positive.code: %% @doc An imap connection
  -module(imap).
  -behaviour(gen_server).
  
  -export([parse/1]).
  %% Interface exports
  -export([start/1, start/2,
           start_link/1, start_link/2,
  
negative.code: -type auth_xoauth2() :: {xoauth2, Account :: binary(), Token :: binary()}.
  -type auth() ::  auth_plain() | auth_xoauth2().
  
  -type cmd() :: {login, auth()}
                 | list.
  -type internal_cmd() :: {cmd, pid() | none, cmd()}.
  
  %% Parse Types
  -type parse_result() :: {atom, binary()}         % Atom    [A-Za-z0-9+]+
                          | integer()              % Number  [0-9]+
                          | {string, binary()}     % String  "*" | {n}*
                          | [parse_result()]       % List    (parse_result())
                          | nil.                   % NIL     NIL
  
  -type parse_state() :: none
                         | {string, binary()}
                         | {atom, binary()}
                         | {number, binary()}.
  
  
  %% Records
  -record(state, {socket :: socket(),
  