Find an email in POP

Just starting out? Need help? Post your questions and find answers here.
Julien
User
User
Posts: 17
Joined: Fri Apr 25, 2003 6:08 pm
Location: France

Find an email in POP

Post by Julien »

Hi
I want will seek an email on a pop waiter. But the email is illegible. There is no working.
Where is the problem in this code :

Thanks

Code: Select all


InitNetwork()

OpenConsole()

#MODE_Authorization = 1
#MODE_Transaction   = 2

Login$        = "pseudo"
Password$     = "pass"
POP_Provider$ = "pop.serveur.fr"

EOL$ = Chr(13)+Chr(10)

Pop3Mode = #MODE_AUTHORIZATION

NetWorkID=OpenNetworkConnection(POP_Provider$, 110)
If NetWorkID<>0
  PrintN("Connected..")
  
  AllocateMemory(0, 2000, 0)
  
  Repeat
    
    NEvent = NetworkClientEvent(NetWorkID)
    
    If NEvent
      ReadLength = ReceiveNetworkData(NetWorkID, UseMemory(0), 2000)
      
      If (ReadLength) > 2
        PokeB(UseMemory(0)+ReadLength-2, 0) ; Remove the CRLF directly
        Line$ = PeekS(UseMemory(0))
        PrintN(Line$)
        
        Gosub ParseLine
      Else
        PrintN("Bad received packet")
      EndIf
    Else
      Delay(20)
    EndIf
    
  ForEver
  
Else
  PrintN("Impossible to connect to the pop3 the server")
EndIf

MessageRequester("Info", "Program finished correctly.", 0)

End

ParseLine:

If Len(Line$) >= 3
  
  If Left(Line$, 3) = "+OK"
    
    Select Pop3Mode
        
      Case #MODE_Authorization
        Gosub Authorization
        
      Case #MODE_Transaction
        Gosub Transaction
        
      Default
        ; PrintN("Error: no such case 1")
        
    EndSelect
    
  Else
    ;  PrintN("Error... Deconnect now ! (-ERR)");
  EndIf
Else
  ; PrintN("Error... Too short packet");
EndIf

Return


; Authorization
;the init phase where the user must login..
;
;

Authorization:

Select AuthStep
    
  Case 0
    a$ = "USER "+Login$+EOL$
    SendNetworkData(NetWorkID, a$, Len(a$))
    
  Case 1
    a$ = "PASS "+Password$+EOL$
    SendNetworkData(NetWorkID, a$, Len(a$))
    Pop3Mode = #MODE_Transaction
    
    ;Case 2
    ;  a$ = "QUIT"+EOL$
    ;  SendNetworkData(0, a$, Len(a$))
    ;  Pop3Mode = #MODE_Transaction
    
EndSelect

AuthStep+1
Return




Transaction:

Select TransStep
    Debug TransStep
  Case 0
    a$ = "STAT"+EOL$
    SendNetworkData(NetWorkID, a$, Len(a$))
    
  Case 1
    a$ = "LIST "+EOL$
    SendNetworkData(NetWorkID, a$, Len(a$))
    
  Case 2
    PrintN("Type msg# to retreive:")
    Nb$ = Input()
    PrintN(Str(1100))
    PrintN("Retrieving...")
    ; Nb$ = "1"
    a$ = "RETR "+Nb$+" 0"+EOL$

    SendNetworkData(NetWorkID, a$, Len(a$))
    TransStep-1
    
    If CreateFile(0, "MAIL.txt")
      FirstTime = 1
      Size = 1
      Repeat
        NEvent = NetworkClientEvent(NetWorkID)
        
        If NEvent
          ReadLength = ReceiveNetworkData(NetWorkID, UseMemory(0), 1999)
          
          PokeB(UseMemory(0)+ReadLength, 0)
          
          a$ = PeekS(UseMemory(0))
          PrintN(a$)
          If FirstTime
            Position = FindString(a$, " ", 5)
            Size$ = Mid(a$, 5, Position-5)
            PrintN(Size$)
            Size = Val(Size$)
            FirstTime = 0
            WriteString(a$)
            Size-ReadLength
          Else
            WriteString(a$)
            Size-ReadLength
          EndIf
          
        Else
          Delay(20)
        EndIf
        
      Until Size <= 0 ; And FirstTime = 0
      CloseFile(0)
      
      PrintN("Mail transfer finished")
    Else
      PrintN("Can't open the file...")
    EndIf
EndSelect

TransStep+1
Return

Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Hi Julien But it dose work
You say that
There is no working
So i take it you ment that it dose not work ??
In case you did.

What i did to test it.

Write my owen login,password and pop3mail ofcouse
Mailed myself a mail (with my standart mail progy) of course

Now when you run it say taht i got 1 mail

Code: Select all

Connected..
+OK InterMail POP3 server ready.
+OK please send PASS command
+OK xxxxxxxxxxx is welcome here
+OK 1 1019
+OK 1 messages
1 1019
Type msg# to retreive:
So i type (1) and Enter
That's it

oh. to save to a file (got confussed by all this gosub and stuff, so did this)
You have to do something about that, cuz next you do something the file will be overwriten.

Code: Select all

InitNetwork() 

OpenConsole() 

#MODE_Authorization = 1 
#MODE_Transaction   = 2 

Login$        = "MyLogin" 
Password$     = "mypassword" 
POP_Provider$ = "pop3.mail.dk" ;<- my pop3

EOL$ = Chr(13)+Chr(10) 

Pop3Mode = #MODE_AUTHORIZATION 

NetWorkID=OpenNetworkConnection(POP_Provider$, 110) 
If NetWorkID<>0 
  PrintN("Connected..") 
  
  AllocateMemory(0, 2000, 0) 
  
  Repeat 
    
    NEvent = NetworkClientEvent(NetWorkID) 
    
    If NEvent 
      ReadLength = ReceiveNetworkData(NetWorkID, UseMemory(0), 2000) 
      
      If (ReadLength) > 2 
        PokeB(UseMemory(0)+ReadLength-2, 0) ; Remove the CRLF directly 
        Line$ = PeekS(UseMemory(0)) 
 ; -------------------------------
 ; my changes
 ; -------------------------------    
        Tuborg$=Tuborg$+Line$ ;<< - Inserted for file
        CreateFile(2, "Tuborg-MAIL2.txt") ;<<-some filename
        WriteStringN(Tuborg$) ;<<- 
        CloseFile(2) ;<< close
; -------------------------------
 ; my changes
 ; -------------------------------  

        PrintN(Line$) 
        
        Gosub ParseLine 
      Else 
        PrintN("Bad received packet") 
      EndIf 
    Else 
      Delay(20) 
    EndIf 
    
  ForEver 
  
Else 
  PrintN("Impossible to connect to the pop3 the server") 
EndIf 

MessageRequester("Info", "Program finished correctly.", 0) 

End 

ParseLine: 

If Len(Line$) >= 3 
  
  If Left(Line$, 3) = "+OK" 
    
    Select Pop3Mode 
        
      Case #MODE_Authorization 
        Gosub Authorization 
        
      Case #MODE_Transaction 
        Gosub Transaction 
        
      Default 
        ; PrintN("Error: no such case 1") 
        
    EndSelect 
    
  Else 
    ;  PrintN("Error... Deconnect now ! (-ERR)"); 
  EndIf 
Else 
  ; PrintN("Error... Too short packet"); 
EndIf 

Return 


; Authorization 
;the init phase where the user must login.. 
; 
; 

Authorization: 

Select AuthStep 
    
  Case 0 
    a$ = "USER "+Login$+EOL$ 
    SendNetworkData(NetWorkID, a$, Len(a$)) 
    
  Case 1 
    a$ = "PASS "+Password$+EOL$ 
    SendNetworkData(NetWorkID, a$, Len(a$)) 
    Pop3Mode = #MODE_Transaction 
    
    ;Case 2 
    ;  a$ = "QUIT"+EOL$ 
    ;  SendNetworkData(0, a$, Len(a$)) 
    ;  Pop3Mode = #MODE_Transaction 
    
EndSelect 

AuthStep+1 
Return 




Transaction:
CreateFile(2, "NewMAIL.txt") 
   WriteStringN(Tuborg$)
    CloseFile(2) 
 

Select TransStep 
    Debug TransStep 
  Case 0 
    a$ = "STAT"+EOL$ 
    SendNetworkData(NetWorkID, a$, Len(a$)) 
    
  Case 1 
    a$ = "LIST "+EOL$ 
    SendNetworkData(NetWorkID, a$, Len(a$)) 
    
  Case 2 
    PrintN("Type msg# to retreive:") 
    Nb$ = Input() 
    PrintN(Str(1100)) 
    PrintN("Retrieving...") 
    ; Nb$ = "1" 
    a$ = "RETR "+Nb$+" 0"+EOL$ 

    SendNetworkData(NetWorkID, a$, Len(a$)) 
    TransStep-1 
    
    If CreateFile(0, "MAIL.txt") 
      FirstTime = 1 
      Size = 1 
      Repeat 
        NEvent = NetworkClientEvent(NetWorkID) 
        
        If NEvent 
          ReadLength = ReceiveNetworkData(NetWorkID, UseMemory(0), 1999) 
          
          PokeB(UseMemory(0)+ReadLength, 0) 
          
          a$ = PeekS(UseMemory(0)) 
          PrintN(a$) 
          If FirstTime 
            Position = FindString(a$, " ", 5) 
            Size$ = Mid(a$, 5, Position-5) 
            PrintN(Size$) 
            Size = Val(Size$) 
            FirstTime = 0 
            WriteString(a$) 
            Size-ReadLength 
          Else 
            WriteString(a$) 
            Size-ReadLength 
          EndIf 
          
        Else 
          Delay(20) 
        EndIf 
        
      Until Size <= 0 ; And FirstTime = 0 
      CloseFile(0) 
      
      PrintN("Mail transfer finished") 
    Else 
      PrintN("Can't open the file...") 
    EndIf 
EndSelect 

TransStep+1 
Return 
Bedst regards
Henrik.[/quote]
Post Reply