mailbox = name-addr / addr-spec
(value)
| 1814 | return name_addr, value |
| 1815 | |
| 1816 | def get_mailbox(value): |
| 1817 | """ mailbox = name-addr / addr-spec |
| 1818 | |
| 1819 | """ |
| 1820 | # The only way to figure out if we are dealing with a name-addr or an |
| 1821 | # addr-spec is to try parsing each one. |
| 1822 | mailbox = Mailbox() |
| 1823 | try: |
| 1824 | token, value = get_name_addr(value) |
| 1825 | except errors.HeaderParseError: |
| 1826 | try: |
| 1827 | token, value = get_addr_spec(value) |
| 1828 | except errors.HeaderParseError: |
| 1829 | raise errors.HeaderParseError( |
| 1830 | "expected mailbox but found '{}'".format(value)) |
| 1831 | if any(isinstance(x, errors.InvalidHeaderDefect) |
| 1832 | for x in token.all_defects): |
| 1833 | mailbox.token_type = 'invalid-mailbox' |
| 1834 | mailbox.append(token) |
| 1835 | return mailbox, value |
| 1836 | |
| 1837 | def get_invalid_mailbox(value, endchars): |
| 1838 | """ Read everything up to one of the chars in endchars. |
no test coverage detected