示例#1
0
def cmdfwd(commandlist, user):
    if user == "NotFound":
        return "init first\n"

    try:
        opts, args = getopt.getopt(commandlist,"d:c:n:")
        receiver = ""
        content = ""
        newcontent = ""
        for opt, arg in opts:
            if opt == "-d":
                if arg.replace('@nctu.edu.tw','') in [x[0] for x in users]:
                    receiver = arg.replace('@nctu.edu.tw','')
                else:
                    return "args error\n"
            elif opt == "-c":
                newcontent = arg
            elif opt == "-n":
                content = cmdrd(['-r',arg],user)
                if content == "args error\n":
                    return content
        fwdlist = contentParser(content,newcontent)
        return cmdwt(['-d',receiver+"@nctu.edu.tw",'-t',fwdlist[0],'-c',fwdlist[1][:-1]],user)


    except getopt.GetoptError:
        return "option error\n"
示例#2
0
文件: hw5.py 项目: jubeatWwW/NPhw
def shell(s, addr):
    while True:
        data = s.recv(2048)
        data, legalstate = quotesHandler(data)

        if legalstate == False:
            s.sendall("args error(quotesHandler)\n")

        commandlist = data.split()
        command = commandlist[0]
        commandlist.pop(0)

        if command == "exit":
            user = getUserName(addr)
            if user != "NotFound":
                for userdel in users:
                    if userdel[0] == user:
                        users.remove(userdel)
                        break
            s.sendall("exit\n")
            s.close()
            break
        elif command == "init":
            s.sendall(cmdinit(commandlist, addr))
            continue
        elif command == "ls":
            s.sendall(cmdls(commandlist, getUserName(addr)))
            continue
        elif command == "wt":
            s.sendall(cmdwt(commandlist, getUserName(addr)))
            continue
        elif command == "rd":
            s.sendall(cmdrd(commandlist, getUserName(addr)))
            continue
        elif command == "rm":
            s.sendall(cmdrm(commandlist, getUserName(addr)))
            continue
        elif command == "re":
            s.sendall(cmdre(commandlist, getUserName(addr)))
            continue
        elif command == "fwd":
            s.sendall(cmdfwd(commandlist, getUserName(addr)))
            continue
        s.sendall("command error\n")
示例#3
0
def cmdre(commandlist, user):
    if user == "NotFound":
        return "init first\n"
    try:
        opts, args = getopt.getopt(commandlist, "c:n:")
        replycontent = ""
        newcontent = ""
        for opt, arg in opts:
            if opt == "-c":
                newcontent = arg
            elif opt == "-n":
                if digitFilter(arg):
                    replycontent = cmdrd(['-r', arg], user)
                    if replycontent == "args error\n":
                        return "args error\n"
                else:
                    return "args error\n"
        wtlist = replycontentParser(replycontent, newcontent)
        return cmdwt([
            '-d', wtlist[0] + "@nctu.edu.tw", '-t', wtlist[1], '-c',
            wtlist[2][:-1]
        ], user)
    except getopt.GetoptError:
        return "option error\n"