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.

§219 ANNOYANCE-FILTER POP3 PROXY SERVER IMPLEMENTATION 179<br />

219. <strong>The</strong> pop<strong>Filter</strong> function handles the actual filtering of messages retrieved by the POP proxy<br />

server. It takes the text of each message, creates mail folder to read it as an istringstream, then<br />

classifies the message, generating a transcript annotated with the classification, which is returned to the<br />

client in lieu of the raw message received from the server.<br />

〈 Utility functions 219 〉 ≡<br />

#ifdef POP3_PROXY_SERVER<br />

void pop<strong>Filter</strong> (const string command , const string argument , char ∗replyBuffer , int<br />

∗replyLength , string &reply )<br />

{<br />

if ((command ≡ "retr") ∧ ((∗replyLength ) > 0) ∧ (replyBuffer [0] ≡ ’+’)) {<br />

〈 Create mail folder to read reply from POP3 server 220 〉;<br />

〈 Classify the message, generating an in-memory transcript of the results 221 〉;<br />

#define not POPFILTER TRACE<br />

#ifdef POPFILTER_TRACE<br />

cerr ≪ "Classification␣done." ≪ endl ;<br />

#endif<br />

#ifdef OLDWAY<br />

ostringstream os ;<br />

#else<br />

unsigned int mtl = mf .sizeMessageTranscript ( );<br />

#ifdef POPFILTER_TRACE<br />

cerr ≪ "Message␣transcript␣predicted␣size:␣" ≪ mtl ≪ endl ;<br />

#endif<br />

char ∗mtbuf = new char[mtl + 16];<br />

ostrstream os (mtbuf , mtl + 16);<br />

#endif<br />

mf .writeMessageTranscript (os );<br />

#ifdef POPFILTER_TRACE<br />

cerr ≪ "Transcript␣written." ≪ endl ;<br />

#endif<br />

mf .clearMessageTranscript ( );<br />

#ifdef POPFILTER_TRACE<br />

cerr ≪ "Transcript␣cleared." ≪ endl ;<br />

cerr ≪ "Message␣transcript␣actual␣size:␣" ≪ os .tellp( ) ≪ endl ;<br />

#endif<br />

reply .erase ( );<br />

#ifndef OLDWAY<br />

os ≪ ’\0’;<br />

#endif<br />

reply = os .str ( );<br />

#ifdef POPFILTER_TRACE<br />

cerr ≪ "Reply␣string␣length:␣" ≪ reply .length ( ) ≪ endl ;<br />

#endif<br />

#ifndef OLDWAY<br />

delete mtbuf ;<br />

#endif<br />

#ifdef POPFILTER_TRACE<br />

cerr ≪ "Reply␣created." ≪ endl ;<br />

#endif<br />

〈 Modify POP3 reply message to reflect change in text length 222 〉;<br />

#ifdef POPFILTER_TRACE

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

Saved successfully!

Ooh no, something went wrong!