|
@@ -25,7 +25,6 @@
|
|
#include <time.h>
|
|
#include <time.h>
|
|
#include <fcntl.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <string.h>
|
|
-#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
|
#include <errno.h>
|
|
#include "isync.h"
|
|
#include "isync.h"
|
|
|
|
|
|
@@ -47,10 +46,10 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags, unsigned int max_size)
|
|
message_t *tmp;
|
|
message_t *tmp;
|
|
char path[_POSIX_PATH_MAX];
|
|
char path[_POSIX_PATH_MAX];
|
|
char newpath[_POSIX_PATH_MAX];
|
|
char newpath[_POSIX_PATH_MAX];
|
|
|
|
+ char suffix[_POSIX_PATH_MAX];
|
|
char *p;
|
|
char *p;
|
|
int fd;
|
|
int fd;
|
|
int ret;
|
|
int ret;
|
|
- struct stat sb;
|
|
|
|
|
|
|
|
if (mbox->uidvalidity != (unsigned int) -1)
|
|
if (mbox->uidvalidity != (unsigned int) -1)
|
|
{
|
|
{
|
|
@@ -137,46 +136,43 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags, unsigned int max_size)
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /* construct the flags part of the file name. */
|
|
|
|
+
|
|
|
|
+ *suffix = 0;
|
|
|
|
+ if (cur->flags)
|
|
|
|
+ {
|
|
|
|
+ snprintf (suffix, sizeof (suffix), ":2,%s%s%s%s",
|
|
|
|
+ (cur->flags & D_FLAGGED) ? "F" : "",
|
|
|
|
+ (cur->flags & D_ANSWERED) ? "R" : "",
|
|
|
|
+ (cur->flags & D_SEEN) ? "S" : "",
|
|
|
|
+ (cur->flags & D_DELETED) ? "T" : "");
|
|
|
|
+ }
|
|
|
|
+
|
|
for (;;)
|
|
for (;;)
|
|
{
|
|
{
|
|
/* create new file */
|
|
/* create new file */
|
|
- snprintf (path, sizeof (path), "%s/tmp/%s.%ld_%d.%d.UID%d",
|
|
|
|
|
|
+ snprintf (path, sizeof (path), "%s/tmp/%s.%ld_%d.%d.UID%d%s",
|
|
mbox->path, Hostname, time (0), MaildirCount++,
|
|
mbox->path, Hostname, time (0), MaildirCount++,
|
|
- getpid (), cur->uid);
|
|
|
|
|
|
+ getpid (), cur->uid, suffix);
|
|
|
|
|
|
- if (stat (path, &sb))
|
|
|
|
|
|
+ if ((fd = open (path, O_WRONLY | O_CREAT | O_EXCL, 0600)) > 0)
|
|
|
|
+ break;
|
|
|
|
+ if (errno != EEXIST)
|
|
{
|
|
{
|
|
- if (errno == ENOENT)
|
|
|
|
- break;
|
|
|
|
|
|
+ perror ("open");
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
sleep (2);
|
|
sleep (2);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- if (cur->flags)
|
|
|
|
- {
|
|
|
|
- /* append flags */
|
|
|
|
- snprintf (path + strlen (path), sizeof (path) - strlen (path),
|
|
|
|
- ":2,%s%s%s%s",
|
|
|
|
- (cur->flags & D_FLAGGED) ? "F" : "",
|
|
|
|
- (cur->flags & D_ANSWERED) ? "R" : "",
|
|
|
|
- (cur->flags & D_SEEN) ? "S" : "",
|
|
|
|
- (cur->flags & D_DELETED) ? "T" : "");
|
|
|
|
- }
|
|
|
|
|
|
+ if (fd < 0)
|
|
|
|
+ continue;
|
|
|
|
|
|
/* give some visual feedback that something is happening */
|
|
/* give some visual feedback that something is happening */
|
|
fputs (".", stdout);
|
|
fputs (".", stdout);
|
|
fflush (stdout);
|
|
fflush (stdout);
|
|
|
|
|
|
-// printf("creating %s\n", path);
|
|
|
|
- fd = open (path, O_WRONLY | O_CREAT | O_EXCL, 0600);
|
|
|
|
- if (fd < 0)
|
|
|
|
- {
|
|
|
|
- perror ("open");
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
ret = imap_fetch_message (imap, cur->uid, fd);
|
|
ret = imap_fetch_message (imap, cur->uid, fd);
|
|
|
|
|
|
if (close (fd))
|
|
if (close (fd))
|
|
@@ -188,8 +184,6 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags, unsigned int max_size)
|
|
snprintf (newpath, sizeof (newpath), "%s/%s%s", mbox->path,
|
|
snprintf (newpath, sizeof (newpath), "%s/%s%s", mbox->path,
|
|
(cur->flags & D_SEEN) ? "cur" : "new", p);
|
|
(cur->flags & D_SEEN) ? "cur" : "new", p);
|
|
|
|
|
|
- // printf ("moving %s to %s\n", path, newpath);
|
|
|
|
-
|
|
|
|
/* its ok if this fails, the next time we sync the message
|
|
/* its ok if this fails, the next time we sync the message
|
|
* will get pulled down
|
|
* will get pulled down
|
|
*/
|
|
*/
|