diff -urN ./src/amailbox.cc ../icewm-1.2.16-md/src/amailbox.cc --- ./src/amailbox.cc 2004-12-08 21:16:46.000000000 +0100 +++ ../icewm-1.2.16-md/src/amailbox.cc 2004-12-08 21:01:17.000000000 +0100 @@ -20,6 +20,8 @@ #include "wmapp.h" #include #include +#include +#include static YColor *taskBarBg = 0; extern ref taskbackPixmap; @@ -64,11 +66,14 @@ state = ERROR; } else server_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - } else if (!strcmp(fURL.scheme(), "file")) + } else if (!strcmp(fURL.scheme(), "file")) { protocol = LOCALFILE; - else + } else if (!strcmp(fURL.scheme(), "maildir")) { + protocol = MAILDIR; + } else { warn(_("Invalid mailbox protocol: \"%s\""), fURL.scheme()); - } else + } + } else warn(_("Invalid mailbox path: \"%s\""), url); if (validURL != url) delete[] validURL; @@ -143,6 +148,31 @@ fMbx->mailChecked(MailBoxStatus::mbxHasMail, fLastCount); fLastSize = st.st_size; } + } else if (protocol == MAILDIR) { + + struct stat st; + + if (fURL.path() == 0) + return; + + if (stat(fURL.path(), &st) == -1) { + fMbx->mailChecked(MailBoxStatus::mbxNoMail, 0); + fLastCount = 0; + fLastSize = 0; + fLastUnseen = 0; + } else { + fLastCount=0; + countMaildirMsgs(fURL.path()); + if (countMailMessages && fLastCount>0) { + fMbx->mailChecked(MailBoxStatus::mbxHasUnreadMail, + fLastCount); + } else if (!countMailMessages && fLastCount>0) { + fMbx->mailChecked(MailBoxStatus::mbxHasUnreadMail, -1); + } else { + fMbx->mailChecked(MailBoxStatus::mbxNoMail, fLastCount); + + } + } } else { sk.connect((struct sockaddr *) &server_addr, sizeof(server_addr)); state = CONNECTING; @@ -150,6 +180,50 @@ } } +void MailCheck::countMaildirMsgs(const char *path) { + + DIR *dir; + struct dirent *entry; + char absolutePath[1025]; + struct stat info; + char *flagsOnMessage; + + if ((dir = opendir(path)) == NULL) + warn("opendir() error on %s", path); + else { + while ((entry = readdir(dir)) != NULL) { + /* Skip '.' and '..' dirs */ + if (strcasecmp(".", entry->d_name) && + strcasecmp("..",entry->d_name)) { + strcpy(absolutePath, path); + strcat(absolutePath, "/"); + strcat(absolutePath, entry->d_name); + if (stat(absolutePath, &info) != 0) + warn("stat() error on %s: %s\n", absolutePath, + strerror(errno)); + else if (S_ISDIR(info.st_mode)) { + countMaildirMsgs(absolutePath); + } else { + /* Last comma on message name, when in cur/ dir */ + flagsOnMessage = strstr(entry->d_name, ":2,"); + /* ignore files that start with a dot */ + if (entry->d_name[0] != '.' + && (flagsOnMessage == NULL + || strchr(flagsOnMessage, 'S') == NULL)) { + fLastCount++; +#ifdef DEBUG + msg("* Maildir/ new message found: %s. " \ + "There are by the moment: %d", entry->d_name, + fLastCount); +#endif + } + } + } + } + closedir(dir); + } +} + void MailCheck::socketConnected() { //puts("CONNECTED"); got = 0; diff -urN ./src/amailbox.h ../icewm-1.2.16-md/src/amailbox.h --- ./src/amailbox.h 2004-12-08 21:16:46.000000000 +0100 +++ ../icewm-1.2.16-md/src/amailbox.h 2004-12-08 18:39:35.000000000 +0100 @@ -33,7 +33,8 @@ enum { LOCALFILE, POP3, - IMAP + IMAP, + MAILDIR } protocol; MailCheck(MailBoxStatus *mbx); @@ -45,6 +46,7 @@ virtual void socketConnected(); virtual void socketError(int err); virtual void socketDataRead(char *buf, int len); + void countMaildirMsgs(const char *path); void error(); private: