Check Gmail in Tonido Shell

Questions related to developing on the Tonido Platform
User avatar
Tonido MVP
Tonido MVP
Posts: 504
Joined: Sun Sep 05, 2010 6:21 pm

Check Gmail in Tonido Shell

Postby facelessuser » Thu Apr 28, 2011 1:19 pm

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.
Gmail script in action
gmail.jpg (22.47 KiB) Viewed 1505 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

Code: Select all

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


Return to “Tonido Platform Development”

Who is online

Users browsing this forum: No registered users and 1 guest