def stateDefault(self, dataDec, module): # Handles commands while in the default state. command = CommonFunctions.commandOnly(dataDec) argument = CommonFunctions.argumentOnly(dataDec) print("State:" + self.state + " Data:" + dataDec + " Command:" + command + " argument:" + argument) if command in commandsUnimplemented: self.code502(module) elif command in commandsAnytime: self.commandsAnytimeRouter(dataDec, module) elif command == "LOGOUT": self.commandLOGOUT(module) elif command == "REGMAIL": self.commandREGMAIL(argument, module) elif command == "ADDMAIL": self.commandADDMAIL(argument, module) elif command == "RMVMAIL": self.commandRMVMAIL(argument, module) elif command == "MYMAILS": self.commandMYMAILS(module) elif command == "LISTMAIL": self.commandLISTMAIL(module) elif command == "VIEWMAIL": self.commandVIEWMAIL(argument, module) elif command == "DELMAIL": self.commandDELMAIL(argument, module) elif command == "MAIL": # added so that if its just mail and from is missing it throws a 501 error self.code501(" valid parameter is FROM:", module) elif command == "MAIL FROM:": self.commandMAIL(dataDec, module) else: self.code500(module)
def stateMail( self, dataDec, module ): # Handles incoming data and commands while in the mail state. command = CommonFunctions.commandOnly(dataDec) argument = CommonFunctions.argumentOnly(dataDec) print("State:" + self.state + " Data:" + dataDec + " Command:" + command + " argument:" + argument) if self.subStateMail == "data": if dataDec == ".": for rcpt in self.rcptBuffer: temp = Storage.email(self.mailFromBuffer, rcpt, self.dataBuffer) temp.saveEmail() Auditing.logMail(self.mailFromBuffer, rcpt) self.commandRSET(module) else: if dataDec[0] == ".": dataDec = dataDec[1:] self.dataBuffer = self.dataBuffer + dataDec + "\n" self.code250(" OK", module) elif command in commandsAnytime: self.commandsAnytimeRouter(dataDec, module) elif command == "RSET": self.commandRSET(module) elif self.subStateMail == "init": self.mailFromBuffer = argument[1:-1] self.subStateMail = "rcpt" self.code250(" OK", module) elif self.subStateMail == "rcpt": if command == "RCPT TO:": validity = CommonFunctions.mailValidationSMTP(argument) if validity == "OK": self.rcptBuffer.append(argument[1:-1]) self.code250(" OK", module) else: self.code553(validity, module) elif command == "DATA": if len(self.rcptBuffer) == 0: self.code503("", module) else: self.subStateMail = "data" self.code354(module) else: self.code500(module)
def stateDefault(self, dataDec, module): # Handles commands while in the Default state. command = CommonFunctions.commandOnly(dataDec) argument = CommonFunctions.argumentOnly(dataDec) print("State:" + self.state + " Data:" + dataDec + " Command:" + command + " argument:" + argument) if command == "LOGOUT": self.commandLOGOUT(module) elif command == "SONGLIST": self.commandSONGLIST(module) elif command == "DOWNSONG": self.commandDOWNSONG(argument, module) elif command == "HELP": self.commandHELP(argument, module) else: CommonFunctions.sendData("Unknown command, try HELP", module, self.securityServer)
def commandsAnytimeRouter( self, data, module): # Routes commands that can be used at any time. command = CommonFunctions.commandOnly(data) argument = CommonFunctions.argumentOnly(data) if command == "VRFY": self.commandVRFY(argument, module) elif command == "EXPN": self.commandEXPN(argument, module) elif command == "HELP": self.commandHELP(argument, module) elif command == "NOOP": self.commandNOOP(module) elif command == "QUIT": self.commandQUIT(module) else: print( "Wrong input" ) # This would probably never occur due to the way the function is used.
def stateGreetings( self, dataDec, module): # Handles commands and data while in the Greetings state. command = CommonFunctions.commandOnly(dataDec) argument = CommonFunctions.argumentOnly(dataDec) print("State:" + self.state + " Data:" + dataDec + " Command:" + command + " argument:" + argument) if command in commandsAnytime: self.commandsAnytimeRouter(dataDec, module) elif command == "HELO": self.commandHELO(argument, module) elif command == "EHLO": self.commandEHLO(argument, module) elif command in commandsImplemented: self.code503("", module) else: self.code500(module) if self.clientDomain != "-": self.state = "default"
def stateLogin(self, dataDec, module): # Handles the login state. command = CommonFunctions.commandOnly(dataDec).upper() argument = CommonFunctions.argumentOnly(dataDec) if (command == "REGISTER" or command == "LOGIN") and CommonFunctions.numberOfWords(argument) == 2: userName = CommonFunctions.firstWord(argument) userPass = CommonFunctions.secondWord(argument) if CommonFunctions.userpassValidate( userName) and CommonFunctions.userpassValidate(userPass): if command == "REGISTER": self.commandREGISTER(argument, module) else: self.commandLOGIN(argument, module) else: self.code503( " Username and Password must be atleast 6 characters long and CAN contain numbers, letters including the following symbols !@#$%^&*()-=_+,.?", module) else: self.code501( " Available commands: \n" "login <username> <password> \n" "register <username> <password>", module)