code: def save_file(fullpath, entry):
      
      with tempfile.NamedTemporaryFile('w', delete=False) as file:
          tmpfile = file.name
          # we can't just use file.write(str(entry)) because otherwise the
          # headers "helpfully" do MIME encoding normalization.
          # str(val) is necessary to get around email.header's encoding
          # shenanigans
          for key, val in entry.items():
              print('{}: {}'.format(key, str(val)), file=file)
          print('', file=file)
          file.write(entry.get_payload())
      shutil.move(tmpfile, fullpath)
docs: Save a message file out, without mangling the headers