Jump to content


Traytip on new Gmail...


  • Please log in to reply
15 replies to this topic

#1 Joelh

Joelh
  • Guests

Posted 31 March 2007 - 09:59 AM

Script for checking new gmails. It is dependent on xmlread.ahk, and it uses the gmail atom function.

#Include XMLRead.ahk ; includes the function 
settimer, checkgmail, 300000 ; checks every 5th minute

checkgmail:
file = gmail.xml
URLDownloadToFile, https://username:password@mail.google.com/mail/feed/atom, %file% ; 
gfrom := XMLRead(file, "feed.entry.author.email")
gtitle := XMLRead(file, "feed.entry.title")
if gfrom contains @ ; traytip only shows if new mail
TrayTip, From: %gfrom%, %gtitle%, 10
filedelete gmail.xml
return



#2 majkinetor

majkinetor
  • Fellows
  • 4511 posts

Posted 31 March 2007 - 10:09 AM

great

#3 toralf

toralf
  • Fellows
  • 3948 posts

Posted 31 March 2007 - 11:17 AM

Thanks for sharing.

Ever considered to sign in?


Any chance to update this to the newer XPath?

For users looking for the XML Read file, here is the link.

#4 majkinetor

majkinetor
  • Fellows
  • 4511 posts

Posted 31 March 2007 - 11:21 AM

THis also reveals goood method to log into your specific account via bookmark, if you set:

https://username:password@mail.google.com/mail/


with your name and pass.

So if you have 3 accounts, you bookmark eatch of them and you can forget about logon.

#5 toralf

toralf
  • Fellows
  • 3948 posts

Posted 31 March 2007 - 11:25 AM

But then you would have your username and password in ascii format on your disc. For firefox there is an extension GMail Manager that handles multiple GMail accounts, but I'm not sure how and where it stores passwords, thus I do not know how much more secure it is. Just my two cents.

BTW: I like you sig.

#6 majkinetor

majkinetor
  • Fellows
  • 4511 posts

Posted 31 March 2007 - 02:03 PM

But then you would have your username and password in ascii format on your disc.

ofc, but that is not the problem simtimes.

#7 joelh

joelh
  • Guests

Posted 04 April 2007 - 01:50 PM

glad you appriciated the other one, this one is not dependent on xmlread, and its abit more discreet

settimer, checkgmail, 300000  

checkgmail:
file = gmail.xml
URLDownloadToFile, https://username:password@mail.google.com/mail/feed/atom, %file%
FileRead, gfrom, %file%
if gfrom contains <email>
menu, tray, icon, someicon.ico
else 
menu, tray, icon, someothericon.icl
filedelete %file%
return


#8 holomind

holomind
  • Members
  • 341 posts

Posted 07 April 2007 - 02:56 AM

great idea, because the original notifier (windows) from google itself sucks ;)
the version for mac on the other hand is quite good.
(the left hand does not know what the right hand does in that company)

is there a way to set an email to "has been read" via the tray icon /atom ?.
eg. if its spam i dont want to open gmail, but get rid of the notifier message.

one workaround could be to get the link in the atom for reading this mail and simply download it like the atom.xml and not open a browserwindow like the original gmail-tray-tool does. because if you open the email for read it is marked as read.

#9 infogulch

infogulch
  • Moderators
  • 717 posts

Posted 14 June 2008 - 01:08 PM

This is a version that requires: xpath in your library, or #Included.

It sees the difference between "New" messages and "Unread" messages.
[*:2kw765km]"New" Messages are messages that the function hasn't seen yet, so it displays a TrayTip Telling you.
After that, it stores the ID of the newest message, and later when it checks agian, it only notifies you if the ID is different.
[*:2kw765km]"Unread" messages are just that: ones marked "Unread" in your Inbox. The TrayTip always shows the number of unread
messages whenever it displays.
[*:2kw765km]If you call the function directly, it will always display a TrayTip, even if there are no "New" messages, but it will still tell you
how many "Unread" ones there are in your Inbox.Kind of like your suggestion to set it "read", holomind.
;  ###  Useage Example:

;Change the username & password below.
GmailInfo("https://[color=red]username:password[/color]@mail.google.com/mail/feed/atom")
F12::GmailInfo()


;  ###   Code:

GmailInfo( pUrl = "", pCheckPeriod = 120, pTrayTimeout = 10)
; pUrl:		    This is saved between calls, so is not necessary to call but once
; pCheckPeriod	Time in secods between checks
; pTrayTimeout	Time in seconds for the TrayTip to display if it finds a new message.
{
	static sUrl, sFile, sNewestID, sTrayTimeout

	ShowTipNow = 1
	sFile := A_Temp . "gmailmessages.xml"
	sUrl  := (pUrl ? pUrl : (sUrl ? sUrl : "https://username:password@mail.google.com/mail/feed/atom"))
	sTrayTimeout := pTrayTimeout*1000
	pCheckPeriod *= 1000
	
	If (pCheckPeriod) {
		If pCheckPeriod is Integer
			SetTimer, GmailInfo_CheckNew, %pCheckPeriod%
	}
	Else {
		SetTimer, GmailInfo_CheckNew, Off
		return
	}
	
	GmailInfo_CheckNew:
		URLDownloadToFile, %sUrl%, %sFile%
		FileRead, FileContents, %sFile%
		
		xPath_Load(FileContents, sFile)
		UnreadCount := xPath(FileContents, "/feed/fullcount/text()")
		NewCount = 0
		Info = (%UnreadCount% Unread)
		Loop %UnreadCount% {
			If ( xPath(FileContents, "/feed/entry[" . A_Index . "]/id/text()") = sNewestID)
				Break
			NewCount := A_Index
			Info .= "`n• " . xPath(FileContents, "/feed/entry[" . A_Index . "]/title/text()")
			Info .= "`n   From:  " . xPath(FileContents, "/feed/entry[" . A_Index . "]/author/name/text()")
;uncomment the next line to display the author's address next to their name. This uses more of the 256 max characters in a traytip though.
			;Info .= " (" . xPath(FileContents, "/feed/entry[" . A_Index . "]/author/email/text()") . ")"
		}
		sNewestID := xPath(FileContents, "/feed/entry[1]/id/text()")
		FileDelete, %sFile%	
		Info := c_decXML(Info)
		If NewCount
			TrayTip, %NewCount% New Gmail Messages!, %Info%
		Else If ShowTipNow
			TrayTip, No New Gmail Messages, %Info%
		SetTimer, TrayTipOff, -%sTrayTimeout%
	return
}

; See topic: http://www.autohotkey.com/forum/viewtopic.php?t=32693
c_decXML(str) {  
	Loop
		If RegexMatch(str, "&#\d+;", dec)        ; matches:   &#[dec];
			StringReplace, str, str, %dec%, % Chr(dec), All		;%
		Else If   RegexMatch(str, "i)&#x[\da-f]+;", hex)        ; matches    &#x[hex];
			StringReplace, str, str, %hex%, % Chr("0x" . hex), All		;%
		Else
			Break
	StringReplace, str, str,  , %A_Space%, All    ;some common character entities
	StringReplace, str, str, ", ", All
	StringReplace, str, str, ', ', All
	StringReplace, str, str, <, <, All
	StringReplace, str, str, >, >, All
	StringReplace, str, str, &, &, All     ;do this last so str doesn't resolve to other entities
	return, str
}

TrayTipOff:
	TrayTip
return
Any comments and suggestions appreciated!
Hope you like it! :)

#10 Krogdor

Krogdor
  • Members
  • 1391 posts

Posted 15 June 2008 - 01:56 AM

Here is my version:

gmail_check:
gmail_file = gmail.xml
URLDownloadToFile, https://[color=red]username:password[/color]@mail.google.com/mail/feed/atom, %gmail_file% 
gmail_msgnumber:=XMLRead(gmail_file, "feed.fullcount")
If (gmail_msgnumber)
{
	gmail_title := XMLRead(gmail_file, "feed.entry.title")
	xpath_load(xml,gmail_file)
	gmail_Link:=Regexreplace(Xpath(xml, "/feed/entry/link/@href/text()"),"(&)amp|;","$1")
	RegExMatch(gmail_Link, "i)(?<=message_id=)[A-Z0-9]+", gmail_Link)
	StringReplace, gmail_title, gmail_title, &, &&, A
	StringReplace, gmail_title, gmail_title, ', ', A
	StringReplace, gmail_title, gmail_title, ", ", A
	StringReplace, gmail_title, gmail_title, >, >, A
	StringReplace, gmail_title, gmail_title, <, <, A
	gmail_Link:="http://mail.google.com/mail/?source=navclient-ff#inbox/" . gmail_link
	If (gmail_msgnumber<>1)
	TP_Show("You have " gmail_msgnumber " new messages;`nClick me to view them.", "gmail_inbox", "Blue", "10", "White" ,10000, "gmail_inbox")
	Else
	TP_Show(gmail_title " `nFrom: " XMLRead(gmail_file, "feed.entry.author.name") "; " XMLRead(gmail_file, "feed.entry.author.email") "`n Click me to see your message."
        , "gmail_message", "Blue", "10", "White" ,10000, "gmail_inbox")
}
filedelete gmail.xml
return
gmail_message:
   Run %gmail_link%
return

gmail_inbox:
   Run http://mail.google.com/mail/?source=navclient-ff#inbox
return


Note that this is reliant on Xpath, XMLRead, and a rather modified version of Rhys's toaster popups:
TP_Show(TP_Message="Hello, World", ClickLabel1="", TP_FontColor="Blue", TP_FontSize="12", TP_BGColor="White", TP_Lifespan=0, RightClickLabel1="")
{
   Global TP_GUI_ID
   global clicklabel:=clicklabel1, rightclicklabel:=rightclicklabel1
   DetectHiddenWindows, On
   SysGet, Workspace, MonitorWorkArea
   Gui, 89:Destroy
   Gui, 89:-Caption +ToolWindow +LastFound +AlwaysOnTop +Border
   Gui, 89:Color, %TP_BGColor%
   Gui, 89:Font, s%TP_FontSize% c%TP_FontColor%
   Gui, 89:Add, Text, gTP_Fade, %TP_Message%
   Gui, 89:Show, Hide
   TP_GUI_ID := WinExist()
   WinGetPos, GUIX, GUIY, GUIWidth, GUIHeight, ahk_id %TP_GUI_ID%
   NewX := WorkSpaceRight-GUIWidth-5
   NewY := WorkspaceBottom-GUIHeight-5
   Gui, 89:Show, Hide x%NewX% y%NewY%

   DllCall("AnimateWindow","UInt",TP_GUI_ID,"Int",500,"UInt","0x00040008") ; TOAST!
   If (TP_Lifespan)
     SetTimer, TP_Fade2, % "-" TP_Lifespan
   Return
}


TP_Fade2:
   DllCall("AnimateWindow","UInt",TP_GUI_ID,"Int",1000,"UInt","0x90000") ; Fade out when clicked
   Gui, 89:Destroy
Return

TP_Fade:
   GetKeyState, RightMouseState, RButton, P
   DllCall("AnimateWindow","UInt",TP_GUI_ID,"Int",1000,"UInt","0x90000") ; Fade out when clicked
   Gui, 89:Destroy
   If RightMouseState = D
   {
	If (rightclicklabel)
	    Goto %rightclicklabel%
   }
   Else
   {
	If (clicklabel)
	    goto %clicklabel%
   }
Return

TP_Wait() {
  Global TP_GUI_ID
  WinWaitClose, ahk_id %TP_GUI_ID%
  return
}

Displays a nice little popup on a new message, you can click it to open the specific message, or right+left click to open your inbox.
If there is more than one new message, it will tell you the number of new messages and will link to the inbox no matter how you click it.

#11 infogulch

infogulch
  • Moderators
  • 717 posts

Posted 15 June 2008 - 05:43 AM

To Krogdor:XMLRead and XPath?? Man, do some consolidating!
no, no, jk jk :D :D ;)

I like your use of Toaster Popup, not as limited as the traytip. I think i'll change mine to use that instead. (btw, you can check the A_GuiEvent built in variable to see if the gui was right clicked or not. without having to get the mouse button state.)The problem with most of these is that if you don't want to read an email right away (or ever, if junkmail), it keeps nagging you about it, that's why holomind asked if there's a way to mark emails "read", to stop the notifier messages.

Hence, I'm checking message id's as another way to only display the notifier once, when a different email comes in, not just unread stuff you've got there already.
:)

#12 Krogdor

Krogdor
  • Members
  • 1391 posts

Posted 15 June 2008 - 05:58 AM

To Krogdor:
XMLRead and XPath?? Man, do some consolidating!
no, no, jk jk Very Happy Very Happy Wink

Yeah well, the original one came with XMLRead, and for my additions I used XPath.... its not like it'll take much effort for someone to change it :p

I like your use of Toaster Popup, not as limited as the traytip. I think i'll change mine to use that instead.

Thanks! :D

(btw, you can check the A_GuiEvent built in variable to see if the gui was right clicked or not. without having to get the mouse button state.)

Right, right... I made this a long time ago. I hadn't even began looking into GUIs at that time. Thanks for the reminder, I'll make the changes.

The problem with most of these is that if you don't want to read an email right away (or ever, if junkmail), it keeps nagging you about it, that's why holomind asked if there's a way to mark emails "read", to stop the notifier messages.

Hence, I'm checking message id's as another way to only display the notifier once, when a different email comes in, not just unread stuff you've got there already.

Mm, well I usually like to deal with my emails as soon as they come in (I'm a high school sophomore as of two days ago, so it's not like I'm getting too many emails) and this isn't really a problem for me... If you like, I can look into doing something like that? Summer = lots of free time xD You could probably do it better than me, though.

Edit: Alright, here's the modified version—relying only on XPath:
gmail_check:
[color=red]gmail_user=username
gmail_pass=password[/color]
URLDownloadToFile, https://%gmail_user%:%gmail_pass%@mail.google.com/mail/feed/atom, gmail.xml 
xpath_load(gmail_xml,"gmail.xml")
gmail_msgnumber:=XPath(gmail_xml, "/feed/fullcount/text()")
If (gmail_msgnumber)
{
	gmail_title := XPath(gmail_xml, "/feed/entry/title/text()")
	xpath_load(xml,gmail_file)
	gmail_Link:=Regexreplace(XPath(gmail_xml, "/feed/entry/link/@href/text()"),"(&)amp|;","$1")
	RegExMatch(gmail_Link, "i)(?<=message_id=)[A-Z0-9]+", gmail_Link)
	StringReplace, gmail_title, gmail_title, &, &&, A
	StringReplace, gmail_title, gmail_title, ', ', A
	StringReplace, gmail_title, gmail_title, ", ", A
	StringReplace, gmail_title, gmail_title, >, >, A
	StringReplace, gmail_title, gmail_title, <, <, A
	gmail_Link:="http://mail.google.com/mail/?source=navclient-ff#inbox/" . gmail_link
	If (gmail_msgnumber<>1)
	TP_Show("You have " gmail_msgnumber " new messages;`nClick me to view them.", "gmail_inbox", "Blue", "10", "White" ,10000, "gmail_inbox")
	Else
	TP_Show(gmail_title " `nFrom: " XPath(gmail_xml, "/feed/entry/author/name/text()") "; " XPath(gmail_xml, "/feed/entry/author/email/text()") "`n Click me to see your message."
        , "gmail_message", "Blue", "10", "White" ,10000, "gmail_inbox")
}
filedelete gmail.xml
return

gmail_message:
   Run % gmail_link
return

gmail_inbox:
   Run http://mail.google.com/mail/?source=navclient-ff#inbox
return

And the new Toaster Popups:
89GuiContextMenu:
  DllCall("AnimateWindow","UInt",TP_GUI_ID,"Int",1000,"UInt","0x90000") ; Fade out when clicked
  Gui, 89:Destroy
  If (rightclicklabel)
    Goto %rightclicklabel%
return

TP_Fade:
   DllCall("AnimateWindow","UInt",TP_GUI_ID,"Int",1000,"UInt","0x90000") ; Fade out when clicked
   Gui, 89:Destroy
	If (clicklabel)
	    goto %clicklabel%
Return
Just change the TP_Fade subroutine, and add the 89GuiContextMenu one... turns out that A_GuiEventInfo will only accept RightClicks from listview, treeview, and for context menus! So I had to add another label. But at least it enables just a right click instead of a left+right click, which annoyed me.

Enjoy~

#13 GMAILER

GMAILER
  • Guests

Posted 11 February 2010 - 05:29 PM

Sorry for bumping an very old thread, but I have a question for this =)! Does anyone still have that XMLread.ahk? I found the download link but it couldnt be used, please share it if you do ;P

#14 GMAILER

GMAILER
  • Guests

Posted 14 February 2010 - 08:36 PM

Sorry for bumping an very old thread, but I have a question for this =)! Does anyone still have that XMLread.ahk? I found the download link but it couldnt be used, please share it if you do ;P

Aaanyone?

#15 Flest

Flest
  • Guests

Posted 27 April 2010 - 09:33 AM

Sorry for bumping an very old thread, but I have a question for this =)! Does anyone still have that XMLread.ahk? I found the download link but it couldnt be used, please share it if you do ;P

You should just use XPath but if you really need XMLReader then the script and documentation is posted below.


XMLRead(source, tree, default = "") { ; v2.04 - by Titan
   If source is integer
   {
      DllCall("SetFilePointer", "UInt", source, "UInt", 0, "UInt", 0, "UInt", 0)
      s := VarSetCapacity(c, DllCall("GetFileSize", "UInt", source, "UInt", 0))
      DllCall("ReadFile", "UInt", source, "Str", c, "UInt", s, "UIntP", s, "UInt", 0)
   }
   Else FileRead, c, %source%
   StringGetPos, t, tree, @
   If (ErrorLevel = 0) {
      StringTrimLeft, a, tree, t + 1
      StringLeft, tree, tree, t
   }
   xc = %A_StringCaseSense%
   StringCaseSense, On
   d = >/%A_Tab%`r`n
   Loop, Parse, tree, .
   {
      e = %A_LoopField%
      i = 1
      StringGetPos, t, e, (
      If (ErrorLevel = 0) {
         StringMid, i, e, t + 2, InStr(e, ")") - t - 2
         StringLeft, e, e, t
         i++
      }
      Loop, Parse, d
         StringReplace, c, c, <%e%%A_LoopField%, <%e% %A_LoopField%, A
      ex := "<" . e . " "
      n = %A_Index%
      Loop {
         StringTrimLeft, c, c, InStr(c, ex, 1) -
         StringReplace, c, c, <, <, UseErrorLevel
         t = %ErrorLevel%
         StringReplace, c, c, />, />, UseErrorLevel
         t -= ErrorLevel
         StringReplace, c, c, </, </, UseErrorLevel
         If (t - ErrorLevel * 2) * -1 - n < 0 or x
            Break
         Else StringTrimLeft, c, c, 1
      }
      StringGetPos, t, c, %ex%, L%i%
      x += ErrorLevel
      StringTrimLeft, c, c, t
      t := InStr(c, "</" . e, 1)
      IfNotEqual, t, 0, StringLeft, c, c, t + StrLen(e) + 2
   }
   If a
      x := !(RegExMatch(c, ex . "[^>]*" . a . "=('|"")(.*?)\1", d) and c := d2)
   Else {
      t := InStr(c, "</" . e . ">", 1)
      x += !t
      StringMid, c, c, InStr(c, ">") + 1, t - 1 - InStr(c, ">")
   }
   StringCaseSense, %xc%
   If x
      c = %default%
   Return, c
}


XMLRead() [version 2.0]
------------------------------------
Reads data from an XML document.
Result := XMLRead(Source, Tree [, Default])

Parameters
Result   The actual value returned by the function. 
Source   The name or handle of the file to read from. Performance is dramatically improved when using a file handle.   
Tree   The complete path of the node using the format parent.child(index)@attribute where each index starts at 0.   
Default   The value to return if there is an error.   

Related

FileRead, IniRead, RegRead, XMLWrite(), XML Tutorial

Examples
; Example 1: get settings from a custom XML file

settings = settings.xml ; file name
version := XMLRead(settings, "application@version") ; 'version' attribute of 'application'
tip_colour := XMLRead(settings, "application.interface.control(2).colour") ; third index of 'control'
close_msg := XMLRead(settings, "application.messages.close", "Closing...") ; using default value of 'Closing...'


; Example 2: aggregate a list of most-downloaded programs on download.com

#Include XMLRead.ahk ; includes the function

title = XML Reader Example
href = http://export.cnet.com/export/download/rss-hot-download.com.com.xml

TrayTip, %title% - Downloading...
   , Downloading RSS XML from:`n%href%, 10, 1
file = %A_Temp%\cnet_%A_Now%.xml
URLDownloadToFile, %href%, %file%
If ErrorLevel { ; if download was unsucessful...
   TrayTip
   MsgBox, 18, %title% - Error, Downloading failed?, 5
   IfMsgBox, Abort
      ExitApp
   IfMsgBox, Retry
      Reload
}

Gui, Font, s14 underline
Gui, Add, Text, vTitle gVisitMain, % XMLRead(file, "rss.channel.title") ; RSS title
Gui, Font
Gui, Add, ListView, w600 r10 gVisit, #|Title|Description|Published

items = 7 ; there number of item elements to parse ...
Loop, %items% {
   LV_Add("", A_Index
      , XMLRead(file, "rss.channel.item(" . A_Index - 1 . ").title") ; item title
      , XMLRead(file, "rss.channel.item(" . A_Index - 1 . ").description") ; item description
      , XMLRead(file, "rss.channel.item(" . A_Index - 1 . ").pubDate")) ; item pubdate (date published)
   link%A_Index% := XMLRead(file, "rss.channel.item(". A_Index - 1 . ").link") ; store the item URL
}

IL := IL_Create(items)
LV_SetImageList(IL)
Loop, %items%
   IL_Add(IL, "shell32.dll", 14)

Loop, 4
   LV_ModifyCol(A_Index, "AutoHdr") ; auto-adjust columns

basex := XMLRead(file, "rss.channel.link") ; main URL
SplitPath, basex, , , , , base
StringReplace, base, base, http://
StringReplace, base, base, www.
StringReplace, base, base, /

Gui, Add, Button, Section w50 gGuiClose Default, &Close
Gui, Add, Text, ys+5, Double-click an item to view it on %base%
RSS := XMLRead(file, "rss@version") ; RSS version (attribute)
FileDelete, %file%
TrayTip
Gui, Show, , %title% - RSS Version %RSS%
Return

VisitMain:
Run, %basex%
Return

Visit:
If A_GuiEvent = DoubleClick
   Run, % link%A_EventInfo% ; opens item's link
Return

GuiClose:
ExitApp