[Imap-uw] UID Validity
Frode Nordahl
frode at nordahl.net
Wed Sep 13 13:00:57 PDT 2006
On 23. aug. 2006, at 23.23, Mark Crispin wrote:
>> * Mark: when MIX is released and we work on migrating users to it,
>> will it be at all possible to convert an mbx -> mix and preserve
>> both the UIDs and the UID Validity settings? I know you have -
>> kwcopy in the new mailutil. Can it be possible to do something
>> similar for uid/uidvalidity?
>
> It isn't be possible to do this with the distributed version of
> mailutil. I consider it to be too special purpose, and too
> dangerous, to be something that I am comfortable with putting in
> the distributed version. However, it shouldn't be a particularly
> difficult change to make as a local hack.
>
> For example, the following is a disgusting kludge, but it should do
> the trick. You probably want to do this in a separate copy of the
> source code just for this special hacked version of mailutil.
>
> (1) Create two new global variables in mailutil.c, newuidvalidity
> and newuidlast.
>
> (2) Early in routine mbxcopy() in mailutil.c, do
> newuidvalidity = source->uid_validity;
> newuidlast = source->uid_last;
>
> (3) In mix.c, prototype newuidvalidity and newuidlast as extern.
>
> (4) In mix_create() in mix.c, change
> fprintf (f,MTAFMT,now,0,now);
> to
> fprintf (f,MTAFMT,newuidvalidity,0,now);
>
> (5) Finally, in mix_append(), just before the lines that read:
> ret = (mix_meta_update (astream) &&
> mix_index_update (astream,&idxf,LONGT) &&
> mix_status_update (astream,&statf,LONGT));
> add
> if (astream->uid_last <= newuidlast) aastream->uid_last =
> newuidlast;
>
> Please let me know how it goes.
Thank you very much for this recipe!
We are about to convert our historic mbox over NFS system to
distributed MBX and I determined that something like this had to be
done in my migration setup. I had not even started to look through
the source code to find where and how.
You just saved me alot of time :-)
Here is the UIDVALIDITY / UIDLAST patch I plan on using for MBX, I
know it is of no use to you, but maby someone on the list will find
it usefull.
diff -ru imap-2006.DEV.SNAP-0608311346.org/src/mailutil/mailutil.c
imap-2006.DEV.SNAP-0608311346/src/mailutil/mailutil.c
--- imap-2006.DEV.SNAP-0608311346.org/src/mailutil/mailutil.c
2006-08-31 02:22:00.000000000 +0200
+++ imap-2006.DEV.SNAP-0608311346/src/mailutil/mailutil.c
2006-09-13 21:44:39.000000000 +0200
@@ -47,6 +47,7 @@
char *suffix = NIL; /* suffer merge mode suffix text */
int ddelim = -1; /* destination delimiter */
FILE *f = NIL;
+extern unsigned long new_uid_validity, new_uid_last;
/* Merge modes */
@@ -419,6 +420,8 @@
char *ndst = NIL;
int ret = NIL;
trycreate = NIL; /* no TRYCREATE yet */
+ new_uid_validity = source->uid_validity;
+ new_uid_last = source->uid_last;
if (create) while (!mail_create (dest,dst) && (mode != mAPPEND)) {
switch (mode) {
case mPROMPT: /* prompt user for new name */
diff -ru imap-2006.DEV.SNAP-0608311346.org/src/osdep/unix/mbx.c
imap-2006.DEV.SNAP-0608311346/src/osdep/unix/mbx.c
--- imap-2006.DEV.SNAP-0608311346.org/src/osdep/unix/mbx.c
2006-08-31 03:41:45.000000000 +0200
+++ imap-2006.DEV.SNAP-0608311346/src/osdep/unix/mbx.c 2006-09-13
21:45:59.000000000 +0200
@@ -47,6 +47,7 @@
#include "dummy.h"
#include "fdstring.h"
+unsigned long new_uid_validity, new_uid_last;
/* Build parameters */
@@ -380,8 +381,9 @@
}
else {
memset (tmp,'\0',HDRSIZE);/* initialize header */
- sprintf (s = tmp,"*mbx*\015\012%08lx00000000\015\012",
- (unsigned long) time (0));
+ sprintf (s = tmp,"*mbx*\015\012%08lx%08lx\015\012",
+ (unsigned long) new_uid_validity,
+ (unsigned long) new_uid_last);
for (i = 0; i < NUSERFLAGS; ++i) {
t = (stream && stream->user_flags[i]) ? stream->user_flags[i] :
((t = default_user_flag (i)) ? t : "");
@@ -1176,6 +1178,10 @@
if (au && ret) (*au) (mailbox,dstream->uid_validity,dst);
else mail_free_searchset (&dst);
fseek (df,15,SEEK_SET); /* update UIDLAST */
+
+ if (dstream->uid_last <= new_uid_last)
+ dstream->uid_last = new_uid_last;
+
fprintf (df,"%08lx",dstream->uid_last);
/* set atime to now-1 if successful
copy */
if (ret) tp[0] = time (0) - 1;
--
Frode Nordahl
More information about the Imap-uw
mailing list