don't bother renaming the message file if we are about to unlink() it

This commit is contained in:
Michael Elkins 2002-01-17 19:33:25 +00:00
parent dd22bd3f22
commit d00a65bebd

63
sync.c
View File

@ -200,36 +200,43 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
mbox->deleted++; mbox->deleted++;
cur->flags |= (tmp->flags & ~(D_RECENT | D_DRAFT)); cur->flags |= (tmp->flags & ~(D_RECENT | D_DRAFT));
/* generate old path */ /* don't bother renaming the file if we are just going to
snprintf (path, sizeof (path), "%s/%s/%s", * remove it later.
mbox->path, cur->new ? "new" : "cur", cur->file);
/* truncate old flags (if present) */
p = strchr (cur->file, ':');
if (p)
*p = 0;
/* generate new path - always put this in the cur/ directory
* because its no longer new
*/ */
snprintf (newpath, sizeof (newpath), "%s/cur/%s:2,%s%s%s%s", if ((cur->flags & D_DELETED) == 0 || (flags & SYNC_EXPUNGE) == 0)
mbox->path, {
cur->file, (cur->flags & D_FLAGGED) ? "F" : "", /* generate old path */
(cur->flags & D_ANSWERED) ? "R" : "", snprintf (path, sizeof (path), "%s/%s/%s",
(cur->flags & D_SEEN) ? "S" : "", mbox->path, cur->new ? "new" : "cur", cur->file);
(cur->flags & D_DELETED) ? "T" : "");
if (rename (path, newpath)) /* truncate old flags (if present) */
{ p = strchr (cur->file, ':');
perror ("rename"); if (p)
return -1; *p = 0;
}
else /* generate new path - always put this in the cur/ directory
{ * because its no longer new
/* update the filename in the msg struct */ */
p = strrchr (newpath, '/'); snprintf (newpath, sizeof (newpath), "%s/cur/%s:2,%s%s%s%s",
free (cur->file); mbox->path,
cur->file = strdup (p + 1); cur->file, (cur->flags & D_FLAGGED) ? "F" : "",
(cur->flags & D_ANSWERED) ? "R" : "",
(cur->flags & D_SEEN) ? "S" : "",
(cur->flags & D_DELETED) ? "T" : "");
if (rename (path, newpath))
{
perror ("rename");
return -1;
}
else
{
/* update the filename in the msg struct */
p = strrchr (newpath, '/');
free (cur->file);
cur->file = strdup (p + 1);
cur->new = 0; /* not any more */
}
} }
} }
} }