The problem you have is the definition of new. New according to what criteria? A simple solution would be to get the unique id (using the appropriate method) for each message and remember the 'last old one' in a file, then next time you access the account just skip messages until you reach the 'last old one'....
Alternatively delete all the 'old' ones (storing them in a file for future reference if required) that way all the emails in the account will be 'new'.
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
| [reply] |
To add to tachyon's suggestion, if you're using the POP3 protocol to access your mailbox, you should use something called the UIDL of the message for this purpose.
The UIDL is a unique identifier for each message. In practice, you can assume that different UIDLs mean different messages.
I would suggest you to store in a file or other form of stable storage, the list of UIDLs whenever you check a mailbox. You can then have three scenarios for each UIDL taken from the mailbox and the file:
- The UIDL from the server is already in the file, which means that this message is old and does not need to be "reported".
- The UIDL from the server is not in the file, which means that this message is new. Its UIDL must be added to the file and this message must be reported.
- The UIDL from the file was not reported by the server, which means that this message was deleted. It can be removed from the file.
I'm using the term "file" in a quite ample way. You should use a form of stable storage appropiate to your web application.
Regards.
| [reply] |
I may be misunderstanding the question, but wouldn't all the emails on your server be considered new if they haven't been downloaded by a mail client? Normally a mail program will download and save messages on your machine, or delete them off the server entirely, so the next it checks the server, any messages there are new. So if you're not downloading or deleting those messages, you'll have to save the date and time of when you check the server in a file somewhere. That way, the _next_ time you look for mail, any messages that are newer than the date in the file can be marked as new.
"We're experiencing some Godzilla-related turbulence..."
| [reply] |
Correction: Oops, the module's name is Mail::POP3Client. Thanks, Ralph. | [reply] |
The problem is that I'm checking the email on the same server (thru a web based client).
tachyon's solution seems cool, but isn't there a special function or something more accurate?
Thanks,
Ralph. | [reply] |
The real "problem" is that POP3 as described in RFC 1725 does not have a way of telling a client how many messages are "new". In fact, there is no notion of "newness" at all. That is why you need a solution like tachyon's.
HTH, --traveler
| [reply] |