Jump to content

Recommended Posts

Posted

Hi All,

I have seen many example on reading gmail atom url. But none is working. I am getting message No authorization using winhttp. Please help me to solve this.

Posted

@JLogan3o13

I am using the below code, but getting error :

 !>Error Getting URL Source!      404>@Error =13     404>@Extended =0

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/so
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <string.au3>

Global $eReturn = _CheckMail("myusername", "mygmailpwd")
Global $Emails = @extended

Switch @error
    Case 0
        Switch @extended
            Case True
                ConsoleWrite("   0>"&$eReturn[0][0] & @CR)
                ConsoleWrite("   "& $Emails & " " & $eReturn[0][1] & @CR)
                For $x = 1 To $Emails
                    ConsoleWrite("!>Title   - " & $eReturn[$x][0] & @CR)
                    ConsoleWrite("+>Name    - " & $eReturn[$x][1] & @CR)
                    ConsoleWrite("->Email   - " & $eReturn[$x][2] & @CR)
                    ConsoleWrite(">summary - " & $eReturn[$x][3] & @CR & @CR)
                Next
            Case Else
                MsgBox(64,"success!","Success! But you have no new emails :(")
        EndSwitch
    Case 1
        MsgBox(0,"Error!","Couldn't get your new emails for some reason...")
    Case 2,3
        MsgBox(0,"Error!","you need to enter an user name and password!")
    Case 4
        MsgBox(16,"Error!","Error Getting URL Source!")
    Case 5
        MsgBox(16,"Error!","No response?")
    Case 6
        MsgBox(16,"Error!","Unauthorized access, possibly a wrong username or password!")
EndSwitch

; #FUNCTION# ====================================================================================================================
; Name ..........: _CheckMail
; Description ...: Checks a Google Email for new emails.
; Syntax ........: _CheckMail($UserName, $Pswd[, $UserAgentString = ""])
; Parameters ....: $UserName            - An unknown value.
;                 $Pswd             - An unknown value.
;                 $UserAgentString   - [optional] An unknown value. Default is "".
; Return values .: A 2d array with email information as follows~
;                   1|Title
;                   2|Name
;                   3|Email
;                   4|Summary
;                   5|Date
;                   6|Time
;
; Author ........: dantay9
; Modified ......: THAT1ANONYMOUSDUDE
; Remarks .......:
; Related .......:
; Link ..........: http://www.autoitscript.com/forum/topic/111853-gmail-email-checker/page__view__findpost__p__819409
; Example .......: Yes
; ===============================================================================================================================

Func _CheckMail($UserName, $Pswd, $UserAgentString = "")
    If Not $UserName Then Return SetError(2,0,0)
    If Not $Pswd Then Return SetError(3,0,0)
    If $UserAgentString Then HttpSetUserAgent($UserAgentString)
    Local $source = InetRead("https://" & $UserName & ":" & $Pswd & "@gmail.google.com/gmail/feed/atom",1)
    If @error Then
        ConsoleWrite("!>Error Getting URL Source!" & @CR & "     404>@Error =" & @error & @CR & "    404>@Extended =" & @extended & @CR)
        Return SetError(4,0,0)
    EndIf
    If $source Then
        $source = BinaryToString($source)
    Else
        Return SetError(5,0,0)
    EndIf
    If StringLeft(StringStripWS($source, 8), 46) == "<HTML><HEAD><TITLE>Unauthorized</TITLE></HEAD>" Then  Return SetError(6, 0, 0)
    If Not Number(StringBetween($source, "<fullcount>", "</fullcount>")) Then Return SetError(0,0,0)
    Local $Email = _StringBetween($source, "<entry>", "</entry>")
    If @error Then Return SetError(1, 0, 0)
    Local $Time
    Local $Count = UBound($Email)
    Local $Datum[$Count + 1][6]
    $Datum[0][0] = StringBetween($source, "<title>", "</title>")
    $Datum[0][1] = StringBetween($source, "<tagline>", "</tagline>")
    For $i = 0 To $Count - 1
        $Datum[$i+1][0] = StringBetween($Email[$i], "<title>", "</title>")
        If Not $Datum[$i+1][0] Then $Datum[$i][0] = "(no subject)"
        $Datum[$i+1][1] = StringBetween($Email[$i], "<name>", "</name>")
        $Datum[$i+1][2] = StringBetween($Email[$i], "<email>", "</email>")
        $Datum[$i+1][3] = StringBetween($Email[$i], "<summary>", "</summary>")
        $Time = StringBetween($Email[$i], "<issued>", "</issued>")
        $Datum[$i+1][4] = DateFromTimeDate($Time)
        $Datum[$i+1][5] = TimeFromTimeDate($Time)
    Next
    Return SetError(0,$Count,$Datum)
EndFunc
Func StringBetween($Str, $S, $E)
    Local $B = _StringBetween($Str, $S, $E)
    If @error Then Return SetError(1,0,0)
    Return SetError(0,0,$B[0])
EndFunc   ;==>StringBetween

; #FUNCTION# ====================================================================================================================
; Name ..........: DateFromTimeDate
; Description ...: Returns email sent date.
; Syntax ........: DateFromTimeDate($String)
; Parameters ....: $String            - A gmail date string
; Return values .: None
; Author ........: ???
; Example .......: No
; ===============================================================================================================================

Func DateFromTimeDate($String)
    Local $RegEx = StringRegExp($String, "(?<Year>d{2}|d{4})(?:-)(?<Month>d{1,2})(?:-)(?<Day>d{1,2})", 1)
    If IsArray($RegEx) Then
        Return Int($RegEx[0]) & "/" & Int($RegEx[1]) & "/" & Int($RegEx[2])
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>DateFromTimeDate

; #FUNCTION# ====================================================================================================================

; Name ..........: TimeFromTimeDate
; Description ...: Returns the email sent time.
; Syntax ........: TimeFromTimeDate($String)
; Parameters ....: $String            - An unknown value.
; Return values .: None
; Author ........: ???
; Example .......: No
; ===============================================================================================================================

Func TimeFromTimeDate($String)
    Local $RegEx = StringRegExp($String, "(?<Hour>d{1,2})(?::)(?<Minute>d{1,2})(?::)(?<Second>d{1,2})", 1)
    If IsArray($RegEx) Then
        Return (Int($RegEx[0]) - 4) & ":" & Int($RegEx[1]) & ":" & Int($RegEx[2]) ;don't know why I have to subtract 4
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>TimeFromTimeDate

 

Posted (edited)

The URL that you are using is incorrect.  It is no longer "gmail.google.com/gmail/feed/atom".  It is now "mail.google.com/mail/feed/atom". 

Edited by TheXman
Posted

@TheXman I changed the code with new url - still same error is coming.

!>Error Getting URL Source!      404>@Error =13     404>@Extended =0

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/so
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <string.au3>

Global $eReturn = _CheckMail("myusername", "mypwd")
Global $Emails = @extended

Switch @error
    Case 0
        Switch @extended
            Case True
                ConsoleWrite("   0>"&$eReturn[0][0] & @CR)
                ConsoleWrite("   "& $Emails & " " & $eReturn[0][1] & @CR)
                For $x = 1 To $Emails
                    ConsoleWrite("!>Title   - " & $eReturn[$x][0] & @CR)
                    ConsoleWrite("+>Name    - " & $eReturn[$x][1] & @CR)
                    ConsoleWrite("->Email   - " & $eReturn[$x][2] & @CR)
                    ConsoleWrite(">summary - " & $eReturn[$x][3] & @CR & @CR)
                Next
            Case Else
                MsgBox(64,"success!","Success! But you have no new emails :(")
        EndSwitch
    Case 1
        MsgBox(0,"Error!","Couldn't get your new emails for some reason...")
    Case 2,3
        MsgBox(0,"Error!","you need to enter an user name and password!")
    Case 4
        MsgBox(16,"Error!","Error Getting URL Source!")
    Case 5
        MsgBox(16,"Error!","No response?")
    Case 6
        MsgBox(16,"Error!","Unauthorized access, possibly a wrong username or password!")
EndSwitch

; #FUNCTION# ====================================================================================================================
; Name ..........: _CheckMail
; Description ...: Checks a Google Email for new emails.
; Syntax ........: _CheckMail($UserName, $Pswd[, $UserAgentString = ""])
; Parameters ....: $UserName            - An unknown value.
;                 $Pswd             - An unknown value.
;                 $UserAgentString   - [optional] An unknown value. Default is "".
; Return values .: A 2d array with email information as follows~
;                   1|Title
;                   2|Name
;                   3|Email
;                   4|Summary
;                   5|Date
;                   6|Time
;
; Author ........: dantay9
; Modified ......: THAT1ANONYMOUSDUDE
; Remarks .......:
; Related .......:
; Link ..........: http://www.autoitscript.com/forum/topic/111853-gmail-email-checker/page__view__findpost__p__819409
; Example .......: Yes
; ===============================================================================================================================

Func _CheckMail($UserName, $Pswd, $UserAgentString = "")
    If Not $UserName Then Return SetError(2,0,0)
    If Not $Pswd Then Return SetError(3,0,0)
    If $UserAgentString Then HttpSetUserAgent($UserAgentString)
    Local $source = InetRead("https://" & $UserName & ":" & $Pswd & "@mail.google.com/gmail/feed/atom",1)
    If @error Then
        ConsoleWrite("!>Error Getting URL Source!" & @CR & "     404>@Error =" & @error & @CR & "    404>@Extended =" & @extended & @CR)
        Return SetError(4,0,0)
    EndIf
    If $source Then
        $source = BinaryToString($source)
    Else
        Return SetError(5,0,0)
    EndIf
    If StringLeft(StringStripWS($source, 8), 46) == "<HTML><HEAD><TITLE>Unauthorized</TITLE></HEAD>" Then  Return SetError(6, 0, 0)
    If Not Number(StringBetween($source, "<fullcount>", "</fullcount>")) Then Return SetError(0,0,0)
    Local $Email = _StringBetween($source, "<entry>", "</entry>")
    If @error Then Return SetError(1, 0, 0)
    Local $Time
    Local $Count = UBound($Email)
    Local $Datum[$Count + 1][6]
    $Datum[0][0] = StringBetween($source, "<title>", "</title>")
    $Datum[0][1] = StringBetween($source, "<tagline>", "</tagline>")
    For $i = 0 To $Count - 1
        $Datum[$i+1][0] = StringBetween($Email[$i], "<title>", "</title>")
        If Not $Datum[$i+1][0] Then $Datum[$i][0] = "(no subject)"
        $Datum[$i+1][1] = StringBetween($Email[$i], "<name>", "</name>")
        $Datum[$i+1][2] = StringBetween($Email[$i], "<email>", "</email>")
        $Datum[$i+1][3] = StringBetween($Email[$i], "<summary>", "</summary>")
        $Time = StringBetween($Email[$i], "<issued>", "</issued>")
        $Datum[$i+1][4] = DateFromTimeDate($Time)
        $Datum[$i+1][5] = TimeFromTimeDate($Time)
    Next
    Return SetError(0,$Count,$Datum)
EndFunc
Func StringBetween($Str, $S, $E)
    Local $B = _StringBetween($Str, $S, $E)
    If @error Then Return SetError(1,0,0)
    Return SetError(0,0,$B[0])
EndFunc   ;==>StringBetween

; #FUNCTION# ====================================================================================================================
; Name ..........: DateFromTimeDate
; Description ...: Returns email sent date.
; Syntax ........: DateFromTimeDate($String)
; Parameters ....: $String            - A gmail date string
; Return values .: None
; Author ........: ???
; Example .......: No
; ===============================================================================================================================

Func DateFromTimeDate($String)
    Local $RegEx = StringRegExp($String, "(?<Year>d{2}|d{4})(?:-)(?<Month>d{1,2})(?:-)(?<Day>d{1,2})", 1)
    If IsArray($RegEx) Then
        Return Int($RegEx[0]) & "/" & Int($RegEx[1]) & "/" & Int($RegEx[2])
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>DateFromTimeDate

; #FUNCTION# ====================================================================================================================

; Name ..........: TimeFromTimeDate
; Description ...: Returns the email sent time.
; Syntax ........: TimeFromTimeDate($String)
; Parameters ....: $String            - An unknown value.
; Return values .: None
; Author ........: ???
; Example .......: No
; ===============================================================================================================================

Func TimeFromTimeDate($String)
    Local $RegEx = StringRegExp($String, "(?<Hour>d{1,2})(?::)(?<Minute>d{1,2})(?::)(?<Second>d{1,2})", 1)
    If IsArray($RegEx) Then
        Return (Int($RegEx[0]) - 4) & ":" & Int($RegEx[1]) & ":" & Int($RegEx[2]) ;don't know why I have to subtract 4
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>TimeFromTimeDate

 

Posted (edited)

When I manually put the following URL into a browser, it brings back the expected information:

https://<username>:<password>@mail.google.com/mail/feed/atom

Try it manually and see if it works for you.

Edited by TheXman
Posted
8 minutes ago, Jahar said:

Local $source = InetRead("https://" & $UserName & ":" & $Pswd & "@mail.google.com/gmail/feed/atom",1)

This is NOT the URL I gave you!

 

Posted

Now that you are using the correct URL and have confirmed that it works manually, you can get to work debugging your script.

Posted

@TheXman I have corrected the url in the code. But still same error.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/so
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <string.au3>

Global $eReturn = _CheckMail("myUserName", "myPwd")
Global $Emails = @extended

Switch @error
    Case 0
        Switch @extended
            Case True
                ConsoleWrite("   0>"&$eReturn[0][0] & @CR)
                ConsoleWrite("   "& $Emails & " " & $eReturn[0][1] & @CR)
                For $x = 1 To $Emails
                    ConsoleWrite("!>Title   - " & $eReturn[$x][0] & @CR)
                    ConsoleWrite("+>Name    - " & $eReturn[$x][1] & @CR)
                    ConsoleWrite("->Email   - " & $eReturn[$x][2] & @CR)
                    ConsoleWrite(">summary - " & $eReturn[$x][3] & @CR & @CR)
                Next
            Case Else
                MsgBox(64,"success!","Success! But you have no new emails :(")
        EndSwitch
    Case 1
        MsgBox(0,"Error!","Couldn't get your new emails for some reason...")
    Case 2,3
        MsgBox(0,"Error!","you need to enter an user name and password!")
    Case 4
        MsgBox(16,"Error!","Error Getting URL Source!")
    Case 5
        MsgBox(16,"Error!","No response?")
    Case 6
        MsgBox(16,"Error!","Unauthorized access, possibly a wrong username or password!")
EndSwitch

; #FUNCTION# ====================================================================================================================
; Name ..........: _CheckMail
; Description ...: Checks a Google Email for new emails.
; Syntax ........: _CheckMail($UserName, $Pswd[, $UserAgentString = ""])
; Parameters ....: $UserName            - An unknown value.
;                 $Pswd             - An unknown value.
;                 $UserAgentString   - [optional] An unknown value. Default is "".
; Return values .: A 2d array with email information as follows~
;                   1|Title
;                   2|Name
;                   3|Email
;                   4|Summary
;                   5|Date
;                   6|Time
;
; Author ........: dantay9
; Modified ......: THAT1ANONYMOUSDUDE
; Remarks .......:
; Related .......:
; Link ..........: http://www.autoitscript.com/forum/topic/111853-gmail-email-checker/page__view__findpost__p__819409
; Example .......: Yes
; ===============================================================================================================================

Func _CheckMail($UserName, $Pswd, $UserAgentString = "")
    If Not $UserName Then Return SetError(2,0,0)
    If Not $Pswd Then Return SetError(3,0,0)
    If $UserAgentString Then HttpSetUserAgent($UserAgentString)
    Local $source = InetRead("https://" & $UserName & ":" & $Pswd & "@mail.google.com/mail/feed/atom",1)
    If @error Then
        ConsoleWrite("!>Error Getting URL Source!" & @CR & "     404>@Error =" & @error & @CR & "    404>@Extended =" & @extended & @CR)
        Return SetError(4,0,0)
    EndIf
    If $source Then
        $source = BinaryToString($source)
    Else
        Return SetError(5,0,0)
    EndIf
    If StringLeft(StringStripWS($source, 8), 46) == "<HTML><HEAD><TITLE>Unauthorized</TITLE></HEAD>" Then  Return SetError(6, 0, 0)
    If Not Number(StringBetween($source, "<fullcount>", "</fullcount>")) Then Return SetError(0,0,0)
    Local $Email = _StringBetween($source, "<entry>", "</entry>")
    If @error Then Return SetError(1, 0, 0)
    Local $Time
    Local $Count = UBound($Email)
    Local $Datum[$Count + 1][6]
    $Datum[0][0] = StringBetween($source, "<title>", "</title>")
    $Datum[0][1] = StringBetween($source, "<tagline>", "</tagline>")
    For $i = 0 To $Count - 1
        $Datum[$i+1][0] = StringBetween($Email[$i], "<title>", "</title>")
        If Not $Datum[$i+1][0] Then $Datum[$i][0] = "(no subject)"
        $Datum[$i+1][1] = StringBetween($Email[$i], "<name>", "</name>")
        $Datum[$i+1][2] = StringBetween($Email[$i], "<email>", "</email>")
        $Datum[$i+1][3] = StringBetween($Email[$i], "<summary>", "</summary>")
        $Time = StringBetween($Email[$i], "<issued>", "</issued>")
        $Datum[$i+1][4] = DateFromTimeDate($Time)
        $Datum[$i+1][5] = TimeFromTimeDate($Time)
    Next
    Return SetError(0,$Count,$Datum)
EndFunc
Func StringBetween($Str, $S, $E)
    Local $B = _StringBetween($Str, $S, $E)
    If @error Then Return SetError(1,0,0)
    Return SetError(0,0,$B[0])
EndFunc   ;==>StringBetween

; #FUNCTION# ====================================================================================================================
; Name ..........: DateFromTimeDate
; Description ...: Returns email sent date.
; Syntax ........: DateFromTimeDate($String)
; Parameters ....: $String            - A gmail date string
; Return values .: None
; Author ........: ???
; Example .......: No
; ===============================================================================================================================

Func DateFromTimeDate($String)
    Local $RegEx = StringRegExp($String, "(?<Year>d{2}|d{4})(?:-)(?<Month>d{1,2})(?:-)(?<Day>d{1,2})", 1)
    If IsArray($RegEx) Then
        Return Int($RegEx[0]) & "/" & Int($RegEx[1]) & "/" & Int($RegEx[2])
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>DateFromTimeDate

; #FUNCTION# ====================================================================================================================

; Name ..........: TimeFromTimeDate
; Description ...: Returns the email sent time.
; Syntax ........: TimeFromTimeDate($String)
; Parameters ....: $String            - An unknown value.
; Return values .: None
; Author ........: ???
; Example .......: No
; ===============================================================================================================================

Func TimeFromTimeDate($String)
    Local $RegEx = StringRegExp($String, "(?<Hour>d{1,2})(?::)(?<Minute>d{1,2})(?::)(?<Second>d{1,2})", 1)
    If IsArray($RegEx) Then
        Return (Int($RegEx[0]) - 4) & ":" & Int($RegEx[1]) & ":" & Int($RegEx[2]) ;don't know why I have to subtract 4
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>TimeFromTimeDate

 

Posted (edited)

That error message is hard-coded into your script and will be given if ANY error occurs. 

I have no idea what the problem could be other than if your username and/or password is either incorrect or has any characters that need to be URL-encoded.

Edited by TheXman
Posted

@TheXman Thanks for your help and time. I am using my username (excluding gmail.com) and password (have no special characters). Kindly help me or provide another method. I have to read unread mails from my specific label.

Posted

What do you get back in the console when you run this test script?  Do you get @error = 13 or a valid response?

Although I shouldn't have to say it, for some reason I'm thinking I should, make sure you put your correct username and password in the constant fields before executing the script.  ;)

 

#include <Constants.au3>
#include <InetConstants.au3>

test()
Func test()
    ;Put your username and password below
    Const $USERNAME = "username", _
          $PASSWORD = "password"

    Local $sReturn

    $sReturn = InetRead("https://" & $USERNAME & ":" & $PASSWORD & "@mail.google.com/mail/feed/atom", $INET_FORCERELOAD )
    If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "InetRead failed - @error = " & @error)

    $sReturn = BinaryToString($sReturn)
    ConsoleWrite(StringLeft($sReturn, 200) & @CRLF)
EndFunc

 

Posted (edited)

What about this script that URL encodes your username and password?  If this doesn't work, I'm out of ideas.  :)

 

#include <Constants.au3>
#include <InetConstants.au3>

test()
Func test()
    ;Put your username and password below
    Const $USERNAME = "username", _
          $PASSWORD = "password"

    Local $sReturn

    $sReturn = InetRead("https://" & URLEncode($USERNAME) & ":" & URLEncode($PASSWORD) & "@mail.google.com/mail/feed/atom", $INET_FORCERELOAD )
    If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "InetRead failed - @error = " & @error)

    $sReturn = BinaryToString($sReturn)
    ConsoleWrite(StringLeft($sReturn, 200) & @CRLF)
EndFunc

Func URLEncode($UnicodeURL)
    $UnicodeBinary = StringToBinary ($UnicodeURL, 4)
    $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1)
    $UnicodeBinaryLength = StringLen($UnicodeBinary2)
    Local $EncodedString
    For $i = 1 To $UnicodeBinaryLength Step 2
        $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2)
        If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar, 4)) Then
            $EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar)
        Else
            $EncodedString &= '%' & $UnicodeBinaryChar
        EndIf
    Next
    Return $EncodedString
EndFunc

 

Edited by TheXman
Posted

Both of the test scripts worked for me.  I'm not sure why they didn't work for you.  I don't have any more ideas right now.

So the first test script got @error = 13 and the second one got @error = 11 or was that supposed to be 13?

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
  • Recently Browsing   0 members

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