Atomic mailer help needed

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

I need to retrieve the subject and date stamp ONLY of any mail on my
POP3 server. The last version of the Atomic mailer I had is very old,
and only lets you retrieve the entire mail, not just the subject/date.

Here it is... does anyone know how to modify it to achieve my goal?
It's probaby really simple, but I just can't work it out right now.

Code: Select all

InitNetwork()

OpenConsole()

#MODE_Authorization = 1
#MODE_Transaction   = 2

Login$        = "login"
Password$     = "password"
POP_Provider$ = "pop.mailserver.com.au"

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

Pop3Mode = #MODE_AUTHORIZATION

NetWorkID=OpenNetworkConnection(POP_Provider$, 110)
If NetWorkID0
  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
    
  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$+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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by DemonHell.
Originally posted by PB

I need to retrieve the subject and date stamp ONLY of any mail on my
POP3 server. The last version of the Atomic mailer I had is very old,
and only lets you retrieve the entire mail, not just the subject/date.
Check out RFC 1725 ( The POP3 specification)

I was doing some similar stuff with POP3 and PB just last night..spooky huh? ( Not working on a spam filter by any chance? )

From looking briefly at the code,
replace the
a$ = "RETR "+Nb$+EOL$
with
a$ = "TOP "+Nb$+" 0"+EOL$

This will download only the header of the message.
From there, you`ll have to do a simple(ish) search on the lines.
Something to be aware of.. headers are multi line, each line separated with the CR-LF pair, and sometimes split lines are indented with the Tab chr.

Hope this helps.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> ( Not working on a spam filter by any chance? )

No -- just something else where I need to see subject/date.
BTW, your tip didn't help (sorry). I'll have to read up on
the POP specs more properly.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by DemonHell.

@PB
Wierd, did you get an error message from the POP3 server??
The TOP command is optional in the POP3 spec..if that doesn`t work, you`re only choice is to download the entire mail and extract date and subject from that.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Wierd, did you get an error message from the POP3 server??

Oops, my mistake (sorry!). Yes, it worked fine. Thanks! :)
Post Reply