PurePOP3 library : POP3 functions

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

Moderator: gnozal

PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: PurePOP3 library : POP3 functions

Post by PB »

@gnozal: Is there a way to get the entire e-mail into memory? At the moment
if I use PurePOP3_GetMessageTextInMemory() it only gets the body, and I
have to use PurePOP3_GetMessageInfo() to get the rest. It doesn't look like
PurePOP3_RetrieveMessage() gets it all into memory, or can it? Because that
is what I'm after, without having to save it to a file. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
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 »

PB wrote:@gnozal: Is there a way to get the entire e-mail into memory? At the moment
if I use PurePOP3_GetMessageTextInMemory() it only gets the body, and I
have to use PurePOP3_GetMessageInfo() to get the rest. It doesn't look like
PurePOP3_RetrieveMessage() gets all into memory, or can it? Thanks!
PurePOP3_RetrieveMessage() get all the message in memory (as you can see if you use PurePOP3_Trace(#True) : have a look at the PurePOP3-DEBUG* files). I could add a function to retrieve the memory address <PurePOP3_MessageBuffer>. Would this help ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: PurePOP3 library : POP3 functions

Post by PB »

Yes please. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Micro update (both libs)

- added PurePOP3_GetMessageBufferAddress() function [3 lines of code, not tested]
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Thank you gnozal, I can confirm it works great! :D
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
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)

What's new :
- new function PurePOP3_SetRetrieveCallback(*ProcedureAddress) : set the progression callback address for PurePOP3_RetrieveMessage() ; usefull to indicate the progress when a big file is retrieved.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
rob6523
User
User
Posts: 59
Joined: Sat Sep 25, 2004 2:02 pm
Location: Netherlands (Ophemert)
Contact:

Post by rob6523 »

@Gnozal

I have this email check program, but occasionally (most of the time when having > 15 messages) I get a memory access error.
The error occurs in PurePOP3_GetMessageTextInMemory()

Thanks,
Rob.

Code: Select all

Enumeration
  #Window_0
  #Listview_0
EndEnumeration

Global Server.s, Port.l, User.s, Pwd.s, Messages.l, Message.l, MessageCounter.l, TmpString.s, Inhoud.s, Afzender.s, Onderwerp.s, Ontvangen.s
Global nEmailnr.l, aantalgewist.l, StartOutlook.l, Spam.l

Server.s = "pop.hccnet.nl" 
Port.l   = 110 
User.s   = "myName" 
Pwd.s    = "MyPwd"

Declare Open_Window_0()

Procedure GetThem()
  
  If Messages 
    ;Debug "Message(s) total size : " + Str(PurePOP3_GetMessagesTotalSize()) + " bytes" 
    For MessageCounter = 1 To Messages 
      ;Debug "Email " + Str(MessageCounter) + " size : " + Str(PurePOP3_GetMessageSize(MessageCounter)) + " bytes" 
      If PurePOP3_RetrieveMessage(MessageCounter) > 0 

        ;Debug "--------------------------" 
        ;Debug "Email info : " + PurePOP3_GetMessageInfo() 
        ;Debug "Email " + Str(MessageCounter) 
        ;MailInfo.s = ""
        ; het splitsen van de email:
        For k=1 To 3 ; 5 geeft ook aantal attachments en de lengte van de email
          TmpString.s = StringField(PurePOP3_GetMessageInfo(), k, Chr(9))
          Select k
          Case 1  ; delivery date
            Ontvangen.s = Mid(TmpString.s,15,Len(TmpString)-14)
          Case 2  ; subject
            Onderwerp.s = Mid(TmpString.s,9,Len(TmpString)-8)
          Case 3  ; from
            Afzender.s = Mid(TmpString.s,6,Len(TmpString)-5)
          EndSelect  
        Next
        ;Debug "EMAIL " + Str(MessageCounter) + " " + MailInfo.s
        
        If PurePOP3_IsMessageHTML()  
           *Message = PurePOP3_GetMessageTextInMemory(1) 
        Else
           *Message = PurePOP3_GetMessageTextInMemory() 
        EndIf 
        If *Message 
          Inhoud.s = PeekS(*Message)
          Inhoud.s = LCase(Inhoud.s)
          ;Debug "*INHOUD*:" + Inhoud.s
        EndIf 
        
        AddGadgetItem (#Listview_0, -1, "Email "+Str(MessageCounter)+" Van: "  + Afzender.s +"  Onderwerp: " + Onderwerp.s+"  Ontvangen: " + Ontvangen.s)
        If FindString(Afzender,"0451.com",1) Or FindString(Inhoud, "watches", 1) Or FindString(Inhoud, "replica", 1) Or FindString(Inhoud, "poor health", 1) Or FindString(Inhoud, "medication", 1) Or FindString(Inhoud, "stamina", 1) Or FindString(Inhoud, "erecti", 1) Or FindString(Inhoud, "orgasm", 1) Or FindString(Inhoud, "corkpencills", 1) Or FindString(Inhoud, "dating", 1)
          SetGadgetItemState(#Listview_0, MessageCounter-1, #PB_ListIcon_Checked)
        EndIf 
 
      EndIf 

    Next ; MessageCounter 
    
    FreeMemory(*Message)
    
  EndIf 
  
EndProcedure 

Procedure Pop3Stuff()

If PurePOP3_OpenPOP3Connection(Server, Port, User, Pwd) = #PurePOP3_Ok 
  
  Messages = PurePOP3_CountMessages() 
  If Messages = 0
     PurePOP3_ClosePOP3Connection()
     PlaySound_("d:\checkmail\lonely.wav",0,0)
  Else
    PlaySound_("c:\windows\media\notify.wav",0,0)
    Open_Window_0()
    SetGadgetState(9, 1)  ; outlook opstarten aangevinkt
  EndIf 
 
  
Else 
    MessageRequester("PROBLEEM MET DE SERVER","SERVER ONBEREIKBAAR FOUTCODE "+ PurePOP3_GetLastServerMessage()) 
EndIf

EndProcedure 

Procedure DoIt()

    nEmailNr.l   = 0
    aantalgewist = 0
    For I = 0 To CountGadgetItems(#Listview_0) - 1 
      nEmailNr.l = nEmailNr.l + 1
      If GetGadgetItemState(#Listview_0, I) = #PB_ListIcon_Checked
        If PurePOP3_DeleteMessage(nEmailNr)
          aantalgewist = aantalgewist + 1
        Else
          MessageRequester("PROBLEEM","DEZE EMAIL NIET KUNNEN VERWIJDEREN" + Chr(10) + "FOUTMELDING: " + PurePOP3_GetLastServerMessage()  + Chr(10) + "EMAIL "+Str(nEmailNr.l)+" NIET GEWIST: " ,#MB_ICONWARNING)
        EndIf
      EndIf
    Next
    If nEmailNr - aantalgewist > 0
      SetGadgetState(9, 1)
    Else 
      SetGadgetState(9, 0)
    EndIf 
    If aantalgewist > 0
      AddGadgetItem (#Listview_0, -1, Str(aantalgewist)+" email(s) werd(en) verwijderd...")
      ;MessageRequester("Aantal verwijderde emails",Str(aantalgewist)+" email(s) werd(en) verwijderd...",#PB_MessageRequester_Ok)
    EndIf 
    
EndProcedure

 
Procedure Open_Window_0()

;  If OpenWindow(#Window_0, 0, 0,  950,520, "CheckMail voor Eus",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
  If OpenWindow(#Window_0, 0, 0,  950,520, "CheckMail 150806",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
  
    AddKeyboardShortcut(0, #PB_Shortcut_Escape, 99)

    If CreateGadgetList(WindowID(#Window_0))
    
      ListViewGadget(#Listview_0, 20, 20, 900, 370)
  
      ListIconGadget(#Listview_0, 25, 25,  890,360, "Wis   Informatie", 890, #PB_ListIcon_CheckBoxes  | #PB_ListIcon_FullRowSelect | #PB_ListIcon_MultiSelect | #PB_ListIcon_AlwaysShowSelection  | #PB_ListIcon_GridLines)
      ;ListIconGadget(#Listview_0, 25, 25, 470, 490, "Wis   Informatie", 490)
      ;AddGadgetColumn(#Listview_0, 50, "Informatie", 490)

      ;ListIconGadget(#Listview_0, 50, 25, 425, 490, "Informatie", 490)
      
      ;TextGadget(4, 20, 10, 180, 24, "Select a DBF-file:")
      ;TextGadget(5, 240, 60, 180, 24, "Selected:")
      ;TextGadget(6, 240, 90, 180, 24, "")
      
      ButtonGadget(7, 440, 400, 80, 30, "Verwijder", #PB_Button_Default   ) 
      ButtonGadget(8, 440, 440, 80, 30, "Einde"    , #PB_Button_Default   ) 
  
      CheckBoxGadget(9, 440, 470, 200, 30, "OUTLOOK OPSTARTEN")
     
    EndIf
    If CreateStatusBar(0, WindowID(#Window_0))
      StatusBarText(0, 0, "Esc - Einde", 0)
    EndIf

    SetGadgetState(9, 1)
    GetThem() ; Haal emails op...
    
    Repeat
 
      WEvent = WaitWindowEvent()
      Select WEvent
        Case #PB_Event_CloseWindow
          Quit = #True
        Case #PB_Event_Gadget

          Select EventGadget()
            Case 7  ; button VERWIJDEREN
              DoIt()
            Case 8  ; button exit 
              Quit = #True
            Case 9  ; 
          EndSelect
          
        Case #PB_Event_Menu
          EventMenu = EventMenu()
          Select EventMenu
            Case 99
              Quit = #True
            Default
          EndSelect
        Default
 
      EndSelect
 
    Until WEvent = #PB_Event_CloseWindow Or Quit
  EndIf
 
  PurePOP3_ClosePOP3Connection() ; close the connection...
   
  StartOutlook.l    = GetGadgetState(9)
 
  If StartOutlook
     Result = RunProgram("C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE" )
  EndIf
  
EndProcedure

FontResult1 =  LoadFont(#PB_Any,"Arial",14)
SetGadgetFont(#PB_Default,FontResult1)

Pop3Stuff()  ; kijk of er emails zijn...

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

Post by gnozal »

Cannot test it until the weekend, but :
- I have tested the lib with > 100 messages with/without attachments and without problems
- In GetThem(), you should FreeMemory(*Message) at the end of the < If *Message / Endif > block

Code: Select all

        If *Message 
          Inhoud.s = PeekS(*Message) 
          Inhoud.s = LCase(Inhoud.s) 
          ;Debug "*INHOUD*:" + Inhoud.s 
          FreeMemory(*Message) ; <---------------
        EndIf 
- if this does not help, you could activate the trace mode [PurePOP3_Trace(#True)] and have a look at the PurePOP3-DEBUG*.txt files to help debugging : you can see all the communications and eventually where the crash occurs.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
rob6523
User
User
Posts: 59
Joined: Sat Sep 25, 2004 2:02 pm
Location: Netherlands (Ophemert)
Contact:

Post by rob6523 »

Thank you Gnozal!

I will try what you suggest and report it back.


Rob.
rob6523
User
User
Posts: 59
Joined: Sat Sep 25, 2004 2:02 pm
Location: Netherlands (Ophemert)
Contact:

Post by rob6523 »

@Gnozal,

Your solution worked fine, Thanks again!

Rob.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: PurePOP3 library : POP3 functions

Post by PB »

Hi gnozal, I just noticed that if I turn on "Create threadsafe executable" for
PureBasic v4.00 then I get this error when using your lib:

Code: Select all

---------------------------
PureBasic - Linker error
---------------------------
POLINK: error: Unresolved external symbol '_PB_StringBasePosition'. 
POLINK: fatal error: 1 unresolved external(s). 
---------------------------
OK   
---------------------------
If I remove your lib, or turn off threadsafe, then my app compiles fine.
Don't know if it's a PureBasic bug or something with your lib? I'm using
the latest version of the lib: installer exe of size 88.1 KB (90,275 bytes).
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
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 »

PB wrote:Hi gnozal, I just noticed that if I turn on "Create threadsafe executable" for
PureBasic v4.00 then I get this error when using your lib:
I assume you use the PB IDE.
Did you enable the UserLibThreadSafe subsystem ?
The library exists in two versions :
- the standard version, located in %Purebasic%\PureLibraries\UserLibraries\ ;
- the thread-safe version, located in %Purebasic%\SubSystems\UserLibThreadSafe\PureLibraries\ .
In order to use this library in thread-safe mode (compiler option /THREAD), you have to enable the
subsystem 'UserLibThreadSafe' in the PB IDE, or add '/SUBSYSTEM UserLibThreadSafe' to the
PBCompiler arguments. In jaPBe, do nothing : it will automatically enable the 'UserLibThreadSafe'
subsystem to use the threadsafe versions of the installed userlibraries.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: PurePOP3 library : POP3 functions

Post by PB »

> In order to use this library in thread-safe mode (compiler option /THREAD),
> you have to enable the subsystem 'UserLibThreadSafe' in the PB IDE

I've never heard of this before, and can't find it in the PB IDE options anywhere.
Where do I find it? I checked the entire "Compiler Options" but there's nothing
there that says UserLibThreadSafe at all.

Edit: Never mind, I just realised to put "UserLibThreadSafe" (no quotes) in
the "Library subsystem" field and it now compiles. Newbies will have fun! :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
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 »

PB wrote:> In order to use this library in thread-safe mode (compiler option /THREAD),
> you have to enable the subsystem 'UserLibThreadSafe' in the PB IDE

I've never heard of this before, and can't find it in the PB IDE options anywhere.
Where do I find it? I checked the entire "Compiler Options" but there's nothing
there that says UserLibThreadSafe at all.
The %Purebasic%\SubSystems\UserLibThreadSafe\PureLibraries\ directory is created by my library installer. The library in this directory is compiled with my custom Tailbite version with option /THRD. This is the way I use to make thread safe libs [ http://www.purebasic.fr/english/viewtop ... &start=392 ].
It should work (not tested for PurePOP3, but works for PureZIP) with thread safe executables.
You have to enable the subsystem just like you would do it for NT4 or OpenGL. I don't use the PB IDE, sorry.
An easier way to test : replace PurePOP3 from %Purebasic%\PureLibraries\UserLibraries\ with PurePOP3 from %Purebasic%\SubSystems\UserLibThreadSafe\PureLibraries\ and compile in thread safe mode.
PB wrote:Edit: Never mind, I just realised to put "UserLibThreadSafe" (no quotes) in the "Library subsystem" field and it now compiles. Newbies will have fun!
In jaPBe, it's automatic !
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: PurePOP3 library : POP3 functions

Post by PB »

> An easier way to test [snip]

Yep, that works better (don't need to specify a subsystem anymore). Thanks!
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply