Skip to content

Commit

Permalink
Upgrade to IMAPClient ver 0.13.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomi Richards committed Jul 5, 2015
1 parent cbcb79f commit 4747eb4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
8 changes: 0 additions & 8 deletions gmailfilter/_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from argparse import ArgumentParser

from gmailfilter._connection import (
IMAPServer,
IMAPConnection,
ServerInfo,
default_credentials_file_location,
Expand Down Expand Up @@ -64,10 +63,3 @@ def configure_argument_parser():
parser.add_argument('-v', '--verbose', action='store_true', help="Be more verbose")
parser.add_argument('--dev', action='store_true', help="Run new, development code.")
return parser.parse_args()


def get_rule_globals_dict():
rule_globals = {
'IMAPServer': IMAPServer
}
return rule_globals
10 changes: 5 additions & 5 deletions gmailfilter/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MessageConnectionProxy(object):
"""A class that knows how to retrieve additional message parts."""

def __init__(self, connection, initial_data):
assert 'UID' in initial_data
assert b'UID' in initial_data
self._connection = connection
self._data = initial_data

Expand All @@ -50,16 +50,16 @@ def get_message_part(self, part_name):
"""
# transform 'BODY.PEEK[HEADER]' into 'BODY[HEADER]'
if part_name.startswith('BODY.PEEK'):
retrieve_key = 'BODY' + part_name[9:]
if part_name.startswith(b'BODY.PEEK'):
retrieve_key = b'BODY' + part_name[9:]
else:
retrieve_key = part_name

# ask the server for 'part_name', but look in our dictionary with
# 'retrieve_key'
if retrieve_key not in self._data:
with self._connection.use_uid():
msg_uid = self._data['UID']
msg_uid = self._data[b'UID']
# for some reason, sometimes a fetch call returns an empty dict.
# until I find out why, I'll simply retry this:
data = {}
Expand Down Expand Up @@ -94,7 +94,7 @@ def get_messages(self):
"""
# TODO - perahps the user wants to filter a different folder?
mbox_details = self._client.select_folder("INBOX")
total_messages = mbox_details['EXISTS']
total_messages = mbox_details[b'EXISTS']
logging.info("Scanning inbox, found %d messages" % total_messages)
# TODO: Research best chunk size - maybe let user tweak this from
# config file?:
Expand Down
8 changes: 4 additions & 4 deletions gmailfilter/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, connection_proxy):
def _get_email(self):
if self._message is None:
self._message = email.message_from_string(
self._connection_proxy.get_message_part('BODY.PEEK[HEADER]')
self._connection_proxy.get_message_part(b'BODY.PEEK[HEADER]').decode()
)
return self._message

Expand All @@ -65,7 +65,7 @@ def list_id(self):
return parse_list_id(list_id) if list_id is not None else None

def uid(self):
return self._connection_proxy.get_message_part('UID')
return self._connection_proxy.get_message_part(b'UID')

def get_headers(self):
# TODO: email objects are dictionaries for the headers, but also expose
Expand All @@ -74,10 +74,10 @@ def get_headers(self):
return self._get_email()

def get_date(self):
return self._connection_proxy.get_message_part('INTERNALDATE')
return self._connection_proxy.get_message_part(b'INTERNALDATE')

def get_flags(self):
return self._connection_proxy.get_message_part('FLAGS')
return self._connection_proxy.get_message_part(b'FLAGS')

def __repr__(self):
return repr(self.subject())
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def run_tests(self):
packages=['gmailfilter'],
# packages=find_packages('gmailfilter'),
# test_suite='gmailfilter.tests',
install_requires=['IMAPClient==0.11'],
install_requires=['IMAPClient==0.13'],
entry_points={
'console_scripts': ['gmailfilter = gmailfilter._command:run']
},
Expand Down

0 comments on commit 4747eb4

Please sign in to comment.