Skip to content

Commit

Permalink
Merge PR #4.
Browse files Browse the repository at this point in the history
Close #4
  • Loading branch information
iredmail committed Sep 9, 2019
1 parent 189e1da commit 67ee385
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 81 deletions.
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ python:
install:
- pip install -r requirements.txt

matrix: # allow Python 3 to fail until web.py is Py3-ready
allow_failures:
- python: "3.7"
git:
depth: 1

before_install: pip install --upgrade pip
install: pip install flake8 pytest -r requirements.txt

before_script: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
script:
- cd tests/
- bash main.sh

# Running unittests requires a fully-working iRedMail server.
#script:
# - cd tests/
# - bash main.sh
16 changes: 8 additions & 8 deletions backends/bk_iredmail_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self):
try:
# bind as vmailadmin
self.conn.bind_s(settings.iredmail_ldap_bind_dn, settings.iredmail_ldap_bind_password)
except Exception, e:
except Exception as e:
web.log_error('VMAILADMIN_INVALID_CREDENTIALS. Detail: %s' % repr(e))

def __del__(self):
Expand Down Expand Up @@ -297,15 +297,15 @@ def __add_or_remove_attr_value(dn, attr, value, action, conn=None):
conn.modify_s(dn, [(ldap.MOD_ADD, attr, str(v))])
except (ldap.NO_SUCH_OBJECT, ldap.TYPE_OR_VALUE_EXISTS):
pass
except Exception, e:
except Exception as e:
msg += str(e)
elif action in ['del', 'delete', 'remove', 'disable']:
for v in values:
try:
conn.modify_s(dn, [(ldap.MOD_DELETE, attr, str(v))])
except ldap.NO_SUCH_ATTRIBUTE:
pass
except Exception, e:
except Exception as e:
msg += str(e)
else:
return (False, 'UNKNOWN_ACTION')
Expand Down Expand Up @@ -344,7 +344,7 @@ def __get_primary_and_alias_domains(domain, with_primary_domain=True, conn=None)
return (True, all_domains)
else:
return (False, 'INVALID_DOMAIN_NAME')
except Exception, e:
except Exception as e:
return (False, repr(e))


Expand Down Expand Up @@ -411,7 +411,7 @@ def add_maillist(mail, form, conn=None):
conn.add_s(dn_ml, ldif_ml)
logger.info('Created: {0}.'.format(mail))
return (True, )
except Exception, e:
except Exception as e:
logger.error('Error while creating {0}: {1}'.format(mail, e))
return (False, repr(e))

Expand All @@ -434,7 +434,7 @@ def remove_maillist(mail, conn=None):
return (True, )
except ldap.NO_SUCH_OBJECT:
return (False, 'ACCOUNT_NOT_EXIST')
except Exception, e:
except Exception as e:
logger.error("Error: {0}".format(e))
return (False, repr(e))

Expand Down Expand Up @@ -491,7 +491,7 @@ def update_maillist(mail, form, conn=None):
return (True, )
except ldap.NO_SUCH_OBJECT:
return (False, 'ACCOUNT_NOT_EXIST')
except Exception, e:
except Exception as e:
return (False, repr(e))
else:
return (True, )
Expand Down Expand Up @@ -532,5 +532,5 @@ def get_existing_maillists(domains=None, conn=None):
existing_lists.update(_addresses)

return (True, existing_lists)
except Exception, e:
except Exception as e:
return (False, repr(e))
18 changes: 9 additions & 9 deletions backends/bk_iredmail_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self):
except (AttributeError, MySQLdb.OperationalError):
# Reconnect if error raised: MySQL server has gone away.
self.conn = self.__connect()
except Exception, e:
except Exception as e:
logger.error("SQL error: {0}".format(e))


Expand All @@ -77,7 +77,7 @@ def __init__(self):
user=settings.iredmail_sql_db_user,
pw=settings.iredmail_sql_db_password)
self.conn.supports_multiple_insert = True
except Exception, e:
except Exception as e:
logger.error("SQL error: {0}".format(e))


Expand Down Expand Up @@ -121,7 +121,7 @@ def is_domain_exists(domain, conn=None):

# Domain not exist
return False
except Exception, e:
except Exception as e:
# Return True as exist to not allow to create new domain/account.
logger.error("SQL error: {0}".format(e))
return True
Expand Down Expand Up @@ -159,7 +159,7 @@ def is_email_exists(mail, conn=None):
return True

return False
except Exception, e:
except Exception as e:
logger.error("SQL error: {0}".format(e))
return True

Expand All @@ -186,7 +186,7 @@ def is_maillist_exists(mail, conn=None):
return True

return False
except Exception, e:
except Exception as e:
logger.error("SQL error: {0}".format(e))
return True

Expand Down Expand Up @@ -305,7 +305,7 @@ def add_maillist(mail, form, conn=None):

logger.info('Created: {0}.'.format(mail))
return (True, )
except Exception, e:
except Exception as e:
logger.error('Error while creating {0}: {1}'.format(mail, e))
return (False, repr(e))

Expand All @@ -331,7 +331,7 @@ def remove_maillist(mail, conn=None):
where='address=$mail')

return (True, )
except Exception, e:
except Exception as e:
logger.error("SQL error: {0}".format(e))
return (False, repr(e))

Expand Down Expand Up @@ -396,7 +396,7 @@ def update_maillist(mail, form, conn=None):
conn.multiple_insert('moderators', records)

return (True, )
except Exception, e:
except Exception as e:
return (False, repr(e))


Expand Down Expand Up @@ -432,5 +432,5 @@ def get_existing_maillists(domains=None, conn=None):
existing_lists.add(_addr)

return (True, list(existing_lists))
except Exception, e:
except Exception as e:
return (False, repr(e))
4 changes: 2 additions & 2 deletions backends/bk_none.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_existing_maillists(domains=None, *args, **kw):
except OSError:
# No such directory.
pass
except Exception, e:
except Exception as e:
return (False, repr(e))

for fn in fns:
Expand All @@ -81,7 +81,7 @@ def get_existing_maillists(domains=None, *args, **kw):
except OSError:
# No such directory.
pass
except Exception, e:
except Exception as e:
return (False, repr(e))

all_lists.sort()
Expand Down
10 changes: 5 additions & 5 deletions libs/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

# Default daemon parameters.
# File mode creation mask of the daemon.
UMASK = 0077
UMASK = 0o077

# Default working directory for the daemon.
WORKDIR = "/"
Expand Down Expand Up @@ -164,7 +164,7 @@ def daemonize(noClose=False):
if not noClose:
_redirectFileDescriptors()

except Exception, e:
except Exception as e:
raise DaemonError('Error during daemonizing: {0} [{1}]'.format(e.strerror, e.errno))


Expand All @@ -175,7 +175,7 @@ def daemonize(noClose=False):
def _fork():
try:
return os.fork()
except OSError, e:
except OSError as e:
raise DaemonError('Cannot fork: {0} [{1}]'.format(e.strerror, e.errno))


Expand All @@ -196,10 +196,10 @@ def _redirectFileDescriptors():

try:
os.close(fd)
except OSError, e:
except OSError as e:
# File descriptor wasn't open. Ignore.
logging.info('Error in _redirectFileDescriptors 1: ({0}, {1})'.format(e.errno, e.strerror))
except Exception, e:
except Exception as e:
logging.info('Error in _redirectFileDescriptors 2: ({0}, {1})'.format(e.errno, e.strerror))

# Redirect standard input, output and error to something safe.
Expand Down
2 changes: 1 addition & 1 deletion libs/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
MLMMJ_SKEL_DIR = '/usr/share/mlmmj/text.skel'

# Default file permission for created files/directories
MLMMJ_FILE_PERMISSION = 0700
MLMMJ_FILE_PERMISSION = 0o700

#
# Absolute path to mlmmj commands. If empty, will try /usr/bin and
Expand Down
Loading

0 comments on commit 67ee385

Please sign in to comment.