root / pithos / im / target / oauth2 / clients / imap.py @ 552ea518
History | View | Annotate | Download (1.6 kB)
1 | 1a7c659b | Antony Chazapis | """
|
---|---|---|---|
2 | 1a7c659b | Antony Chazapis | The MIT License
|
3 | 1a7c659b | Antony Chazapis |
|
4 | 1a7c659b | Antony Chazapis | Copyright (c) 2007-2010 Leah Culver, Joe Stump, Mark Paschal, Vic Fryzel
|
5 | 1a7c659b | Antony Chazapis |
|
6 | 1a7c659b | Antony Chazapis | Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 1a7c659b | Antony Chazapis | of this software and associated documentation files (the "Software"), to deal
|
8 | 1a7c659b | Antony Chazapis | in the Software without restriction, including without limitation the rights
|
9 | 1a7c659b | Antony Chazapis | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 1a7c659b | Antony Chazapis | copies of the Software, and to permit persons to whom the Software is
|
11 | 1a7c659b | Antony Chazapis | furnished to do so, subject to the following conditions:
|
12 | 1a7c659b | Antony Chazapis |
|
13 | 1a7c659b | Antony Chazapis | The above copyright notice and this permission notice shall be included in
|
14 | 1a7c659b | Antony Chazapis | all copies or substantial portions of the Software.
|
15 | 1a7c659b | Antony Chazapis |
|
16 | 1a7c659b | Antony Chazapis | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 1a7c659b | Antony Chazapis | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 1a7c659b | Antony Chazapis | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19 | 1a7c659b | Antony Chazapis | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 1a7c659b | Antony Chazapis | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 1a7c659b | Antony Chazapis | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 1a7c659b | Antony Chazapis | THE SOFTWARE.
|
23 | 1a7c659b | Antony Chazapis | """
|
24 | 1a7c659b | Antony Chazapis | |
25 | 1a7c659b | Antony Chazapis | import oauth2 |
26 | 1a7c659b | Antony Chazapis | import imaplib |
27 | 1a7c659b | Antony Chazapis | |
28 | 1a7c659b | Antony Chazapis | |
29 | 1a7c659b | Antony Chazapis | class IMAP4_SSL(imaplib.IMAP4_SSL): |
30 | 1a7c659b | Antony Chazapis | """IMAP wrapper for imaplib.IMAP4_SSL that implements XOAUTH."""
|
31 | 1a7c659b | Antony Chazapis | |
32 | 1a7c659b | Antony Chazapis | def authenticate(self, url, consumer, token): |
33 | 1a7c659b | Antony Chazapis | if consumer is not None and not isinstance(consumer, oauth2.Consumer): |
34 | 1a7c659b | Antony Chazapis | raise ValueError("Invalid consumer.") |
35 | 1a7c659b | Antony Chazapis | |
36 | 1a7c659b | Antony Chazapis | if token is not None and not isinstance(token, oauth2.Token): |
37 | 1a7c659b | Antony Chazapis | raise ValueError("Invalid token.") |
38 | 1a7c659b | Antony Chazapis | |
39 | 1a7c659b | Antony Chazapis | imaplib.IMAP4_SSL.authenticate(self, 'XOAUTH', |
40 | 1a7c659b | Antony Chazapis | lambda x: oauth2.build_xoauth_string(url, consumer, token)) |