Subject: mail_partial_text and mailgets

From: John-Paul Robinson <[email-masked]>
Date: Sun, 18 Jun 2000 05:10:26 -0500

I'm attempting to use mail_partial_fetch() in order to throttle message
downloads. This function requires that a mailgets function be defined.

In order to understand the mailgets functionality, I'm experimenting
with the dos_default_gets() function in a slightly modified imapcopy.c.
(I've modified msg_string_init() to loop on mail_partial_text() to load
the message instead of relying on mail_fetchheader_full's pre-fetchtext
flag.)

I can't seem to figure out what is going wrong with the partial fetch. 
It appears to read the message in the 500 byte increments I've
specified, but when I go to read the STRING in mail_append_full() the
size is 0, instead of the corret message size. It looks like the rest of
the STRING data contains the message, though. The zero size causes a
zero-length message to be appended to the destination mailbox.

What are the requirements for the mailgets function when doing partial
fetching? I chose the dos_default_gets() because it is relatively
simple.  Is more complexity required for partial fetching. I tried
looking at the mailpartial.c in pine but I couldn't weed out the basic
functionality of mailgets from it.

Thanks for any hints,

...john-paul
-- 
------------------------------------------------------------------
 For information about this mailing list, and its archives, see: 
 http://www.washington.edu/imap/c-client-list.html
------------------------------------------------------------------

---

From: John-Paul Robinson <[email-masked]>
Date: Sun, 18 Jun 2000 20:30:57 -0500

Okay, I spent some more quality time with mail_partial_text() today.  Is
the reason that the mail_partial_* functions require a mailgets function
because this is the only way that the partial data can be returned to
the main application? In other words, the mailgets serves as a callback
to return the requested data from the mail_partial_* functions.

It appears that the mail_partial_* functions handle constructing the
partial request for all but the imap4r1 driver.  They do this by calling
the text() driver function, as a result the the entire message is loaded
into into the cache.  They then call mailgets to return the part
requested by the caller in a STRING.  The imap driver provides it's own
msgdata function, and, in the case of partial fetches, calls the
mailgets with a network stream without loading the data in the the
message cache (which it would normally do for other calls).

So, I have two questions.  The first is, if I want to do partial fetches
on an imap connection, do I need to construct the message myself from
the char strings read through mailgets?  Is it possible to load that
message into the cache once it is constructed, since the whole point of
the exercise is to avoid retrieving the entire message?

The second question is do I need to consider the type of readfn_t
function sent to mailgets based on the data source, e.g.
imap_parse_string calls mailgets with netgetbuffer for literals and
mailread for quoted strings, but the rest of the drivers always send a
mailread? Does it make a difference or is it not an issue because the
mailgets only invokes whichever function is passed and then works with
the returned char buffer?

Thanks,

...john-paul

---

From: Mark Crispin <[email-masked]>
Date: Mon, 19 Jun 2000 13:23:12 -0700 (PDT)

On Sun, 18 Jun 2000 05:10:26 -0500, John-Paul Robinson wrote:
> size is 0, instead of the corret message size.

That's because you have to set up the message size in your msg_string_init().
At the minimum, you have to set s->size to the value of the size argument to
msg_string_init().

I think that you will find it to be very difficult to tie a mailgets function
to a STRING structure.  The reason is that the mailgets function is called by
the IMAP client code to read things in, whereas the STRING structure's methods
are called by mail_append() to write things out.  You would need to write a
coroutine to do this, and C doesn't have coroutines (you can't longjump() back
and forth, you can only do it one way).

Consequently, you have to read the message in first, buffer it someplace, and
then write it from the buffer.

---

From: Mark Crispin <[email-masked]>
Date: Mon, 19 Jun 2000 15:28:05 -0700 (PDT)

On Sun, 18 Jun 2000 20:30:57 -0500, John-Paul Robinson wrote:
> if I want to do partial fetches
> the char strings read through mailgets?

Yes.

> Is it possible to load that

Yes.  Use function imap_cache() for this purpose.  Note that you can only do
this for IMAP streams; do not use it for any other type of stream.  However,
in general, there is no point to doing a partial fetch except with IMAP
streams.

> function sent to mailgets based on the data source

No.  Or, at least, not in a properly written mailgets function.

> mailread?

That's because literals are of potentially enormous size.  That is not the
same with quoted strings.  With other drivers, the data is in memory anyway.

> Does it make a difference or is it not an issue because the

It is not an issue.