Changeset 143:b09900646458
- Timestamp:
- 29/04/10 22:10:51 (22 months ago)
- Author:
- Menno Smits <menno@…>
- Branch:
- default
- Message:
-
#42: Folder names with double quotes around them have the double quotes stripped
Work around an imaplib misfeature which prevents quoting when folder names
start and end with double quotes.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r135
|
r143
|
|
| 329 | 329 | typ, data = self._imap.list('', self._encode_folder_name(folder)) |
| 330 | 330 | self._checkok('list', typ, data) |
| | 331 | data = [x for x in data if x] |
| 331 | 332 | return len(data) == 1 and data[0] != None |
| 332 | 333 | |
| … |
… |
|
| 629 | 630 | def _encode_folder_name(self, name): |
| 630 | 631 | if self.folder_encode: |
| 631 | | return imap_utf7.encode(name) |
| 632 | | return name |
| | 632 | name = imap_utf7.encode(name) |
| | 633 | # imaplib assumes that if a command argument (in this case a |
| | 634 | # folder name) has double quotes around it, then it doesn't |
| | 635 | # need quoting. This "feature" prevents creation of folders |
| | 636 | # with names that start and end with double quotes. |
| | 637 | # |
| | 638 | # To work around this IMAPClient performs the quoting |
| | 639 | # itself. This adds start and end double quotes which also |
| | 640 | # serves to fool IMAP4._checkquote into not attempting further |
| | 641 | # quoting. A hack but it works. |
| | 642 | return _quote_arg(name) |
| 633 | 643 | |
| 634 | 644 | |
| … |
… |
|
| 671 | 681 | |
| 672 | 682 | |
| | 683 | def _quote_arg(arg): |
| | 684 | arg = arg.replace('\\', '\\\\') |
| | 685 | arg = arg.replace('"', '\\"') |
| | 686 | return '"%s"' % arg |
-
|
r142
|
r143
|
|
| 117 | 117 | |
| 118 | 118 | self.client.append('foobar', sentinel.msg, ['FLAG', 'WAVE'], None) |
| 119 | | |
| | 119 | |
| 120 | 120 | self.assert_(self.client._imap.method_calls == |
| 121 | | [('append', ('foobar', |
| | 121 | [('append', ('"foobar"', |
| 122 | 122 | '(FLAG WAVE)', |
| 123 | 123 | None, |
| … |
… |
|
| 136 | 136 | self.assert_(datetime_to_imap.called) |
| 137 | 137 | self.assert_(self.client._imap.method_calls == |
| 138 | | [('append', ('foobar', |
| | 138 | [('append', ('"foobar"', |
| 139 | 139 | '(FLAG WAVE)', |
| 140 | 140 | '"somedate"', |
-
|
r140
|
r143
|
|
| 144 | 144 | |
| 145 | 145 | test_folders = ['foobar', |
| | 146 | '"foobar"', |
| | 147 | 'foo "bar"', |
| 146 | 148 | 'stuff & things', |
| 147 | 149 | u'test & \u2622'] |
| … |
… |
|
| 153 | 155 | |
| 154 | 156 | assert client.folder_exists(folder) |
| 155 | | assert folder in extract_normal_folders(client.list_folders()) |
| | 157 | assert folder in extract_normal_folders(client.list_folders()), repr(folder) |
| 156 | 158 | |
| 157 | 159 | client.select_folder(folder) |