Sign in to follow this  
Followers 0
=sinister=

Email Count

3 posts in this topic

#1 ·  Posted (edited)

I use this UDF to get the number of messages for a pop3 email:

Func _POP3MailCount($Server, $Username, $Password)
    Global $Recv, $Str, $Count, $Check, $Str1, $Error, $RecPoint, $Bit, $MCount
    TCPStartup()
    Global $Socket = TCPConnect(TCPNameToIP($Server), 110)
    If $Socket = -1 Then
        SetError(1)
        Return
    EndIf
    Do
        $Recv = TCPRecv($Socket, 512)
    Until $Recv <> ""
    $Recv = ""
    TCPSend($Socket, "user " & $Username & @CRLF)
    Do
        $Recv = TCPRecv($Socket, 512)
    Until $Recv <> ""
    $Recv = ""
    TCPSend($Socket, "pass " & $Password & @CRLF)
    Do
        $Recv = TCPRecv($Socket, 512)
    Until $Recv <> ""
    $Error = StringInStr($Recv, "-ERR")
    If $Error > 0 Then
        SetError(5)
        TCPSend($Socket, 'quit' & @CRLF)
        TCPCloseSocket($Socket)
        $Error = $Error + 1
        Return
    EndIf
    $Recv = ""
    TCPSend($Socket, 'list' & @CRLF)
    Do
        $Recv = TCPRecv($Socket, 10240)
        $RecPoint = StringInStr($Recv, ".")
        Sleep(1000)
    Until $RecPoint > 0
    $Str = StringSplit($Recv, @LF)
    $Str1 = StringSplit($Str[1], " ")
    $Check = StringIsDigit($Str1[1])
    If $Check = 1 Then
        $Count = 0
        $Bit = 0
    Else
        $Count = 1
        $Bit = 1
    EndIf
    Do
        $Count = $Count + 1
        $Str1 = StringSplit($Str[$Count], " ")
        $Check = StringIsDigit($Str1[1])
    Until $Check = 0
    If $Bit = 1 Then
        $MCount = $Count - 2
    Else
        $MCount = $Count - 1
    EndIf
    
    TCPSend($Socket, 'quit' & @CRLF)
    TCPCloseSocket($Socket)

    Return $MCount
EndFunc ;==>_POP3MailCount

I'm trying to get it so it will download the latest email received, but I don't know how to receive a email, how would I retreive the actual email?

Edited by big_daddy

Share this post


Link to post
Share on other sites



anyone....

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Well, you don't get as much help here as you used to...

What I want is for my script to Count my mail, but then retrieve that message number. This UDF works for counting:

Func _mailchk($popsrv, $srvuser, $srvpass)
    
    Global $mail, $i, $disp, $recv, $str, $count, $check, $str1, $err, $recpoint, $bit, $mcount, $recpoint1, $error
    
    
    TCPStartup ()
    
    Global $socket = TCPConnect (TCPNameToIP ($popsrv), 110)
    If $socket = -1 Then
        MsgBox(8240, 'Error', 'Error; could not connect to server ' & $popsrv, 5)
        Return
    EndIf
    
    Do
        $recv = TCPRecv ($socket, 512)
    Until $recv <> ""
    $recv = ""
    
    TCPSend ($socket, "user " & $srvuser & @CRLF)
    
    Do
        $recv = TCPRecv ($socket, 512)
    Until $recv <> ""
    $recv = ""
    
    
    TCPSend ($socket, "pass " & $srvpass & @CRLF)
    
    Do
        $recv = TCPRecv ($socket, 512)
    Until $recv <> ""
    $err = StringInStr($recv, "-ERR")
    If $err > 0 Then
        MsgBox(4112, "authentication failed", "Invalid User Name or Password for " & $popsrv, 8)
        TCPSend ($socket, 'quit' & @CRLF)
        TCPCloseSocket ($socket)
        $error = $error + 1
        Return
    EndIf
    $recv = ""
    
    
    TCPSend ($socket, 'list' & @CRLF)
    Do
        $recv = TCPRecv ($socket, 10240)
        $recpoint = StringInStr($recv, ".")
        Sleep(1000)
    Until $recpoint > 0
    
    $str = StringSplit($recv, @LF)
    $str1 = StringSplit($str[1], " ")
    $check = StringIsDigit($str1[1])
    If $check = 1 Then
        $count = 0
        $bit = 0
    Else
        $count = 1
        $bit = 1
    EndIf
    
    Do
        $count = $count + 1
        $str1 = StringSplit($str[$count], " ")
        $check = StringIsDigit($str1[1])
    Until $check = 0
    If $bit = 1 Then
        $mcount = $count - 2
    Else
        $mcount = $count - 1
    EndIf
    
    TCPSend ($socket, 'quit' & @CRLF)
    TCPCloseSocket ($socket)
    
    Return $mcount
EndFunc

but when I use the Pop3Retr() function, it won't work!! So then I tried:

Func _Pop3List($msg = -1)
    If $pop3_IsAuth = 1 Then
        Local $ret
        Local $AddMsg = ""
        
        If $msg <> - 1 Then
            $AddMsg = " " & $msg
        EndIf
        
; Send List
        $ret = TCPSend ($pop3_socket, "LIST" & $AddMsg & @CRLF)
        If @error Then
            SetError($pop3_error_list_refused)
            Return -1
        EndIf
        $ret = _WaitTcpResponse()
        If @error Then
            SetError($pop3_error_no_TCP_response)
            Return -1
        EndIf
        While $msg = -1 And Not StringRegExp($ret, "\r\n\.\r\n")
            $ret = $ret & _WaitTcpResponse()
            If @error Then
                SetError($pop3_error_no_TCP_response)
                Return -1
            EndIf
        WEnd
        
; Stripping useless infos for complete listing
        $ret = StringSplit(StringStripCR($ret), @LF)
        If $msg = -1 Then
            _ArrayDelete($ret, $ret[0])
            _ArrayDelete($ret, $ret[0] - 1)
            _ArrayDelete($ret, 1)
            $ret[0] = $ret[0] - 3
        Else
            _ArrayDelete($ret, $ret[0])
            $ret[0] = $ret[0] - 1
            $ret[1] = StringReplace($ret[1], "+OK ", "")
        EndIf
        Return $ret
    EndIf
EndFunc ;==>_Pop3List
Func _Pop3Retr($msg)
    If $pop3_IsAuth = 1 Then
        Local $ret
        
; Send Retr
        $ret = TCPSend ($pop3_socket, "RETR " & $msg & @CRLF)
        If @error Then
            SetError($pop3_error_retr_refused)
            Return -1
        EndIf
        $ret = _Pop3WaitForOK()
        If @error Then
            SetError($pop3_error_no_OK_response)
            Return -1
        EndIf
        
        $ret = _WaitTcpResponse()
        If @error Then
            SetError($pop3_error_no_TCP_response)
            Return -1
        EndIf
        
; Downloading until final dot and cariage return.
        While Not StringRegExp($ret, "\r\n\.\r\n")
            $ret = $ret & _WaitTcpResponse()
            If @error Then
                SetError($pop3_error_no_TCP_response)
                Return -1
            EndIf
        WEnd
        Return $ret
    Else
        SetError($pop3_error_no_auth)
        Return -1
    EndIf
EndFunc ;==>_Pop3Retr
Func _pop3Connect($server, $login, $passwd, $port = 110)
    Local $ret
    If $pop3_IsConnected = 0 Then
        Local $server2
        TCPStartUp ()
; Basic name to IP conversion
        If StringRegExp($server, "[a-zA-Z]") Then
            $server2 = TCPNameToIP ($server)
        Else
            $server2 = $server
        EndIf
        $pop3_socket = TCPConnect ($server2, $port)
        If @error Then
            SetError($pop3_error_tcpconnect_failed)
            Return -1
        Else
            $pop3_IsConnected = 1
        EndIf
        
; We need a first OK from pop3 server
        $ret = _Pop3WaitForOK()
        If @error Then
            SetError($pop3_error_no_OK_response)
            Return -1
        EndIf
        
; Send user
        $ret = TCPSend ($pop3_socket, "USER " & $login & @CRLF)
        If @error Then
            SetError($pop3_error_user_refused)
            Return -1
        EndIf
        $ret = _Pop3WaitForOK()
        If @error Then
            SetError($pop3_error_no_OK_response)
            Return -1
        EndIf
        
; Send passwd
        $ret = TCPSend ($pop3_socket, "PASS " & $passwd & @CRLF)
        If @error Then
            SetError($pop3_error_passwd_refused)
            Return -1
        EndIf
        $ret = _Pop3WaitForOK()
        If @error Then
            SetError($pop3_error_no_OK_response)
            Return -1
        EndIf
        
        $pop3_IsAuth = 1
        Return 0
    Else
        SetError($pop3_error_already_connected)
        Return -1
    EndIf
EndFunc ;==>_pop3Connect
$Server = "mail.test.com"
$User = "user@test.com"
$Pass = "password"
_Pop3Connect($Server, $User, $pass)
While 1
$Test = UBound(_Pop3List())
MsgBox(0, "Test", _Pop3Retr($Test))
WEnd

but i'm trying to use it in a loop and it won't retreive the LATEST email count

please please please someone help me!

Edited by =sinister=

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0