R: sequence number to uid conversion

Toschi Pietro Pietro.Toschi at actalis.it
Thu Nov 8 07:33:55 EST 2007


Thank you Bron, very interesting!
I'll try starting from the more crc32-safe way and I'll let you and the list know  my results.

P.




Pietro Toschi
Actalis S.p.A. Gruppo AlmavivA
Via Luigi Rizzo, 20
00136 Roma
www.actalis.it
Office: 06-39933169
Mobile: 335-7244764
Fax: 06-39935348
 

-----Messaggio originale-----
Da: Bron Gondwana [mailto:brong at fastmail.fm] 
Inviato: giovedì 8 novembre 2007 13.30
A: Toschi Pietro
Cc: cyrus-devel at lists.andrew.cmu.edu
Oggetto: Re: sequence number to uid conversion

On Thu, Nov 08, 2007 at 11:17:23AM +0100, Toschi Pietro wrote:
> 
> Hi
> For an experiment I'm working at, I need to modify imapd.c so that COPY
> and STORE commands are registered via syslog along with UIDs of messages
> they apply to. It seems an easy job when clients issue commands
> prepended with UID (eg. UID STORE <args>, UID COPY <args>), but I can't
> face any way to convert a message sequence number to a message UID when
> using the simple form. Is there some function and data structure that I
> can use to obtain a message UID given a folder and a message sequence
> number?

This is also something I'm looking at doing - I want to log both the UID
and the GUID to the log.  I also want to make sure that APPEND gets
logged as well, and DELETE.

You should find that you can use the macro UID(msgno) or if you
really feel like it the function index_getuid(msgno) from index.c.

Both of these require the mailbox to be selected.  Otherwise you
can always just fetch it directly from the memory-mapped mailbox
index:

uid = ntohl(*((bit32 *)(mailbox->index_base + mailbox->start_offset +
                        (msgno - 1) * mailbox->record_size)));

(yeah, a bit unwieldy!)

Or there's the nice interface way:

struct index_record record;
mailbox_read_index_record(mailbox, msgno, &record);
uid = record.uid;

Which has the added benefit that it will work once I finish
writing crc32 support in and you can't go doing random memory
offset reads any more without missing out on the crc32 check.

Bron.


More information about the Cyrus-devel mailing list