It is currently Sun Aug 30, 2015 4:48 am

All times are UTC - 6 hours [ DST ]

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Check Gmail in Tonido Shell
PostPosted: Thu Apr 28, 2011 1:19 pm 
Tonido MVP
Tonido MVP
User avatar
Joined: Sun Sep 05, 2010 6:21 pm
Posts: 504

Here is a little script that will tell you how many emails currently in your inbox or other folder you specify. It only gives you a summary, but I thought it was still niffty anyways.
File comment: Gmail script in action
gmail.jpg [ 22.47 KiB | Viewed 1465 times ]

This only works on the Plug!
This script taps into unix functionality to timeout the script. I am new to Python and do not know how to do similar functionality in windows yet.

This also works on any linux system from command line with python 2.5+ I believe. It might not work on python 3.0+.

This is provided as is, and I am not responsible if your plug explodes.

  • Download the script and save as
  • change the username and password field to your own.
  • place script on plug
  • chmod +x
  • launch script by specifying folder to check and max emails to list
  • example usage: ./ inbox 10

import sys
import socket
import urllib
import errno
import os
import signal
from xml.dom import minidom
from functools import wraps

username = "user"
password = "pass"
label    = str(sys.argv[1])
limit    = int(sys.argv[2])

class TimeoutError(Exception):

def timeout(seconds=10, error_message=os.strerror(errno.ETIME)):
    def decorator(func):
        def _handle_timeout(signum, frame):
            raise TimeoutError(error_message)

        def wrapper(*args, **kwargs):
            signal.signal(signal.SIGALRM, _handle_timeout)
                result = func(*args, **kwargs)
            return result

        return wrapper

    return decorator

GMAIL_URL = 'https://'+urllib.quote(username)+':'+urllib.quote(password)+''+urllib.quote(label)+'/'

def utfEncode(string):
    return unicode(string).encode('utf-8')

def printEmails(emails):
    print '%s: %s\n' %(utfEncode(emails['labelname']),utfEncode(emails['labelcount']))
    for email in emails['emails']:
        print 'Title:   %s'      %utfEncode(email['title'])
        print 'Sender:  %s <%s>' %(utfEncode(email['sender']),utfEncode(email['address']))
        print 'Summary: %s\n'    %utfEncode(email['summary'])

def getGmail(label,maxCount):
    url = GMAIL_URL
        xml = urllib.urlopen(url)
        dom = minidom.parse(xml)
        print '\nError: Could not get emails\n'
    mail = []
    for node in dom.getElementsByTagName('entry'):
        if maxCount == 0:
        author = node.getElementsByTagName('author')[0]
            'title'  : node.getElementsByTagName('title')[0],
            'summary': node.getElementsByTagName('summary')[0],
            'sender' : author.getElementsByTagName('name')[0],
            'address': author.getElementsByTagName('email')[0]
        maxCount -= 1
    count = dom.getElementsByTagName('fullcount')[0]
    return {
        'emails'    : mail,
        'labelname' : label,
        'labelcount': count


My Tonido Plugins:

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours [ DST ]

 Who is online

Users browsing this forum: No registered users and 0 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: