diff -urN icewm-1.2.25/src/amailbox.cc icewm-1.2.25_maildir/src/amailbox.cc --- icewm-1.2.25/src/amailbox.cc 2006-02-03 07:24:27.000000000 +0100 +++ icewm-1.2.25_maildir/src/amailbox.cc 2006-03-18 13:39:40.000000000 +0100 @@ -20,6 +20,8 @@ #include "wmapp.h" #include #include +#include +#include static YColor *taskBarBg = 0; extern ref taskbackPixmap; @@ -64,7 +66,9 @@ state = ERROR; } else server_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - } else if (!strcmp(fURL.scheme(), "file")) + } else if (!strcmp(fURL.scheme(), "maildir")) + protocol = MAILDIR; + else if (!strcmp(fURL.scheme(), "file")) protocol = LOCALFILE; else warn(_("Invalid mailbox protocol: \"%s\""), fURL.scheme()); @@ -143,6 +147,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 { if (sk.connect((struct sockaddr *) &server_addr, sizeof(server_addr)) == 0) @@ -306,6 +335,46 @@ sk.read(bf, sizeof(bf)); } +void MailCheck::countMaildirMsgs(const char *path) { + + DIR *dir; + struct dirent *entry; + char absolutePath[1025]; + struct stat info; + + 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 { + if (strstr(path, "new")!=NULL + && strcmp(strstr(path,"new"),"new")==0) { + fLastCount++; +#ifdef DEBUG + msg("Maildir/ new message found. There are by the" \ + "moment: %d", fLastCount); +#endif + } + } + } + } + closedir(dir); + } +} + + MailBoxStatus::MailBoxStatus(const char *mailbox, YWindow *aParent): YWindow(aParent), fMailBox(newstr(mailbox)), check(this) { diff -urN icewm-1.2.25/src/amailbox.h icewm-1.2.25_maildir/src/amailbox.h --- icewm-1.2.25/src/amailbox.h 2006-02-03 07:24:27.000000000 +0100 +++ icewm-1.2.25_maildir/src/amailbox.h 2006-03-18 13:39:40.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: