The Annoyance Filter.pdf - Fourmilab
The Annoyance Filter.pdf - Fourmilab
The Annoyance Filter.pdf - Fourmilab
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
§147 ANNOYANCE-FILTER MAIL FOLDER 127<br />
147. Message header lines may contain sequences of characters encoded in Quoted−Printable or<br />
Base64 form (since mail headers must not contain 8 bit characters). To better extract words from these<br />
lines, we test for such subsequences and replace them with the encoded text. Due to the fact that, in<br />
the fullness of time, this code will be fed every conceivable kind of nonconforming trash, it must be<br />
completely bulletproof. <strong>The</strong> flailing around with p4 protects against falling into a loop when decoding<br />
a sequence fails.<br />
〈 Check for encoded header line and decode 147 〉 ≡<br />
if (inHeader ) {<br />
string sc = s;<br />
string ::size type p, p1 , p2 , p3 , p4 ;<br />
char etype ;<br />
unsigned int ndecodes = 0;<br />
string charset ;<br />
stringCanonicalise (sc);<br />
p4 = 0;<br />
while (((p = sc.find ("=?", p4 )) ≠ string ::npos )) {<br />
p4 = p + 2;<br />
if (((p1 = sc.find ("?q?", p4 )) ≠ string ::npos ) ∨ ((p1 = sc.find ("?b?", p4 )) ≠ string ::npos ))<br />
{<br />
charset = sc.substr (p4 , p1 − p4 );<br />
etype = sc[p1 + 1];<br />
p4 = p1 + 3;<br />
if ((p2 = sc.find ("?=", p4 )) ≠ string ::npos ) {<br />
p1 += 3;<br />
p3 = p2 − p1 ;<br />
string drt ;<br />
if (etype ≡ ’q’) {<br />
drt = quotedPrintableMIMEdecoder ::decodeEscapedText (sc.substr (p1 , p3 ), this);<br />
}<br />
else {<br />
assert(etype ≡ ’b’);<br />
drt = base64MIMEdecoder ::decodeEscapedText (sc.substr (p1 , p3 ), this);<br />
}<br />
〈 Interpret header quoted string if character set known 148 〉;<br />
sc.replace (p, (p2 − p) + 2, drt );<br />
p4 = p + drt .length ( );<br />
ndecodes ++;<br />
}<br />
}<br />
}<br />
if (ndecodes > 0) {<br />
s = sc;<br />
}<br />
}<br />
This code is cited in section 256.<br />
This code is used in section 141.