Gmail Checker — File Browser

GmailCheckerv1.0 / GmailCheckerv1.0 / Gmail Checker / checkgmail.mrc

checkgmail.mrc — 7.71 KB — Download this file

;
;  ---------------------------------------------------------
;  Gmail Checker by FiberOPtics @ mirc.fiberoptics@gmail.com
;  ---------------------------------------------------------
; 
;  Check the readme.txt for information regarding this addon.
;


; This signal event is optional and not necessary for the checking of unread emails.
; I've added it so that you can put your custom code in it. Some example code is within
; the event, though you may delete/change it as you please it.

on *:signal:gmail:{
  var %text = * Gmail Checker: found $1 unread emails on account $2
  echo -ac info %text
  ;  titlebar %text
  ; ...
}

alias checkgmail {
  var %e = echo -ac info * Gmail checker:
  if ($version < 6.15) %e you need atleast mIRC version 6.15
  elseif (!$regex(gm,$1,/^\S+?@gmail\.com$/)) %e you must specify an email address
  else {
    var %s = $iif(@gmail.* iswm $3,$3,$+(@gmail.,$ticks,$r(11111,99999)))
    gmail %s email $1
    gmail %s show $show
    gmail %s total 0
    gmail %s num $iif($2 isnum 1-,$2,99999)
    if ($gmail($1,cookie)) {
      window -h %s
      if ($gmail(%s,show)) %e checking for unread emails on account $1, stand by...
      sockopen %s mail.google.com 80
    }
    else gmail_getcookie %s
  }
}

alias gmail_reset {
  var %e = echo -ac info * Gmail checker:
  if ($gmail($$1,cookie)) {
    unset $+(%,gmail_,$1,_cookie)
    %e cookie for account $1 has been reset
  }
  else %e there is no cookie for account $1
}

on *:sockopen:@gmail.*:{
  var %email = $gmail($sockname,email)
  if ($sockerr) echo -ac info * Gmail checker: error connecting to account %email $+ , try again.
  else {
    var %sw = sockwrite -tn $sockname
    %sw GET /mail/?&ik=&search=inbox&view=tl HTTP/1.1
    %sw Host: mail.google.com
    %sw Connection: close
    %sw Cookie: $gmail(%email,cookie)
    %sw
  }
}

on *:sockread:@gmail.*:{
  if ($sockerr) return
  var %tmp, %s = $sockname
  sockread %tmp
  while ($sockbr) && (!$sockerr) {
    if (!$sock(%s).mark) {
      tokenize 32 %tmp
      if (HTTP/1.? * * iswm $1-) && ($2-3 != 200 OK) {
        gmail_error 1 %s
        return
      }
      if (* !iswm $1) sockmark %s 1
    }
    elseif (* iswm %tmp) aline %s %tmp
    sockread %tmp 
  }
}

on *:sockclose:@gmail.*:{
  var %s = $sockname
  set %gmail.session %s
  if ($fline(%s,*"<span id*_user_*@*\">*,1)) {
    filter -wk %s parsegmail
    .signal gmail $gmail(%s,total) $gmail(%s,email)
    gmail_cleanup %s
  }
  else gmail_error 2 %s
}

alias -l parsegmail {
  var %s = %gmail.session
  if ($gmail(%s,total) >= $gmail(%s,num)) return
  if ($regex(%s,$1,/<span id.+?_user_(.+?)\\"><b>(.+?)<\/b>.+?&nbsp;"\54"<b>(.+?)<\/b>(?:"\54"(.+?)&hellip;)?/)) {
    inc $+(%,gmail.,%s,.total)
    if ($gmail(%s,show)) {
      echo -a 
      echo -a $(#,) $+ $gmail(%s,total)
      echo -a From: $regml(%s,2) ( $+ $regml(%s,1) $+ )
      echo -a Subject: $gmail_html($regml(%s,3))
      if ($regml(%s,4) != $null) echo -a Excerpt: $gmail_html($ifmatch) $+ ...
    }
  }
}

alias -l gmail_html {
  var %a = $1
  while ($regex(gm,%a,/(&#(\d+?);)/)) %a = $replace(%a,$regml(gm,1),$chr($regml(gm,2)))
  return %a
}

alias -l gmail {
  if ($isid) {
    if ($2 == cookie) return $($+(%,gmail_,$1,_cookie),2)
    return $($+(%,gmail.,$1,.,$2),2)
  }
  if ($2 == cookie) set $+(%,gmail_,$1,_cookie) $3-
  else set $+(%,gmail.,$1,.,$2) $3-
}

menu menubar,status,channel,query {
  -
  Gmail Checker
  .Check Gmail Account: checkgmail $input(Enter a gmail address,eo) $input(Enter a number or press enter to check all,eo)
  .$submenu($gmail_accounts($1))
  .-
  .Unload Addon: .unload -rs checkgmail.mrc
}

alias -l gmail_accounts {
  if ($1 == begin) return -
  if ($gettok($var(%gmail_*_cookie,$1),2,95)) return Check $ifmatch : checkgmail $ifmatch $!input(Enter number or press enter to check all,eo)
  if ($1 == end) return -
}

on *:load:{
  var %e = echo -ac info * Gmail checker:
  if ($version < 6.15) {
    %e Error: this addon only works on mIRC version 6.15 or higher
    .unload -rs checkgmail.mrc
  }
  else {
    %e addon successfully loaded. 
    echo -a 
    %e Usage: /checkgmail <email> [N] or use the popup interface in the menubar/status/channel/query windows..
  }
}

on *:unload:{
  unset %gmail*
  sockclose @gmail.*
  close -@ @gmail.*
  .timer@gmail.* off
  echo -ac info * Gmail checker: addon unloaded.
}

; Code for retrieving cookie with COM, only issued once per email account.

alias -l gmail_getcookie {
  var %e = echo -ac info * Gmail checker:
  gmail $1 pass $input(Enter your gmail password for account $gmail($1,email),po)
  if (* !iswm $gmail($1,pass)) {
    %e you did not fill in the password... aborting.
    gmail_cleanup $1
  }
  else {
    %e retrieving cookie... this may take a while, depending on your connection.

    ; Uncomment the following two lines to see how the cookie is actually retrieved:
    ; 
    ; .comopen $1 internetexplorer.application
    ; !.echo -q $com($1,visible,4,bool,true)

    ie.navigate $1 http://mail.google.com/mail/?logout
    gmail_timer $1
  }
}

alias -l gmail_timer .timer $+ $1 -m 50 400 gmail_check $1

alias -l gmail_check {

  ; do not change the way the if/elseif/else's are structured,
  ; even if it may seem to you like they could be simplified with
  ; && or || etc. They are put like that for a good reason.

  if ($ie.prop($1,readystate) == 4) {
    var %url = $ie.prop($1,locationurl)
    if (!$gmail($1,login)) {
      if (*ServiceLogin* iswm %url) { 
        .timer $+ $1 off
        gmail $1 login 1 
        gmail_login $1 
      }
    }
    else {
      if (http://mail.google.com/mail/* iswm %url) {
        gmail $gmail($1,email) cookie $ie.cookie($1)
        .timer $+ $1 off
        checkgmail $gmail($1,email) $gmail($1,num) $1
      }
      elseif (%url == https://www.google.com/accounts/ServiceLoginAuth) gmail_error 3 $1
    }
  }
  elseif (!$timer($1).reps) gmail_error 1 $1
}

alias -l gmail_error {
  var %e = echo -ac info * Gmail checker:
  if ($1 == 1) %e unable to retrieve cookie for account $gmail($2,email) $+ , try again later.
  elseif ($1 == 2) %e an error has occurred, try again later. $&
    If the problem persists, delete the cookie by typing: /gmail_reset $gmail($2,email)
  elseif ($1 == 3) %e you've supplied the wrong email/pass, try again.
  gmail_cleanup $2
}

alias -l gmail_cleanup {
  .timer $+ $1 off
  if ($com($1)) .comclose $1 $com($1,quit,1)
  sockclose $1  
  close -@ $1
  unset $+(%,gmail.,$1,.*) 
  unset %gmail.session
}

alias -l gmail_login {
  var %t
  %t = $com($1,document,3,dispatch* ie.doc)
  .comclose ie.doc $com(ie.doc,getelementbyid,1,bstr*,gaia_loginform,dispatch* ie.form)
  %t = $com(ie.form,email,2,dispatch* ie.form.email)
  .comclose ie.form.email $com(ie.form.email,value,4,bstr*,$gmail($1,email))
  %t = $com(ie.form,passwd,2,dispatch* ie.form.passwd)
  .comclose ie.form.passwd $com(ie.form.passwd,value,4,bstr*,$gettok($gmail($1,pass),1,32))
  %t = $com(ie.form,submit,1)
  .comclose ie.form
  gmail_timer $1
  return
  :error
  tokenize 32 ie.doc ie.form ie.form.email ie.form.passwd
  scon -r if ($com( $* )) .comclose $*
  gmail_error 1 $1
}

alias -l ie.navigate {
  if ($appactive) .timer 1 0 showmirc -s 
  if (!$com($1)) .comopen $1 internetexplorer.application
  $(,,$com($1,navigate,1,bstr*,$2))
}

alias -l ie.prop if ($com($1)) return $(,,$com($1,$2,2)) $com($1).result

alias -l ie.cookie {
  var %t
  if ($com($1)) { 
    %t = $com($1,document,2,dispatch* ie.cookie)
    if ($com(ie.cookie)) {
      %t = $com(ie.cookie,cookie,2)
      %t = $com(ie.cookie).result
      .comclose ie.cookie
    }
  }
  $iif(%t,return %t,gmail_error 1 $1)
}