Jump to content

Recommended Posts

Hi friends,

 

I'm trying to implement a script to read inbox of a IMAP thunderbird  server to sort and process mails with some particular text in subject field. I'm working on it for many days and not able to make much progress. When I execute the script, I get connected to the server and server responds with the text: * OK The Microsoft Exchange IMAP4 service is ready.

But the capability check always results in timeout.

I have tried the the commands from telnet command line and the capability request worked with this response: * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+
0 OK CAPABILITY completed.

Please help. Am I missing anything in my AutoIT code?

Thank you so much.

#RequireAdmin
Opt("TCPTimeout", 5000) ;5 seconds
OnAutoItExitRegister ( "_OnExit" )
TCPStartup()
Global $IMAPsocket = -1

;IMAP Server Info
Global $IMAPserver = InputBox("", "IMAP Server", "imap.server.com")
Global $IMAPport = InputBox("", "IMAP Server Port Number", "143")

;User Info
Global $UserName = InputBox("", "UserName", "UserName")
Global $Password = InputBox("", "Password", "Password")

_ConnectToServer($IMAPserver, $IMAPport)
_CheckCapability()

;Connect to IMAP Server
Func _ConnectToServer($IMAPserver, $IMAPport)
    TCPStartup()
    $IMAPsocket = TCPConnect(TCPNameToIP($IMAPserver), $IMAPport)
    If $IMAPsocket = -1 Then
        MsgBox(0, "Error", "Could Not Connect to server with error: " & @Error)
        Return
    EndIf
    $iTime = TimerInit ()
    Do
        If TimerDiff ($iTime) > 15000 Then
            msgbox(0, "TCPConnect - Error", "TCPConnect - Timeout")
            Return
        EndIf

        $sRecv = TCPRecv($IMAPsocket, 64)
        If $sRecv <> "" Then
            Msgbox(0,"Response received from server for TCPConnect: ", $sRecv)
            ExitLoop
        ElseIf @error then
            msgbox(0,"TCPRecv - Error", "TCPreceive Error: ", @error)
            Return
        EndIf
    Until StringLeft($sRecv, 3) = "* OK"
EndFunc   ;=>IMAPConnectToServer

;Check capability
Func _CheckCapability()
$Ret  = TCPSend($IMAPsocket, "0 capability")
 If @error Then
        MsgBox(0, "Error", "Could Not send capability check to server with error: " & @Error)
        Return
 EndIf
    $iTime = TimerInit ()
    Do
        If TimerDiff ($iTime) > 15000 Then
            msgbox(0, "", "TCP receive capability - timeout")
            Return
        EndIf

        $sRecv = TCPRecv($IMAPsocket, 400)
        If $sRecv <> "" Then
            Msgbox(0,"Received Response for capability check", $sRecv)
            ExitLoop
        ElseIf @error then
            msgbox(0,"TCP capability check Error", @error)
            Return
        EndIf
    Until StringLeft($sRecv, 4) = "* CAP"
EndFunc ;=>_CheckCapability

;Run when Program Ends
Func _OnExit()
    If $IMAPsocket Then
        TCPCloseSocket($IMAPsocket)
    EndIf
    TCPShutdown()
EndFunc   ;==>endscript

References:  

 

 https://tools.ietf.org/html/rfc3501#page-24

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...