From: Menno Smits Date: Sat, 19 Feb 2011 23:37:20 +0000 (+0000) Subject: resynced with trunk X-Git-Tag: 0.8~40 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=ab00ac1183d5c737da03cdaa35c85b85d0437768;p=imapclient.git resynced with trunk --- ab00ac1183d5c737da03cdaa35c85b85d0437768 diff --cc imapclient/imapclient.py index 7aae1eb,b2dd6c6..7288b89 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@@ -109,33 -156,38 +127,44 @@@ class IMAPClient(object) """ typ, data = self._imap.namespace() self._checkok('namespace', typ, data) + return Namespace(*parse_response(data)) - match = self.re_sep.match(data[0]) - if match: - return match.group(1) - else: - raise self.Error('could not determine folder separator') + def get_folder_delimiter(self): + """Determine the folder separator used by the IMAP server. + + WARNING: The implementation just picks the first folder + separator from the first namespace returned. This is not + particularly sensible. Use namespace instead(). + + @return: The folder separator. + @rtype: string + """ + warnings.warn(DeprecationWarning('get_folder_delimiter is going away. Use namespace() instead.')) + for part in self.namespace(): + for ns in part: + return ns[1] + raise self.Error('could not determine folder separator') def list_folders(self, directory="", pattern="*"): - """Get a listing of folders on the server. + """Get a listing of folders on the server as a list of + ``(flags, delimiter, name)`` tuples. - The default behaviour (no args) will list all folders for the logged in - user. + Calling list_folders with no arguments will list all + folders. - @param directory: The base directory to look for folders from. - @param pattern: A pattern to match against folder names. Only folder - names matching this pattern will be returned. Wildcards accepted. - @return: A list of (flags, delim, folder_name). Each folder name will - be either a string or a unicode string (if the folder on the - server required decoding). If the folder_encode attribute is - False, no decoding will be performed and only ordinary strings - will be returned. + Specifying *directory* will limit returned folders to that + base directory. Specifying *pattern* will limit returned + folders to those with matching names. Wildcards (``*`` and + ``?``) are supported in *pattern*. + + #XXX check wildcard facts + + Each folder name will be either a string or a unicode string + (if the folder on the server required decoding). If the + folder_encode attribute is False, no decoding will be + performed and only ordinary strings will be returned. + + #XXX check the above is still true """ return self._do_list('LIST', directory, pattern) @@@ -437,29 -512,23 +471,24 @@@ typ, data = self._imap._command_complete('FETCH', tag) self._checkok('fetch', typ, data) typ, data = self._imap._untagged_response(typ, data, 'FETCH') - # appears to be a special case - no 'untagged' responses (ie, no - # folders) results in [None] - if data == [None]: - return {} - return parse_fetch_response(data) - def append(self, folder, msg, flags=(), msg_time=None): - """Append a message to a folder - - @param folder: Folder name to append to. - @param msg: Message body as a string. - @param flags: Sequnce of message flags to set. If not specified no - flags will be set. - @param msg_time: Optional date and time to set for the message. The - server will set a time if it isn't specified. If msg_time contains - timezone information (tzinfo), this will be honoured. Otherwise the - local machine's time zone sent to the server. - @type msg_time: datetime.datetime - @return: The append response returned by the server. - @rtype: str + """Append a message to *folder*. + + *msg* should be a string contains the full message including + headers. + + *flags* should be a sequence of message flags to set. If not + specified no flags will be set. + + *msg_time* is an optional datetime instance specifying the + date and time to set on the message. The server will set a + time if it isn't specified. If *msg_time* contains timezone + information (tzinfo), this will be honoured. Otherwise the + local machine's time zone sent to the server. + + Returns the APPEND response as returned by the server. """ if msg_time: time_val = '"%s"' % datetime_to_imap(msg_time) @@@ -554,9 -637,9 +583,8 @@@ else: typ, data = self._imap.store(msg_list, cmd, flag_list) self._checkok('store', typ, data) - return self._flatten_dict(parse_fetch_response((data))) - def _flatten_dict(self, fetch_dict): return dict([ (msgid, data.values()[0])