#!/usr/bin/env python ### Check Gmail for new mail and alert via mobile phone (K790i) ### # probably works with all sony ericsson phones # Copyright 2009 Ertug Karamatli # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . MAIL = '' PASS = '' import time import sys import libgmail import bluetooth def bt_conn(): try: sockfd = bluetooth.BluetoothSocket(bluetooth.RFCOMM) sockfd.connect(('00:18:13:AC:C6:D6', 1)) sockfd.send('AT*SEUIS=1\n\r') time.sleep(1) except bluetooth.BluetoothError: print 'bt error: trying recon recurs' sockfd = bt_conn() time.sleep(2) return sockfd def gmail_conn(): print 'Loging in' ga = libgmail.GmailAccount(MAIL, PASS) ga.login() print 'Login ok' return ga #def lert_by_sound(): def alert_by_tel(): msg=str(count) + ' yeni mail' print msg sockfd.send('AT+CRMP=5\n\r') time.sleep(1) sockfd.send('AT*SELERT="'+msg+'",6,1\n\r') time.sleep(3) sockfd.send('AT*SEDEL=1\n\r') time.sleep(1) sockfd.send('AT+CRMP=0\n\r') time.sleep(1) if sys.argv[1] == 'tel': sockfd = bt_conn() ga = gmail_conn() c_prev=-1 while 1: try: count = ga.getUnreadMsgCount() if count > c_prev: c_prev=count time.sleep(60) except bluetooth.BluetoothError: print 'bt error: trying recon' sockfd = bt_conn() time.sleep(2) except: print 'gmail error: trying recon' ga = gmail_conn() time.sleep(2) sockfd.close() def get_mail(): folder = ga.getUnreadMessages() for thread in folder: #print thread.id, len(thread), thread.subject for msg in thread: print " ", msg.id, msg.number, msg.subject print msg.source