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.

§130 ANNOYANCE-FILTER MAIL FOLDER 113<br />

130. <strong>The</strong> nextLine method returns the next line from the mail folder to the caller, while parsing the<br />

mail folder into headers, recognising MIME multi-part messages and their boundaries and encodings.<br />

We wrap a grand while loop around the entire function so code within it can ignore the current input<br />

line (which may, depending on where you are in the process, be the concatenation of header lines with<br />

continuations), with a simple continue.<br />

〈 Class implementations 11 〉 +≡<br />

bool mailFolder ::nextLine (string &s)<br />

{<br />

while (true ) {<br />

bool decoderEOF = false ;<br />

if (lookedAhead ) {<br />

s = lookAheadLine ;<br />

lookedAhead = false ;<br />

}<br />

else {<br />

if (mdp ≠ Λ) {<br />

if ((asp ≠ Λ) ? (¬asp ⃗ nextString (s)) : (¬(mdp ⃗ getDecodedLine (s)))) {<br />

if (asp ≠ Λ) {<br />

if (Annotate (’d’)) {<br />

ostringstream os ;<br />

os ≪ "Closing␣" ≪ asp ⃗ name ( ) ≪ "␣application␣file␣decoder.";<br />

reportParserDiagnostic(os );<br />

}<br />

asp ⃗ close ( );<br />

asp = Λ;<br />

}<br />

s = mdp ⃗ getTerminatorSentinel ( );<br />

decoderEOF = mdp ⃗ isEndOfFile ( );<br />

if (decoderEOF ) {<br />

s = "";<br />

}<br />

if (Annotate (’d’)) {<br />

ostringstream os ;<br />

os ≪ "Closing␣out␣" ≪ mdp ⃗ name ( ) ≪ "␣decoder.␣␣" ≪<br />

mdp ⃗ getEncodedLineCount ( ) ≪ "␣lines␣decoded.";<br />

reportParserDiagnostic(os );<br />

os .str ("");<br />

os ≪ "End␣sentinel:␣" ≪ s;<br />

reportParserDiagnostic(os );<br />

}<br />

〈 Reset MIME decoder state 142 〉;<br />

inPartHeader = ¬((s.substr (0, 2) ≡ "−−") ∧ (s.substr (2,<br />

partBoundary .length ( )) ≡ partBoundary ) ∧ (s.substr (partBoundary .length ( ) + 2,<br />

2) ≡ "−−"));<br />

if ((¬inPartHeader ) ∧ (¬(partBoundaryStack .empty ( )))) {<br />

partBoundary = partBoundaryStack .top( );<br />

partBoundaryStack .pop( );<br />

}<br />

}<br />

}<br />

else {

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

Saved successfully!

Ooh no, something went wrong!