Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A little and simple GMail checker.
#
# Guia rapida
#
1. pygmail.py - Verifica los nuevos correos.
2. credentials.crd - Guarda sus credenciales encriptadas y es esencial para que pygmail.py funcione correctamente.
3. crypt_pygmail.py - Genera el archivo credentials.crd
4. Si usa crontab, es muy recomendable editar el valor de la variable "path_to_credentials_file" en el archivo pygmail.py para indicarle al programa exactamente donde encontrar el archivo credentials.crd
¿Problemas, sugerencias, etc? <luislopez72@gmail.com>
#
# Quick Guide
#
1. pygmail.py - Checks new Emails
2. credentials.crd - Stores your credentials crypted and is essential for pygmail.py to work correctly.
3. crypt_pygmail.py - Generates the credentials.crd file
4. If you use crontab, it's highly recomended you edit the value of "path_to_credentials_file" variable in pygmail.py to indicate to the program where exactly is the credentials.crd file.
Issues, suggestions,etc? <luislopez72@gmail.com>
#!/usr/bin/env python
# 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 <http://www.gnu.org/licenses/>.
###########################################################
# Created by Luis Lopez <luislopez72@gmail.com>
# CryptPyGMail v1.0
# filename: crypt_pygmail.py
###########################################################
from getpass import getpass
from base64 import encodestring
user = raw_input( "Su usuario de GMail: " )
passwd = getpass( "Pass [no vera lo que tipea]: " )
crypted = encodestring( "%s:%s" % (user, passwd)).replace( "\n", "" )
try:
f = open( "credentials.crd", "w" )
f.seek(0)
f.write( crypted )
f.close()
except IOError:
print "Error al crear el archivo credentials.crd verifique que puede crear archivos aqui :)"
exit()
#!/usr/bin/env python
# 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 <http://www.gnu.org/licenses/>.
###########################################################
# Created by Luis Lopez <luislopez72@gmail.com>
# PyGmail v2.1
# filename: pygmail.py
# note: You must install notify-send.
###########################################################
from urllib2 import Request, urlopen
from re import search
from os import system
#
# FUNCTIONS
#
# Display a message using a pop-up notification
def show_msg( text ):
notify = "notify-send -u normal 'GMail\n %s'" % text
system( notify )
# Return the user's crypted credentials from a file
def load_credentials( path ):
try:
f = open( path , "r" )
credentials = f.read()
f.close()
except IOError:
msg = "Error al abrir el archivo: %s" % str(path)
show_msg( msg )
exit()
return credentials
#
# MAIN CODE
#
# Path to the credentials file
credentials_file = "./credentials.crd"
# Check if the credentials file exists
credentials = load_credentials( credentials_file )
# Create the request object and add the Authorization header
request = Request( "https://mail.google.com/mail/feed/atom" )
request.add_header( "Authorization", "Basic %s" % str(credentials) )
# Get the GMail athom response
try:
response = urlopen( request )
except:
msg = "Error! Verifique su conexion o las credenciales de GMail por favor."
show_msg( msg )
exit()
# Get the number of unreaded Emails
for line in response:
matched = search( r"<fullcount>(?P<unreaded>\d+)</fullcount>", line )
if matched:
break
# Display the number of new emails
if int( matched.group("unreaded") ) != 0:
msg = "He encontrado %i email(s) sin leer" % int( matched.group("unreaded") )
show_msg( msg )
exit()
@hegosoft

This comment has been minimized.

Copy link

hegosoft commented Sep 18, 2019

Hola si quisiera en androide Borrar una Carpeta del Correo a la cual envio todos los anuncios y demas cosas de poca como seria el scrip para cada vez que lo ejecute si su tamaño es mayor de 50mb se borre o aunque no me pueda comprobar el tamaño que borre su contenido
puedes ayudar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.