(self, fws, string, charset)
| 436 | self._current_line.push(' ', '') |
| 437 | |
| 438 | def feed(self, fws, string, charset): |
| 439 | # If the charset has no header encoding (i.e. it is an ASCII encoding) |
| 440 | # then we must split the header at the "highest level syntactic break" |
| 441 | # possible. Note that we don't have a lot of smarts about field |
| 442 | # syntax; we just try to break on semi-colons, then commas, then |
| 443 | # whitespace. Eventually, this should be pluggable. |
| 444 | if charset.header_encoding is None: |
| 445 | self._ascii_split(fws, string, self._splitchars) |
| 446 | return |
| 447 | # Otherwise, we're doing either a Base64 or a quoted-printable |
| 448 | # encoding which means we don't need to split the line on syntactic |
| 449 | # breaks. We can basically just find enough characters to fit on the |
| 450 | # current line, minus the RFC 2047 chrome. What makes this trickier |
| 451 | # though is that we have to split at octet boundaries, not character |
| 452 | # boundaries but it's only safe to split at character boundaries so at |
| 453 | # best we can only get close. |
| 454 | encoded_lines = charset.header_encode_lines(string, self._maxlengths()) |
| 455 | # The first element extends the current line, but if it's None then |
| 456 | # nothing more fit on the current line so start a new line. |
| 457 | try: |
| 458 | first_line = encoded_lines.pop(0) |
| 459 | except IndexError: |
| 460 | # There are no encoded lines, so we're done. |
| 461 | return |
| 462 | if first_line is not None: |
| 463 | self._append_chunk(fws, first_line) |
| 464 | try: |
| 465 | last_line = encoded_lines.pop() |
| 466 | except IndexError: |
| 467 | # There was only one line. |
| 468 | return |
| 469 | self.newline() |
| 470 | self._current_line.push(self._continuation_ws, last_line) |
| 471 | # Everything else are full lines in themselves. |
| 472 | for line in encoded_lines: |
| 473 | self._lines.append(self._continuation_ws + line) |
| 474 | |
| 475 | def _maxlengths(self): |
| 476 | # The first line's length. |
no test coverage detected