Mark Crispin wrote:

On Thu, 5 Aug 2004, Crispin Olson wrote:

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?



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 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

Reply via email to