--- pine/strings.c_orig 2004-03-12 10:48:17.783992528 +0100 +++ pine/strings.c 2004-03-12 11:01:37.929351944 +0100 @@ -2912,7 +2912,7 @@ int rfc1522_token PROTO((char *, char **)); int rfc1522_valtok PROTO((int)); int rfc1522_valenc PROTO((int)); -int rfc1522_valid PROTO((char *, char **, char **, char **, +int rfc1522_valid PROTO((char *, int, char **, char **, char **, char **)); char *rfc1522_8bit PROTO((void *, int)); char *rfc1522_binary PROTO((void *, int)); @@ -2949,7 +2949,7 @@ rfc1522_decode(d, len, s, charset) while(s && (sw = strstr(s, RFC1522_INIT))){ /* validate the rest of the encoded-word */ - if(rfc1522_valid(sw, &cset, &enc, &txt, &ew)){ + if(rfc1522_valid(sw, 1, &cset, &enc, &txt, &ew)){ if(!rv) rv = d; /* remember start of dest */ @@ -3222,10 +3222,15 @@ rfc1522_valenc(c) /* * rfc1522_valid - validate the given string as to it's rfc1522-ness + * if relaxchk is true, double the maximum length of an encoded word. + * this is necessary to decode overlong encoded words generated by + * numerous incompliant implementations of RFC 2047 (1522). + */ int -rfc1522_valid(s, charset, enc, txt, endp) +rfc1522_valid(s, relaxchk, charset, enc, txt, endp) char *s; + int relaxchk; char **charset; char **enc; char **txt; @@ -3237,7 +3242,11 @@ rfc1522_valid(s, charset, enc, txt, endp rv = rfc1522_token(c = s+RFC1522_INIT_L, rfc1522_valtok, RFC1522_DLIM, &e) && rfc1522_token(++e, rfc1522_valtok, RFC1522_DLIM, &t) && rfc1522_token(++t, rfc1522_valenc, RFC1522_TERM, &p) - && p - s <= RFC1522_MAXW; + && p - s <= RFC1522_MAXW * (relaxchk ? 2 : 1); + /* + * relax the length condition by doubling the max length of an + * encoded word. It's is needed for some longer encoded words. + */ if(charset) *charset = c; @@ -3288,7 +3297,7 @@ rfc1522_encode(d, len, s, charset) } else if(*p == RFC1522_INIT[0] && !strncmp((char *) p, RFC1522_INIT, RFC1522_INIT_L)){ - if(rfc1522_valid((char *) p, NULL, NULL, NULL, (char **) &q)) + if(rfc1522_valid((char *) p, 0, NULL, NULL, NULL, (char **) &q)) p = q + RFC1522_TERM_L - 1; /* advance past encoded gunk */ } else if(*p == ESCAPE && match_escapes((char *)(p+1))){