code: def guess_encoding(blob):
      
      # this is a bit of a hack to support different versions of python magic.
      # Hopefully at some point this will no longer be necessary
      #
      # the version with open() is the bindings shipped with the file source from
      # http://darwinsys.com/file/ - this is what is used by the python-magic
      # package on Debian/Ubuntu.  However it is not available on pypi/via pip.
      #
      # the version with from_buffer() is available at
      # https://github.com/ahupp/python-magic and directly installable via pip.
      #
      # for more detail see https://github.com/pazz/alot/pull/588
      if hasattr(magic, 'open'):
          m = magic.open(magic.MAGIC_MIME_ENCODING)
          m.load()
          return m.buffer(blob)
      elif hasattr(magic, 'from_buffer'):
          m = magic.Magic(mime_encoding=True)
          return m.from_buffer(blob)
      else:
          raise Exception('Unknown magic API')
docs: uses file magic to determine the encoding of the given data blob.
  
      :param blob: file content as read by file.read()
      :type blob: data
      :returns: encoding
      :rtype: str