diff --git a/unattended-upgrade b/unattended-upgrade index 86358b19..c0441567 100755 --- a/unattended-upgrade +++ b/unattended-upgrade @@ -27,7 +27,6 @@ import contextlib import copy import datetime import errno -import email.charset import fcntl import fnmatch import gettext @@ -40,6 +39,7 @@ import grp import inspect import io from importlib.abc import Loader +import importlib import importlib.util import locale import logging @@ -71,7 +71,6 @@ except ImportError: from collections import defaultdict, namedtuple from datetime import date -from email.message import Message from gettext import gettext as _ from io import StringIO from optparse import ( @@ -1613,9 +1612,21 @@ def _send_mail_using_mailx(from_address, to_address, subject, body): def _send_mail_using_sendmail(from_address, to_address, subject, body): + # workaround LP:2080940, email.errors changes as part of a security + # update in python itself so import this as late as possible + import email + import email.charset + import email.errors + importlib.reload(email.errors) + import email.generator + import email.message + importlib.reload(email) + importlib.reload(email.charset) + importlib.reload(email.message) + importlib.reload(email.generator) # type: (str, str, str, str) -> int # format as a proper mail - msg = Message() + msg = email.message.Message() msg['Subject'] = subject msg['From'] = from_address msg['To'] = to_address