This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Gmail Notify Channel

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Gmail Notify Channel

Post by BigToe »

Hey there, after looking for quite a while and finding nothing i thought this would be the most appropriate forum to write the following request

I need a script that will fetch from my gmail account any new email received and labelled under 'my friends label' and will write to channel #friends the subject of that email.

Thank you
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

You can take a look at this script

Code: Select all

######################################################################################
# GMAIL Notifier #################################################### v.0.12 #########
################################################### from game_over ###################
# NEED OPENSSL AND TLS PACKAGE TO WORK ###############################################
package require tls 1.4 ;                                                            #
###### Info ##########################################################################
# This is script who shows you RSS feed from your gmail mail profile under SSL       #
# connection, emulation of base64 tcl pure encoding and custom browser using cookies.#
# In this script i try to get efect like your browser do because if you use direct   #
# link to your mail you may be hacked. I recommend you to use this script only in    #
# your local machines. If you use this script don't forget to secure your machine.   #
# Tcl is open sourse and everyone can read your private data.                        #
###### Settings ######################################################################
# set here your email ################################################################
set gacc "your mail here@gmail.com"
# set here your password #############################################################
set gpass "your password here"
# set your nickname in irc ###########################################################
set gnick "your nick here"
# autochesk your mail and if you have new msg (in minutes) ###########################
set gresponce 10
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##
set ::defnick 0
set ::SetCookie ""
if {[timerexists {checkmail $::botnick "" "" ""}]==""} {set ::starGttime [timer $gresponce {checkmail $::botnick "" "" ""}]}
bind msg - !gmail checkmail
bind DCC -|- gread readmail
proc checkmail {nick host hand text} {
	global gpass gacc gresponce
	set abc [split "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ""]
	set para ""; set gipm [split "$gacc:$gpass" ""]; set Bpat ""; set bcount 0; set bnum ""; set nam ""
	foreach mpig $gipm {binary scan $mpig B* X; set Bpat "$Bpat$X"}
	foreach sixbits [split $Bpat ""] {
		if {$bcount == 5} {binary scan [binary format B8 00$bnum$sixbits] c1 bnum; set para "$para[lindex $abc $bnum]"; set bnum ""; set bcount 0} else {set bnum "$bnum$sixbits"; incr bcount 1}
	}
	if {$nick != $::botnick} {set ::defnick 1}
	if {$bcount != 5 && $bcount != 0} {set nam [expr 6 - $bcount]; set bnum "$bnum[string repeat 0 $nam]"; binary scan [binary format B8 00$bnum] c1 bnum; set para "$para[lindex $abc $bnum]"}
	set Gsock [::tls::socket -async mail.google.com 443]
	set ::Gltv $Gsock ; after 3000 check_for_web
	fconfigure $Gsock -buffering line -encoding binary
	puts $Gsock "GET /mail/feed/atom/ HTTP/1.0"
	puts $Gsock "Accept: */*"
	puts $Gsock "Host: mail.googlel.com"
	if {$::SetCookie != ""} {puts $Gsock "Cookie: $::SetCookie"}
	puts $Gsock "Authorization: Basic $para[string repeat = [expr $nam / 2]]"
	puts $Gsock "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
	puts $Gsock "Content-Type: text/html"
	puts $Gsock ""
	fileevent $Gsock readable "readGmail $Gsock"
	if {[timerexists {checkmail $::botnick "" "" ""}]==""} {set ::starGttime [timer $gresponce {checkmail $::botnick "" "" ""}]}
}

proc check_for_web {} {
	global gnick
	if {$::Gltv != 0} {
		if {$::defnick==1} {putquick "PRIVMSG $gnick :Request timed out!"}
	}
}

proc readGmail {k} {
	set dfl ""
	while {[gets $k data] >= 0} {
		set data [string map { \{ "" \} "" \" ""} $data]
		if {[string match *Set-Cookie:* $data] && $::SetCookie == ""} {set ::SetCookie [string map {";" ""} [lindex $data 1]]}
		if {[string match *</feed>* $data]} {set ::Gltv 0}
		append dfl "$data\n"; unset data
	}
	readgm [split $dfl \n]; close $k;
}
set ::emils 0
proc readgm {lin} {
	global gnick
	if {$::Gltv != 0} {return 0}
	if {[regexp -all {<fullcount>(.*?)</fullcount>} $lin -> mails] == 1 && $::defnick == 1} {
		putquick "PRIVMSG $gnick :You have $mails emails! Type on DCC .gread <num of email> to read titles!"
	} elseif {[regexp -all {<fullcount>(.*?)</fullcount>} $lin -> mails] == 1 && $::defnick == 0 && $::emils < $mails} {
		putquick "PRIVMSG $gnick :You have new email! Type on DCC .gread <num of email> to read titles!"
	} else {return 0}; set ::emils $mails
	set begin [lsearch -regexp $lin "<fullcount>"]; set count 0; set f 0; set ::titlet ""; set ::summary ""; set ::namet ""; set ::mailt ""; set ::issyt ""
	foreach nil $lin {
		if {$begin < $count} {
			if {[regexp {<title>(.*?)</title>} $nil -> title] == 1} {append ::titlet " [string map "{{}} -" [list "$title"]]"}
			if {[regexp {<summary>(.*?)</summary>} $nil -> summar] == 1} {append ::summary " [string map "{{}} -" [list "$summar"]]"}
			if {[regexp {<issued>(.*?)</issued>} $nil -> issy] == 1} {append ::issyt " [string map "{{}} -" [list "$issy"]]"}
			if {[string mat *<author>* $nil]} {set f 1} elseif {[string mat *</author>* $nil]} {set f 0}
			if {[regexp {<name>(.*?)</name>} $nil -> name] == 1 && $f == 1} {append ::namet " [string map "{{}} -" [list "$name"]]"}
			if {[regexp {<email>(.*?)</email>} $nil -> mail] == 1 && $f == 1} {append ::mailt " [string map "{{}} -" [list "$mail"]]"}
		}
		incr count 1
	}
	unset begin; unset count
}
proc readmail {handle idx text} {
	global gnick
	if {$handle!=$gnick} {return 0}
	if {[string is digit -strict -failindex 1234567890 [lindex $text 0]]==1 && [lindex $text 0]<=[llength $::titlet] && [llength $::titlet]>0 && [lindex $text 0]>0} {
		set text [expr [lindex $text 0] - 1]; putquick "PRIVMSG $gnick : Title:[lindex [lindex $::titlet $text] 0] Summary:[lindex $::summary $text] Name:[lindex $::namet $text] Email:[lindex $::mailt $text] Date:[lindex $::issyt $text]"
	} else {putquick "PRIVMSG $gnick : ERR: You don't have this number of letters!"; return 0}
}
Post Reply