Hi everybody,
I just would like to download the new mails I received on my POP3 server
(and keep a copy on the server)
I use PHP 4.3 and IMAP functions (they are compatible with both POP3 and
IMAP servers).
When I use OUTLOOK, no problem, in less than 5 seconds, it answers me:
" you have XX new messages"
But, I can't manage to do the same thing within the same time in PHP!!!
I believe it's a IMAP functions problem.
First, I thought that each new mail was the last message returned by the
IMAP functions.
For exemple, when I connect to the POP3 servers, I get the total number of
messages.
Let's say I have 600 messages, the 600th messages is supposed to be the last
message.
So, here is the process:
1- X=total number of messages
2- I download the Xth message
3- Is it a NEW message?
YES-> download it, X=X-1, then go to step 2
NO -> Go to step 4
4- End
So, if I have already downloaded the 600th message, obviously, i know I have
already dowloaded ALL the mails, and I can say immediately "no new message".
BUT, this is wrong with some servers (like ovh.com).
They do not sort the emails like this!!
If I send a new mail to myself, it will not be the last message!!! It will
appear for example in the middle of the list!!!!!!!!!!! !!!!!!!!!!!
So the only solution is:
1- Download the whole list of emails!!!!!!!!
2- compare EACH mail on the server with the locals mails!!
3- If the mail on the server is not on my local machine, then I download it
Suppose I have no new mail, I read 600 mails for nothing!!
So it takes more than 1 minute just to say: "no mail"!
Do you have another idea?
Some important points with POP3:
- no uid!! Even the field MESSAGE_ID is not usedul. Sometimes it is empty!!
- udate is sometimes empty!! (0)
- date can have several formats
- when you use the SORT imap function (or search) it download the whole
list!! So it makes a lot of time!!
How can OUTLOOK know the number of new mail in less than 5 seconds (even
with OVH)????
Can I do the same thing with PHP scripts?????
thanks for your help
Rod 4 1972
WebRod wrote: First, I thought that each new mail was the last message returned by the IMAP functions.
Nope, this ain't the case. First thing to remember with POP3 is that
you can *never* assume the messages are in the same order on two
subsequent connections - the standard doesn't specify the order in any
way.
For exemple, when I connect to the POP3 servers, I get the total number of messages.
Yes. And there's actually more than one way to accomplish that :)
Let's say I have 600 messages, the 600th messages is supposed to be the last message. So, here is the process:
[SNIP] So, if I have already downloaded the 600th message, obviously, i know I have already dowloaded ALL the mails, and I can say immediately "no new message".
As I said, you can't count on this.
Some important points with POP3: - no uid!! Even the field MESSAGE_ID is not usedul. Sometimes it is empty!!
This isn't actually the case. POP3 has extended command UIDL, which
returns you a list of unique identifiers (just like LIST returns the
sizes of messages). After this, you only need to check the UID with
stored UIDs of the messages you've already downloaded. This is quite
fast even with thousands of messages.
The downside is that not all servers provide UIDL-command since it's
not required by the standard. If this is the case, the only solution
is to download message headers (using command like TOP) only and
comparing them to headers already received. This takes somewhat longer
(but not as long as it'd take to download the whole messages) and
isn't as reliable as using UIDs.
How can OUTLOOK know the number of new mail in less than 5 seconds (even with OVH)????
For example (O=Outlook, S=Server, indented for readability):
S: +OK Welcome
O: USER example
S: +OK
O: PASS example
S: +OK
O: UIDL
S: +OK List follows
1 abcdef
2 abcdeg
3 abcdeh
4 abcdei
5 abcdej
One more thing... the user contribution at http://www.php.net/manual/en/function.imap-uid.php isn't too good, put
it gives good pointers on how to proceed. To be honest, I don't
believe it works to begin with - fgets shouldn't be used on a protocol
like POP3 where we can't know beforehand how much data we should
receive :(
--
Markku Uttula
Markku Uttula wrote: One more thing... the user contribution at http://www.php.net/manual/en/function.imap-uid.php isn't too good, put it gives good pointers on how to proceed. To be honest, I don't believe it works to begin with - fgets shouldn't be used on a protocol like POP3 where we can't know beforehand how much data we should receive :(
Oops - my bad... fgets only does reading up to newline. Sorry to bash
the user contribution.
--
Markku Uttula
many thanks for all your messages.
Actually, irelaised that is should not try to do that with imap functions.
I now use POP PEAR functions and it does exactly what you are saying.
So many thanks.
The problem with this function is that the mails are not formatted.
I get some text like this:
=?ISO-8859-1?Q?eBay_-_F=E9licitation s=A0!_Achat_?
Anyway, i use mb_decode_mimeh eader and the problem is solved.
A last one, sometimes i get "_" instead of spaces!!
Before or even after i use mb_decode_mimeh eader.
Any idea?
many thanks!
"Markku Uttula" <ma***********@ disconova.com> a écrit dans le message de
news: 41************* **********@news .yhteys.mtv3.fi ... WebRod wrote: First, I thought that each new mail was the last message returned by the IMAP functions.
Nope, this ain't the case. First thing to remember with POP3 is that you can *never* assume the messages are in the same order on two subsequent connections - the standard doesn't specify the order in any way.
For exemple, when I connect to the POP3 servers, I get the total number of messages.
Yes. And there's actually more than one way to accomplish that :)
Let's say I have 600 messages, the 600th messages is supposed to be the last message. So, here is the process: [SNIP] So, if I have already downloaded the 600th message, obviously, i know I have already dowloaded ALL the mails, and I can say immediately "no new message".
As I said, you can't count on this.
Some important points with POP3: - no uid!! Even the field MESSAGE_ID is not usedul. Sometimes it is empty!!
This isn't actually the case. POP3 has extended command UIDL, which returns you a list of unique identifiers (just like LIST returns the sizes of messages). After this, you only need to check the UID with stored UIDs of the messages you've already downloaded. This is quite fast even with thousands of messages.
The downside is that not all servers provide UIDL-command since it's not required by the standard. If this is the case, the only solution is to download message headers (using command like TOP) only and comparing them to headers already received. This takes somewhat longer (but not as long as it'd take to download the whole messages) and isn't as reliable as using UIDs.
How can OUTLOOK know the number of new mail in less than 5 seconds (even with OVH)????
For example (O=Outlook, S=Server, indented for readability):
S: +OK Welcome O: USER example S: +OK O: PASS example S: +OK O: UIDL S: +OK List follows 1 abcdef 2 abcdeg 3 abcdeh 4 abcdei 5 abcdej . at this point Outlook can check if it has some or all of the messages 1 through 5 and retrieve those it hasn't.
Can I do the same thing with PHP scripts?????
Certainly. I'd suggest reading RFC-1939 as starters http://www.faqs.org/rfcs/rfc1939.html - that way you should get to know how POP3 really works. It's not really much to read (when compared to something like IMAP, which is a pain in the ...)
After that, check http://www.php.net/manual/en/function.imap-uid.php - to be more precise, check the last user contributed comment on the page. After you've read the RFC, you see the comment is meant to only retrieve UID of *one* message (which of course is very unefficient, since you can get them all during one session). Also, remember what I said about the messages not necessarily being in the same order on next connection - you need to retrieve the messages you want (if you're not only counting them) during the same session... ie. do not issue QUIT before you're done.
And last but not least - though this propably is quite obvious - you need to remember that it's imperative you store locally the UIDs of the messages you've already "received"/"checked"/whatever. Otherwise this won't work.
-- Markku Uttula This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alexander Franksmann |
last post by:
Hello,
I'm going to write a anti-spam-program based on a Whitelist.
"If the mail sender is found in the database, my program should move
the mail into another mailbox"
The mailserver fetched the mails from the clean pop3-account.
The problem is a problem because the function imap_move() can only
move mails from one folder in the mailbox into...
|
by: WebRod |
last post by:
Bonjour,
comment savoir en moins de 5 secondes (enfin rapidement quoi) combien de
nouveaux messages non récupérés se trouvent dans une BAL sur une serveur
POP3 (pas d'imap donc)????
(en sachant que lorsque l'on récupère les emails, on ne les supprime pas du
serveur au fur et à mesure)
Parceque OUTLOOK y arrive bien lui!!
|
by: zZ |
last post by:
Hi All,
By a mistake I posted a question using one of my real mail addresses. It was
then bombarded in one month by so-called MS Patch (swen32), counted 800-1000
virus mails. Even now it's about 20 virus mails a day.
Is it usual? bad luck, or targeted?
|
by: Chad Myers |
last post by:
I'm looking for an app that would allow me to
download mails from various POP3 accounts and
put them into my Exchange inbox on the server
side (rather than having to have outlook open
to do it all the time).
There are many products that do this, but
they're very expensive considering it's just
for me and just for tinkering.
|
by: Praveen Naregal |
last post by:
Hello all,
Does .NET includes any support for POP3 protocol? Or else any c#
implementation of POP3 client is available?
Regards,
--
Praveen Naregal
| |
by: Ajeet YS |
last post by:
Hello,
Well, I don't know if this is the right forum to post this query, but I
didn't find any other suitable one.
I am developing a program to access mails from a pop3 server's mailbox.
For this I am using System.Net.Sockets namespace. I am able to get all the
messages from the server & read them. Upon reading each mail DELE command is...
|
by: Lucvdv |
last post by:
A class in my app starts a new thread, and fires events from within that
thread.
The result, if nothing is done to prevent it, is that the events are
executed in the wrong thread in a form having a member of that class.
A user class doesn't have an Invoke method: how can I make the worker
thread invoke the events in the main UI thread...
|
by: Crouchie1998 |
last post by:
I have written a POP3 class using sockets & it works perfectly fine.
When I try and check an account like Gmail, which uses SSL, my program
freezes. How do I make my POP3 class SSL compatible
Gmail info (not needed to answer this question though):
POP3: pop.gmail.com
Port: 995
SSL: Yes
|
by: Shimon Sim |
last post by:
Is there a way to get e-mails with attachments using .NET 2.0?
If not does anybody knows a component that can do this?
Thank you,
Shimon.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| | |