<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def renamescript(self, oldname, newname):
 """Rename a script on the server See MANAGESIEVE specifications, section 2.11.1 As this command is optional, we emulate it if the server does not support it. :param oldname: current script's name :param newname: new script's name :rtype: boolean """

        if "VERSION" in self.__capabilities:
            code, data = self.__send_command(
                "RENAMESCRIPT",
                [oldname.encode("utf-8"), newname.encode("utf-8")])
            if code == "OK":
                return True
            return False

        (active_script, scripts) = self.listscripts()
        condition = (
            oldname != active_script and
            (scripts is None or oldname not in scripts)
        )
        if condition:
            self.errmsg = b"Old script does not exist"
            return False
        if newname in scripts:
            self.errmsg = b"New script already exists"
            return False
        oldscript = self.getscript(oldname)
        if oldscript is None:
            return False
        if not self.putscript(newname, oldscript):
            return False
        if active_script == oldname:
            if not self.setactive(newname):
                return False
        if not self.deletescript(oldname):
            return False
        return True