Going further with my question... ;-)

It stemmed from that consideration (and related ones) of RFC3501:

   2.3.1.1.        Unique Identifier (UID) Message Attribute

      A 32-bit value assigned to each message, which when used with the
      unique identifier validity value (see below) forms a 64-bit value
      that MUST NOT refer to any other message in the mailbox or any
      subsequent mailbox with the same name forever. [...]

Assuming the behavior shown by Dovecot isn't related to a bad config of mine (see my previous post) but really indicates a slight oversight, I quickly and dirtily added some lines in the code of function mbox_mailbox_create(). The resulting binary seems to behave correctly (this is with dovecot-1.2.0). But I must sure be overlooking something, or? Not only because I perhaps dangerously make use of some functions beyond what they are intended for, but also wrt the overall logics of Dovecot.
Anyway, here's my attempt:


    /* create the mailbox file */
    fd = open(path, O_RDWR | O_CREAT | O_EXCL, 0660);
    if (fd != -1) {

        /* A shameless adaptation of mbox_write_pseudo() from:
                src/lib-storage/index/mbox/mbox-storage.c */

#include "str.h"
#include "mbox-from.h"
#include "message-date.h"
#include "write-full.h"
#include "hostpid.h"

        string_t *str;

/* Let's prepare the pseudo message, without trying to be clever wrt the
           uidvalidity value: just make use of the current time. */
        str = t_str_new(1024);
        str_printfa(str,
            "%s"
            "Date: %s\n"
            "From: Mail System Internal Data <mailer-dae...@%s>\n"
"Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA"
            "\nMessage-ID: <%...@%s>\n"
            "X-IMAP: %u  %010u\n"
            "Status: RO\n"
            "\n"
"This text is part of the internal format of your mail folder, and is not\n" "a real message. It is created automatically by the mail system software.\n" "If deleted, important folder data will be lost, and it will be re-created\n"
            "with the data reset to initial values.\n"
            "\n",
            mbox_from_create("MAILER_DAEMON", ioloop_time),
            message_date_create(ioloop_time),
            my_hostname,
            dec2str(ioloop_time), my_hostname,
            (uint32_t)ioloop_time, 0
        );

/* Write the message to the mailbox file; in case of problem, just try to revert to the original behavior by truncating the file (i.e. no
           pseudo message at all). */
        if (pwrite_full(fd, str_data(str), str_len(str), 0) < 0) {
i_info("mbox_mailbox_create(): failed to write pseudo message to %s(%d)", path, errno);
            /* Should a failure here be considered fatal? */
            if (ftruncate(fd, 0) < 0)
i_info("mbox_mailbox_create(): failed to truncate file %s(%d)", path, errno);
        }

/* OK, it should now be safe to rely on Dovecot's ability to build the
           indexes and to correctly recognize the pseudo message. */

        (void)close(fd);
        return 0;
    }

In the hope this may prove useful as a skeleton for a better code, should a better handling of the UIDVALIDITY with the mbox format be considered useful,
Axel



Reply via email to