X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=buffy.c;h=5fdf7253433768ae8f77c83b30a8cf108d457232;hp=0db6026e5ef74d432c7e17c98bcb80c8510a753a;hb=bd0ed9bc7c534be30b0140b341b4d8a390483dbd;hpb=1ee89902de184a640c171ae3285bff6882a791bd diff --git a/buffy.c b/buffy.c index 0db6026..5fdf725 100644 --- a/buffy.c +++ b/buffy.c @@ -30,141 +30,24 @@ static time_t ImapBuffyTime = 0; /* last time we started checking for mai static short BuffyCount = 0; /* how many boxes with new mail */ static short BuffyNotify = 0; /* # of unnotified new boxes */ -#ifdef BUFFY_SIZE - -/* Find the last message in the file. - * upon success return 0. If no message found - return -1 */ - -static int fseeko_last_message (FILE * f) -{ - LOFF_T pos; - char buffer[BUFSIZ + 9]; /* 7 for "\n\nFrom " */ - int bytes_read; - int i; /* Index into `buffer' for scanning. */ - - p_clear(buffer, 1); - fseeko (f, 0, SEEK_END); - pos = ftello (f); - - /* Set `bytes_read' to the size of the last, probably partial, buffer; 0 < - * `bytes_read' <= `BUFSIZ'. */ - bytes_read = pos % BUFSIZ; - if (bytes_read == 0) - bytes_read = BUFSIZ; - /* Make `pos' a multiple of `BUFSIZ' (0 if the file is short), so that all - * reads will be on block boundaries, which might increase efficiency. */ - while ((pos -= bytes_read) >= 0) { - /* we save in the buffer at the end the first 7 chars from the last read */ - strncpy (buffer + BUFSIZ, buffer, 5 + 2); /* 2 == 2 * m_strlen(CRLF) */ - fseeko (f, pos, SEEK_SET); - bytes_read = fread (buffer, sizeof (char), bytes_read, f); - if (bytes_read == -1) - return -1; - for (i = bytes_read; --i >= 0;) - if (!m_strncmp(buffer + i, "\n\nFrom ", m_strlen("\n\nFrom "))) { /* found it - go to the beginning of the From */ - fseeko (f, pos + i + 2, SEEK_SET); - return 0; - } - bytes_read = BUFSIZ; - } - - /* here we are at the beginning of the file */ - if (!m_strncmp("From ", buffer, 5)) { - fseeko (f, 0, 0); - return (0); - } - - return (-1); -} - -/* Return 1 if the last message is new */ -static int test_last_status_new (FILE * f) -{ - HEADER *hdr; - ENVELOPE *tmp_envelope; - int result = 0; - - if (fseeko_last_message (f) == -1) - return (0); - - hdr = header_new(); - tmp_envelope = mutt_read_rfc822_header (f, hdr, 0, 0); - if (!(hdr->read || hdr->old)) - result = 1; - - envelope_delete(&tmp_envelope); - header_delete(&hdr); - - return result; -} - -static int test_new_folder (const char *path) -{ - FILE *f; - int rc = 0; - int typ; - - typ = mx_get_magic (path); - - if (typ != M_MBOX && typ != M_MMDF) - return 0; - - if ((f = fopen (path, "rb"))) { - rc = test_last_status_new (f); - fclose (f); - } - - return rc; -} - -BUFFY *buffy_find_mailbox (const char *path) -{ - struct stat sb; - struct stat tmp_sb; - int i = 0; - - if (stat (path, &sb) != 0) - return NULL; - - if (!list_empty(Incoming)) { - for (i = 0; i < Incoming->length; i++) { - if (stat (Incoming->data[i], &tmp_sb) == 0 && - sb.st_dev == tmp_sb.st_dev && sb.st_ino == tmp_sb.st_ino) - return ((BUFFY*) Incoming->data[i]); - } - } - return (NULL); -} - -void buffy_update_mailbox (BUFFY * b) -{ - struct stat sb; - - if (!b) - return; - - if (stat (b->path, &sb) == 0) - b->size = (long) sb.st_size; - else - b->size = 0; - return; -} -#endif - /* func to free buffy for list_del() */ -static void buffy_free (BUFFY** p) { +static inline void buffy_free (BUFFY** p) { p_delete(&(*p)->path); p_delete(p); } +/* Return the index number of path in Incoming list */ int buffy_lookup (const char* path) { int i = 0; + if (list_empty(Incoming) || !path || !*path) return (-1); + for (i = 0; i < Incoming->length; i++) { - if (!m_strcmp(((BUFFY*)Incoming->data[i])->path, path) ) + if (!m_strcmp(((BUFFY *)Incoming->data[i])->path, path)) return (i); } + return (-1); } @@ -174,9 +57,6 @@ int buffy_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, BUFFY* tmp; char buf[_POSIX_PATH_MAX]; int i = 0; -#ifdef BUFFY_SIZE - struct stat sb; -#endif /* BUFFY_SIZE */ while (MoreArgs (s)) { mutt_extract_token (path, s, 0); @@ -215,30 +95,11 @@ int buffy_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, tmp->notified = 1; tmp->newly_created = 0; -#ifdef BUFFY_SIZE - /* for buffy_size, it is important that if the folder is new (tested by - * reading it), the size is set to 0 so that later when we check we see - * that it increased . without buffy_size we probably don't care. - */ - if (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; - } - else - tmp->size = 0; -#endif /* BUFFY_SIZE */ } return 0; } -#ifdef BUFFY_SIZE -/* people use buffy_size on systems where modified time attributes are BADLY - * broken. Ignore them. - */ -#define STAT_CHECK (sb.st_size > tmp->size) -#else #define STAT_CHECK (sb.st_mtime > sb.st_atime || (tmp->newly_created && sb.st_ctime == sb.st_mtime && sb.st_ctime == sb.st_atime)) -#endif /* BUFFY_SIZE */ /* values for force: * 0 don't force any checks + update sidebar @@ -298,9 +159,6 @@ int buffy_check (int force) * be ready for when it does. */ tmp->newly_created = 1; tmp->magic = -1; -#ifdef BUFFY_SIZE - tmp->size = 0; -#endif continue; } @@ -319,12 +177,6 @@ int buffy_check (int force) BuffyCount++; tmp->new = 1; } -#ifdef BUFFY_SIZE - else { - /* some other program has deleted mail from the folder */ - tmp->size = (long) sb.st_size; - } -#endif } else if (STAT_CHECK || tmp->msgcount == 0) { /* sidebar visible */ @@ -454,10 +306,6 @@ int buffy_check (int force) } } -#ifdef BUFFY_SIZE - else if (Context && Context->path) - tmp->size = (long) sb.st_size; /* update the size */ -#endif if (tmp->new <= 0) tmp->notified = 0; @@ -466,7 +314,7 @@ int buffy_check (int force) tmp->has_new = tmp->new > 0; } if (BuffyCount > 0 && force != 2) - sidebar_draw (CurrentMenu); + sidebar_draw (); return (BuffyCount); } @@ -486,7 +334,7 @@ int buffy_list (void) pos += m_strlen(strncat (buffylist, _("New mail in "), sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */ if (Incoming) { for (i = 0; i < Incoming->length; i++) { - tmp = (BUFFY*) Incoming->data[i]; + tmp = Incoming->data[i]; /* Is there new mail in this mailbox? */ if (tmp->new <= 0 || (have_unnotified && tmp->notified)) continue; @@ -500,12 +348,9 @@ int buffy_list (void) if (!first) pos += m_strlen(strncat (buffylist + pos, ", ", sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */ - /* Prepend an asterisk to mailboxes not already notified */ - if (!tmp->notified) { - /* pos += m_strlen(strncat(buffylist + pos, "*", sizeof(buffylist)-1-pos)); __STRNCAT_CHECKED__ */ - tmp->notified = 1; - BuffyNotify--; - } + tmp->notified = 1; + BuffyNotify--; + pos += m_strlen(strncat (buffylist + pos, path, sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */ first = 0; } @@ -515,7 +360,7 @@ int buffy_list (void) } if (!first) { /* on new mail: redraw sidebar */ - sidebar_draw (CurrentMenu); + sidebar_draw (); mutt_message ("%s", buffylist); return (1); } @@ -535,7 +380,7 @@ int buffy_notify (void) } /* - * mutt_buffy() -- incoming folders completion routine + * buffy_next() -- incoming folders completion routine * * given a folder name, this routine gives the next incoming folder with new * new mail. @@ -545,25 +390,23 @@ void buffy_next (char *s, size_t slen) int l = 0; int c = 0, i = 0; - if (list_empty(Incoming)) - return; - mutt_expand_path (s, _POSIX_PATH_MAX); - if (buffy_check (0) == 0) { - *s = '\0'; - return; - } + if (!buffy_check (0)) { + *s = '\0'; + return; + } /* - * If buffy_lookup returns the index, + * buffy_lookup returns the index, * or -1 if not found (-1..Incoming->length-1); * plus one --> (0..Incoming->length). * Modulo mapps it into the correct range. */ i = 1 + buffy_lookup (s); - for (l=0; l < Incoming->length; l++) { + for (l = 0; l < Incoming->length; l++) { c = (l+i) % Incoming->length; - if ((!Context || !Context->path || m_strcmp(((BUFFY*) Incoming->data[c])->path, Context->path)) && + + if (m_strcmp(((BUFFY*) Incoming->data[c])->path, s) && ((BUFFY*) Incoming->data[c])->new > 0) break; } @@ -571,7 +414,7 @@ void buffy_next (char *s, size_t slen) *s = '\0'; /* something went wrong since we're here when buffy_check * reported new mail */ - buffy_check (0); + buffy_check (1); } else { m_strcpy(s, slen, ((BUFFY*)Incoming->data[c])->path); mutt_pretty_mailbox (s);