Mailing List Archive

_ic_fetch in imapcommands.c
Does anyone have a good understanding of what happens in this function and a minute to explain why things are done the way they are? I'm not trying to criticize anything in imapcommands.c, just trying to understand it more and hope someone who perhaps understands it well could shed some light on things a bit :D

My questions are in the portion of _ic_fetch that read:

/* if there is no parsing at all, this loop is not needed */
for (i=fetch_start; i<=fetch_end && !no_parsing_at_all; i++)
{
thisnum = (imapcommands_use_uid ? i : ud->mailbox.seq_list[i]);
insert_rfcsize = 0;

if (imapcommands_use_uid)
{
if (i > ud->mailbox.msguidnext-1)
{
/* passed the last one */
fprintf(ci->tx,"%s OK FETCH completed\r\n",tag);
list_freelist(&fetch_list.start);
return 0;
}

/* check if the message with this UID belongs to this mailbox */
if (binary_search(ud->mailbox.seq_list, ud->mailbox.exists,
i, &fn) == -1) {
continue;
}

From what I've been reading in the code, the seq_list array of mailbox is built from db_getmailbox() in db.c and the SQL behind that only fetches messages that have the mailbox_idnr of the mailbox to which ud->mailbox refers.

Why the need to do binary_search() on the ud->mailbox.seq_list if we already know that all those messages belong to that mailbox and couldn't be otherwise? Unless I'm missing something?

Another thing I'm wondering is why the sequential looping

for (i=fetch_start; i<=fetch_end && !no_parsing_at_all; i++)

If we already have ud->mailbox.seq_list which is the entire list of message_idnr's for the mailbox; why not lop through ud->mailbox.seq_list after finding what index fetch_start would be in ud->mailbox.seq_list and what index fetch_end would be.

Thanks for any help, it is MUCH appreciated :D

Blessings in Jesus,
Paul F. De La Cruz
Re: _ic_fetch in imapcommands.c [ In reply to ]
this requires some serious digging in my memory - i'm not even going to
guarantee my answers :p

Op 3-mrt-04 om 3:43 heeft Paul F. De La Cruz het volgende geschreven:

> Does anyone have a good understanding of what happens in this function
> and a minute to explain why things are done the way they are? I'm not
> trying to criticize anything in imapcommands.c, just trying to
> understand it more and hope someone who perhaps understands it well
> could shed some light on things a bit :D
>
> My questions are in the portion of _ic_fetch that read:
>
> /* if there is no parsing at all, this loop is not needed */
> for (i=fetch_start; i<=fetch_end && !no_parsing_at_all; i++)
> {
> thisnum = (imapcommands_use_uid ? i : ud->mailbox.seq_list[i]);
> insert_rfcsize = 0;
>
> if (imapcommands_use_uid)
> {
> if (i > ud->mailbox.msguidnext-1)
> {
> /* passed the last one */
> fprintf(ci->tx,"%s OK FETCH completed\r\n",tag);
> list_freelist(&fetch_list.start);
> return 0;
> }
>
> /* check if the message with this UID belongs to this mailbox */
> if (binary_search(ud->mailbox.seq_list, ud->mailbox.exists,
> i, &fn) == -1) {
> continue;
> }
>
> From what I've been reading in the code, the seq_list array of mailbox
> is built from db_getmailbox() in db.c and the SQL behind that only
> fetches messages that have the mailbox_idnr of the mailbox to which
> ud->mailbox refers.
>
> Why the need to do binary_search() on the ud->mailbox.seq_list if we
> already know that all those messages belong to that mailbox and
> couldn't be otherwise? Unless I'm missing something?
>

from the top of my head: you can specify a range of message-(u)ids with
the fetch command. When using logical numbers, there are no gaps so a
check is not needed. When using uid's however, gaps are allowed (and
common) so we need to check for every UID specified that it does exist.
For example when requesting:

A UID FETCH 30000:40000 FAST

will cause a loop for i from 30000 'till 40000 but it is not guaranteed
that every number specified will exist in the mailbox.

> Another thing I'm wondering is why the sequential looping
>
> for (i=fetch_start; i<=fetch_end && !no_parsing_at_all; i++)
>
> If we already have ud->mailbox.seq_list which is the entire list of
> message_idnr's for the mailbox; why not lop through
> ud->mailbox.seq_list after finding what index fetch_start would be in
> ud->mailbox.seq_list and what index fetch_end would be.
>

ehh.. well.. dont know :) i think i build the basis of fetch primarily
upon using logical numbers, not uids. Changing above would probably
require some other loop-variable or splitting the loop into a version
for UID FETCH and a version for just FETCH. Furthermore, please remind
that the start or end specified with the UID need not to exist; the
most common example probably is UID FETCH 1:*.

regards roel

> Thanks for any help, it is MUCH appreciated :D
>
> Blessings in Jesus,
> Paul F. De La Cruz
> _______________________________________________
> Dbmail-dev mailing list
> Dbmail-dev@dbmail.org
> http://twister.fastxs.net/mailman/listinfo/dbmail-dev
>

_________________________
R.A. Rozendaal
IC&S
T: +31 30 63 55 736
F: +31 30 63 55 731
www.ic-s.nl