code: def modutf7_encode(data: str) -> bytes:
      
      ret = bytearray()
      is_usascii = True
      encode_start = None
      for i, symbol in enumerate(data):
          charpoint = ord(symbol)
          if is_usascii:
              if charpoint == 0x26:
                  ret.extend(b'&-')
              elif 0x20 <= charpoint <= 0x7e:
                  ret.append(charpoint)
              else:
                  encode_start = i
                  is_usascii = False
          else:
              if 0x20 <= charpoint <= 0x7e:
                  to_encode = data[encode_start:i]
                  encoded = _modified_b64encode(to_encode)
                  ret.append(0x26)
                  ret.extend(encoded)
                  ret.extend((0x2d, charpoint))
                  is_usascii = True
      if not is_usascii:
          to_encode = data[encode_start:]
          encoded = _modified_b64encode(to_encode)
          ret.append(0x26)
          ret.extend(encoded)
          ret.append(0x2d)
      return bytes(ret)
docs: Encode the string using modified UTF-7.
  
      Args:
          data: The input string to encode.