# Author: Bhavik Shah
# Description: Simple script that uses the python imap library
# to retrieve number of messages and unread messages from your
# imap email account.
###########################################################################
# Script retirado de: <http://bhaviksblog.com/03/have-conky-check-your-email/>
# Editado e traduzido por Leandro NK <http://www.vivaolinux.com.br/perfil/verPerfil.php?login=%20leandro>
import imaplib
# Username should be your username with '@gmail.com' added
# I think the @gmail.com is required.
# If you're trying it with something other than gmail
# you should make the username the full email address
# example@domain.com
username = 'seulogin@gmail.com' # seu login
password = 'suasenha' # sua senha
mailbox = 'INBOX' # inbox is default
# only tested with gmail and my university email
# it should work with any imap server
# change mail server and port to match your server's info
mailserver = 'imap.gmail.com'
port = 993
# connect to gmail's server (uses SSL, port 993)
server = imaplib.IMAP4_SSL(mailserver,port)
# gmail uses ssl...if your imap mail server doesn't comment the above
# line and uncomment this one.
# server = imaplib.IMAP4(mailserver,port)
# login with the variables provided up top
server.login(username,password)
# select your mailbox
server.select(mailbox)
# pull info for that mailbox
data = str(server.status(mailbox, '(MESSAGES UNSEEN)'))
# print it all out
print # escreva um nome para exibir
print 'seunome@gmail.com'
tokens = data.split()
# clean up output with str_replace()
print 'Mensagens',tokens[3]
print 'Nao lidas',tokens[5].replace(')\'])','')
print
# close the mailbox
server.close()
# logout of the server
server.logout()