PurePOP3 library : POP3 functions

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

Moderator: gnozal

User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Very *very* nice lib :)

Is there anyway you could add a function to grab the complete header text (rather than having to examine the memory buffer).

eg:

Code: Select all


PurePOP3_GetMessageHeader() 

Get header from retrieved message.

Must be used after PurePOP3_RetrieveMessage().

Returned values :
- String like 'Return-Path: <xxx@xxx.com><9>X-Original-To: xx@xxx.com<9>Delivered-To: xxx@xxx-xxx.xxx.com<9>Organization: xxx<9>Content-Type: text/plain; charset=us-ascii'
  where <9> is TAB (ASCII code 9)
- Empty string : error


Example

If PurePOP3_RetrieveMessage(MessageNumber.l) > 0
      Debug "Header info : " + PurePOP3_GetMessageHeader()
EndIf
Being able to parse the header easily would be great for checking against spam lists, etc
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

DoubleDutch wrote:Very *very* nice lib :)

Is there anyway you could add a function to grab the complete header text (rather than having to examine the memory buffer).
I will try to remember this for the next version :wink:
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Thats great, thanks - having header data would have endless uses. :)

I had some really strange problems with the libs using the threaded versions.
It seemed to be something to do with the SMTP library and then sometimes the pop3 library refusing to get a connection until you reran the program.

I think however I was wrong and that it may actually be nothing to do with your libs, but actually something to do with PureBasic itself and some kind of issue with linked lists being accessed (even if you mutex and reload the index) with different threads. Someone (in the know) needs to do a write-up on exactly how strings work in a multithreaded purebasic program - and what exactly are the rules... Fred?

Anyhow - I think I've fixed the problem by using a database to store the data in - rather than linked lists. The major benefit is that all email 'transactions' are now 'backup up' in a an mdb. :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

If you include the top procedure (even if its not called) it will crash the main routine with an invalid memory error after a couple of passes.

Code: Select all

Procedure SmtpErrorText(code)
	error$=""
	Select code
		Case	#PureSMTP_FileError
			error$="SMTP error => File error"
		Case	#PureSMTP_NoConnection
			error$="SMTP error => No connection"
		Case	#PureSMTP_BadResponse
			error$="SMTP error => Bad response ("+PureSMTP_GetLastServerMessage()+")"
		Case	#PureSMTP_MemoryAllocationProblem
			error$="SMTP error => Memory allocation problem"
		Case	#PureSMTP_AuthentificationFailed
			error$="SMTP error => Authentication failed"
		Case	#PureSMTP_ServerTimeOut
			error$="SMTP error => Server timeout"
		Default
			error$="SMTP error => Unknown error code:"+Str(code)
	EndSelect
EndProcedure

For loop=1 To 100
Server.s = "mail.domain.com"
Port.l = 110
User.s = "user@domain.com"
Pwd.s = "pass"
;
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 "<start>"
        Debug PeekS(*Message)
        Debug "<end>"
        FreeMemory(*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
Next
Very strange?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

It looks like if you include any command from puresmtp and purepop3 within the same program, they mess each other up - if you use more than one pass.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

DoubleDutch wrote:If you include the top procedure (even if its not called) it will crash the main routine with an invalid memory error after a couple of passes.
Very strange?
Very !
Can't reproduce it though.
DoubleDutch wrote:It looks like if you include any command from puresmtp and purepop3 within the same program, they mess each other up - if you use more than one pass.
Do you have some code ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

After a reboot - the problem has gone away!

Weird...

Thanks anyhow.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I've done some tests with attachments and PureSmtp and PurePop3 both seem to append extra an extra $0D0A to the end of the file (each adds 2 bytes).

The file was a text file consisting of 'blah blah blah!' (15 bytes, no CR)
PureSMTP made it 17 bytes long (verified with TheBat and Outlook) and PurePop3 made it 19 bytes long (verified with a direct PurePOP3_SaveAttachementsToFile command)

Also, during the course of the 'testing', I think I may have found an attachment type that is not compatible (from TheBat), here is a dump of the raw message:

<Dump><n°0>
+OK 1213 octets follow.
Return-Path: <user@domain.com>
X-Original-To: user@domain.com
Delivered-To: user@domain.com
Received: from [192.168.0.11] (xxxx.dsl.xx.co.uk [xxx])
by spunkyxxxxxxxxamhost.com (Postfix) with ESMTP id 37444433371DC
for <user@domain.com>; Tue, 16 Jan 2007 13:44:49 -0800 (PST)
Date: Tue, 16 Jan 2007 21:44:56 +0000
From: User Test at ezxretary <user@domain.com>
X-Mailer: The Bat! (v3.95.6) Professional
X-Priority: 3 (Normal)
Message-ID: <30102445813.200745346214456@exxxxy.com>
To: user@domain.com
Subject: test
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----------2016923D21EACDB9"

------------2016923D21EACDB9
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello ,



--
Best regards,
User mailto:user@domain.com
------------2016923D21EACDB9
Content-Type: text/plain;
name="this is a test.txt"
Content-transfer-encoding: base64
Content-Disposition: attachment;
filename="this is a test.txt"

YmxhaCBibGFoIGJsYWgh
------------2016923D21EACDB9--

.
</Dump>


I've changed any identifying marks to stop my email from being spammed! ;)

When PurePop3 saves the attachment, it ends up as:

YmxhaCBibGFoIGJsYWgh

It should be:

blah blah blah!

Maybe its the extra two '--' that TheBat puts at the end of an attachment boundary string?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

DoubleDutch wrote:I've done some tests with attachments and PureSmtp and PurePop3 both seem to append extra an extra $0D0A to the end of the file (each adds 2 bytes).
I know :wink:
Only for plain text.
Maybe I will fix it.
DoubleDutch wrote:Also, during the course of the 'testing', I think I may have found an attachment type that is not compatible (from TheBat)
It's because TheBat writes 'Content-transfer-encoding', and PurePOP3 is looking for 'Content-Transfer-Encoding:' (but TheBat writes 'Content-Disposition:' and not 'Content-disposition:') ...
I will have to ignore the case ...
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 »

Update (Both libs)

- should fix the 'Content-transfer-encoding' case problem
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Thanks for the quick fix. :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Frontier
User
User
Posts: 74
Joined: Thu Dec 22, 2005 2:43 pm
Location: Chios, Greece
Contact:

Post by Frontier »

Hi gnozal, let me be another one thanking you for your great lib :)

Any chance to provide us with a version that works with Unicode programs?

Thank you very much in advance.
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

I just tried this and it works; however, I noticed the Debug information (from the example in the Help file for this lib) states I have 41 Emails when I only had one (a test one I had just typed up).

Ideas?

TIA
Intrigued - Registered PureBasic, lifetime updates user
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Frontier wrote:Any chance to provide us with a version that works with Unicode programs?
It was a big work to get a working unicode PureSMTP or PureZIP. I will try to do it when I have time and some POP3 servers to test.
Intrigued wrote: noticed the Debug information (from the example in the Help file for this lib) states I have 41 Emails when I only had one (a test one I had just typed up)
The PurePOP3_CountMessages() simply sends "STAT" + #CRLF to the POP3 server and parses the answer (wich is like '+OK NbMessages TotalSize' -> +OK 48 447343).
Maybe you could get some more information on this issue by activating the trace mode and looking in the log files to see what the server answers ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Frontier
User
User
Posts: 74
Joined: Thu Dec 22, 2005 2:43 pm
Location: Chios, Greece
Contact:

Post by Frontier »

gnozal wrote:
Frontier wrote:Any chance to provide us with a version that works with Unicode programs?
It was a big work to get a working unicode PureSMTP or PureZIP. I will try to do it when I have time and some POP3 servers to test.

Anything I can do to help you? I am proficient in C/C++ and Unicode, as I program mainly for Windows CE Devices.
Post Reply