--- Kernel/System/Encode.pm	2008-03-11 16:18:01.000000000 +0100
+++ Kernel/System/Encode.pm	2008-03-11 16:19:31.000000000 +0100
@@ -195,37 +195,33 @@
         return $Param{Text};
     }
 
-    # if no encode is needed
-    if ( $Param{From} =~ /^$Param{To}$/i ) {
-        if ( $Param{To} =~ /^utf(-8|8)/i ) {
-            Encode::_utf8_on( $Param{Text} );
-        }
-        return $Param{Text};
-    }
 
-    # encode is needed
+    # always decode/encode, as some picky DB backends (like Postgres)
+    # fail horribly when trying to insert broken sequences. When recoding,
+    # Encode.pm does the right thing [tm] and replaces broken byte sequences
+    # by some safe character (usually '?'). Broken sequences usually happen
+    # when user mail has encoding A and some mail gateway appends some
+    # footer/disclaimer in encoding B (without doing the needed MIME magic)
+    if ( $Param{Force} ) {
+        Encode::_utf8_off( $Param{Text} );
+    }
+    if ( !eval { Encode::from_to( $Param{Text}, $Param{From}, $Param{To} ) } ) {
+        print STDERR
+            "Charset encode '$Param{From}' -=> '$Param{To}' ($Param{Text}) not supported!\n";
+    }
     else {
-        if ( $Param{Force} ) {
-            Encode::_utf8_off( $Param{Text} );
-        }
-        if ( !eval { Encode::from_to( $Param{Text}, $Param{From}, $Param{To} ) } ) {
-            print STDERR
-                "Charset encode '$Param{From}' -=> '$Param{To}' ($Param{Text}) not supported!\n";
-        }
-        else {
 
-            # set utf-8 flag
-            if ( $Param{To} =~ /^utf(8|-8)$/i ) {
+        # set utf-8 flag
+        if ( $Param{To} =~ /^utf(8|-8)$/i ) {
 
-                #                Encode::encode_utf8($Param{Text});
-                Encode::_utf8_on( $Param{Text} );
-            }
-            if ( $Self->{Debug} ) {
-                print STDERR "Charset encode '$Param{From}' -=> '$Param{To}' ($Param{Text})!\n";
-            }
+            #                Encode::encode_utf8($Param{Text});
+            Encode::_utf8_on( $Param{Text} );
+        }
+        if ( $Self->{Debug} ) {
+            print STDERR "Charset encode '$Param{From}' -=> '$Param{To}' ($Param{Text})!\n";
         }
-        return $Param{Text};
     }
+    return $Param{Text};
 }
 
 =item SetIO()
