On Wed, Aug 04, 2004 at 12:25:39PM +0200, Dominik Vogt wrote: > > I don't feel confortable playing around with the Makefiles so I just added > > #define USE_MAILDIR at the top of Goodies.c (I'm hoping that someone who > > knows more can do this right). > > Using compile time configuration in general and #ifdef in > particular is not the right way in fvwm. Every feature has to be > configurable at run time. Here is what I would do: > > - Add a new config variable, e.g. MailDir > - Add a flag that indicates whether MailBox or MailDir is used. > - Split the __cool_get_inboxstatus() function into two sub > functions __cool_get_inboxstatus_mailbox() and > cool_get_inboxstatus_maildir() and call one of them from > cool_get_inboxstatus() according to the flag state. >
Done. Set "*FvwmTaskBar: MailDir" in the config file to toggle the flag. I considered adding Postfix-style detection (checking for the '/' at the end of the filename). I can't decide which of the two is the better idea, so I decided to attach both versions. -- Infinite complexity begets infinite beauty. Infinite precision begets infinite perfection.
--- Goodies.c.orig Sun Jun 29 20:55:22 2003 +++ Goodies.c Thu Aug 19 23:43:23 2004 @@ -20,6 +20,7 @@ #include <stdio.h> #include <unistd.h> #include <fcntl.h> +#include <dirent.h> #include <pwd.h> #include "libs/ftime.h" #include <sys/stat.h> @@ -83,6 +84,7 @@ int ShowTips = False; char *statusfont_string = NULL; int last_date = -1; +Bool using_MailDir = False; void cool_get_inboxstatus(); @@ -173,6 +175,7 @@ "IgnoreOldMail", "ShowTips", "DateFormat", + "MailDir", NULL }; @@ -255,6 +258,9 @@ do_display_clock = False; } break; + case 12: /* MailDir */ + using_MailDir = True; + break; default: /* unknow option */ return False; @@ -502,6 +508,7 @@ else { str = _("You have mail"); + //str = using_MailDir ? _("You have mail (maildir)") : _("You have mail (mbox)"); } PopupTipWindow(win_width, 0, str); @@ -712,7 +719,17 @@ /* (based on the code of 'coolmail' By Byron C. Darrah */ /*-----------------------------------------------------*/ -void cool_get_inboxstatus() +/* filter to show only new entries */ +int maildir_filter(const struct dirent * a) +{ + if (!strcmp(a->d_name, ".") || !strcmp(a->d_name, "..")) + { + return 0; + } + return 1; +} + +void cool_get_inboxstatus_mbox() { static off_t oldsize = 0; off_t newsize; @@ -752,6 +769,79 @@ } oldsize = newsize; +} + +void cool_get_inboxstatus_maildir() +{ + static int oldsize = 0; + int newsize; + struct dirent **newlist; + struct dirent **curlist; + char * alt_mailpath; + int curent, newent; + + alt_mailpath = malloc(strlen(mailpath) + strlen("/new") + 1); + strcpy(alt_mailpath, mailpath); + strcat(alt_mailpath, "/new"); + newent = scandir(alt_mailpath, &newlist, maildir_filter, alphasort); + free(alt_mailpath); + + alt_mailpath = malloc(strlen(mailpath) + strlen("/cur") + 1); + strcpy(alt_mailpath, mailpath); + strcat(alt_mailpath, "/cur"); + curent = scandir(alt_mailpath, &curlist, maildir_filter, alphasort); + free(alt_mailpath); + + newsize = curent + newent; + + if (newent > 0) + { + anymail = 1; + unreadmail = 1; + } + else if (curent > 0) + { + anymail = 1; + unreadmail = 0; + } + else + { + anymail = 0; + unreadmail = 0; + } + if (newsize > oldsize && unreadmail) + { + newmail = 1; + mailcleared = 0; + } + else + { + newmail = 0; + } + + oldsize = newsize; + + /* forgot this bit of garbage-cleaning in the original patch */ + while(curent--) + { + free(curlist[curent]); + } + free(curlist); + while(newent--) + { + free(newlist[newent]); + } + free(newlist); +} + +void cool_get_inboxstatus() +{ + if (using_MailDir) + { + cool_get_inboxstatus_maildir(); + } else { + cool_get_inboxstatus_mbox(); + } } /*---------------------------------------------------------------------------*/
--- Goodies.c.orig Sun Jun 29 20:55:22 2003 +++ Goodies.c Thu Aug 19 23:55:00 2004 @@ -20,6 +20,7 @@ #include <stdio.h> #include <unistd.h> #include <fcntl.h> +#include <dirent.h> #include <pwd.h> #include "libs/ftime.h" #include <sys/stat.h> @@ -712,7 +713,17 @@ /* (based on the code of 'coolmail' By Byron C. Darrah */ /*-----------------------------------------------------*/ -void cool_get_inboxstatus() +/* filter to show only new entries */ +int maildir_filter(const struct dirent * a) +{ + if (!strcmp(a->d_name, ".") || !strcmp(a->d_name, "..")) + { + return 0; + } + return 1; +} + +void cool_get_inboxstatus_mbox() { static off_t oldsize = 0; off_t newsize; @@ -752,6 +763,79 @@ } oldsize = newsize; +} + +void cool_get_inboxstatus_maildir() +{ + static int oldsize = 0; + int newsize; + struct dirent **newlist; + struct dirent **curlist; + char * alt_mailpath; + int curent, newent; + + alt_mailpath = malloc(strlen(mailpath) + strlen("/new") + 1); + strcpy(alt_mailpath, mailpath); + strcat(alt_mailpath, "/new"); + newent = scandir(alt_mailpath, &newlist, maildir_filter, alphasort); + free(alt_mailpath); + + alt_mailpath = malloc(strlen(mailpath) + strlen("/cur") + 1); + strcpy(alt_mailpath, mailpath); + strcat(alt_mailpath, "/cur"); + curent = scandir(alt_mailpath, &curlist, maildir_filter, alphasort); + free(alt_mailpath); + + newsize = curent + newent; + + if (newent > 0) + { + anymail = 1; + unreadmail = 1; + } + else if (curent > 0) + { + anymail = 1; + unreadmail = 0; + } + else + { + anymail = 0; + unreadmail = 0; + } + if (newsize > oldsize && unreadmail) + { + newmail = 1; + mailcleared = 0; + } + else + { + newmail = 0; + } + + oldsize = newsize; + + /* forgot this bit of garbage-cleaning in the original patch */ + while(curent--) + { + free(curlist[curent]); + } + free(curlist); + while(newent--) + { + free(newlist[newent]); + } + free(newlist); +} + +void cool_get_inboxstatus() +{ + if ((strlen(mailpath)-1) && (mailpath[strlen(mailpath)-1] == '/')) + { + cool_get_inboxstatus_maildir(); + } else { + cool_get_inboxstatus_mbox(); + } } /*---------------------------------------------------------------------------*/