diff -ru xbuffy3.2.1time/xbuffy.c xbuffy3.2.1patch/xbuffy.c --- xbuffy3.2.1time/xbuffy.c Fri Mar 21 19:26:06 1997 +++ xbuffy3.2.1patch/xbuffy.c Sat Mar 22 05:11:54 1997 @@ -36,6 +36,8 @@ #include #include #include +#include +#include #ifndef SUN #include #include @@ -199,7 +201,8 @@ num = CountNNTP(currentBox, NULL, &beenTouched); } #endif /* NNTP */ - if (boxInfo[i].type == MAILBOX) + if ((boxInfo[i].type == MAILBOX) || (boxInfo[i].type == MAILDIR) || + (boxInfo[i].type == MHDIR)) { num = CountUnixMail(currentBox, NULL, &beenTouched); } @@ -484,7 +487,8 @@ #endif /* update the number on the box (in case there are new articles) */ - if (currentBox->type == MAILBOX) + if ((currentBox->type == MAILBOX) || (currentBox->type == MAILDIR) || + (currentBox->type == MHDIR)) { number = CountUnixMail(currentBox, mailHeaders, &beenTouched); @@ -655,42 +659,16 @@ return(retVal); } -int CountUnixMail(mailBox, headerString, beenTouched) +int CountMBoxMail(mailBox, headerString) BoxInfo_t *mailBox; DynObject headerString; - Boolean *beenTouched; { FILE *fp = 0; char buffer[MAX_STRING]; char From[MAX_STRING], Subject[MAX_STRING]; - register int count = 0; int status; register Boolean in_header = FALSE; - struct stat f_stat; - struct timeval t[2]; - - *beenTouched = FALSE; - - if (isLocked(mailBox->box)) - return (mailBox->n); - - if (stat(mailBox->box, &f_stat)) - { - mailBox->st_size = 0; - mailBox->box_mtime = 0; - return (0); - } - - if ((f_stat.st_size != mailBox->st_size) || - (f_stat.st_mtime > mailBox->box_mtime)) - { - mailBox->st_size = f_stat.st_size; - mailBox->box_mtime = f_stat.st_mtime; - *beenTouched = TRUE; - } - - if ((!*beenTouched) && (headerString == NULL)) - return (mailBox->n); + register int count = 0; fp = fopen(mailBox->box, "r"); if (fp == NULL) @@ -723,7 +701,6 @@ if (header_cmp(buffer, "From", NULL)) { strcpy(From, buffer); - } @@ -773,6 +750,169 @@ } fclose(fp); + return count; +} + +int CountDirMail(mailBox, headerString) + BoxInfo_t *mailBox; + DynObject headerString; +{ + DIR *dp = 0; + FILE *fp = 0; + char buffer[MAX_STRING]; + char From[MAX_STRING], Subject[MAX_STRING]; + char path[_POSIX_PATH_MAX]; + int status; + register Boolean found = FALSE; + register Boolean mailfile = TRUE; + struct dirent *de; + register int count = 0; + + if (mailBox->type == MAILDIR) { + sprintf(path, "%s/new", mailBox->box); + } else { + strcpy(path,mailBox->box); + } + dp = opendir(path); + if (dp == NULL) + return 0; + + while ((de = readdir (dp)) != NULL) + { + mailfile = TRUE; + if (mailBox->type == MHDIR) { + char *p; + p = de->d_name; + while (*p && mailfile) + { + if (!isdigit (*p)) mailfile = FALSE; + p++; + } + } else if (mailBox->type == MAILDIR) { + if (*de->d_name == '.') mailfile = FALSE; + } + if (mailfile) + { + if (mailBox->type == MAILDIR) count++; + if (headerString != NULL || mailBox->type == MHDIR) { + /* Ok, we need to get the From: and Subject: lines */ + From[0] = Subject[0] = '\0'; + found = FALSE; + status = NEW_MSG; + if (mailBox->type == MAILDIR) { + sprintf(path, "%s/new/%s",mailBox->box,de->d_name); + } else { + sprintf(path, "%s/%s",mailBox->box,de->d_name); + } + fp = fopen(path, "r"); + if (fp != NULL) { + while (!found && fgets(buffer, MAX_STRING - 2, fp) != 0) + { + long CL; + int has_CL; + + buffer[MAX_STRING - 1] = '\0'; /* just in case */ + if ((strchr(buffer, '\n') == NULL) && (!feof(fp))) + { /* read to end of line */ + int c; + while ((c = getc(fp)) != EOF && c != '\n'); /* keep reading */ + } + if (headerString != NULL && + header_cmp(buffer, "From", NULL)) + { + strcpy(From, buffer); + } + else if (headerString != NULL && + header_cmp(buffer, "Subject", NULL)) + { + strcpy(Subject, buffer); + } + else if (mailBox->type == MHDIR && + header_cmp(buffer, "Status", NULL)) + { + remove_header_keyword(buffer); + if (*buffer == 'N') + status = NEW_MSG; + else + status = READ_MSG; + } + else if (buffer[0] == LINEFEED && (mailBox->type == MAILDIR || + status == NEW_MSG)) + { + if (mailBox->type == MHDIR) count++; + if (strlen(From) != 0) + DynInsert(headerString, + ((DynHigh(headerString) > 0) ? (DynSize(headerString)) : 0), + From, strlen(From)); + + if (strlen(Subject) != 0) + DynInsert(headerString, + ((DynHigh(headerString) > 0) ? (DynSize(headerString)) : 0), + Subject, strlen(Subject)); + found = TRUE; + } + } + fclose(fp); + } + } + } + } + closedir(dp); + + return count; +} + +int CountUnixMail(mailBox, headerString, beenTouched) + BoxInfo_t *mailBox; + DynObject headerString; + Boolean *beenTouched; +{ + struct stat f_stat; + struct timeval t[2]; + register int count = 0; + char path[_POSIX_PATH_MAX]; + + *beenTouched = FALSE; + + if (mailBox->type == MAILBOX) { + if (isLocked(mailBox->box)) + return (mailBox->n); + } + + if (mailBox->type == MAILDIR) { + sprintf(path,"%s/new",mailBox->box); + } else { + strcpy(path,mailBox->box); + } + + if (stat(path, &f_stat)) + { + mailBox->st_size = 0; + mailBox->box_mtime = 0; + return (0); + } + + if ((f_stat.st_size != mailBox->st_size) || + (f_stat.st_mtime > mailBox->box_mtime)) + { + mailBox->st_size = f_stat.st_size; + mailBox->box_mtime = f_stat.st_mtime; + *beenTouched = TRUE; + } + + if ((!*beenTouched) && (headerString == NULL)) + return (mailBox->n); + + switch (mailBox->type) { + case MAILBOX: + count = CountMBoxMail(mailBox, headerString); + break; + case MAILDIR: + case MHDIR: + count = CountDirMail(mailBox, headerString); + break; + } + /* Restore access time of mailbox. */ t[0].tv_sec = f_stat.st_atime; @@ -849,7 +989,7 @@ tempBox.type = BoxType; tempBox.boxNum = nBoxes; - if (BoxType = NNTPBOX) + if (BoxType == NNTPBOX) { tempBox.articles = DynCreate(sizeof(Articles_t), 2); #ifdef DEBUG @@ -857,6 +997,31 @@ DynParanoid(tempBox.articles, 1);*/ #endif + } else if (BoxType == MAILBOX) + { + struct stat st; + char tmp[_POSIX_PATH_MAX]; + + if (stat (box, &st) != -1) { + if (S_ISDIR (st.st_mode)) { + /* check for maildir mailbox */ + sprintf(tmp, "%s/cur", box); + if (stat (tmp, &st) == 0 && S_ISDIR (st.st_mode)) { + tempBox.type = MAILDIR; + } else { + /* check for mh mailbox */ + sprintf(tmp, "%s/.mh_sequences", box); + if (access (tmp, F_OK) == 0) { + tempBox.type = MHDIR; + } else { + sprintf(tmp, "%s/.xmhcache", box); + if (access (tmp, F_OK) == 0) { + tempBox.type = MHDIR; + } + } + } + } + } } if ((pollTime <= 0) || (pollTime >= 3600)) tempBox.pollTime = envPolltime; @@ -1024,7 +1189,8 @@ line[0] = '\0'; - if (currentBox->type == MAILBOX) + if ((currentBox->type == MAILBOX) || (currentBox->type == MAILDIR) || + (currentBox->type == MHDIR)) { switch (currentBox->BoxNameType) { @@ -1330,7 +1496,8 @@ headerUp[i] = FALSE; - if (boxInfo[i].type == MAILBOX) + if ((boxInfo[i].type == MAILBOX) || (boxInfo[i].type == MAILDIR) || + (boxInfo[i].type == MHDIR)) boxInfo[i].n = CountUnixMail(&boxInfo[i], NULL, &dummy); #ifdef NNTP diff -ru xbuffy3.2.1time/xbuffy.h xbuffy3.2.1patch/xbuffy.h --- xbuffy3.2.1time/xbuffy.h Fri Mar 21 19:24:40 1997 +++ xbuffy3.2.1patch/xbuffy.h Thu Mar 20 16:23:16 1997 @@ -42,6 +42,8 @@ enum BoxType_e { MAILBOX = 0, + MAILDIR, + MHDIR, NNTPBOX, };