Subject: Question about mail_partial_body/text

From: "Crispin Olson" <[email-masked]>
Date: Thu, 5 Aug 2004 00:55:18 -0400

I've dug around and found a few comments and even some examples of how to
use these functions. However, it begs the question - why do these functions
need callback drivers? Why cant they return the data in a string like the
mail_fetch... functions? I realise they would need new function names -
(mail_partial_fetch..? ) so existing clients don't break.

The reason - I'd love to see chunking of imap attachments in PHP (having my
webserver barf when some fool mails a 50meg powerpoint file to a few dozen
colleagues is a PITA), and the gods at Zend/PHP are more likely to let that
happen if there is a function in c-client (for which PHP-IMAP is but a thin
veneer).

Crispin Olson

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

---

From: Mark Crispin <[email-masked]>
Date: Tue, 17 Aug 2004 17:55:33 -0700 (Pacific Daylight Time)

On Thu, 5 Aug 2004, Crispin Olson wrote:
> mail_fetch... functions?

The original intent of partial fetching was to permit resource-limited 
clients to do so without requiring a potentially huge memory buffer.  You 
don't generally want to do a fetch-as-string for a 600MB video file.

I don't think that a callback function is all that hard to write.

-- Mark --

http://staff.washington.edu/mrc
Science does not emerge from voting, party politics, or public debate.
Si vis pacem, para bellum.

---

From: Crispin Olson <[email-masked]>
Date: Tue, 17 Aug 2004 22:41:03 -0400

Mark Crispin wrote:

> clients to do so without requiring a potentially huge memory buffer.  
> You don't generally want to do a fetch-as-string for a 600MB video file.

I understand. And that was *exactly* the reason why I wanted to 
implement using it. When I said "return a string" I meant a string that 
was the size of the buffer requested.
A PHP script has, by default, 8MB max of memory allocated to it. In a 
heavily loaded webserver even that is too high. Right now, deploying the 
popular IMP webmail program requires a memory limit beyond 2x the max 
attachment size (because the base 64 decode is also done in string 
memory).  Problems arise when someone puts a large attachment in a 
shared IMAP folder, and a dozen people want to see it at the same time.

> I don't think that a callback function is all that hard to write.
I think the issue was that the documentation on how to use string 
drivers with mail_partial_body was hard to find - I found some examples 
from you in postings on another imap list. I've submitted a working 
patch to PHP-DEV. One thing I did find by experimentation was that the 
4th and 5th parameters of "mail_partial_body" aren't start offset and 
end offset (as the examples suggested), they are start and length (which 
makes more sense anyway)

However to provide the best level of functionality I'd like to be able 
to hook a body fetch up to a stream handle - that way it can also be 
hooked through an inline decoding filter/pipe (e.g. base64 or UUencode) 
and need a trivial amount of inprocess memory to deliver an attachment 
to a webmail client.  I don't suppose theres any direct way to achieve 
this with C-Client (the string drivers only operate during a call to 
e.g. mail_fetchbody as far as my reading of the documentation tells me) 
? I would need to implement my own internal buffer, and call 
mail_partial_body as needed to populate it?
Any help/advice is much appreciated.

Crispin Olson