commit bb62e2c18daaec9194e6bcf35577b1a7a3fd1222
parent 49b36e7869b384efcf61ff1f98973c6fba9c203b
Author: Michael Elkins <me@mutt.org>
Date: Mon, 12 Nov 2001 23:03:33 +0000
merge maildir_sync() and maildir_close(). the maxuid in a maildir still
needs to be updated in --fast mode, and the sync code already checks to see
if any changes were made to the mailbox.
Diffstat:
M | isync.h | | | 3 | +-- |
M | maildir.c | | | 104 | ++++++++++++++++++++++++++++++++++++++----------------------------------------- |
M | main.c | | | 16 | ++++++---------- |
3 files changed, 57 insertions(+), 66 deletions(-)
diff --git a/isync.h b/isync.h
@@ -183,9 +183,8 @@ int imap_append_message (imap_t *, int, message_t *);
mailbox_t *maildir_open (const char *, int fast);
int maildir_expunge (mailbox_t *, int);
-int maildir_sync (mailbox_t *);
int maildir_set_uidvalidity (mailbox_t *, unsigned int uidvalidity);
-void maildir_close (mailbox_t *);
+int maildir_close (mailbox_t *);
message_t * find_msg (message_t * list, unsigned int uid);
void free_message (message_t *);
diff --git a/maildir.c b/maildir.c
@@ -343,8 +343,47 @@ update_maxuid (mailbox_t * mbox)
return ret;
}
+#define _24_HOURS (3600 * 24)
+
+static void
+maildir_clean_tmp (const char *mbox)
+{
+ char path[_POSIX_PATH_MAX];
+ DIR *dirp;
+ struct dirent *entry;
+ struct stat info;
+ time_t now;
+
+ snprintf (path, sizeof (path), "%s/tmp", mbox);
+ dirp = opendir (path);
+ if (dirp == NULL)
+ {
+ fprintf (stderr, "maildir_clean_tmp: opendir: %s: %s (errno %d)\n", path, strerror (errno), errno);
+ return;
+ }
+ /* assuming this scan will take less than a second, we only need to
+ * check the time once before the following loop.
+ */
+ time (&now);
+ while ((entry = readdir (dirp)))
+ {
+ snprintf (path, sizeof (path), "%s/tmp/%s", mbox, entry->d_name);
+ if (stat (path, &info))
+ fprintf (stderr, "maildir_clean_tmp: stat: %s: %s (errno %d)\n", path, strerror (errno), errno);
+ else if (S_ISREG (info.st_mode) && now - info.st_ctime >= _24_HOURS)
+ {
+ /* this should happen infrequently enough that it won't be
+ * bothersome to the user to display when it occurs.
+ */
+ printf ("Warning: removing stale file %s\n", path);
+ if (unlink (path))
+ fprintf (stderr, "maildir_clean_tmp: unlink: %s: %s (errno %d)\n", path, strerror (errno), errno);
+ }
+ }
+}
+
int
-maildir_sync (mailbox_t * mbox)
+maildir_close (mailbox_t * mbox)
{
message_t *cur = mbox->msgs;
char path[_POSIX_PATH_MAX];
@@ -386,6 +425,16 @@ maildir_sync (mailbox_t * mbox)
if (mbox->maxuidchanged)
ret = update_maxuid (mbox);
+ /* per the maildir(5) specification, delivery agents are supposed to
+ * set a 24-hour timer on items placed in the `tmp' directory.
+ */
+ maildir_clean_tmp (mbox->path);
+
+ free (mbox->path);
+ free_message (mbox->msgs);
+ memset (mbox, 0xff, sizeof (mailbox_t));
+ free (mbox);
+
return ret;
}
@@ -427,56 +476,3 @@ maildir_set_uidvalidity (mailbox_t * mbox, unsigned int uidvalidity)
return (ret);
}
-
-#define _24_HOURS (3600 * 24)
-
-static void
-maildir_clean_tmp (const char *mbox)
-{
- char path[_POSIX_PATH_MAX];
- DIR *dirp;
- struct dirent *entry;
- struct stat info;
- time_t now;
-
- snprintf (path, sizeof (path), "%s/tmp", mbox);
- dirp = opendir (path);
- if (dirp == NULL)
- {
- fprintf (stderr, "maildir_clean_tmp: opendir: %s: %s (errno %d)\n", path, strerror (errno), errno);
- return;
- }
- /* assuming this scan will take less than a second, we only need to
- * check the time once before the following loop.
- */
- time (&now);
- while ((entry = readdir (dirp)))
- {
- snprintf (path, sizeof (path), "%s/tmp/%s", mbox, entry->d_name);
- if (stat (path, &info))
- fprintf (stderr, "maildir_clean_tmp: stat: %s: %s (errno %d)\n", path, strerror (errno), errno);
- else if (S_ISREG (info.st_mode) && now - info.st_ctime >= _24_HOURS)
- {
- /* this should happen infrequently enough that it won't be
- * bothersome to the user to display when it occurs.
- */
- printf ("Warning: removing stale file %s\n", path);
- if (unlink (path))
- fprintf (stderr, "maildir_clean_tmp: unlink: %s: %s (errno %d)\n", path, strerror (errno), errno);
- }
- }
-}
-
-void
-maildir_close (mailbox_t * mbox)
-{
- /* per the maildir(5) specification, delivery agents are supposed to
- * set a 24-hour timer on items placed in the `tmp' directory.
- */
- maildir_clean_tmp (mbox->path);
-
- free (mbox->path);
- free_message (mbox->msgs);
- memset (mbox, 0xff, sizeof (mailbox_t));
- free (mbox);
-}
diff --git a/main.c b/main.c
@@ -316,18 +316,14 @@ main (int argc, char **argv)
*/
else if (delete)
maildir_expunge (mail, 1);
-
- /* write changed flags back to the mailbox */
- if (mail->changed)
- {
- if (!quiet)
- printf ("Committing changes to %s\n", mail->path);
- if (maildir_sync (mail))
- exit (1);
- }
}
- maildir_close (mail);
+ /* write changed flags back to the mailbox */
+ if (!quiet)
+ printf ("Committing changes to %s\n", mail->path);
+
+ if (maildir_close (mail))
+ exit (1);
cleanup:
if (all)