hello community of dreamincode, ive decided to write a python script to check my gmail account for new mail, its made of various pieces of code obtained from the interwebs:
and i get the following output in the stderr file:
sadly googleing for "python IMAP4.search "Bad file descriptor"" hasnt returned anything helpfull
thanks for any help
#!/usr/bin/python -O import daemon import time import os import signal import sys import imaplib class GmailCheckDaemon(daemon.DaemonContext): def __init__(self): super(GmailCheckDaemon, self).__init__() self.signal_map[signal.SIGTERM] = self.sigtermHandler self.stdout = open('/home/lapb/programs/gmailCheckDaemonStdOut.log', 'wb') self.stderr = open('/home/lapb/programs/gmailCheckDaemonStdErr.log', 'wb') self.mail = imaplib.IMAP4_SSL('imap.gmail.com','993') self.mail.login('myaddress@gmail.com','mypassword') self.mail.select() def run(self): with self: unreads = len(self.mail.search(None, 'UnSeen')[1][0].split()) if unreads > 0: popup = 'kdialog --title "New mail" --passivepopup "there are' + str(unreads) + 'unread emails" 1' os.system(popup) while True: oldunreads = unreads unreads = len(self.mail.search(None, 'UnSeen')[1][0].split()) count = unreads - oldunreads if count > 0: popup = 'kdialog --title "New mail" --passivepopup "there are' + str(count) + 'unread emails" 1' os.system(popup) time.sleep(60) def sigtermHandler(self, *args): self.mail.close() self.mail.logout() sys.exit(0) if __name__ == '__main__': daemon = GmailCheckDaemon() daemon.run()
and i get the following output in the stderr file:
Traceback (most recent call last): File "/home/lapb/programs/checkgmail.py", line 43, in <module> daemon.run() File "/home/lapb/programs/checkgmail.py", line 22, in run unreads = len(self.mail.search(None, 'UnSeen')[1][0].split()) File "/usr/lib/python2.7/imaplib.py", line 627, in search typ, dat = self._simple_command(name, *criteria) File "/usr/lib/python2.7/imaplib.py", line 1070, in _simple_command return self._command_complete(name, self._command(name, *args)) File "/usr/lib/python2.7/imaplib.py", line 859, in _command raise self.abort('socket error: %s' % val) imaplib.abort: socket error: [Errno 9] Bad file descriptor
sadly googleing for "python IMAP4.search "Bad file descriptor"" hasnt returned anything helpfull
thanks for any help