/* 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 " */
}
/* 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;
return result;
}
-int test_new_folder (const char *path)
+static int test_new_folder (const char *path)
{
FILE *f;
int rc = 0;
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;
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;
BUFFY **tmp,*tmp1;
char buf[_POSIX_PATH_MAX];
struct stat sb;
+ char f1[PATH_MAX], f2[PATH_MAX];
+ char *p, *q;
while (MoreArgs (s))
{
{
for (tmp = &Incoming; *tmp;)
{
- FREE (&((*tmp)->path));
tmp1=(*tmp)->next;
FREE (tmp); /* __FREE_CHECKED__ */
*tmp=tmp1;
/* 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)
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;
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;
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)
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
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))
}
}
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;
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;
* 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';
}