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

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$)


*Buffer = AllocateMemory(3000)

connid = OpenNetworkConnection("", 80)

;request to get a ClientLogin authentication token from google
request$ = "POST 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.."


  cEvent = NetworkClientEvent(connid)
  Select cEvent
    Case #PB_NetworkEvent_Data
      ReceiveNetworkData(connid, *Buffer, 3000)
      response$ = PeekS(*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:" + Chr(10)
          request$ + "Cookie: " + auth$ + Chr(10) + Chr(10)
          SendNetworkString(connid, request$)
      Next x
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.