code: def mimewrap(path, filename=None, ctype=None):
      
  
      with open(path, 'rb') as f:
          content = f.read()
      if not ctype:
          ctype = guess_mimetype(content)
          # libmagic < 5.12 incorrectly detects excel/powerpoint files as
          # 'application/msword' (see #179 and #186 in libmagic bugtracker)
          # This is a workaround, based on file extension, useful as long
          # as distributions still ship libmagic 5.11.
          if (ctype == 'application/msword' and
                  not libmagic_version_at_least(513)):
              mimetype, _ = mimetypes.guess_type(path)
              if mimetype:
                  ctype = mimetype
  
      maintype, subtype = ctype.split('/', 1)
      if maintype == 'text':
          part = MIMEText(content.decode(guess_encoding(content), 'replace'),
                          _subtype=subtype,
                          _charset='utf-8')
      elif maintype == 'image':
          part = MIMEImage(content, _subtype=subtype)
      elif maintype == 'audio':
          part = MIMEAudio(content, _subtype=subtype)
      else:
          part = MIMEBase(maintype, subtype)
          part.set_payload(content)
          # Encode the payload using Base64
          email.encoders.encode_base64(part)
      # Set the filename parameter
      if not filename:
          filename = os.path.basename(path)
      part.add_header('Content-Disposition', 'attachment',
                      filename=filename)
      return part
docs: Take the contents of the given path and wrap them into an email MIME
      part according to the content type.  The content type is auto detected from
      the actual file contents and the file name if it is not given.
  
      :param path: the path to the file contents
      :type path: str
      :param filename: the file name to use in the generated MIME part
      :type filename: str or None
      :param ctype: the content type of the file contents in path
      :type ctype: str or None
      :returns: the message MIME part storing the data from path
      :rtype: subclasses of email.mime.base.MIMEBase