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