12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

138 MAIL FOLDER ANNOYANCE-FILTER §165<br />

165. This static method tests for an argument to a header field and stores the argument, if present,<br />

into arg . <strong>The</strong> argument name is canonicalised to lower case, but the argument is left as-is. Quotes are<br />

deleted from quoted arguments.<br />

〈 Class implementations 11 〉 +≡<br />

bool mailFolder ::parseHeaderArgument (string &s, const string target , string &arg )<br />

{<br />

if (s.length ( ) > target .length ( )) {<br />

string sc = s;<br />

string ::size type p, p1 ;<br />

stringCanonicalise (sc);<br />

if (((p = sc.find (target )) ≠ string ::npos ) ∧ (sc.length ( ) ><br />

(p + target .length ( ))) ∧ (sc[p + target .length ( )] ≡ ’=’)) {<br />

p += target .length ( ) + 1;<br />

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

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

if ((p1 = s.find (’"’, p + 1)) ≠ string ::npos ) {<br />

arg = s.substr (p + 1, p1 − (p + 1));<br />

return true ;<br />

}<br />

}<br />

else {<br />

string ::size type i = p;<br />

for ( ; i < s.length ( ); i++) {<br />

if (¬isISOspace (s[i])) {<br />

break;<br />

}<br />

}<br />

if (i < s.length ( )) {<br />

int n = 0;<br />

while ((i + n) < s.length ( )) {<br />

if ((isISOspace (s[i + n])) ∨ (s[i + n] ≡ ’;’)) {<br />

break;<br />

}<br />

n++;<br />

}<br />

arg = s.substr (i, n);<br />

}<br />

else {<br />

arg = "";<br />

}<br />

return true ;<br />

}<br />

}<br />

}<br />

}<br />

return false ;<br />

}

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

Saved successfully!

Ooh no, something went wrong!