storme Posted June 5, 2009 Posted June 5, 2009 (edited) G'day AllI searched throught the forum for something like this but didn't have much luck untill 'monoceres' asked a question in another thread and I did a slightly different search and came up with THIS from 'RobSaunders'. After a little cleaning up this little script may come in handy for someone else.Simply give the script the username, password, server and optionally port and it will return TRUE if everything is OK or False if it isn't. @error codes are returned to indicate what was wrong in the information. The header has all the information you may need and an example is included.If any one has any suggestions or finds a problem please let me know ASAP.expandcollapse popup#cs If _PopCheck('Something@somewhere.com', 'password', "mail.somewhere.com") Then MsgBox(0, "WORKING", "ALL is OK!" & @CR & "Password good") Else MsgBox(0, "ERROR", "Error number = " & @error & @CR & " Extended = " & @extended) EndIf #ce ; #FUNCTION# ;==================================================================================================================== ; ; Name...........: _PopCheck ; Description ...: Check username, password and server are correct for a popserver ; Syntax.........: _PopCheck($sUserID, $sPassword, $sServer, $nPort) ; Parameters ....: $sUserID - User id (usually the full Email address) ; $sPassword - Password for pop account ; $sServer - POP server address ; $nPort - POP port on server (Default = 110) ; Return values .: Success - returns TRUE ; Failure - Returns FALSE and Sets @Error: ; |1 - Unable to start TCP @extended = Windows API WSAStartup return ; |2 - Unable to convert server to IP address @extended = Windows API WSAGetError return ; |3 - Bad conneciton @extended = Windows API WSAGetLasterror return ; |4 - Communications failure (Disconnected) @extended = Windows API WSAGetLasterror return ; |5 - invalid user name or password ; Author ........: Storme (john Morrison) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; ;=============================================================================================================================== Func _PopCheck($sUserID, $sPassword, $sServer, $nPort = 110) Local $nRtnVal = TCPStartup() If Not $nRtnVal Then SetError(1, @error) ; Unable to start TCP Return False EndIf Local $sIp = TCPNameToIP($sServer) If $sIp = "" Then SetError(2, @error) ; Unable to convert server to IP address Return False EndIf Local $socket = TCPConnect($sIp, $nPort) If $socket = -1 Then ;* ConsoleWrite('Error: Bad connection' & @CRLF) SetError(3, @error) ; Bad conneciton Return False Else Local $sStep = 'login' Do Local $sRecv = TCPRecv($socket, 512) If @error Then ;* ConsoleWrite('Notice: Disconnected!' & @CRLF) SetError(4, @error) ; Communications failure Return False ElseIf StringInStr($sRecv, '+OK') = 1 Then ;* ConsoleWrite($sRecv & @CRLF) Switch $sStep Case 'login' ;* ConsoleWrite('Login: Username...' & @CRLF) TCPSend($socket, 'user ' & $sUserID & @CRLF) $sStep = 'pass' Case 'pass' ;* ConsoleWrite('Login: Password...' & @CRLF) TCPSend($socket, 'pass ' & $sPassword & @CRLF) $sStep = 'finished' Case 'finished' ;* ConsoleWrite('Disconnecting') TCPSend($socket, 'QUIT' & @CRLF) TCPCloseSocket($socket) $socket = -1 $sStep = '' EndSwitch ElseIf StringInStr($sRecv, '-ERR') = 1 Then ;* ConsoleWrite('Error: ' & $sRecv & @CRLF) ;* ConsoleWrite('Disconnecting') TCPSend($socket, 'QUIT' & @CRLF) TCPCloseSocket($socket) SetError(5) ; invalid user name or password Return False EndIf Until $socket = -1 EndIf Return True EndFunc ;==>_PopCheckAnother AutoIT Lover John MorrisonEDIT:6th June 2009: Fixed minor code mistake Edited June 6, 2009 by storme Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E
James Posted June 5, 2009 Posted June 5, 2009 What about SSL? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
storme Posted June 5, 2009 Author Posted June 5, 2009 What about SSL?Sorry but I don't know anything about SSL and don't have any accounts I can experiment on so there is nothing I can do at the moment. So if you use SSL and more importantly if you can supply some details on how to handle SSL then I'd be interested to add it to the code.Come to think of it I don't think any of my customers use SSL on their pop accounts.Thanks for the replyJohn Morrison Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E
Roman9 Posted June 5, 2009 Posted June 5, 2009 Why do you do: TCPCloseSocket($socket) TCPSend($socket, 'QUIT' & @CRLF) TCPCloseSocket($socket) ?
storme Posted June 6, 2009 Author Posted June 6, 2009 Why do you do:TCPCloseSocket($socket) TCPSend($socket, 'QUIT' & @CRLF) TCPCloseSocket($socket)?That woule be because I messed up The original script didn't user "QUIT" and I didn't like leaving it up to the server to clean up.So I added the "QUIT/TCPCloseSocket" and missed removeing the original TCPCloseSocket.I'll edit the first message with the new code.Thanks for picking that upJohn Morrison Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now