anchor.diff:  	    format_body(PartHeaders, Body);
   	{{"multipart/alternative",Opts}, Encoding} ->
   	    {value, {_,Boundary}} = lists:keysearch("boundary",1,Opts),
  -	    [{Headers,Body}|Parts] = parse_multipart(Msg, Boundary),
  -	    PartHeaders =
  -		lists:foldl(fun({K,V},MH) ->
  -				    add_header(K,V,MH)
  -			    end, #mail{}, Headers),
  -	    format_body(PartHeaders, Body);
  +	    Parts = parse_multipart(Msg, Boundary),
  +	    HParts =
  +		lists:map(
  +		  fun({Head,Body}) ->
  +			  NewHead =
  +			      lists:foldl(fun({K,V},MH) ->
  +						  add_header(K,V,MH)
  +					  end, #mail{}, Head),
  +			  {NewHead, Body}
  +		  end, Parts),
  +	    {H1,B1} = select_alt_body(["text/html","text/plain"],HParts),
  +	    format_body(H1,B1);
   	{{"multipart/signed",Opts}, Encoding} ->
   	    {value, {_,Boundary}} = lists:keysearch("boundary",1,Opts),
   	    [{Headers,Body}|Parts] = parse_multipart(Msg, Boundary),
  
positive.code: 	    {pre_html, Decoded};
  	{{"text/plain",_}, Encoding} ->
  	    Decoded = decode_message(Encoding, Msg),
  	    {pre, [], Decoded};
  	{{"multipart/mixed",Opts}, Encoding} ->
  	    {value, {_,Boundary}} = lists:keysearch("boundary",1,Opts),
  	    [{Headers,Body}|Parts] = parse_multipart(Msg, Boundary),
  
negative.code:     process_parts(Ps, [], [], [{Head, lists:reverse([B|Body])}|Res]);
  process_parts([{part_body,B}|Ps], Head, Body, Res) ->
      process_parts(Ps, Head, [B|Body], Res).
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % The text to wrap may be arbitrarily nested. We deal with this
  % without flattening the whole thing.
  %
  
  wrap_text(Text, Max) ->
      wrap_text(Text, [], [], 0, Max).
  
  wrap_text([], [], Unwrapped, Col, Max) ->
      if
  	Col < Max ->
  	    lists:reverse(Unwrapped);
  	true ->
  	    [$\n|lists:reverse(Unwrapped)]
      end;
  
  wrap_text([], Cont, Unwrapped, Col, Max) ->
      wrap_text(Cont, [], Unwrapped, Col, Max);
  
  wrap_text([L|Rest], [], Unwrapped, Col, Max) when list(L) ->
      wrap_text(L, Rest, Unwrapped, Col, Max);
  
  wrap_text([L|Rest], Cont, Unwrapped, Col, Max) when list(L) ->
      wrap_text(L, [Rest|Cont], Unwrapped, Col, Max);
  
  wrap_text([C|Rest], Cont, Unwrapped, Col, Max) when Col < Max ->
      case char_class(C) of
  	space ->
  	    [lists:reverse(Unwrapped),
  	     [C|wrap_text(Rest, Cont, [], Col+1, Max)]];
  	tab ->
  	    [lists:reverse(Unwrapped),
  	     [C|wrap_text(Rest, Cont, [], Col+8, Max)]];
  	nl ->
  	    [lists:reverse(Unwrapped),
  	     [C|wrap_text(Rest, Cont, [], 0, Max)]];
  	text ->
  	    wrap_text(Rest, Cont, [C|Unwrapped], Col+1, Max)
      end;
  wrap_text([C|Rest], Cont, Unwrapped, Col, Max) when Col >= Max ->
      case char_class(C) of
  	space ->
  	    [[$\n|lists:reverse(Unwrapped)], [C],
  	     wrap_text(Rest, Cont, [], length(Unwrapped), Max)];
  	tab ->
  	    [[$\n|lists:reverse(Unwrapped)], [C],
  	     wrap_text(Rest, Cont, [], length(Unwrapped), Max)];
  	nl ->
  	    [[$\n|lists:reverse(Unwrapped)], [C],
  	     wrap_text(Rest, Cont, [], length(Unwrapped), Max)];
  	text ->
  	    wrap_text(Rest, Cont, [C|Unwrapped], Col+1, Max)
      end.
  
  char_class($\n) -> nl;
  char_class($\r) -> nl;
  char_class($ )  -> space;
  char_class($\t) -> tab;
  char_class(O)   -> text.
      
  	
  	
  