Global $a_pop3_info[5] = [5000, 0, 0, 0, 0]
Func pop3_Timeout($i_time)
$a_pop3_info[0] = $i_time
EndFunc
Func pop3_Open($s_server, $i_port, $s_login, $s_passw)
Local $i_socket, $i_timer, $s_recv
If TCPStartup() Then
If ($a_pop3_info[1] == 0) Then
$a_pop3_info[1] = TCPConnect(TCPNameToIP($s_server), $i_port)
If ($a_pop3_info[1] <> -1) Then
$i_timer = TimerInit()
While (TimerDiff($i_timer) <= $a_pop3_info[0])
$s_recv = TCPRecv($a_pop3_info[1], 65535)
If $s_recv Then
$i_timer = TimerInit()
If StringInStr($s_recv, '+OK') Then
TCPSend($a_pop3_info[1], 'USER ' & $s_login & @CRLF)
While (TimerDiff($i_timer) <= $a_pop3_info[0])
$s_recv = TCPRecv($a_pop3_info[1], 65535)
If $s_recv Then
$i_timer = TimerInit()
If StringInStr($s_recv, '+OK') Then
TCPSend($a_pop3_info[1], 'PASS ' & $s_passw & @CRLF)
While (TimerDiff($i_timer) <= $a_pop3_info[0])
$s_recv = TCPRecv($a_pop3_info[1], 65535)
If $s_recv Then
$i_timer = TimerInit()
If StringInStr($s_recv, '+OK') Then
Return SetError(0, 0, 1)
EndIf
EndIf
Wend
Return SetError(3, 0, 0)
EndIf
EndIf
Wend
Return SetError(2, 0, 0)
EndIf
EndIf
Wend
Return SetError(1, 0, 0)
EndIf
EndIf
EndIf
Return 0
EndFunc
Func pop3_Info()
Local $i_timer, $s_recv, $a_split
If $a_pop3_info[1] Then
TCPSend($a_pop3_info[1], 'STAT' & @CRLF)
$i_timer = TimerInit()
While (TimerDiff($i_timer) <= $a_pop3_info[0])
$s_recv = TCPRecv($a_pop3_info[1], 65535)
If $s_recv Then
$i_timer = TimerInit()
If StringInStr($s_recv, '+OK') Then
$a_split = StringSplit($s_recv, ' ')
If (IsArray($a_split) And ($a_split[0] == 3)) Then
$a_pop3_info[2] = $a_split[2]
$a_pop3_info[3] = $a_split[3]
Return 1
EndIf
EndIf
EndIf
Wend
EndIf
Return 0
EndFunc
Func pop3_Count()
Return $a_pop3_info[2]
EndFunc
Func pop3_TitalSize()
Return $a_pop3_info[3]
EndFunc
Func pop3_Next()
If ($a_pop3_info[4] >= $a_pop3_info[2]) Then
$a_pop3_info[4] = 0
Return False
EndIf
$a_pop3_info[4] += 1
Return True
EndFunc
Func pop3_Number()
Return $a_pop3_info[4]
EndFunc
Func pop3_Size()
Local $i_timer, $s_recv, $a_split
If $a_pop3_info[1] Then
While TCPSend($a_pop3_info[1], 'LIST ' & $a_pop3_info[4] & @CRLF & @CRLF) <> 0
$i_timer = TimerInit()
While (TimerDiff($i_timer) <= $a_pop3_info[0])
$s_recv = TCPRecv($a_pop3_info[1], 65535)
If $s_recv Then
$i_timer = TimerInit()
If StringInStr($s_recv, '+OK') Then
$a_split = StringSplit($s_recv, ' ')
If (IsArray($a_split) And ($a_split[0] == 3)) Then
Return $a_split[3]
EndIf
EndIf
EndIf
Wend
Wend
EndIf
Return 0
EndFunc
Func pop3_Read()
Local $i_timer, $s_recv, $a_split, $s_data
If $a_pop3_info[1] Then
While TCPSend($a_pop3_info[1], 'RETR ' & $a_pop3_info[4] & @CRLF & @CRLF) <> 0
$i_timer = TimerInit()
While (TimerDiff($i_timer) <= $a_pop3_info[0])
$s_recv = TCPRecv($a_pop3_info[1], 65535)
If $s_recv Then
$i_timer = TimerInit()
If StringInStr($s_recv, '+OK') Then
$a_split = StringSplit($s_recv, ' ')
If (IsArray($a_split) And ($a_split[0] == 3)) Then
Do
$s_data &= TCPRecv($a_pop3_info[1], 65535)
Until (StringLen($s_data) >= $a_split[2])
Return $s_data
EndIf
EndIf
EndIf
Wend
Wend
EndIf
Return ''
EndFunc
Func pop3_Delete()
Local $i_timer, $s_recv, $a_split
If $a_pop3_info[1] Then
While TCPSend($a_pop3_info[1], 'DELE ' & $a_pop3_info[4] & @CRLF & @CRLF) <> 0
$i_timer = TimerInit()
While (TimerDiff($i_timer) <= $a_pop3_info[0])
$s_recv = TCPRecv($a_pop3_info[1], 65535)
If $s_recv Then
$i_timer = TimerInit()
If StringInStr($s_recv, '+OK') Then
Return 1
EndIf
EndIf
Wend
Wend
EndIf
Return 0
EndFunc
Func pop3_Close()
Local $i_result, $i_timer, $s_recv
If $a_pop3_info[1] Then
TCPSend($a_pop3_info[1], 'QUIT' & @CRLF)
$i_timer = TimerInit()
While (TimerDiff($i_timer) <= $a_pop3_info[0])
$s_recv = TCPRecv($a_pop3_info[1], 65535)
If $s_recv Then
$i_timer = TimerInit()
If StringInStr($s_recv, '+OK') Then
$i_result = 1
EndIf
EndIf
Wend
TCPCloseSocket($a_pop3_info[1])
TCPShutdown()
$a_pop3_info[0] = 5000
$a_pop3_info[1] = 0
$a_pop3_info[2] = 0
$a_pop3_info[3] = 0
$a_pop3_info[4] = 0
EndIf
Return $i_result
EndFunc