PurePOP3 library : POP3 functions

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

PurePOP3 library : POP3 functions

Post by gnozal »

PurePOP3 library V1 *BETA* (Last update : PB5.0x NOV 7th 2012)

Overview
POP3 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

Example

Code: 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
Last edited by gnozal on Tue Aug 18, 2009 11:53 am, edited 30 times in total.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Kiffi
Addict
Addict
Posts: 1353
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

Hallo gnozal,

thank's for your library. Well done! :D

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
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Kiffi wrote:Hallo gnozal,
thank's for your library. Well done! :D
Thanks :D
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 ? :wink: ])...
There is a for-next-loop in the 2nd example file PurePop3_Test2.pb.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
tycoon
New User
New User
Posts: 8
Joined: Sun Oct 23, 2005 1:43 pm

Post 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
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
tycoon
New User
New User
Posts: 8
Joined: Sun Oct 23, 2005 1:43 pm

Post 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
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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).
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
tycoon
New User
New User
Posts: 8
Joined: Sun Oct 23, 2005 1:43 pm

Post 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
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
tycoon
New User
New User
Posts: 8
Joined: Sun Oct 23, 2005 1:43 pm

Post 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... :cry: and far more ways sending mails :x and much more things to check... :twisted:

It's a nice lib and I hope you find a way out of this jungle...

I will check the next release!

Lars
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Hi Gnozal,
just testing this library of yours for the first time.
It's pretty easy to use 8)

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
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

fsw wrote:Hi Gnozal,
just testing this library of yours for the first time.
It's pretty easy to use 8)
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').
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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!
Last edited by netmaestro on Wed Feb 22, 2006 4:27 am, edited 3 times in total.
BERESHEIT
Post Reply