POP3 User Library
I know I'm doing something wrong here, but I'm not sure what.
Haven't gotten the hang of memory handling, yet. Could someone please help me with this? I'm trying to get the email message and place it in the #Editor_0 gadget.
Code: Select all
Size = POP3_GetMsgSize(GetGadgetState(#Mail_list)+1)
*buffer = AllocateMemory(Size)
; POP3_BufferMsgHeader(GetGadgetState(#Mail_list)+1, *buffer )
*myCallBack = POP3_SetDebugCallBack( @myCallBack() )
POP3_BufferMsgBody( GetGadgetState(#Mail_list)+1, *buffer, *myCallBack )
SetGadgetText(#Editor_0, PeekS(*buffer))
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
@GeoTrail :
Size = POP3_GetMsgSize(GetGadgetState(#Mail_list)+1)
*buffer = AllocateMemory(Size)
; POP3_BufferMsgHeader(GetGadgetState(#Mail_list)+1, *buffer )
*myCallBack = POP3_SetDebugCallBack( @myCallBack() )
POP3_BufferMsgBody( GetGadgetState(#Mail_list)+1, *buffer, *myCallBack )
SetGadgetText(#Editor_0, PeekS(*buffer))
You have 2 problems with your code GeoTrail :
1) - the callback. POP3_SetDebugCallBack() is used purely for debugging purposes (since the library is potentially still under development). This is the wrong callback to specify for POP3_BufferMsgBody().... I'll show you the correct method below.
2) The function POP3_BufferMsgBody() runs asychronously (presuming no initail error is reported by the function and it begins downloading the message)... this means that it returns execution to your program immediately.... the callback function is used by the library to call your application whenever data is received - to signal the download percentage, or an error, or that the message has completed. Your code tries to use the buffer immediately - when in fact the message will not be completed yet.. you need to use the signal from the callback to know that the message is done downloading.
Here is a skeleton example of what you need to do :-
Hope this clear some things up - good luck.... if you still have problems let me know.
BrendanE
Size = POP3_GetMsgSize(GetGadgetState(#Mail_list)+1)
*buffer = AllocateMemory(Size)
; POP3_BufferMsgHeader(GetGadgetState(#Mail_list)+1, *buffer )
*myCallBack = POP3_SetDebugCallBack( @myCallBack() )
POP3_BufferMsgBody( GetGadgetState(#Mail_list)+1, *buffer, *myCallBack )
SetGadgetText(#Editor_0, PeekS(*buffer))
You have 2 problems with your code GeoTrail :
1) - the callback. POP3_SetDebugCallBack() is used purely for debugging purposes (since the library is potentially still under development). This is the wrong callback to specify for POP3_BufferMsgBody().... I'll show you the correct method below.
2) The function POP3_BufferMsgBody() runs asychronously (presuming no initail error is reported by the function and it begins downloading the message)... this means that it returns execution to your program immediately.... the callback function is used by the library to call your application whenever data is received - to signal the download percentage, or an error, or that the message has completed. Your code tries to use the buffer immediately - when in fact the message will not be completed yet.. you need to use the signal from the callback to know that the message is done downloading.
Here is a skeleton example of what you need to do :-
Code: Select all
Global *buffer, inTransaction
*buffer = AllocateMemory( <sufficient memory> )
inTransaction = 0
Procedure messageCallBack(msg, param1, param2)
Select msg
Case #POP3MSG_DOWNLOADCOMPLETE
; Now you can send the message text to your window/text buffer/whatever here...
inTransaction = 0
Case #POP3MSG_ERROR
; check the last error and presume that the connection is lost
inTransaction = 0
Case #POP3MSG_DOWNLOADPROGRESS
; you could do something with the percentage (param1) like update a progress bar or whatever...
EndProcedure
POP3_Init/Connect/Logon to your email account....
..... now to buffer the message body as you wish to...
If inTransaction = 0
If POP3_BufferMsgBody( <msgnumber>, *buffer, @messageCallBack() )
inTransaction = 1
EndIf
EndIf
BrendanE
@Shanarra : Sorry - I missed seeing your question!!
Well it downloads the complete message text / attachments and all in whatever encoded format they are in... you would have to parse those yourself.
Try downloading a message and saving it as .eml - then use Outlook to open it - you'll see what I mean.
Cheers, BrendanE
Well it downloads the complete message text / attachments and all in whatever encoded format they are in... you would have to parse those yourself.
Try downloading a message and saving it as .eml - then use Outlook to open it - you'll see what I mean.
Cheers, BrendanE
in a real world app you must ensure you have allocated enough to contain the entire message (you did this correctly in your previous code using the GetMsgSize() function)... (remembering to either free up the memory - or reallocate the same block every time).
but if you want to work on a test scenario and you know that your message sizes will be small - yes, 1000 will be fine.
but if you want to work on a test scenario and you know that your message sizes will be small - yes, 1000 will be fine.
Hi,
Thanks for this great library. Very usefull.
I just noticed one problem: sometimes (depends on the POP3 server and the message header format) the function POP3_HeaderFrom() returns a blank string for the field From. I think it is because it exists more than one space character between the "From:" and the following text in the message header. Thus a small parser problem.
Thanks for this great library. Very usefull.
I just noticed one problem: sometimes (depends on the POP3 server and the message header format) the function POP3_HeaderFrom() returns a blank string for the field From. I think it is because it exists more than one space character between the "From:" and the following text in the message header. Thus a small parser problem.
Ok I will parse the From field myself meanwhile you fix it in the library.
I use this library for checking new e-mails and for deleting spam messages before downloading to my mailboxes. It works fine. Thanks to PureBasic and bpePOP3.
You could add a function to return the Message_ID (unique identifier for each message) coming from the header. Sometimes it is usefull to know it.
I use this library for checking new e-mails and for deleting spam messages before downloading to my mailboxes. It works fine. Thanks to PureBasic and bpePOP3.
You could add a function to return the Message_ID (unique identifier for each message) coming from the header. Sometimes it is usefull to know it.
PureBasic: one of the best programming tools ever ! PB is light, easy, crossplatform, powerfull, fast, extendable, enjoyable and... tasty 
