Bug 160488

Summary: Rewrite header adds the new header too many times
Product: [Applications] kmail Reporter: András Manţia <amantia>
Component: filteringAssignee: kdepim bugs <kdepim-bugs>
Status: RESOLVED NOT A BUG    
Severity: normal    
Priority: NOR    
Version: 1.9.50   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:

Description András Manţia 2008-04-06 21:20:14 UTC
Version:            (using Devel)
Installed from:    Compiled sources

For some mails I need to rewrite the header Content-Type, otherwise KMail uses the wrong encoding for it.
So I set up a filter:
Rewrite header: Content-Type
Replace: . (tried with empty field as well)
With: text/plain;charset="iso-8859-2"

The original mail was:
Content-Type: text/plain;
  charset=ISO-8859-1

After I applied the filter manually:
Content-Type: text/plain;
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2";
  charset="iso-8859-2"

If I apply the filter again on the same message I get much-much-more (several pages) of
  charset="iso-8859-2";
Comment 1 Thomas McGuire 2008-04-15 18:19:09 UTC
That is not a bug.
The "Rewrite Header" filter rule will replace each occurence of the given text with something else.
In your case, you used ".", which is the regular expression for "any character".
So each character will be replaces with "text/plain;charset="iso-8859-2"", leading to many of those strings.
Use a better regular expression, preferable something that matches the incorrect charset only.

KMail also has a fallback character encoding for the reader window, see the config options (though that only works in the lastest SVN version).