tags:

views:

23

answers:

2

I'm building a little script that will connect to an IMAP account and grab the content of the email and also the attachments. It works well for the most part, but when a really large file comes in, it causes the script to time out. Is there any way that I can check the file size before trying to grab it? I think that would be the simplest solution. Otherwise, I may have to upgrade to a server that has more memory.

+1  A: 

Check out imap-fetch-overview() and imap-fetchstructure()

They look like they'll give you the size in bytes (depending on the server).

Scott Saunders
I'm currently using imap_fetchstructure() and I just noticed it passes back bytes. How exactly does imap_fetchstructure() work? Does it actually grab the attachments right when you call it?
mike
`imap_fetchstructure()` will not fetch the attachments; it asks the IMAP server to return the structure to you (yes, there is an IMAP command to do that). Then you use `imap_fetchbody()` to get the bit you want.
staticsan
+1  A: 

You can use imap_fetch_overview to retrieve information for one or more headers, including the size.

Mike Pelley