Ticket #5725: publicstate.diff
| File publicstate.diff, 4.6 KB (added by itamar, 12 months ago) |
|---|
-
smtp.py
1009 1009 self.code = -1 1010 1010 self.log = util.LineLog(logsize) 1011 1011 1012 def setResponseHandlers(self, expected, succeeded, failed): 1013 """ 1014 Set the functions that will handle successful and failed responses. 1015 1016 @param expected: A C{list} of C{int}, response codes indicating success. 1017 1018 @param succeeded: A callable that takes two arguments, the response 1019 code (an C{int}) and a C{bytes} description, which will be called 1020 if the response code matches the codes in the expected list. 1021 1022 @param failed: A callable that takes two arguments, the response code 1023 (an C{int}) and a C{bytes} description, which will be called if 1024 the response code does not matche the expected list. 1025 """ 1026 self._expected = expected 1027 self._okresponse = succeeded 1028 self._failresponse = failed 1029 1012 1030 def sendLine(self, line): 1013 1031 # Log sendLine only if you are in debug mode for performance 1014 1032 if self.debug: … … 1018 1036 1019 1037 def connectionMade(self): 1020 1038 self.setTimeout(self.timeout) 1039 self.setResponseHandlers([220], self.smtpState_helo, 1040 self.smtpConnectionFailed) 1021 1041 1022 self._expected = [ 220 ]1023 self._okresponse = self.smtpState_helo1024 self._failresponse = self.smtpConnectionFailed1025 1026 1042 def connectionLost(self, reason=protocol.connectionDone): 1027 1043 """We are no longer connected""" 1028 1044 self.setTimeout(None) … … 1080 1096 1081 1097 def smtpState_helo(self, code, resp): 1082 1098 self.sendLine('HELO ' + self.identity) 1083 self. _expected = SUCCESS1084 self._okresponse = self.smtpState_from1099 self.setResponseHandlers(SUCCESS, self.smtpState_from, 1100 self.smtpConnectionFailed) 1085 1101 1086 1102 def smtpState_from(self, code, resp): 1087 1103 self._from = self.getMailFrom() 1088 self._failresponse = self.smtpTransferFailed1089 1104 if self._from is not None: 1090 1105 self.sendLine('MAIL FROM:%s' % quoteaddr(self._from)) 1091 self. _expected = [250]1092 self._okresponse = self.smtpState_to1106 self.setResponseHandlers([250], self.smtpState_to, 1107 self.smtpTransferFailed) 1093 1108 else: 1094 1109 # All messages have been sent, disconnect 1095 1110 self._disconnectFromServer() … … 1101 1116 self.toAddresses = iter(self.getMailTo()) 1102 1117 self.toAddressesResult = [] 1103 1118 self.successAddresses = [] 1104 self. _okresponse = self.smtpState_toOrData1105 self._expected = xrange(0,1000)1119 self.setResponseHandlers(xrange(0,1000), self.smtpState_toOrData, 1120 self.smtpTransferFailed) 1106 1121 self.lastAddress = None 1107 1122 return self.smtpState_toOrData(0, '') 1108 1123 … … 1116 1131 except StopIteration: 1117 1132 if self.successAddresses: 1118 1133 self.sendLine('DATA') 1119 self. _expected = [ 354 ]1120 self._okresponse = self.smtpState_data1134 self.setResponseHandlers([354], self.smtpState_data, 1135 self.smtpTransferFailed) 1121 1136 else: 1122 1137 return self.smtpState_msgSent(code,'No recipients accepted') 1123 1138 else: … … 1130 1145 def ebTransfer(err): 1131 1146 self.sendError(err.value) 1132 1147 d.addCallbacks(self.finishedFileTransfer, ebTransfer) 1133 self. _expected = SUCCESS1134 self._okresponse = self.smtpState_msgSent1148 self.setResponseHandlers(SUCCESS, self.smtpState_msgSent, 1149 self.smtpTransferFailed) 1135 1150 1136 1137 1151 def smtpState_msgSent(self, code, resp): 1138 1152 if self._from is not None: 1139 1153 self.sentMail(code, resp, len(self.successAddresses), … … 1142 1156 self.toAddressesResult = [] 1143 1157 self._from = None 1144 1158 self.sendLine('RSET') 1145 self. _expected = SUCCESS1146 self._okresponse = self.smtpState_from1159 self.setResponseHandlers(SUCCESS, self.smtpState_from, 1160 self.smtpConnectionFailed) 1147 1161 1148 1162 ## 1149 1163 ## Helpers for FileSender … … 1217 1231 raise NotImplementedError 1218 1232 1219 1233 def _disconnectFromServer(self): 1220 self. _expected = xrange(0, 1000)1221 self._okresponse = self.smtpState_disconnect1234 self.setResponseHandlers(xrange(0, 1000), self.smtpState_disconnect, 1235 self.smtpState_disconnect) 1222 1236 self.sendLine('QUIT') 1223 1237 1224 1238
