(self, lines)
| 470 | self._cur.set_payload(EMPTYSTRING.join(lines)) |
| 471 | |
| 472 | def _parse_headers(self, lines): |
| 473 | # Passed a list of lines that make up the headers for the current msg |
| 474 | lastheader = '' |
| 475 | lastvalue = [] |
| 476 | for lineno, line in enumerate(lines): |
| 477 | # Check for continuation |
| 478 | if line[0] in ' \t': |
| 479 | if not lastheader: |
| 480 | # The first line of the headers was a continuation. This |
| 481 | # is illegal, so let's note the defect, store the illegal |
| 482 | # line, and ignore it for purposes of headers. |
| 483 | defect = errors.FirstHeaderLineIsContinuationDefect(line) |
| 484 | self.policy.handle_defect(self._cur, defect) |
| 485 | continue |
| 486 | lastvalue.append(line) |
| 487 | continue |
| 488 | if lastheader: |
| 489 | self._cur.set_raw(*self.policy.header_source_parse(lastvalue)) |
| 490 | lastheader, lastvalue = '', [] |
| 491 | # Check for envelope header, i.e. unix-from |
| 492 | if line.startswith('From '): |
| 493 | if lineno == 0: |
| 494 | # Strip off the trailing newline |
| 495 | mo = NLCRE_eol.search(line) |
| 496 | if mo: |
| 497 | line = line[:-len(mo.group(0))] |
| 498 | self._cur.set_unixfrom(line) |
| 499 | continue |
| 500 | elif lineno == len(lines) - 1: |
| 501 | # Something looking like a unix-from at the end - it's |
| 502 | # probably the first line of the body, so push back the |
| 503 | # line and stop. |
| 504 | self._input.unreadline(line) |
| 505 | return |
| 506 | else: |
| 507 | # Weirdly placed unix-from line. |
| 508 | defect = errors.MisplacedEnvelopeHeaderDefect(line) |
| 509 | self.policy.handle_defect(self._cur, defect) |
| 510 | continue |
| 511 | # Split the line on the colon separating field name from value. |
| 512 | # There will always be a colon, because if there wasn't the part of |
| 513 | # the parser that calls us would have started parsing the body. |
| 514 | i = line.find(':') |
| 515 | |
| 516 | # If the colon is on the start of the line the header is clearly |
| 517 | # malformed, but we might be able to salvage the rest of the |
| 518 | # message. Track the error but keep going. |
| 519 | if i == 0: |
| 520 | defect = errors.InvalidHeaderDefect("Missing header name.") |
| 521 | self.policy.handle_defect(self._cur, defect) |
| 522 | continue |
| 523 | |
| 524 | assert i>0, "_parse_headers fed line with no : and no leading WS" |
| 525 | lastheader = line[:i] |
| 526 | lastvalue = [line] |
| 527 | # Done with all the lines, so handle the last header. |
| 528 | if lastheader: |
| 529 | self._cur.set_raw(*self.policy.header_source_parse(lastvalue)) |
no test coverage detected