/*
- * Copyright (C) 1996-2000 Michael R. Elkins <me@cs.hmc.edu>
+ * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#endif
int mx_access (const char*, int);
+int mx_check_empty (const char *);
#endif
if (flags & M_IGNORE)
{
- struct stat st;
-
/* check to see if there are any messages in the folder */
- if (stat (folder, &st) != 0)
- {
- mutt_endwin (strerror (errno));
- exit (1);
- }
-
- if (st.st_size == 0)
+ switch (mx_check_empty (folder))
{
- mutt_endwin _("Mailbox is empty.");
- exit (1);
+ case -1:
+ mutt_endwin (strerror (errno));
+ exit (1);
+ case 1:
+ mutt_endwin _("Mailbox is empty.");
+ exit (1);
}
}
/*
- * Copyright (C) 1996-2000 Michael R. Elkins <me@cs.hmc.edu>
+ * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
return ((ctx->changed || msg_mod) ? M_REOPENED : M_NEW_MAIL);
}
+/*
+ * Returns:
+ * 1 if the mailbox is not empty
+ * 0 if the mailbox is empty
+ * -1 on error
+ */
+int mbox_check_empty (const char *path)
+{
+ struct stat st;
+
+ if (stat (path, &st) == -1)
+ return -1;
+
+ return ((st.st_size == 0));
+}
return NULL;
}
+
+
+/*
+ * Returns:
+ * 1 if there are no messages in the mailbox
+ * 0 if there are messages in the mailbox
+ * -1 on error
+ */
+int maildir_check_empty (const char *path)
+{
+ DIR *dp;
+ struct dirent *de;
+ int r = 1; /* assume empty until we find a message */
+ char realpath[_POSIX_PATH_MAX];
+ int iter = 0;
+
+ /* Strategy here is to look for any file not beginning with a period */
+
+ do {
+ /* we do "cur" on the first iteration since its more likely that we'll
+ * find old messages without having to scan both subdirs
+ */
+ snprintf (realpath, sizeof (realpath), "%s/%s", path,
+ iter == 0 ? "cur" : "new");
+ if ((dp = opendir (realpath)) == NULL)
+ return -1;
+ while ((de = readdir (dp)))
+ {
+ if (*de->d_name != '.')
+ {
+ r = 0;
+ break;
+ }
+ }
+ closedir (dp);
+ iter++;
+ } while (r && iter < 2);
+
+ return r;
+}
+
+/*
+ * Returns:
+ * 1 if there are no messages in the mailbox
+ * 0 if there are messages in the mailbox
+ * -1 on error
+ */
+int mh_check_empty (const char *path)
+{
+ DIR *dp;
+ struct dirent *de;
+ int r = 1; /* assume empty until we find a message */
+
+ if ((dp = opendir (path)) == NULL)
+ return -1;
+ while ((de = readdir (dp)))
+ {
+ if (mh_valid_message (de->d_name))
+ {
+ r = 0;
+ break;
+ }
+ }
+ closedir (dp);
+
+ return r;
+}
/*
- * Copyright (C) 1996-2000 Michael R. Elkins <me@cs.hmc.edu>
+ * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
* Copyright (C) 1999-2000 Thomas Roessler <roessler@guug.de>
*
* This program is free software; you can redistribute it and/or modify
}
}
}
+
+/*
+ * Return:
+ * 1 if the specified mailbox contains 0 messages.
+ * 0 if the mailbox contains messages
+ * -1 on error
+ */
+int mx_check_empty (const char *path)
+{
+ switch (mx_get_magic (path))
+ {
+ case M_MBOX:
+ case M_MMDF:
+ case M_KENDRA:
+ return mbox_check_empty (path);
+ case M_MH:
+ return mh_check_empty (path);
+ case M_MAILDIR:
+ return maildir_check_empty (path);
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+ /* not reached */
+}
/*
* Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
- * Copyright (C) 1999-2000 Thomas Roessler <roessler@guug.de>
+ * Copyright (C) 1999-2002 Thomas Roessler <roessler@guug.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
int mbox_parse_mailbox (CONTEXT *);
int mmdf_parse_mailbox (CONTEXT *);
void mbox_unlock_mailbox (CONTEXT *);
+int mbox_check_empty (const char *);
int mh_read_dir (CONTEXT *, const char *);
int mh_sync_mailbox (CONTEXT *, int *);
int mh_check_mailbox (CONTEXT *, int *);
int mh_buffy (const char *);
+int mh_check_empty (const char *);
int maildir_read_dir (CONTEXT *);
int maildir_check_mailbox (CONTEXT *, int *);
+int maindir_check_empty (const char *);
int maildir_commit_message (CONTEXT *, MESSAGE *, HEADER *);
int mh_commit_message (CONTEXT *, MESSAGE *, HEADER *);