12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

60 QUOTED-PRINTABLE MIME DECODER ANNOYANCE-FILTER §65<br />

65. <strong>The</strong> static method decodeEscapedText decodes text in its string argument, returning a string<br />

with escape sequences replaced by the encoded characters.<br />

〈 Class implementations 11 〉 +≡<br />

string quotedPrintableMIMEdecoder ::decodeEscapedText (const string s, mailFolder ∗m)<br />

{<br />

string r = "";<br />

}<br />

string ::size type p;<br />

for (p = 0; p < s.length ( ); p++) {<br />

bool decoded = false ;<br />

if (s[p] ≡ ’=’) {<br />

if (p > (s.length ( ) − 3)) {<br />

if (verbose ) {<br />

cerr ≪ "decodeEscapedText:␣escape␣too␣near␣end␣of␣string:␣" ≪ s ≪ endl ;<br />

}<br />

}<br />

else {<br />

int n1 = hex to nybble (s[p + 1]), n2 = hex to nybble (s[p + 2]);<br />

if ((n1 < 0) ∨ (n2 < 0)) {<br />

if (verbose ) {<br />

cerr ≪ "decodeEscapedText:␣invalid␣escape␣sequence␣\"" ≪ s.substr (p,<br />

3) ≪ "\"" ≪ endl ;<br />

}<br />

}<br />

else {<br />

r += static cast〈char〉((n1 ≪ 4) | n2 );<br />

decoded = true ;<br />

p += 2;<br />

}<br />

}<br />

}<br />

if (¬decoded ) {<br />

r += s[p];<br />

}<br />

}<br />

return r;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!