Skip to content

Commit

Permalink
Re-raise original error in mimemail:decode_header/2 (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
maltoe authored Oct 13, 2021
1 parent a39c02e commit ae6693a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/mimemail.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
%% in the case of a message/rfc822 attachment, body can be a single 5-tuple MIME structure.
%%
%% You should see the relevant RFCs (2045, 2046, 2047, etc.) for more information.
%%
%% Note that parts of this module (e.g., `decode/2') use the
%% <a href="https://hex.pm/packages/iconv"><tt>iconv</tt></a> library for string conversion,
%% which you will need to explicitly list as a dependency.

-module(mimemail).

Expand Down Expand Up @@ -188,13 +192,12 @@ decode_header(Value, Charset) ->
RTokens = tokenize_header(Value, []),
Tokens = lists:reverse(RTokens),
Decoded = try decode_header_tokens_strict(Tokens, Charset)
catch Type:Reason ->
catch Type:Reason:Stacktrace ->
case decode_header_tokens_permissive(Tokens, Charset, []) of
{ok, Dec} -> Dec;
error ->
% re-throw original error
% may also use erlang:raise/3 to preserve original traceback
erlang:Type(Reason)
erlang:raise(Type, Reason, Stacktrace)
end
end,
iolist_to_binary(Decoded).
Expand Down

0 comments on commit ae6693a

Please sign in to comment.