Hello, world!

The X-DSPAM-Factors header can contain arbitrary 8-bit characters,
which confuses several programs parsing messages. This patch modifies
it to have all characters except for the obviously safe region encoded
using the "%xx" syntax (quoted-printable would suit mail headers better,
but it is pretty impractical here since the tokens often contain equal
signs).

                                Have a nice fortnight
-- 
Martin `MJ' Mares                          <[EMAIL PROTECTED]>   
http://mj.ucw.cz/
Faculty of Math and Physics, Charles University, Prague, Czech Rep., Earth
Ctrl and Alt keys stuck -- press Del to continue.

--- dspam-3.8.0/src/dspam.c.mj  2006-12-12 16:33:45.000000000 +0100
+++ dspam-3.8.0/src/dspam.c     2007-05-25 13:38:09.000000000 +0200
@@ -3079,9 +3092,16 @@
             while(node_ft != NULL) {
               struct dspam_factor *f = (struct dspam_factor *) node_ft->ptr;
               if (f) {
+               char *s, *t;
                 strlcat(data, ",\n\t", sizeof(data));
-                snprintf(scratch, sizeof(scratch), "%s, %2.5f",
-                         f->token_name, f->value);
+               s = f->token_name;
+               t = scratch;
+               while (*s && t < scratch + sizeof(scratch) - 16)
+                 if (*s >= ' ' && *s < 0x7f && *s != '%')
+                   *t++ = *s++;
+                 else
+                   t += sprintf(t, "%%%02x", (unsigned char) *s++);
+               snprintf(t, 15, ", %2.5f", f->value);
                 strlcat(data, scratch, sizeof(data));
               }
               node_ft = c_nt_next(CTX->factors, &c_ft);

Reply via email to