Get a reply from the server. Returns a tuple consisting of: - server response code (e.g. '250', or such, if all goes well) Note: returns -1 if it can't read response code. - server response string corresponding to response code (multiline respon
(self)
| 385 | self.send(f'{s}{CRLF}') |
| 386 | |
| 387 | def getreply(self): |
| 388 | """Get a reply from the server. |
| 389 | |
| 390 | Returns a tuple consisting of: |
| 391 | |
| 392 | - server response code (e.g. '250', or such, if all goes well) |
| 393 | Note: returns -1 if it can't read response code. |
| 394 | |
| 395 | - server response string corresponding to response code (multiline |
| 396 | responses are converted to a single, multiline string). |
| 397 | |
| 398 | Raises SMTPServerDisconnected if end-of-file is reached. |
| 399 | """ |
| 400 | resp = [] |
| 401 | if self.file is None: |
| 402 | self.file = self.sock.makefile('rb') |
| 403 | while 1: |
| 404 | try: |
| 405 | line = self.file.readline(_MAXLINE + 1) |
| 406 | except OSError as e: |
| 407 | self.close() |
| 408 | raise SMTPServerDisconnected("Connection unexpectedly closed: " |
| 409 | + str(e)) |
| 410 | if not line: |
| 411 | self.close() |
| 412 | raise SMTPServerDisconnected("Connection unexpectedly closed") |
| 413 | if self.debuglevel > 0: |
| 414 | self._print_debug('reply:', repr(line)) |
| 415 | if len(line) > _MAXLINE: |
| 416 | self.close() |
| 417 | raise SMTPResponseException(500, "Line too long.") |
| 418 | resp.append(line[4:].strip(b' \t\r\n')) |
| 419 | code = line[:3] |
| 420 | # Check that the error code is syntactically correct. |
| 421 | # Don't attempt to read a continuation line if it is broken. |
| 422 | try: |
| 423 | errcode = int(code) |
| 424 | except ValueError: |
| 425 | errcode = -1 |
| 426 | break |
| 427 | # Check if multiline response. |
| 428 | if line[3:4] != b"-": |
| 429 | break |
| 430 | |
| 431 | errmsg = b"\n".join(resp) |
| 432 | if self.debuglevel > 0: |
| 433 | self._print_debug('reply: retcode (%s); Msg: %a' % (errcode, errmsg)) |
| 434 | return errcode, errmsg |
| 435 | |
| 436 | def docmd(self, cmd, args=""): |
| 437 | """Send a command, and return its response code.""" |