forked from comzeradd/radicale-imap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
reind33r
committed
Sep 26, 2019
1 parent
ddebfa8
commit 3089e59
Showing
3 changed files
with
24 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# radicale-imap IMAP authentication plugin for Radicale. | ||
# Copyright (C) 2017 Unrud <[email protected]> | ||
# Copyright (C) 2018 Nikos Roussos <[email protected]>. | ||
# Copyright (C) 2019 Louis Guidez <[email protected]>. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -28,18 +29,14 @@ class Auth(BaseAuth): | |
[auth] | ||
type = radicale_imap | ||
imap_host = example.com:143 | ||
imap_secure = True | ||
imaps_host = example.com:143 | ||
""" | ||
|
||
def is_authenticated(self, user, password): | ||
# Parse configuration options | ||
host = '' | ||
if self.configuration.has_option('auth', 'imap_host'): | ||
host = self.configuration.get('auth', 'imap_host') | ||
secure = True | ||
if self.configuration.has_option('auth', 'imap_secure'): | ||
secure = self.configuration.getboolean('auth', 'imap_secure') | ||
if self.configuration.has_option('auth', 'imaps_host'): | ||
host = self.configuration.get('auth', 'imaps_host') | ||
try: | ||
if ':' in host: | ||
address, port = host.rsplit(':', maxsplit=1) | ||
|
@@ -50,23 +47,23 @@ def is_authenticated(self, user, password): | |
raise RuntimeError( | ||
'Failed to parse address %r: %s' % (host, e)) from e | ||
|
||
# Attempt connection with IMAP server | ||
# Attempt connection with IMAPs server | ||
try: | ||
connection = imaplib.IMAP4(host=address, port=port) | ||
connection = imaplib.IMAP4_SSL(host=address, port=port) | ||
except (OSError, imaplib.IMAP4.error) as e: | ||
raise RuntimeError('Failed to communicate with IMAP server %r: ' | ||
raise RuntimeError('Failed to communicate with IMAPs server %r: ' | ||
'%s' % (host, e)) from e | ||
|
||
# Upgrade connection to StartTLS | ||
context = ssl.create_default_context() | ||
if not secure: | ||
context.check_hostname = False | ||
context.verify_mode = ssl.CERT_NONE | ||
try: | ||
connection.starttls(context) | ||
except (imaplib.IMAP4.error, ssl.CertificateError) as e: | ||
raise RuntimeError('Failed to establish secure connection with %r: %s' | ||
% (host, e)) from e | ||
# context = ssl.create_default_context() | ||
# if not secure: | ||
# context.check_hostname = False | ||
# context.verify_mode = ssl.CERT_NONE | ||
# try: | ||
# connection.starttls(context) | ||
# except (imaplib.IMAP4.error, ssl.CertificateError) as e: | ||
# raise RuntimeError('Failed to establish secure connection with %r: %s' | ||
# % (host, e)) from e | ||
|
||
# Attempt to authenticate user | ||
try: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,12 @@ | |
|
||
|
||
setup( | ||
name='radicale-imap', | ||
version='0.1.2', | ||
author='Nikos Roussos', | ||
author_email='[email protected]', | ||
url='https://gitlab.com/comzeradd/radicale-imap/', | ||
description='Radicale IMAP authentication plugin', | ||
name='radicale-imaps', | ||
version='0.1.0', | ||
author='Louis Guidez', | ||
author_email='[email protected]', | ||
url='https://github.com/reind33r/radicale-imaps', | ||
description='Radicale IMAPs authentication plugin', | ||
include_package_data=True, | ||
zip_safe=False, | ||
packages=find_packages(), | ||
|