'Move one message over a specific destination message,
which may or may not already exist.'

def movemessage(self, n, tofolder, ton):

    path = self.getmessagefilename(n)
    f = open(path)
    f.close()
    del f
    topath = tofolder.getmessagefilename(ton)
    backuptopath = tofolder.getmessagefilename((',%d' % ton))
    try:
        os.rename(topath, backuptopath)
    except os.error:
        pass
    try:
        os.rename(path, topath)
    except os.error:
        ok = 0
        try:
            tofolder.setlast(None)
            shutil.copy2(path, topath)
            ok = 1
        finally:
            if (not ok):
                try:
                    os.unlink(topath)
                except os.error:
                    pass
        os.unlink(path)
    self.removefromallsequences([n])
