Skip to content

Commit a598848

Browse files
committed
replace non-ascii chars in header values for messages that don't respect RFC2047
1 parent 842dd8b commit a598848

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/parse.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,9 @@ static char *mdecodeRFC2047(char *string, int length, char *charsetsave)
10871087
}
10881088
else {
10891089
free(storage);
1090+
/* make sure there are only ascii chars in the string
1091+
** for messages that don't respect rfc2047 */
1092+
i18n_replace_non_ascii_chars(string);
10901093
return string;
10911094
}
10921095
}

src/proto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ char *unobfuscate_email_address (char *);
9999
char *i18n_convstring(char *, char *, char *, size_t *);
100100
char *i18n_utf2numref(char *, int);
101101
unsigned char *i18n_numref2utf(char *);
102+
int i18n_replace_non_ascii_chars(char *);
102103

103104
char *PushByte(struct Push *, char);
104105
char *PushString(struct Push *, const char *);

src/string.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,25 @@ unsigned char *i18n_numref2utf(char *string){
452452
return headofutfstr;
453453
}
454454

455+
/* replaces all non 7-bit ascii chars in string by a ?
456+
** returns the number of replaced chars
457+
*/
458+
int i18n_replace_non_ascii_chars(char *string)
459+
{
460+
char *ptr = string;
461+
int count = 0;
462+
463+
while (*ptr) {
464+
if (!isascii(*ptr) || *ptr < 0x20) {
465+
*ptr = '?';
466+
count++;
467+
}
468+
ptr++;
469+
}
470+
471+
return count;
472+
}
473+
455474
#endif
456475
/* end of I18N hack */
457476

0 commit comments

Comments
 (0)