Imap mail - Multiple bodies at once

Hello Sitepoint.

How can I request a list of all mail available in my inbox? And how can I do the same thing but with a limit of 20 e-mails instead?

I want to do this on only one request if it’s possible, not in a loop where I send and receive multiple requests for all mail that is available in my inbox. A request to receive them all at once.

The information I want from all the emails is who sent it, the subject, the message and the date.

Appreciate all the tips I can get


Does an IMAP server allow multiple messages to be handled at once? If not, surely a short wrapper function would achieve what you need?

That’s the same as the loop.

After you create the connection, you start a loop and keep sending requests for mails.

Should be able to tell the server what I need with one request.

Are you saying that the IMAP protocol does support it, but the PHP IMAP library doesn’t implement it? I had a quick look down the RFC and couldn’t see anything specific, but like most of them, they’re not really designed for quick skim-reading.

No I am not saying that, are you saying it doesn’t?

Not conclusively, as I said, it’s a bit heavy-going. I just wondered as you said you should be able to tell the server what you need with one request - and that’s only true, if the IMAP protocol gives you a way to do that. I couldn’t tell whether you meant that it does, or that you’d like it to.

What’s the reason for needing to retrieve them in one hit rather than via a loop?

Here is an object oriented library around the imap extension that might be useful to you.

It is bad to tell the receptionist to go to the storeroom and get paper 1, later when she comes back, I ask her to go back to exact same place to pick up paper 2. After she has done that , she comes back and I tell her AGAIN!? to go back to that exact same place and pick up paper 3. This will continue 20 times, to begin with.

I already know what I want the first time I asked here. I should be able to say: "hey here is a list of everything I want from the storeroom, so she can pick everything up while she is there. What a waste of time otherwise, to Send her back to the same place a hundred times after each time she returns. It’s like I’m “running her” in a really bad way.

We’re talking code here, not people. Code doesn’t mind doing the same thing over and over again. It’s basically one of the main selling points of computers in general :wink:

Also, to use your analogy, if the boxes you’re asking for are too big / too heavy to all be carried at once, you can bet the receptionist will take multiple trips to the store room to make their life easier instead of trying to take all your boxes with them at once. Consider IMAP to be a case where you know beforehand that if your ask for all the boxes at once the receptionist will refuse to do it because they can’t be carried all at once.

Sure, she gladly takes several rounds instead of one, if the boxes are too heavy. But she will bother if she has to wait for me to say, which one is the next box, on every occasion she comes back. If she already has a complete list in front of her, she can work much faster. Plus web traffic will decrease, as send and receive do not have to be applied at each occasion, which happens behind the scenes. The socket / stream opens and waits to receive requests.

One request is better than 100s :slight_smile:

It may be related to improvements to the protocol

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.