Page 1 of 23
PurePOP3 library : POP3 functions
Posted: Sat Oct 01, 2005 12:02 pm
by gnozal
PurePOP3 library V1 *BETA* (Last update : PB5.0x NOV 7th 2012)
OverviewPOP3 functions for Purebasic.
Features :
- count messages at POP3 server
- get message text
- get message attachments
- and more
Note : TLS/SSL is not supported
Functions
PB3.94 :
http://gnozal.ucoz.com/PurePOP3.htm
PB4.xx :
http://gnozal.ucoz.com/PurePOP3_.htm
ExampleCode: Select all
Server.s = "my.server.de"
Port.l = 110
User.s = "gnozal"
Pwd.s = "mypass"
;
If PurePOP3_OpenPOP3Connection(Server, Port, User, Pwd) = #PurePOP3_Ok
Debug "Connected"
; PurePOP3_Trace(#TRUE)
Messages = PurePOP3_CountMessages()
Debug "You have " + Str(Messages) + " messages(s)"
If Messages
Debug "Message(s) total size : " + Str(PurePOP3_GetMessagesTotalSize()) + " bytes"
Debug "Message " + Str(Messages) + " size : " + Str(PurePOP3_GetMessageSize(Messages)) + " bytes"
Debug "Retrieve message " + Str(Messages)
If PurePOP3_RetrieveMessage(Messages) > 0
Debug "--------------"
Debug "Message info : " + PurePOP3_GetMessageInfo()
*Message = PurePOP3_GetMessageTextInMemory()
If *Message
Debug "Message text :"
Debug ""
Debug PeekS(*Message)
Debug ""
PurePOP3_FreeMessagePointer(*Message)
EndIf
Attachements.s = PurePOP3_ListAttachementsForMessage()
If Attachements
Debug "----------------"
Debug "Attachement(s) : " + Attachements
If PurePOP3_SaveAttachementsToFile("")
Debug "Attachement(s) saved to current directory"
Else
Debug "Could not save attachement(s)"
EndIf
Else
Debug "--------------"
Debug "No attachments"
EndIf
EndIf
EndIf
PurePOP3_ClosePOP3Connection()
Else
Debug PurePOP3_GetLastServerMessage()
EndIf
Download
Only available for Purebasic Windows x86
PB3.94 :
http://gnozal.ucoz.com/PurePOP3.zip
PB4.0x :
http://gnozal.ucoz.com/PurePOP3_.zip
PB4.1x :
http://gnozal.ucoz.com/PurePOP3__.zip
PB4.2x :
http://gnozal.ucoz.com/PurePOP3___.zip
PB4.3x :
http://gnozal.ucoz.com/PurePOP3_430.zip
PB4.4x :
http://gnozal.ucoz.com/PurePOP3_440.zip
PB4.5x :
http://gnozal.ucoz.com/PurePOP3_450.zip
PB4.6x :
http://gnozal.ucoz.com/PurePOP3_460.zip
PB5.0x :
http://gnozal.ucoz.com/PurePOP3_500.zip
Posted: Sat Oct 01, 2005 12:07 pm
by gnozal
Lately, I had access to a POP3 server so I can post a beta version of my lib, as requested by some PureSMTP users.
I have tested it with one POP3 server and 3 mailers (including PureSMTP).
It has beta status because I could not test it with many POP3 servers.
In case of problem, you can activate the debug mode with PurePOP3_Trace(#TRUE) and send me the PurePOP3-DEBUG*.txt files (please delete personal information if applicable).
Thanks.
Posted: Sat Oct 01, 2005 2:33 pm
by Kiffi
Hallo gnozal,
thank's for your library. Well done!
There's a little bug in your Example-Code PurePop3_Test1.pb.
It's better to put your Message-Analyze into a for-next-loop.
Code: Select all
If PurePOP3_OpenPOP3Connection(Server, Port, User, Pwd) = #PurePOP3_Ok
Debug "Connected"
; PurePOP3_Trace(#TRUE)
Messages = PurePOP3_CountMessages()
Debug "You have " + Str(Messages) + " message(s)"
If Messages
Debug "Message(s) total size : " + Str(PurePOP3_GetMessagesTotalSize()) + " bytes"
For MessageCounter = 1 To Messages
Debug "Message " + Str(MessageCounter) + " size : " + Str(PurePOP3_GetMessageSize(MessageCounter)) + " bytes"
Debug "Retrieve message " + Str(MessageCounter)
If PurePOP3_RetrieveMessage(MessageCounter) > 0
Debug "--------------"
Debug "Message info : " + PurePOP3_GetMessageInfo()
*Message = PurePOP3_GetMessageTextInMemory()
If *Message
Debug "Message text :"
Debug "<start>"
Debug PeekS(*Message)
Debug "<end>"
EndIf
Attachements.s = PurePOP3_ListAttachementsForMessage()
If Attachements
Debug "----------------"
Debug "Attachement(s) : " + Attachements
If PurePOP3_SaveAttachementsToFile("")
Debug "Attachement(s) saved to current directory"
Else
Debug "Could not save attachement(s)"
EndIf
Else
Debug "--------------"
Debug "No attachments"
EndIf
EndIf
Next ; MessageCounter
EndIf
PurePOP3_ClosePOP3Connection()
Else
Debug PurePOP3_GetLastServerMessage()
EndIf
Greetings ... Kiffi
Posted: Sat Oct 01, 2005 3:08 pm
by gnozal
Kiffi wrote:Hallo gnozal,
thank's for your library. Well done!

Thanks
Kiffi wrote:There's a little bug in your Example-Code PurePop3_Test1.pb. It's better to put your Message-Analyze into a for-next-loop.
Greetings ... Kiffi
It's not really a bug, it's just an example (with the last message only [who knows how many messages one has ?

])...
There is a for-next-loop in the 2nd example file PurePop3_Test2.pb.
Posted: Sat Oct 01, 2005 5:21 pm
by gnozal
Library update
Bug fix
PurePOP3_RetrieveMessage() fixed ; all POP3 servers don't reply the same way after RETR command.
Thanks for the feedback.
Posted: Sun Oct 23, 2005 1:52 pm
by tycoon
Hi!
Nearly perfect Lib!
But one question:
Is there any posibility to store the complete message (text and attachment(s)) in one file?
CU
Posted: Mon Oct 24, 2005 7:55 am
by gnozal
Nearly perfect Lib!
Thanks, it's still WIP.
Is there any posibility to store the complete message (text and attachment(s)) in one file?
Actually, the only way is to activate the debug mode with PurePOP3_Trace(#true) and get the PurePOP3-DEBUG-RETR.txt file.
Posted: Mon Oct 24, 2005 2:54 pm
by tycoon
Hi!
For now I rewrite my code to handle your output...perhaps it is better. We will see
A little function for saving the complete mail is a good feature for a new release of your lib.
CU
Posted: Tue Oct 25, 2005 7:52 am
by gnozal
Update
Changes
- Optional parameter FileName for function PurePOP3_RetrieveMessage()
If FileName is specified, the retrieved data is saved to the file (all the data : the header, the messages and all the attachements).
Posted: Sat Oct 29, 2005 2:50 pm
by tycoon
At first: Thanks for new parameter!!!
Pop3 seems to be a very "non-standard" protocol.
Month ago I tried to write my own pop3-retrival code but it did not work correctly.
It seems that so many diffrent formats are in use, that nobody can write a real good analyse routine to catch the mail from the mail-server.
Here is a little sample code from Eudora (sender) and my local mercury mail server:
Code: Select all
Received: from spooler by loassis.de (Mercury/32 v4.01a); 29 Oct 2005 15:10:25 +0200
X-Envelope-To: <rom>
Return-path: <fl>
Received: from fl (192.168.132.60) by loassis.de (Mercury/32 v4.01a) with ESMTP ID MG00000A;
29 Oct 2005 15:10:20 +0200
Message-Id: <6.1.2.0.0.20051029150955.021df2e8@pop3.loassis.de>
X-Sender: fl@192.168.132.60
X-Mailer: QUALCOMM Windows Eudora Version 6.1.2.0
Date: Sat, 29 Oct 2005 15:10:20 +0200
To: rom
From: Lars <fl>
Subject: Test
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"; format=flowed
134567890
This mail returns no Body-Text... With
PurePOP3_GetMessageTextInMemory() but 134567890 should be correct.
In some cases the last two caracters are missing...
I do not have any suggestions for that pop3-behavior (I think this is not a library problem!!!). I bet: if you write the same mail with outlook or use another mail-server you get the correct result.
With the new (optional) parameter I can try to parse the mail with a separate routine. And the lib is now -the- replacement for getmail.exe.
Hope to see more releases!
If you need more example codes let me know.
Lars
Posted: Mon Oct 31, 2005 9:54 am
by gnozal
tycoon wrote:Pop3 seems to be a very "non-standard" protocol.
Yes, I noticed ...
So I had to build my [beta] library from examples I got from different mailers and pop3 servers. And it's worse when it comes to attachments.
I will continue to work on this library when I have some spare time.
Posted: Tue Nov 01, 2005 11:50 am
by tycoon
So I had to build my [beta] library from examples I got from different mailers and pop3 servers.
...and ther are many mail-servers...

and far more ways sending mails

and much more things to check...
It's a nice lib and I hope you find a way out of this jungle...
I will check the next release!
Lars
Posted: Tue Jan 03, 2006 8:05 am
by fsw
Hi Gnozal,
just testing this library of yours for the first time.
It's pretty easy to use
One thing though:
While using "PurePOP3_GetMessageTextInMemory" I always get 3 chars less than it should be.
Don't know why, because the file PurePOP3-DEBUG-RETR.txt is complete.
PurePOP3_GetMessageSize reports 8 bytes less than the size of PurePOP3-DEBUG-RETR.txt.
Thanks in advance.
fsw
Posted: Tue Jan 03, 2006 8:55 am
by gnozal
fsw wrote:Hi Gnozal,
just testing this library of yours for the first time.
It's pretty easy to use

Thanks.
Please remember it is still beta. POP3 seems to be a very "non-standard" protocol : each server answers differently, and attachements are a nightmare...
fsw wrote:One thing though:
While using "PurePOP3_GetMessageTextInMemory" I always get 3 chars less than it should be.
Don't know why, because the file PurePOP3-DEBUG-RETR.txt is complete.
IIRC, PurePOP3_GetMessageTextInMemory() doesn't copy the last 3 characters '2E0D0A' wich are the 'End of message' marker.
fsw wrote:PurePOP3_GetMessageSize reports 8 bytes less than the size of PurePOP3-DEBUG-RETR.txt.
PurePOP3_GetMessageSize() returns the value obtained with the POP3 'LIST' command.
IIRC, the PurePOP3-DEBUG-RETR.txt file is bigger because of the header (the first line like '+OK 19032 bytes').
Posted: Tue Jan 03, 2006 9:11 am
by netmaestro
I've played with it some and I must say it is two thumbs up. Very easy to use and gets the job done nicely.
One thing I noticed though, is that PurePOP3_GetMessageInfo() reports one attachment for a message that does not have any files attached. I'm guessing the message itself is counted as an attachment? Do we have to subtract 1 from that number to get the number of attached files? btw, thanks for the nice lib!