From 8d6d84d87f4b820ebb23d917b2c1127ee662f1f1 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sat, 20 Jan 2018 10:54:56 -0500 Subject: [PATCH] run mailconfig.py's email address validator outside of the virtualenv during questions.sh We don't have the virtualenv this early in setup. Broken by 0088fb45533b349e47c7f04e95a618862735ddf1. Fixes #1326. See https://discourse.mailinabox.email/t/that-is-not-a-valid-email-error-during-mailinabox-installation/2793. --- management/mailconfig.py | 9 +++++++++ setup/questions.sh | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/management/mailconfig.py b/management/mailconfig.py index fc75e1ab..82c922e4 100755 --- a/management/mailconfig.py +++ b/management/mailconfig.py @@ -1,5 +1,14 @@ #!/usr/local/lib/mailinabox/env/bin/python +# NOTE: +# This script is run both using the system-wide Python 3 +# interpreter (/usr/bin/python3) as well as through the +# virtualenv (/usr/local/lib/mailinabox/env). So only +# import packages at the top level of this script that +# are installed in *both* contexts. We use the system-wide +# Python 3 in setup/questions.sh to validate the email +# address entered by the user. + import subprocess, shutil, os, sqlite3, re import utils from email_validator import validate_email as validate_email_, EmailNotValidError diff --git a/setup/questions.sh b/setup/questions.sh index 57da5c92..3d227d81 100644 --- a/setup/questions.sh +++ b/setup/questions.sh @@ -12,7 +12,9 @@ if [ -z "$NONINTERACTIVE" ]; then apt_get_quiet install dialog python3 python3-pip || exit 1 fi - # email_validator is repeated in setup/management.sh + # Installing email_validator is repeated in setup/management.sh, but in setup/management.sh + # we install it inside a virtualenv. In this script, we don't have the virtualenv yet + # so we install the python package globally. hide_output pip3 install "email_validator>=1.0.0" || exit 1 message_box "Mail-in-a-Box Installation" \ @@ -49,7 +51,7 @@ you really want. # user hit ESC/cancel exit fi - while ! management/mailconfig.py validate-email "$EMAIL_ADDR" + while ! python3 management/mailconfig.py validate-email "$EMAIL_ADDR" do input_box "Your Email Address" \ "That's not a valid email address.\n\nWhat email address are you setting this box up to manage?" \