The following function is lifted from unixdrop.cpp in the korn distribution. It is (C) Sirtaj Singh Kang <taj@kde.org> and is used under the GPL license (and the author's permission). It has been slightly modified for formatting reasons. Definition at line 1258 of file kbiffmonitor.cpp. { QFile mbox(mailbox); char buffer[MAXSTR]; int count = 0; int msg_count = 0; bool in_header = false; bool has_content_len = false; bool msg_read = false; long content_length = 0; oldCount = 0; curCount = 0; if (mbox.open(IO_ReadOnly) == false) return 0; buffer[MAXSTR-1] = 0; while (mbox.readLine(buffer, MAXSTR-2) > 0) { // read a line from the mailbox if (!strchr(buffer, '\n') && !mbox.atEnd()) { // read till the end of the line if we // haven't already read all of it. int c; while((c=mbox.getch()) >=0 && c !='\n'); } if (!in_header && real_from(buffer)) { // check if this is the start of a message has_content_len = false; in_header = true; msg_read = false; } else if (in_header) { // check header fields if we're already in one if (compare_header(buffer, "Content-Length")) { has_content_len = true; content_length = atol(buffer + 15); } // This should handle those folders that double as IMAP or POP // folders. Possibly PINE uses these always if (strcmp(buffer, "Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA\n") == 0) { oldCount--; curCount--; } else { if (compare_header(buffer, "Status")) { const char *field = buffer; field += 7; while (field && (*field== ' ' || *field == '\t')) field++; if (*field == 'N' || *field == 'U' || *field == 0x0a) msg_read = false; else msg_read = true; } // Netscape *sometimes* uses X-Mozilla-Status to determine // unread vs read mail. The only pattern I could see for // sure, though, was that Read mails started with an '8'. // I make no guarantees on this... else if (compare_header(buffer, "X-Mozilla-Status")) { const char *field = buffer; field += 17; while (field && (*field== ' ' || *field == '\t')) field++; if (*field == '8') msg_read = true; else msg_read = false; } else if (buffer[0] == '\n' ) { if (has_content_len) mbox.at(mbox.at() + content_length); in_header = false; oldCount++; if (!msg_read) { count++; } else { curCount++; } } } }//in header if(++msg_count >= 100 ) { qApp->processEvents(); msg_count = 0; } }//while mbox.close(); return count; }
|