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 inline void buffy_free (BUFFY** p) {
p_delete(&(*p)->path);
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);
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
* be ready for when it does. */
tmp->newly_created = 1;
tmp->magic = -1;
-#ifdef BUFFY_SIZE
- tmp->size = 0;
-#endif
continue;
}
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 */
}
}
-#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;
* 0 success
* -1 failure
*/
-static int _mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused)), int *index_hint)
+static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused)), int *index_hint)
{
char tempfile[_POSIX_PATH_MAX];
char buf[32];
return rc;
}
-static int mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) {
-#ifdef BUFFY_SIZE
- BUFFY* tmp = NULL;
-#endif
- int rc = _mbox_sync_mailbox (ctx, unused, index_hint);
-
-#ifdef BUFFY_SIZE
- if ((tmp = buffy_find_mailbox (ctx->path)) && tmp->new == 0)
- buffy_update_mailbox (tmp);
-#endif
- return (rc);
-}
-
/* close a mailbox opened in write-mode */
int mbox_close_mailbox (CONTEXT * ctx)
{
return (M_MBOX);
}
else if ((f = fopen (path, "r")) != NULL) {
-#ifndef BUFFY_SIZE
struct utimbuf times;
-#endif
+
fgets (tmp, sizeof (tmp), f);
if (m_strncmp("From ", tmp, 5) == 0)
magic = M_MBOX;
else if (m_strcmp(MMDF_SEP, tmp) == 0)
magic = M_MMDF;
safe_fclose (&f);
-#ifndef BUFFY_SIZE
+
/* need to restore the times here, the file was not really accessed,
* only the type was accessed. This is important, because detection
* of "new mail" depends on those times set correctly.
times.actime = st->st_atime;
times.modtime = st->st_mtime;
utime (path, ×);
-#endif
} else {
mutt_perror (path);
return (-1); /* fopen failed */