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.

§136 ANNOYANCE-FILTER MAIL FOLDER 119<br />

136. When we’re reading a mail folder consisting of a directory of individual mail messages, when we<br />

reach the end of a message file we wish to seamlessly advance to the next file, logically concatenating<br />

the files in the directory. This method, which should be called whenever the next file in the directory<br />

is required, searches the directory for the next eligible file and opens it. We return true if the file was<br />

opened successfully and false if the end of the directory was hit whilst looking for the next file.<br />

〈 Class implementations 11 〉 +≡<br />

#ifdef HAVE_DIRECTORY_TRAVERSAL<br />

bool mailFolder ::findNextFileInDirectory (string &fname )<br />

{<br />

assert(dirFolder );<br />

if (dh ≡ Λ) {<br />

return false ; /∗ End of directory already encountered ∗/<br />

}<br />

while (true ) {<br />

struct dirent ∗de ;<br />

struct stat fs ;<br />

de = readdir (dh );<br />

if (de ≡ Λ) {<br />

closedir (dh );<br />

dh = Λ;<br />

return false ;<br />

}<br />

cfName = dirName + pathSeparator + de ⃗ d name ;<br />

if (stat (cfName .c str ( ), &fs ) ≡ 0) {<br />

if (S_ISREG(fs .st mode )) {<br />

fname = cfName ;<br />

return openNextFileInDirectory ( );<br />

}<br />

}<br />

else {<br />

if (verbose ) {<br />

cerr ≪ "Cannot␣get␣status␣of␣" ≪ cfName ≪ ".␣␣Skipping." ≪ endl ;<br />

}<br />

}<br />

}<br />

}<br />

#endif

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

Saved successfully!

Ooh no, something went wrong!