473,394 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

IMAP Tkinter Issue

Sorry to repost... but 4am didn't get much responses.

I've been trying to implement this script, it polls an IMAP inbox for
unread messages and displays the sender and subject in a scrollable
window using Tkinter. However, when I try to change the search
parameters on line 55 from 'unread' (UNSEEN) to 'read' (SEEN), the
tkinter window doesn't even pop up anymore.

Any idea how to change the parameters of this program and yet still keep
it functional?



my code: (if you can't see line 55, search for 'UNSEEN')


#!/usr/bin/env python
import imaplib, string, sys, os, re, rfc822
from Tkinter import *

PollInterval = 60 # seconds

def getimapaccount():
try:
f = open(('info.imap'))
except IOError, e:
print 'Unable to open ~/.imap: ', e
sys.exit(1)
global imap_server, imap_user, imap_password
try:
imap_server, imap_user, imap_password = string.split(f.readline())
except ValueError:
print 'Invalid data in ~/.imap'
sys.exit(1)
f.close()

class msg: # a file-like object for passing a string to rfc822.Message
def __init__(self, text):
self.lines = string.split(text, '\015\012')
self.lines.reverse()
def readline(self):
try: return self.lines.pop() + '\n'
except: return ''

class Mailwatcher(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack(side=TOP, expand=YES, fill=BOTH)
self.scroll = Scrollbar(self)
self.list = Listbox(self, font='7x13',
yscrollcommand=self.scroll.set,
setgrid=1, height=6, width=80)
self.scroll.configure(command=self.list.yview)
self.scroll.pack(side=LEFT, fill=BOTH)
self.list.pack(side=LEFT, expand=YES, fill=BOTH)

def getmail(self):
self.after(1000*PollInterval, self.getmail)
self.list.delete(0,END)
try:
M = imaplib.IMAP4(imap_server)
M.login(imap_user, imap_password)
except Exception, e:
self.list.insert(END, 'IMAP login error: ', e)
return

try:
result, message = M.select(readonly=1)
if result != 'OK':
raise Exception, message
typ, data = M.search(None, '(UNSEEN)')
for num in string.split(data[0]):
try:
f = M.fetch(num, '(BODY[HEADER.FIELDS (SUBJECT FROM)])')
m = rfc822.Message(msg(f[1][0][1]), 0)
subject = m['subject']
except KeyError:
f = M.fetch(num, '(BODY[HEADER.FIELDS (FROM)])')
m = rfc822.Message(msg(f[1][0][1]), 0)
subject = '(no subject)'
fromaddr = m.getaddr('from')
if fromaddr[0] == "": n = fromaddr[1]
else: n = fromaddr[0]
text = '%-20.20s %s' % (n, subject)
self.list.insert(END, text)
len = self.list.size()
if len > 0: self.list.see(len-1)
except Exception, e:
self.list.delete(0,END)
print sys.exc_info()
self.list.insert(END, 'IMAP read error: ', e)
M.logout()
getimapaccount()
root = Tk(className='mailwatcher')
root.title('mailwatcher')
mw = Mailwatcher(root)
mw.getmail()
mw.mainloop()
Mar 23 '06 #1
0 1100

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fabian Müller | last post by:
Hello, I would like to access (open) my remote IMAP Mailbox with the imap_open() function in PHP Version 5.0.4. The Mailbox is located at the german provider freenet.de. The imap_open()...
0
by: dekoffie | last post by:
Hello there, I'm trying to create a connection with an IMAP server which is secured through SSL. I can get the connection just fine, and I get a first respone from the server. But then I send...
0
by: Kevin F | last post by:
I've been trying to implement this script, it polls an IMAP inbox for unread messages and displays the sender and subject in a scrollable window using Tkinter. However, when I try to change the...
2
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
0
by: slimdizzy | last post by:
I have a bit of code that when using POP in the imap_open connect string it will return the filenames of the attachments, but when using IMAP it does not. Been racking my brain over this for a...
7
by: krishnakant Mane | last post by:
hello all, I seam to have noticed this a bit late but it appears to me that tkinter is being used very widely for gui development on all platform? is that right? since fredric lundh has written a...
44
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file...
0
by: wolfonenet | last post by:
Hi All, My setup is: WinXP Python 2.5.1 TKinter version: $Revision: 50704 $ Tcl: 8.4 Debugger: WinPdb
8
by: karthikbalaguru | last post by:
Hi, One of my python program needs tkinter to be installed to run successfully. I am using Redhat 9.0 and hence tried installing by copying the tkinter-2.2.2-36.i386.rpm alone from the CD 3 to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.