Advertisement
hbrown0579

Mail Speaker

Aug 19th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. import imaplib
  2. import os
  3. import email
  4. import email.header
  5. from time import sleep
  6.  
  7. while True:
  8.     getmail = imaplib.IMAP4_SSL('imap.gmail.com','993')
  9.     getmail.login('EMAIL','PASSWORD')
  10.     getmail.select('Inbox')
  11.     typ, data = getmail.search(None, 'ALL')
  12.     if len(getmail.search(None, 'ALL')[1][0].split()) > 0:
  13.         for num in data[0].split():
  14.             typ, data = getmail.fetch(num, '(RFC822)')
  15.         msg = email.message_from_string(data[0][1])
  16.         if msg.get_content_maintype() == 'multipart':
  17.             for part in msg.walk():
  18.                 if part.get_content_type() == "text/plain":
  19.                     content = part.get_payload(decode=True)
  20.         else:
  21.             content = msg.get_payload(decode=True)
  22.         content = content.strip()
  23.         decodesubj = email.header.decode_header(msg['Subject'])[0]
  24.         subject = unicode(decodesubj[0])
  25.         saycommand = 'aoss swift -n Callie "' + content + ' "'
  26.         print saycommand
  27.         if subject == "Say":
  28.             os.system(saycommand)
  29.         getmail.select('Inbox')
  30.         typ, data = getmail.search(None, 'ALL')
  31.         for num in data[0].split():
  32.             getmail.store(num, '+FLAGS', '\\Deleted')
  33.         getmail.expunge()
  34.         getmail.close()
  35.         getmail.logout()
  36.     else:
  37.         getmail.close()
  38.         getmail.logout()
  39.     sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement