From: Menno Smits Date: Sat, 14 Nov 2009 15:30:03 +0000 (+0000) Subject: Prototype code for handling FETCHs directly X-Git-Tag: 0.7~59^2~22 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=37a30a8e2e0d9dcfa74a74b590799b046c86b215;p=imapclient.git Prototype code for handling FETCHs directly --- diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 055ec79..64a2674 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -448,6 +448,33 @@ class IMAPClient(object): return parser(data) + def altfetch(self, messages, parts): + if not messages: + return {} + + msg_list = messages_to_str(messages) + parts_list = seq_to_parenlist([p.upper() for p in parts]) + + if self.use_uid: + tag = self._imap._command('UID', 'FETCH', msg_list, parts_list) + else: + tag = self._imap._command('FETCH', msg_list, parts_list) + + print tag + lines = [] + while True: + line = self._imap._get_line() + if line.startswith(tag): + break + lines.append(line) + return lines + + #self._checkok('fetch', typ, data) + + #parser = FetchParser() + #return parser(data) + + def append(self, folder, msg, flags=(), msg_time=None): '''Append a message to a folder @@ -812,7 +839,11 @@ def datetime_to_imap(dt): ''' if not dt.tzinfo: dt = dt.replace(tzinfo=FixedOffset.for_system()) - return dt.strftime("%d-%b-%Y %H:%M:%S %z") - + +i = IMAPClient('127.0.0.1') +i.login('mailtest', 'foobar') +i.select_folder('INBOX') +i._imap.debug = 5 +print i.altfetch(1, ['FLAGS', 'RFC822']) diff --git a/run_altfetch.py b/run_altfetch.py new file mode 100644 index 0000000..3732590 --- /dev/null +++ b/run_altfetch.py @@ -0,0 +1,9 @@ +from pprint import pprint +from imapclient import IMAPClient + +i = IMAPClient('localhost') +i.login('mailtest', 'foobar') +i.select_folder('INBOX') +msgs = i.search() +print msgs +pprint(i.altfetch(msgs[0], 'RFC822'))