diff -u -r --new-file WMMail.app-0.64/configure.in WMMail.app-0.64-sylpheed/configure.in --- WMMail.app-0.64/configure.in 2000-07-03 11:51:00.000000000 +0200 +++ WMMail.app-0.64-sylpheed/configure.in 2003-03-27 18:30:35.000000000 +0100 @@ -119,6 +119,14 @@ fi AC_SUBST(MH_SUPPORT) +AC_ARG_ENABLE(sylpheed, [ --disable-sylpheed disable sylpheed folder support], , enable_sylpheed=yes) +if test "$enable_sylpheed" = yes; then + SYLPHEED_SUPPORT="#define SYLPHEED_SUPPORT" +else + SYLPHEED_SUPPORT="#undef SYLPHEED_SUPPORT" +fi +AC_SUBST(SYLPHEED_SUPPORT) + AC_ARG_ENABLE(maildir, [ --disable-maildir disable MailDir support], , enable_maildir=yes) if test "$enable_maildir" = yes; then MAILDIR_SUPPORT="#define MAILDIR_SUPPORT" diff -u -r --new-file WMMail.app-0.64/src/config.h.in WMMail.app-0.64-sylpheed/src/config.h.in --- WMMail.app-0.64/src/config.h.in 2000-07-03 11:51:01.000000000 +0200 +++ WMMail.app-0.64-sylpheed/src/config.h.in 2003-03-27 18:31:09.000000000 +0100 @@ -50,6 +50,9 @@ /* support for mh folders */ @MH_SUPPORT@ +/* support for sylpheed folders (similar to mh)*/ +@SYLPHEED_SUPPORT@ + /* support for MailDir */ @MAILDIR_SUPPORT@ diff -u -r --new-file WMMail.app-0.64/src/Makefile.am WMMail.app-0.64-sylpheed/src/Makefile.am --- WMMail.app-0.64/src/Makefile.am 2000-07-03 11:51:01.000000000 +0200 +++ WMMail.app-0.64-sylpheed/src/Makefile.am 2003-03-27 18:30:51.000000000 +0100 @@ -25,8 +25,10 @@ wmmail_PROGRAMS = WMMail -WMMail_SOURCES = global.c imap.c list.c maildir.c mbox.c mh.c net.c pop3.c \ +WMMail_SOURCES = global.c \ + imap.c list.c maildir.c mbox.c mh.c sylpheed.c net.c pop3.c \ properties.c std_icons.c wmmail.c wmutil.c -noinst_HEADERS = config.h imap.h list.h maildir.h mbox.h mh.h net.h pop3.h \ +noinst_HEADERS = config.h \ + imap.h list.h maildir.h mbox.h mh.h sylpheed.h net.h pop3.h \ properties.h std_icons.h wmmail.h wmutil.h diff -u -r --new-file WMMail.app-0.64/src/properties.c WMMail.app-0.64-sylpheed/src/properties.c --- WMMail.app-0.64/src/properties.c 2000-07-03 11:51:01.000000000 +0200 +++ WMMail.app-0.64-sylpheed/src/properties.c 2003-03-27 18:31:22.000000000 +0100 @@ -605,6 +605,11 @@ mailbox->type = TYPE_MH; else #endif +#ifdef SYLPHEED_SUPPORT + if (!strcasecmp(mailbox_type_text, "sylpheed")) + mailbox->type = TYPE_SYLPHEED; + else +#endif #ifdef MAILDIR_SUPPORT if (!strcasecmp(mailbox_type_text, "maildir")) mailbox->type = TYPE_MAILDIR; @@ -628,6 +633,9 @@ #ifdef MH_SUPPORT "\"mh\", " #endif +#ifdef SYLPHEED_SUPPORT + "\"sylpheed\", " +#endif #ifdef MAILDIR_SUPPORT "\"MailDir\", " #endif diff -u -r --new-file WMMail.app-0.64/src/sylpheed.c WMMail.app-0.64-sylpheed/src/sylpheed.c --- WMMail.app-0.64/src/sylpheed.c 1970-01-01 01:00:00.000000000 +0100 +++ WMMail.app-0.64-sylpheed/src/sylpheed.c 2003-03-27 18:30:12.000000000 +0100 @@ -0,0 +1,243 @@ +/* + * WMMail - Window Maker Mail + * + * Copyright (c) 1996, 1997, 1998 Per Liden + * Copyright (c) 1997, 1998 Bryan Chan + * Copyright (c) 2003 Alberto Gonz'alez Palomo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * sylpheed.c: functions to handle Sylpheed-style mail folders + * + * Version 1.0, 2003-02-01 + * Modified from mh.c version 1.1, following the code in GKrellM + * Mailwatch plugin version 2.1, function "check_sylpheed_maildir()". + * + * GKrellM Mailwatch: http://gkrellm.luon.net/mailwatch.phtml + * Sylpheed: http://sylpheed.good-day.net/ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "wmmail.h" +#include "wmutil.h" + +#ifdef SYLPHEED_SUPPORT + +/* + * Supported key(s) in the Options dictionary: + * + * Path + * + * This module contains routines to check a Sylpheed-style (similar + * to MH) mail folder during the periodic update of wmmail_status. + * We can classify a given mail folder as being in one of the states + * listed below. + * + * The states and their corresponding effects on wmmail_status are: + * + * - no folder or empty folder NO_MAIL + * - no new mails OLD_MAIL + * - same number of new mails or fewer no change + * - more new mails than last time NEW_MAIL + * + * We assume that overriding automatically changes wmmail_status + * to OLD_MAIL. + * + */ + +/* internal function */ +static int count_mail(char *, int *, int *); + + +#define GET_ENTRY(x,y,z) { proplist_t sub_key = PLMakeString(z); \ + y = PLGetDictionaryEntry(x, sub_key); \ + PLRelease(sub_key); } + +int SYLPHEED_check(Mailbox *mailbox, int *beep, int *redraw, int *run) +{ + proplist_t path; + char *mailbox_path; + int prev_status, + prev_new_mail_count; + + prev_status = mailbox->status; + prev_new_mail_count = mailbox->new_mail_count; + + GET_ENTRY(mailbox->options, path, "Path"); + if (path == NULL) + { + croak("mailbox \"%s\" missing option \"Path\"; ignored", mailbox->name); + return False; + } + else if (!PLIsString(path)) + { + croak("mailbox \"%s\" has invalid path; ignored", mailbox->name); + return False; + } + else + mailbox_path = expand_path(PLGetString(path)); + + if ( count_mail(mailbox_path, + &mailbox->total_mail_count, + &mailbox->new_mail_count) ) + { + if (mailbox->total_mail_count == 0) + { + /* there is no mail in the mailbox */ + mailbox->status = NO_MAIL; + } + else if (mailbox->new_mail_count == 0) + { + /* there are no new mails */ + mailbox->status = OLD_MAIL; + } + else if (mailbox->new_mail_count > prev_new_mail_count) + { + /* new mails have arrived! */ + if (mailbox->status == NEW_MAIL && always_new_mail_exec) + *run |= True; + else if (mailbox->status == NEW_MAIL) + *run |= False; + else + *run |= True; + + *beep = True; + + mailbox->status = NEW_MAIL; + } + + /* else no change */ + } + else + { + /* no such mailbox */ + croak("error reading Sylpheed folder \"%s\"; ignored", mailbox->name); + wfree(mailbox_path); + return False; + } + + *redraw |= (prev_status != mailbox->status); + + mailbox->last_update = time(NULL); + + wfree(mailbox_path); + return True; +} + + +#define SYLPHEED_MESSAGE_IS_NEW 1 +#define SYLPHEED_MESSAGE_IS_UNREAD 2 +#define COUNT_UNREAD_AS_NEW False + +static int count_mail(char *path, int *total_mail_count, int *new_mail_count) +{ + struct dirent *entry; + DIR *folder; + FILE *seq; + char buf[512]; + int new_mail = 0, + all_mail = 0, + first_unseen = 0, + last_unseen = 0; + int version;/* Read from ".sylpheed_mark": format version. */ + int num; /* Read from ".sylpheed_mark": message number. */ + int flags; /* Read from ".sylpheed_mark": message flags. */ + int files_seen = 0;/* Files mentioned in the ".sylpheed_mark" file. */ + int files_in_dir = 0;/* Files physically in the directory (folder). */ + + /* Count total messages. */ + if ( !(folder = opendir(path)) ) + { + croak("cannot open directory %s", path); + return False; + } + + while ((entry = readdir(folder)) != NULL) + { + char *tmp = entry->d_name; + int is_message = True; + + while (*tmp) { (void) (isdigit(*tmp++) || (is_message = False)); } + + if (is_message) { files_in_dir++; } + } + + closedir(folder); + + sprintf(buf, "%s/.sylpheed_mark", path); + + /* find the new messages in the folder */ + if (seq = fopen(buf, "r")) + { + if (fread(&version, sizeof(version), 1, seq) != 1 || version != 2) + { + fclose(seq); + croak(".sylpheed_mark format version not supported: %d", version); + return False; + } + + while (fread(&num, sizeof(num), 1, seq) == 1) + { + if (fread(&flags, sizeof(flags), 1, seq) != 1) + break; + + if (flags & SYLPHEED_MESSAGE_IS_NEW) + new_mail++; + else if (COUNT_UNREAD_AS_NEW && flags & SYLPHEED_MESSAGE_IS_UNREAD) + new_mail++; + + files_seen++; + } + + if (files_seen < files_in_dir) + { + /* This happens when new messages arrive and Sylpheed still hasn't + * processed that folder, such as when it's not running. + */ + new_mail += (files_in_dir - files_seen); + all_mail = files_in_dir; + } + else + { + /* files_seen should never be greater than files_in_dir, unless + * the .sylpheed_mark file gets corrupted. We take all_mail from + * it, so that hopefully the user would notice if this number is + * bigger than the number of actual message files. + */ + all_mail = files_seen; + } + + fclose(seq); + } + else + { + croak(".sylpheed_mark not found or unreadable in %s", path); + return False; + } + + *total_mail_count = all_mail; + *new_mail_count = new_mail; + + return True; +} + +#endif diff -u -r --new-file WMMail.app-0.64/src/sylpheed.h WMMail.app-0.64-sylpheed/src/sylpheed.h --- WMMail.app-0.64/src/sylpheed.h 1970-01-01 01:00:00.000000000 +0100 +++ WMMail.app-0.64-sylpheed/src/sylpheed.h 2003-03-27 18:30:12.000000000 +0100 @@ -0,0 +1,37 @@ +/* + * WMMail - Window Maker Mail + * + * Copyright (c) 1996, 1997, 1998 Per Liden + * Copyright (c) 1997, 1998 Bryan Chan + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * sylpheed.h: function prototypes for sylpheed.c + * + * Version 1.0, 2003-02-01 + * + */ + +#ifndef SYLPHEED_H +#define SYLPHEED_H + +#include "wmmail.h" + +int SYLPHEED_check(Mailbox *, /* pointer to Mailbox structure */ + int *, /* whether we should beep */ + int *, /* whether we should redraw */ + int *); /* whether we should execute-on-new-mail */ + +#endif diff -u -r --new-file WMMail.app-0.64/src/wmmail.c WMMail.app-0.64-sylpheed/src/wmmail.c --- WMMail.app-0.64/src/wmmail.c 2000-07-03 11:51:01.000000000 +0200 +++ WMMail.app-0.64-sylpheed/src/wmmail.c 2003-03-27 18:31:37.000000000 +0100 @@ -52,6 +52,10 @@ # include "mh.h" #endif +#ifdef SYLPHEED_SUPPORT +# include "sylpheed.h" +#endif + #ifdef MAILDIR_SUPPORT # include "maildir.h" #endif @@ -96,7 +100,7 @@ void help(void) { - fprintf(stderr, + fprintf(stderr, "WMMail version %s%s by Bryan Chan (bryan.chan@utoronto.ca)\n" "based on asmail version 0.50, by Per Liden (per@rsn.hk-r.se)\n" "\n" @@ -546,6 +550,11 @@ ret = MH_check(mailbox, &beep, &redraw, &run); else #endif +#ifdef SYLPHEED_SUPPORT + if (IS_SYLPHEED(mailbox)) + ret = SYLPHEED_check(mailbox, &beep, &redraw, &run); + else +#endif #ifdef MAILDIR_SUPPORT if (IS_MAILDIR(mailbox)) ret = MAILDIR_check(mailbox, &beep, &redraw, &run); diff -u -r --new-file WMMail.app-0.64/src/wmmail.h WMMail.app-0.64-sylpheed/src/wmmail.h --- WMMail.app-0.64/src/wmmail.h 2000-07-03 11:51:01.000000000 +0200 +++ WMMail.app-0.64-sylpheed/src/wmmail.h 2003-03-27 18:31:42.000000000 +0100 @@ -77,14 +77,17 @@ #ifdef MH_SUPPORT # define TYPE_MH (1<<1) #endif +#ifdef SYLPHEED_SUPPORT +# define TYPE_SYLPHEED (1<<2) +#endif #ifdef MAILDIR_SUPPORT -# define TYPE_MAILDIR (1<<2) +# define TYPE_MAILDIR (1<<3) #endif #ifdef POP3_SUPPORT -# define TYPE_POP3 (1<<3) +# define TYPE_POP3 (1<<4) #endif #ifdef IMAP_SUPPORT -# define TYPE_IMAP (1<<4) +# define TYPE_IMAP (1<<5) #endif #ifdef MBOX_SUPPORT @@ -93,6 +96,9 @@ #ifdef MH_SUPPORT # define IS_MH(x) ((x)->type & TYPE_MH) #endif +#ifdef SYLPHEED_SUPPORT +# define IS_SYLPHEED(x) ((x)->type & TYPE_SYLPHEED) +#endif #ifdef MAILDIR_SUPPORT # define IS_MAILDIR(x) ((x)->type & TYPE_MAILDIR) #endif