Scan printables/quoted-pairs until endchars and return unquoted ptext. This function turns a run of qcontent, ccontent-without-comments, or dtext-with-quoted-printables into a single string by unquoting any quoted printables. It returns the string, the remaining value, and a flag t
(value, endchars)
| 1012 | "Non-ASCII characters found in header token")) |
| 1013 | |
| 1014 | def _get_ptext_to_endchars(value, endchars): |
| 1015 | """Scan printables/quoted-pairs until endchars and return unquoted ptext. |
| 1016 | |
| 1017 | This function turns a run of qcontent, ccontent-without-comments, or |
| 1018 | dtext-with-quoted-printables into a single string by unquoting any |
| 1019 | quoted printables. It returns the string, the remaining value, and |
| 1020 | a flag that is True iff there were any quoted printables decoded. |
| 1021 | |
| 1022 | """ |
| 1023 | if not value: |
| 1024 | return '', '', False |
| 1025 | fragment, *remainder = _wsp_splitter(value, 1) |
| 1026 | vchars = [] |
| 1027 | escape = False |
| 1028 | had_qp = False |
| 1029 | for pos in range(len(fragment)): |
| 1030 | if fragment[pos] == '\\': |
| 1031 | if escape: |
| 1032 | escape = False |
| 1033 | had_qp = True |
| 1034 | else: |
| 1035 | escape = True |
| 1036 | continue |
| 1037 | if escape: |
| 1038 | escape = False |
| 1039 | elif fragment[pos] in endchars: |
| 1040 | break |
| 1041 | vchars.append(fragment[pos]) |
| 1042 | else: |
| 1043 | pos = pos + 1 |
| 1044 | return ''.join(vchars), ''.join([fragment[pos:]] + remainder), had_qp |
| 1045 | |
| 1046 | def get_fws(value): |
| 1047 | """FWS = 1*WSP |
no test coverage detected