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:

Re: PurePOP3 library : POP3 functions

Post by gnozal »

rdority wrote:Well unfortunately my entire experience so far with PB has rested on the shoulders of PurePop3. My little app which I spent months on worked fairly well in Xp but now I can't even use it in Windows 7.
Windows Se7en 64 bits can run 32 bit apps.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
rdority
User
User
Posts: 34
Joined: Mon Mar 30, 2009 10:46 pm
Location: Vancouver, BC

Re: PurePOP3 library : POP3 functions

Post by rdority »

It's true there is an Xp mode that can be applied on a task by task basis in Windows 7 however that didn't make the app start working again. So much for paying the extra cash for W7 professional. ;)
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PurePOP3 library : POP3 functions

Post by gnozal »

Update (PB4.5x version)

- Fixed a bug with some multipart messages.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

PurePOP3 crash

Post by C64 »

One of my apps crashed with an Illegal Operation error today, so I re-ran it with the purifier on and it says the FreeMemory() command in this snippet is using an invalid memory ID. Am I using the following snippet properly? If I delete the FreeMemory() command then my app runs fine and no crash happens, but I don't think that's a good idea to do.

Code: Select all

body$=""
html=PurePOP3_IsMessageHTML()
b=PurePOP3_GetMessageTextInMemory(html)
If b
  body$=PeekS(b)
  FreeMemory(b); Purifier hates this line.
EndIf
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PurePOP3 crash

Post by IdeasVacuum »

Hi

This post should be on gnozal's section. The function requires a pointer to a string in memory, as per the example in the PurePop3 help, which also states that it must be used after a PurePOP3_RetrieveMessage() call:

Get text from retrieved message.
If HTML is #True, the retrieved text is "text/html" (default is "text/plain")

Must be used after PurePOP3_RetrieveMessage().

Returned values :
- > 0 : memory pointer to message text [ASCIIZ]
- 0 : error

Code: Select all

If PurePOP3_RetrieveMessage(MessageNumber.l) > 0
      *Message = PurePOP3_GetMessageTextInMemory()
      If *Message
        Debug "Message text : " + PeekS(*Message)
        FreeMemory(*Message)
      EndIf
EndIf


IdeasVacuum
If it sounds simple, you have not grasped the complexity.
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

Re: PurePOP3 crash

Post by C64 »

IdeasVacuum wrote:This post should be on gnozal's section
Sorry! Perhaps a forum moderator could move it for me, please.
IdeasVacuum wrote:The function requires a pointer to a string in memory, as per the example in the PurePop3 help, which also states that it must be used after a PurePOP3_RetrieveMessage() call
I didn't post my full code to save time, but the code sample I posted is just part of my source. I have already retrieved the message before the code is executed. My code shows that b<>0, which means the mail body HAS been read correctly, and indeed my program shows me the body correctly (stored in body$), but then trying to free it is causing a invalid memory access error. It shouldn't if the body has been read, correct?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: PurePOP3 crash

Post by ts-soft »

You have to remove FreeMemory, FreeMemory is only for allocated Memory with PB, not for
pointer to Strings.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

Re: PurePOP3 crash

Post by C64 »

ts-soft wrote:You have to remove FreeMemory, FreeMemory is only for allocated Memory with PB, not for
pointer to Strings.
But the help file says to use FreeMemory(), just as IdeasVacuum posted. How else can I free it?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PurePOP3 crash

Post by gnozal »

ts-soft wrote:You have to remove FreeMemory, FreeMemory is only for allocated Memory with PB, not for
pointer to Strings.
PurePOP3_GetMessageTextInMemory() returns a pointer to allocated memory with AllocateMemory().

Now, although I never experienced a problem myself, maybe there is an issue because the memory is allocated in the library, and FreeMemory() is executed in the main code.
I may have to add a function to free the memory from the library.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: PurePOP3 library : POP3 functions

Post by ts-soft »

This problem comes with to small allocated memory! Your allocations miss the place for the nullbyte(s) for strings?

Code: Select all

Define.s Text = "Hello"

Define *mem = AllocateMemory(Len(Text)); to small!

PokeS(*mem, Text)

FreeMemory(*mem)

Test this with and without purifier :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PurePOP3 library : POP3 functions

Post by gnozal »

ts-soft wrote:This problem comes with to small allocated memory! Your allocations miss the place for the nullbyte(s) for strings?
The library code allocates extra space for the null bytes.
And the library does not trigger any error with the purifier.
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:

Re: PurePOP3 library : POP3 functions

Post by gnozal »

I have updated the library (PB 4.50 version).

I have added a new function PurePOP3_FreeMessagePointer() to free the memory allocated by PurePOP3_GetMessageTextInMemory().

Code: Select all

If PurePOP3_RetrieveMessage(MessageNumber.l) > 0
         *Message = PurePOP3_GetMessageTextInMemory()
         If *Message
            Debug "Message text : " + PeekS(*Message)
            PurePOP3_FreeMessagePointer(*Message)
         EndIf
EndIf 
Please test.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

Re: PurePOP3 library : POP3 functions

Post by C64 »

Thank you, no more crash when using PurePOP3_FreeMessagePointer() now. :D
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

PurePOP3_IsMessageHTML() hangs

Post by C64 »

I've got an email with a 35 KB image attachment, and when I use the PurePOP3_IsMessageHTML() command, it just hangs. I know it hangs because the following code just prints "start" to the debug output window and never the "finish", and my program just sits there without continuing, even after 5 minutes. I can post the trace output if you like, but would rather not for privacy reasons. Maybe you can just look at the command first and see if something obvious was missed?

Code: Select all

Debug "start"
h=PurePOP3_IsMessageHTML()
Debug "finish"
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PurePOP3_IsMessageHTML() hangs

Post by gnozal »

C64 wrote:I've got an email with a 35 KB image attachment, and when I use the PurePOP3_IsMessageHTML() command, it just hangs. I know it hangs because the following code just prints "start" to the debug output window and never the "finish", and my program just sits there without continuing, even after 5 minutes. I can post the trace output if you like, but would rather not for privacy reasons. Maybe you can just look at the command first and see if something obvious was missed?
Without the traces, I can do zip.
There is nothing obvious with "multipart/related", "multipart/alternative", etc... ; every mail client sends the stuff differently.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Post Reply