FANDOM


This article is a code snippet written in PureBasic.

About Edit

This is a proof of concept gmail new mail checker. This will read the gmail atom feed, located at http://mail.google.com/mail/feed/atom.

Code Edit

;epidemicz 3/26/2010
;quick and dirty (really dirty) proof of concept gmail new mail checker

;be sure to fill out user & pass
user$ = "user" 
pass$ = "pass"

email$ = user$ + "%40gmail%2Ecom"


;needed for content-length: header -- google api doc doesn't say you need this
;but if you don't send content-length header with the request it will give error
;len is basically the length of the last section of the first request$
len = 57 + Len(email$) + Len(pass$)

InitNetwork()

*Buffer = AllocateMemory(3000)

connid = OpenNetworkConnection("mail.google.com", 80)

;request to get a ClientLogin authentication token from google
;http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html
request$ = "POST https://www.google.com/accounts/ClientLogin HTTP/1.0" + Chr(10)
request$ + "Content-type: application/x-www-form-urlencoded" + Chr(10) 
request$ + "Connection: keep-alive" + Chr(10)
request$ + "Content-length: " + Str(Len) + Chr(10) + Chr(10) 
request$ + "&Email=" + email$ + "&Passwd=" + pass$ + "&accountType=HOSTED_OR_GOOGLE&service=mail"

SendNetworkString(connid, request$)

Debug "Logging in.."


Delay(2000)

Repeat
  cEvent = NetworkClientEvent(connid)
  
  Select cEvent
    Case #PB_NetworkEvent_Data
      ReceiveNetworkData(connid, *Buffer, 3000)
      response$ = PeekS(*Buffer)
      
      FreeMemory(*Buffer)  
      *Buffer = AllocateMemory(3000) 
      
      For x = 1 To CountString(response$, Chr(10))
        curline$ = StringField(response$, x, Chr(10))
        
        Debug curline$
        
        If FindString(curline$, "Auth=", 0)
          ;for some reason the auth token must have GX= in front of it
          auth$ = "GX=" + Mid(curline$, 6)
          
          Debug "sending request for mail feed.."

          ;forming request for gmail atom feed
          request$ = "GET /mail/feed/atom/ HTTP/1.1" + Chr(10) 
          request$ + "Host: mail.google.com" + Chr(10)
          request$ + "Cookie: " + auth$ + Chr(10) + Chr(10)
          
          SendNetworkString(connid, request$)
          
          Delay(2000)          
        EndIf
      Next x
  EndSelect    
  
Until cEvent = 0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.