X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..647ac5444d022537a1f0854dd309494c511dfe07:/buffy.c?ds=sidebyside diff --git a/buffy.c b/buffy.c index d0998ff..40c229e 100644 --- a/buffy.c +++ b/buffy.c @@ -48,7 +48,7 @@ static short BuffyNotify = 0; /* # of unnotified new boxes */ /* Find the last message in the file. * upon success return 0. If no message found - return -1 */ -int fseek_last_message (FILE * f) +static int fseek_last_message (FILE * f) { LOFF_T pos; char buffer[BUFSIZ + 9]; /* 7 for "\n\nFrom " */ @@ -94,7 +94,7 @@ int fseek_last_message (FILE * f) } /* Return 1 if the last message is new */ -int test_last_status_new (FILE * f) +static int test_last_status_new (FILE * f) { HEADER *hdr; ENVELOPE* tmp_envelope; @@ -114,7 +114,7 @@ int test_last_status_new (FILE * f) return result; } -int test_new_folder (const char *path) +static int test_new_folder (const char *path) { FILE *f; int rc = 0; @@ -128,12 +128,37 @@ int test_new_folder (const char *path) if ((f = fopen (path, "rb"))) { rc = test_last_status_new (f); - fclose (f); + safe_fclose (&f); } return rc; } +void mutt_buffy_cleanup (const char *buf, struct stat *st) +{ + struct utimbuf ut; + BUFFY *tmp; + + if (option(OPTCHECKMBOXSIZE)) + { + tmp = mutt_find_mailbox (buf); + if (tmp && !tmp->new) + mutt_update_mailbox (tmp); + } + else + { + /* fix up the times so buffy won't get confused */ + if (st->st_mtime > st->st_atime) + { + ut.actime = st->st_atime; + ut.modtime = time (NULL); + utime (buf, &ut); + } + else + utime (buf, NULL); + } +} + BUFFY *mutt_find_mailbox (const char *path) { BUFFY *tmp = NULL; @@ -160,7 +185,7 @@ void mutt_update_mailbox (BUFFY * b) return; if (stat (b->path, &sb) == 0) - b->size = (long) sb.st_size; + b->size = (off_t) sb.st_size; else b->size = 0; return; @@ -171,6 +196,8 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e BUFFY **tmp,*tmp1; char buf[_POSIX_PATH_MAX]; struct stat sb; + char f1[PATH_MAX], f2[PATH_MAX]; + char *p, *q; while (MoreArgs (s)) { @@ -181,7 +208,6 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e { for (tmp = &Incoming; *tmp;) { - FREE (&((*tmp)->path)); tmp1=(*tmp)->next; FREE (tmp); /* __FREE_CHECKED__ */ *tmp=tmp1; @@ -194,11 +220,16 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e /* Skip empty tokens. */ if(!*buf) continue; - /* simple check to avoid duplicates */ + /* avoid duplicates */ + p = realpath (buf, f1); for (tmp = &Incoming; *tmp; tmp = &((*tmp)->next)) { - if (mutt_strcmp (buf, (*tmp)->path) == 0) + q = realpath ((*tmp)->path, f2); + if (mutt_strcmp (p ? p : buf, q ? q : (*tmp)->path) == 0) + { + dprint(3,(debugfile,"mailbox '%s' already registered as '%s'\n", buf, (*tmp)->path)); break; + } } if(data == M_UNMAILBOXES) @@ -216,7 +247,7 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e if (!*tmp) { *tmp = (BUFFY *) safe_calloc (1, sizeof (BUFFY)); - (*tmp)->path = safe_strdup (buf); + strfcpy ((*tmp)->path, buf, sizeof ((*tmp)->path)); (*tmp)->next = NULL; /* it is tempting to set magic right here */ (*tmp)->magic = 0; @@ -235,7 +266,7 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e stat ((*tmp)->path, &sb) == 0 && !test_new_folder ((*tmp)->path)) { /* some systems out there don't have an off_t type */ - (*tmp)->size = (long) sb.st_size; + (*tmp)->size = (off_t) sb.st_size; } else (*tmp)->size = 0; @@ -260,6 +291,10 @@ int mutt_buffy_check (int force) struct stat contex_sb; time_t t; + sb.st_size=0; + contex_sb.st_dev=0; + contex_sb.st_ino=0; + #ifdef USE_IMAP /* update postponed count as well, on force */ if (force) @@ -308,7 +343,7 @@ int mutt_buffy_check (int force) tmp->magic = M_POP; else #endif - if (stat (tmp->path, &sb) != 0 || sb.st_size == 0 || + if (stat (tmp->path, &sb) != 0 || (S_ISREG(sb.st_mode) && sb.st_size == 0) || (!tmp->magic && (tmp->magic = mx_get_magic (tmp->path)) <= 0)) { /* if the mailbox still doesn't exist, set the newly created flag to @@ -358,7 +393,7 @@ int mutt_buffy_check (int force) else if (option(OPTCHECKMBOXSIZE)) { /* some other program has deleted mail from the folder */ - tmp->size = (long) sb.st_size; + tmp->size = (off_t) sb.st_size; } if (tmp->newly_created && (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime)) @@ -396,7 +431,7 @@ int mutt_buffy_check (int force) } } else if (option(OPTCHECKMBOXSIZE) && Context && Context->path) - tmp->size = (long) sb.st_size; /* update the size */ + tmp->size = (off_t) sb.st_size; /* update the size of current folder */ if (!tmp->new) tmp->notified = 0; @@ -429,7 +464,7 @@ int mutt_buffy_list (void) continue; strfcpy (path, tmp->path, sizeof (path)); - mutt_pretty_mailbox (path); + mutt_pretty_mailbox (path, sizeof (path)); if (!first && pos + strlen (path) >= COLS - 7) break; @@ -476,59 +511,34 @@ int mutt_buffy_notify (void) * mutt_buffy() -- incoming folders completion routine * * given a folder name, this routine gives the next incoming folder with new - * new mail. + * mail. */ void mutt_buffy (char *s, size_t slen) { - int count; BUFFY *tmp = Incoming; + int pass, found = 0; - mutt_expand_path (s, _POSIX_PATH_MAX); - switch (mutt_buffy_check (0)) - { - case 0: - - *s = '\0'; - break; - - case 1: + mutt_expand_path (s, slen); - while (tmp && !tmp->new) - tmp = tmp->next; - if (!tmp) - { - *s = '\0'; - mutt_buffy_check (1); /* buffy was wrong - resync things */ - break; - } - strfcpy (s, tmp->path, slen); - mutt_pretty_mailbox (s); - break; - - default: - - count = 0; - while (count < 3) - { - if (mutt_strcmp (s, tmp->path) == 0) - count++; - else if (count && tmp->new) - break; - tmp = tmp->next; - if (!tmp) + if (mutt_buffy_check (0)) + { + for (pass = 0; pass < 2; pass++) + for (tmp = Incoming; tmp; tmp = tmp->next) { - tmp = Incoming; - count++; + mutt_expand_path (tmp->path, sizeof (tmp->path)); + if ((found || pass) && tmp->new) + { + strfcpy (s, tmp->path, slen); + mutt_pretty_mailbox (s, slen); + return; + } + if (mutt_strcmp (s, tmp->path) == 0) + found = 1; } - } - if (count >= 3) - { - *s = '\0'; - mutt_buffy_check (1); /* buffy was wrong - resync things */ - break; - } - strfcpy (s, tmp->path, slen); - mutt_pretty_mailbox (s); - break; + + mutt_buffy_check (1); /* buffy was wrong - resync things */ } + + /* no folders with new mail */ + *s = '\0'; }