diff options
-rw-r--r-- | alot/commands/globals.py | 15 | ||||
-rw-r--r-- | alot/helper.py | 11 |
2 files changed, 8 insertions, 18 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 310a59db..b95d37b9 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -743,8 +743,8 @@ class ComposeCommand(Command): priority='error') raise self.ApplyError() try: - with open(path, 'rb') as f: - template = helper.try_decode(f.read()) + with open(path, 'r') as f: + template = f.read() self.envelope.parse_template(template) except Exception as e: ui.notify(str(e), priority='error') @@ -804,11 +804,12 @@ class ComposeCommand(Command): self.envelope.attach(sig, filename=name) logging.debug('attached') else: - with open(sig, 'rb') as f: - sigcontent = f.read() - mimetype = helper.guess_mimetype(sigcontent) - if mimetype.startswith('text'): - sigcontent = helper.try_decode(sigcontent) + try: + with open(sig, 'r') as f: + sigcontent = f.read() + except UnicodeDecodeError: + ui.notify('Could not read signature', priority = 'error') + else: self.envelope.body += '\n' + sigcontent else: ui.notify('could not locate signature: %s' % sig, diff --git a/alot/helper.py b/alot/helper.py index 8a7261e5..4283faea 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -195,17 +195,6 @@ def guess_encoding(blob): raise Exception('Unknown magic API') -def try_decode(blob): - """Guess the encoding of blob and try to decode it into a str. - - :param bytes blob: The bytes to decode - :returns: the decoded blob - :rtype: str - """ - assert isinstance(blob, bytes), 'cannot decode a str or non-bytes object' - return blob.decode(guess_encoding(blob)) - - def libmagic_version_at_least(version): """ checks if the libmagic library installed is more recent than a given |