- # now we have got a decoded subject, try to convert into the encoding
- unless ($charset eq $enc) {
- eval { Encode::from_to($enc_str, $charset, $enc) };
- if ($@) {
- $charset = _GuessCharset( $enc_str );
- Encode::from_to($enc_str, $charset, $enc);
- }
- }
+ # now we have got a decoded subject, try to convert into the encoding
+ unless ( $charset eq $to_charset ) {
+ my $orig_str = $enc_str;
+ eval { Encode::from_to( $enc_str, $charset, $to_charset, Encode::FB_CROAK ) };
+ if ($@) {
+ $enc_str = $orig_str;
+ $charset = _GuessCharset( $enc_str );
+ Encode::from_to( $enc_str, $charset, $to_charset );
+ }
+ }