imapdb(query).select(imapdb.INBOX.sender, imapdb.INBOX.subject, imapdb.INBOX.seen), issue 1269, thanks Alan
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.4.1-alpha.2+timestamp.2013.01.10.23.11.16
|
Version 2.4.1-alpha.2+timestamp.2013.01.10.23.15.01
|
||||||
|
|||||||
+28
-24
@@ -5623,11 +5623,22 @@ class IMAPAdapter(NoSQLAdapter):
|
|||||||
# mapped names (which native
|
# mapped names (which native
|
||||||
# mailbox has what table name)
|
# mailbox has what table name)
|
||||||
|
|
||||||
db.mailboxes <dict> # tablename, server native name pairs
|
imapdb.mailboxes <dict> # tablename, server native name pairs
|
||||||
|
|
||||||
# To retrieve a table native mailbox name use:
|
# To retrieve a table native mailbox name use:
|
||||||
db.<table>.mailbox
|
imapdb.<table>.mailbox
|
||||||
|
|
||||||
|
### New features v2.4.1:
|
||||||
|
|
||||||
|
# Declare mailboxes statically with tablename, name pairs
|
||||||
|
# This avoids the extra server names retrieval
|
||||||
|
|
||||||
|
imapdb.define_tables({"inbox": "INBOX"})
|
||||||
|
|
||||||
|
# Selects without content/attachments/email columns will only
|
||||||
|
# fetch header and flags
|
||||||
|
|
||||||
|
imapdb(q).select(imapdb.INBOX.sender, imapdb.INBOX.subject)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
types = {
|
types = {
|
||||||
@@ -5848,11 +5859,6 @@ class IMAPAdapter(NoSQLAdapter):
|
|||||||
charset = message.get_content_charset()
|
charset = message.get_content_charset()
|
||||||
return charset
|
return charset
|
||||||
|
|
||||||
def reset_mailboxes(self):
|
|
||||||
"Forces the adapter to retrieve mailbox names from the server"
|
|
||||||
self.connection.mailbox_names = self.static_names = None
|
|
||||||
self.get_mailboxes()
|
|
||||||
|
|
||||||
def get_mailboxes(self):
|
def get_mailboxes(self):
|
||||||
""" Query the mail database for mailbox names """
|
""" Query the mail database for mailbox names """
|
||||||
if self.static_names:
|
if self.static_names:
|
||||||
@@ -5919,6 +5925,8 @@ class IMAPAdapter(NoSQLAdapter):
|
|||||||
if mailbox_names:
|
if mailbox_names:
|
||||||
# optional statically declared mailboxes
|
# optional statically declared mailboxes
|
||||||
self.static_names = mailbox_names
|
self.static_names = mailbox_names
|
||||||
|
else:
|
||||||
|
self.static_names = None
|
||||||
if not isinstance(self.connection.mailbox_names, dict):
|
if not isinstance(self.connection.mailbox_names, dict):
|
||||||
self.get_mailboxes()
|
self.get_mailboxes()
|
||||||
|
|
||||||
@@ -5965,7 +5973,7 @@ class IMAPAdapter(NoSQLAdapter):
|
|||||||
query = self.common_filter(query, [self.get_query_mailbox(query),])
|
query = self.common_filter(query, [self.get_query_mailbox(query),])
|
||||||
return str(query)
|
return str(query)
|
||||||
|
|
||||||
def select(self,query,fields,attributes):
|
def select(self, query, fields, attributes):
|
||||||
""" Search and Fetch records and return web2py rows
|
""" Search and Fetch records and return web2py rows
|
||||||
"""
|
"""
|
||||||
# move this statement elsewhere (upper-level)
|
# move this statement elsewhere (upper-level)
|
||||||
@@ -5998,18 +6006,22 @@ class IMAPAdapter(NoSQLAdapter):
|
|||||||
# ten records (change for non-experimental implementation)
|
# ten records (change for non-experimental implementation)
|
||||||
# However, light responses are not guaranteed with this
|
# However, light responses are not guaranteed with this
|
||||||
# approach, just fewer messages.
|
# approach, just fewer messages.
|
||||||
# TODO: change limitby single to 2-tuple argument
|
|
||||||
limitby = attributes.get('limitby', None)
|
limitby = attributes.get('limitby', None)
|
||||||
messages_set = search_result[1][0].split()
|
messages_set = search_result[1][0].split()
|
||||||
# descending order
|
# descending order
|
||||||
messages_set.reverse()
|
messages_set.reverse()
|
||||||
if limitby is not None:
|
if limitby is not None:
|
||||||
# TODO: asc/desc attributes
|
# TODO: orderby, asc/desc, limitby from complete message set
|
||||||
messages_set = messages_set[int(limitby[0]):int(limitby[1])]
|
messages_set = messages_set[int(limitby[0]):int(limitby[1])]
|
||||||
# Partial fetches are not used since the email
|
|
||||||
# library does not seem to support it (it converts
|
# keep the requests small for header/flags
|
||||||
# partial messages to mangled message instances)
|
if any([(field.name in ["content",
|
||||||
imap_fields = "(RFC822)"
|
"attachments", "email"]) for
|
||||||
|
field in fields]):
|
||||||
|
imap_fields = "(RFC822 FLAGS)"
|
||||||
|
else:
|
||||||
|
imap_fields = "(RFC822.HEADER FLAGS)"
|
||||||
|
|
||||||
if len(messages_set) > 0:
|
if len(messages_set) > 0:
|
||||||
# create fetch results object list
|
# create fetch results object list
|
||||||
# fetch each remote message and store it in memmory
|
# fetch each remote message and store it in memmory
|
||||||
@@ -6025,13 +6037,8 @@ class IMAPAdapter(NoSQLAdapter):
|
|||||||
"raw_message": data[0][1]}
|
"raw_message": data[0][1]}
|
||||||
fr["multipart"] = fr["email"].is_multipart()
|
fr["multipart"] = fr["email"].is_multipart()
|
||||||
# fetch flags for the message
|
# fetch flags for the message
|
||||||
ftyp, fdata = self.connection.uid("fetch", uid, "(FLAGS)")
|
fr["flags"] = self.driver.ParseFlags(data[1])
|
||||||
if ftyp == "OK":
|
fetch_results.append(fr)
|
||||||
fr["flags"] = self.driver.ParseFlags(fdata[0])
|
|
||||||
fetch_results.append(fr)
|
|
||||||
else:
|
|
||||||
# error retrieving the flags for this message
|
|
||||||
raise Exception("IMAP error retrieving flags: %s" % fdata)
|
|
||||||
else:
|
else:
|
||||||
# error retrieving the message body
|
# error retrieving the message body
|
||||||
raise Exception("IMAP error retrieving the body: %s" % data)
|
raise Exception("IMAP error retrieving the body: %s" % data)
|
||||||
@@ -6090,9 +6097,6 @@ class IMAPAdapter(NoSQLAdapter):
|
|||||||
# If there is no encoding found in the message header
|
# If there is no encoding found in the message header
|
||||||
# force utf-8 replacing characters (change this to
|
# force utf-8 replacing characters (change this to
|
||||||
# module's defaults). Applies to .sender, .to, .cc and .bcc fields
|
# module's defaults). Applies to .sender, .to, .cc and .bcc fields
|
||||||
#############################################################################
|
|
||||||
# TODO: External function to manage encoding and decoding of message strings
|
|
||||||
#############################################################################
|
|
||||||
item_dict["%s.sender" % tablename] = self.encode_text(message["From"], charset)
|
item_dict["%s.sender" % tablename] = self.encode_text(message["From"], charset)
|
||||||
if "%s.to" % tablename in fieldnames:
|
if "%s.to" % tablename in fieldnames:
|
||||||
item_dict["%s.to" % tablename] = self.encode_text(message["To"], charset)
|
item_dict["%s.to" % tablename] = self.encode_text(message["To"], charset)
|
||||||
|
|||||||
Reference in New Issue
Block a user