anchor.diff:      decode_scan(Rest);
   decode([C|Cs]) ->
       [C | decode(Cs)].
  -     
  +
   decode_scan([]) -> [];
   decode_scan([$?,$b,$?|Rest]) ->
       decode_b64(Rest,[]);
  
positive.code: lowercase_ch(C) -> C.
  
  add_header("content-transfer-encoding", Value, H) ->
      H#mhead{transfer_encoding = lowercase(Value)};
  add_header("content-type", Value, H) ->
      H#mhead{content_type = parse_header_value(Value)};
  add_header("from", Value, H) ->    H#mhead{from = Value};
  add_header("to", Value, H) ->      H#mhead{to = Value};
  add_header("cc", Value, H) ->      H#mhead{cc = Value};
  add_header("bcc", Value, H) ->     H#mhead{bcc = Value};
  add_header("subject", Value, H) -> H#mhead{subject = Value};
  add_header("date", Value, H) ->    H#mhead{date = Value};
  add_header(Other, Value, H) ->     H#mhead{other = [{Other,Value}|
  						      H#mhead.other]}.
      
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  pop_request(Command, Server, User, Password) ->
  
negative.code: 	    {error, "Failed to contact mail server."}
      end.
  
  						%
  
  
  
  ploop(init, State) ->
      case receive_reply(State) of
  	{ok, Reply, State2} ->
  						% io:format("INIT got +OK ~s\n", [Reply]),
  	    psend("USER " ++ State#pstate.user, State#pstate.port),
  	    ploop(user, State2);
  	{error, Reason, State2} ->
  						% io:format("INIT got -ERR ~s\n", [Reason]),
  	    State#pstate.from ! {pop_response, {error, Reason}},
  	    gen_tcp:close(State#pstate.port);
  	{more, State2} ->
  						% io:format("INIT got more\n", []),
  	    ploop(init, State2)
      end;
  
  ploop(user, State) ->
      case receive_reply(State) of
  	{ok, Reply, State2} ->
  						% io:format("USER got +OK ~s\n", [Reply]),
  	    psend("PASS " ++ State#pstate.pass, State#pstate.port),
  	    ploop(pass, State2);
  	{error, Reason, State2} ->
  						% io:format("USER got -ERR ~s\n", [Reason]),
  	    State#pstate.from ! {pop_response, {error, Reason}},
  	    gen_tcp:close(State#pstate.port);
  	{more, State2} ->
  						% io:format("USER got more\n", []),
  	    ploop(user, State2)
      end;
  ploop(pass, State) ->
      case receive_reply(State) of
  	{ok, Reply, State2} ->
  						% io:format("PASS got +OK ~s\n", [Reply]),
  	    next_cmd(State);
  	{error, Reason, State2} ->
  						% io:format("PASS got -ERR ~s\n", [Reason]),
  	    State#pstate.from ! {pop_response, {error, Reason}},
  	    gen_tcp:close(State#pstate.port);
  	{more, State2} ->
  						% io:format("PASS got more\n", []),
  	    ploop(pass, State2)
      end;
  ploop(sl, State) ->
      case receive_reply(State) of
  	{ok, Reply, State2} ->
  						% io:format("SL got +OK ~s\n", [Reply]),
  	    next_cmd(State2#pstate{reply=[{ok,Reply}|State2#pstate.reply]});
  	{error, Reason, State2} ->
  						% io:format("SL got -ERR ~s\n", [Reason]),
  	    next_cmd(State2#pstate{reply=[{error,Reason}|
  					  State2#pstate.reply]});
  	{more, State2} ->
  						% io:format("SL got more\n", []),
  	    ploop(sl, State2)
      end;
  ploop(sized, State) ->
      case receive_reply(State) of
  	{ok, Reply, State2} ->
  	    Size = to_int(Reply),
  						% io:format("MLINE got +OK size=~p\n", [Size]),
  	    ploop(sized_cont, State2#pstate{remain=Size,lines=[]});
  	{error, Reason, State2} ->
  						% io:format("MLINE got -ERR ~s\n", [Reason]),
  	    next_cmd(State2#pstate{reply=[{error,Reason}|
  					  State2#pstate.reply]});
  	{more, State2} ->
  						% io:format("MLINE got more\n", []),
  	    ploop(ml, State2)
      end;
  ploop(sized_cont, State) ->
      case receive_data(State) of
  	{error, Reason, State2} ->
  						% io:format("SCONT got -ERR ~s\n", [Reason]),
  	    next_cmd(State2#pstate{reply=[{error,Reason}|
  					  State2#pstate.reply]});
  	{more, State2} ->
  						% io:format("SCONT got more\n", []),
  	    ploop(sized_cont, State2);
  	{done, State2} ->
  						% io:format("SCONT got done\n", []),
  	    Data = lists:reverse(State2#pstate.lines),
  	    next_cmd(State2#pstate{reply=[{ok, Data}|State2#pstate.reply]})
      end;
  ploop(ml, State) ->
      case receive_reply(State) of
  	{ok, Reply, State2} ->
  						% io:format("MLINE got +OK ~s\n", [Reply]),
  	    ploop(ml_cont, State2#pstate{lines=[]});
  	{error, Reason, State2} ->
  						% io:format("MLINE got -ERR ~s\n", [Reason]),
  	    next_cmd(State2#pstate{reply=[{error,Reason}|
  					  State2#pstate.reply]});
  	{more, State2} ->
  						% io:format("MLINE got more\n", []),
  	    ploop(ml, State2)
      end;
  ploop(ml_cont, State) ->
      case receive_reply(State) of
  	{line, Line, State2} ->
  						% io:format("MCONT got +OK ~s\n", [Line]),
  	    Lines = State2#pstate.lines,
  	    ploop(ml_cont, State2#pstate{lines=[Line|Lines]});
  	{error, Reason, State2} ->
  						% io:format("MCONT got -ERR ~s\n", [Reason]),
  	    next_cmd(State2#pstate{reply=[{error,Reason}|
  					  State2#pstate.reply]});
  	{more, State2} ->
  						% io:format("MCONT got more\n", []),
  	    ploop(ml_cont, State2);
  	{done, State2} ->
  						% io:format("MCONT got done\n", []),
  	    Lines = lists:reverse(State2#pstate.lines),
  	    next_cmd(State2#pstate{reply=[{ok, Lines}|State2#pstate.reply]})
      end.
  
  						%
  
  next_cmd(State=#pstate{cmd=Cmd,reply=Reply}) when Cmd==[]->
      State#pstate.from ! {pop_response, lists:reverse(Reply)},
  