[dovecot] Re: message order reversed on copying
Charlie Brady
charlieb-dovecot at e-smith.com
Sun Apr 6 22:12:11 EEST 2003
On 6 Apr 2003, Timo Sirainen wrote:
> On Sat, 2003-04-05 at 10:15, Kimura Fuyuki wrote:
> > I noticed an annoying behavior of dovecot: the message order (sequence
> > numbering) is reversed on COPYing in the maildir.
> >
> > I suspect that the following code in maildir-save.c is working like
> > "pushing".
>
> Order for new mails is currently the same as the order in which
> readdir() returns the mails. I guess some filesystems list the files in
> the order they were written to the directory, but many don't. It anyway
> can't be relied on, so I won't even try.
>
> Better fix for this comes once I add support for UIDPLUS IMAP extension.
> That requires knowing the new UID for mail in destination mailbox, so I
> have to update the indexes immediately, which also saves the mail order
> permanently.
You shouldn't need to do that. All you need to do is to sort the new
message files (by name or by mtime - by name will be faster), before
processing them. I remember fixing this same problem in the maildir
patches for UW-imap, and this is pretty much all it took:
- if (!(dir = opendir (tmp)))
- return;
- while (d = readdir (dir)) {
- if (d->d_name[0] == '.')
- continue; /* skip .files */
+ nfiles = scandir (tmp, &names, NULL, maildir_namesort);
+ for (i = 0; i < nfiles; i++)
+ {
+ struct direct *d = names[i];
sprintf (file,"%s/../new/%s",LOCAL->dir,d->d_name);
/* make sure this is a normal file */
- if (stat (file,&sbuf) == 0 && S_ISREG (sbuf.st_mode)) {
+ if (d->d_name[0] != '.' && stat (file, &sbuf) == 0 && S_ISREG (sbuf.st_mode))
+ {
As a workaround, Kimura, you can delete dovecot's .imap.* index files, and
the new UIDs will be sorted again - until next time.
--
Charlie
More information about the dovecot
mailing list