Skip to content

Commit

Permalink
Adds new method for logging in using a UTF-8 username and password (#186
Browse files Browse the repository at this point in the history
)
  • Loading branch information
stumpylog authored Aug 31, 2022
1 parent 1506986 commit 559d76d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions imap_tools/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ def login(self, username: str, password: str, initial_folder: Optional[str] = 'I
self.login_result = login_result
return self # return self in favor of context manager

def login_utf8(self, username: str, password: str, initial_folder: Optional[str] = 'INBOX') -> 'BaseMailBox':
"""Authenicate to an account with a UTF-8 username and/or password"""

# rfc2595 section 6 - PLAIN SASL mechanism
encoded = (
b"\0"
+ username.encode("utf8")
+ b"\0"
+ password.encode("utf8")
)

# Assumption is the server supports AUTH=PLAIN capability
login_result = self.client.authenticate("PLAIN", lambda x: encoded)
check_command_status(login_result, MailboxLoginError)

if initial_folder is not None:
self.folder.set(initial_folder)
self.login_result = login_result

return self

def xoauth2(self, username: str, access_token: str, initial_folder: Optional[str] = 'INBOX') -> 'BaseMailBox':
"""Authenticate to account using OAuth 2.0 mechanism"""
auth_string = 'user={}\1auth=Bearer {}\1\1'.format(username, access_token)
Expand Down

0 comments on commit 559d76d

Please sign in to comment.