Changeset 201:f8f625bffdcb
- Timestamp:
- 01/27/11 13:21:41 (16 months ago)
- Author:
- Menno Smits <menno@…>
- Branch:
- default
- Parents:
- 200:ed6498330d85 (diff), 199:b796e986ac3b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
- Message:
-
Merged from trunk
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r195
|
r201
|
|
| 485 | 485 | |
| 486 | 486 | |
| 487 | | def fetch(self, messages, parts): |
| | 487 | def fetch(self, messages, parts, modifiers=None): |
| 488 | 488 | """Retrieve selected data items for one or more messages. |
| 489 | 489 | |
| 490 | 490 | @param messages: Message IDs to fetch. |
| 491 | 491 | @param parts: A sequence of data items to retrieve. |
| | 492 | @param modifiers: An optional sequence of modifiers. |
| 492 | 493 | @return: A dictionary indexed by message number. Each item is itself a |
| 493 | 494 | dictionary containing the requested message parts. |
| … |
… |
|
| 500 | 501 | msg_list = messages_to_str(messages) |
| 501 | 502 | parts_list = seq_to_parenlist([p.upper() for p in parts]) |
| | 503 | modifiers_list = None |
| | 504 | if modifiers is not None: |
| | 505 | modifiers_list = seq_to_parenlist([m.upper() for m in modifiers]) |
| 502 | 506 | |
| 503 | 507 | if self.use_uid: |
| 504 | | tag = self._imap._command('UID', 'FETCH', msg_list, parts_list) |
| | 508 | tag = self._imap._command('UID', 'FETCH', msg_list, parts_list, modifiers_list) |
| 505 | 509 | else: |
| 506 | | tag = self._imap._command('FETCH', msg_list, parts_list) |
| | 510 | tag = self._imap._command('FETCH', msg_list, parts_list, modifiers_list) |
| 507 | 511 | typ, data = self._imap._command_complete('FETCH', tag) |
| 508 | 512 | self._checkok('fetch', typ, data) |
-
|
r200
|
r201
|
|
| 6 | 6 | import imaplib |
| 7 | 7 | import response_lexer |
| | 8 | from operator import itemgetter |
| | 9 | import warnings |
| 8 | 10 | #imaplib.Debug = 5 |
| 9 | 11 | |
| … |
… |
|
| 30 | 32 | RECENT = r'\Recent' # This flag is read-only |
| 31 | 33 | |
| | 34 | class Namespace(tuple): |
| | 35 | def __new__(cls, personal, other, shared): |
| | 36 | return tuple.__new__(cls, (personal, other, shared)) |
| | 37 | |
| | 38 | personal = property(itemgetter(0)) |
| | 39 | other = property(itemgetter(1)) |
| | 40 | shared = property(itemgetter(2)) |
| | 41 | |
| 32 | 42 | |
| 33 | 43 | class IMAPClient(object): |
| … |
… |
|
| 70 | 80 | ReadOnlyError = imaplib.IMAP4.readonly |
| 71 | 81 | |
| 72 | | re_sep = re.compile('^\(\("[^"]*" "([^"]+)"\)\)') |
| 73 | 82 | re_status = re.compile(r'^\s*"?(?P<folder>[^"]+)"?\s+' |
| 74 | 83 | r'\((?P<status_items>.*)\)$') |
| … |
… |
|
| 134 | 143 | return False |
| 135 | 144 | |
| | 145 | def namespace(self): |
| | 146 | """Return the namespace for the account as a (personal, other, shared) tuple. |
| | 147 | |
| | 148 | Each element may be None if no namespace of that type exists, |
| | 149 | or a sequence of (prefix, separator) pairs. |
| | 150 | |
| | 151 | For convenience the tuple elements may be accessed |
| | 152 | positionally or attributes named "personal", "other" and |
| | 153 | "shared". |
| | 154 | |
| | 155 | See RFC 2342 for more details. |
| | 156 | """ |
| | 157 | typ, data = self._imap.namespace() |
| | 158 | self._checkok('namespace', typ, data) |
| | 159 | return Namespace(*parse_response(data)) |
| | 160 | |
| 136 | 161 | def get_folder_delimiter(self): |
| 137 | 162 | """Determine the folder separator used by the IMAP server. |
| 138 | 163 | |
| | 164 | WARNING: The implementation just picks the first folder |
| | 165 | separator from the first namespace returned. This is not |
| | 166 | particularly sensible. Use namespace instead(). |
| | 167 | |
| 139 | 168 | @return: The folder separator. |
| 140 | 169 | @rtype: string |
| 141 | 170 | """ |
| 142 | | typ, data = self._imap.namespace() |
| 143 | | self._checkok('namespace', typ, data) |
| 144 | | |
| 145 | | match = self.re_sep.match(data[0]) |
| 146 | | if match: |
| 147 | | return match.group(1) |
| 148 | | else: |
| 149 | | raise self.Error('could not determine folder separator') |
| | 171 | warnings.warn(DeprecationWarning('get_folder_delimiter is going away. Use namespace() instead.')) |
| | 172 | for part in self.namespace(): |
| | 173 | for ns in part: |
| | 174 | return ns[1] |
| | 175 | raise self.Error('could not determine folder separator') |
| 150 | 176 | |
| 151 | 177 | def list_folders(self, directory="", pattern="*"): |
| … |
… |
|
| 486 | 512 | self._checkok('fetch', typ, data) |
| 487 | 513 | typ, data = self._imap._untagged_response(typ, data, 'FETCH') |
| 488 | | # appears to be a special case - no 'untagged' responses (ie, no |
| 489 | | # folders) results in [None] |
| 490 | | if data == [None]: |
| 491 | | return {} |
| 492 | | |
| 493 | 514 | return parse_fetch_response(data) |
| 494 | 515 | |
| … |
… |
|
| 616 | 637 | typ, data = self._imap.store(msg_list, cmd, flag_list) |
| 617 | 638 | self._checkok('store', typ, data) |
| 618 | | |
| 619 | 639 | return self._flatten_dict(parse_fetch_response((data))) |
| 620 | 640 | |