Skip to content

Commit

Permalink
changed IMAP4 to IMAP4_ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
reind33r committed Sep 26, 2019
1 parent ddebfa8 commit 3089e59
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Radicale IMAP authentication plugin

IMAP authentication plugin for [Radicale](http://radicale.org/).
This is a simplification fork of [RadicaleIMAP](https://github.com/Unrud/RadicaleIMAP).
This is a fork of [radicale-imap](https://github.com/comzeradd/radicale-imap) that uses IMAP4_SSL instead of IMAP4 to initiate connection.

## Installation

Expand All @@ -11,8 +11,7 @@ This is a simplification fork of [RadicaleIMAP](https://github.com/Unrud/Radical

[auth]
type = radicale_imap
imap_host = address:port
imap_secure = True
imaps_host = address:port

## License

Expand Down
35 changes: 16 additions & 19 deletions radicale_imap/__init__.py
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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions setup.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 3089e59

Please sign in to comment.