mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list obs-mbox-list = *([CFWS] ",") mailbox *("," [mailbox / CFWS]) For this routine we go outside the formal grammar in order to improve error handling. We recognize the end of the mailbox list only at the end of the value or
(value)
| 1870 | return invalid_mailbox, value |
| 1871 | |
| 1872 | def get_mailbox_list(value): |
| 1873 | """ mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list |
| 1874 | obs-mbox-list = *([CFWS] ",") mailbox *("," [mailbox / CFWS]) |
| 1875 | |
| 1876 | For this routine we go outside the formal grammar in order to improve error |
| 1877 | handling. We recognize the end of the mailbox list only at the end of the |
| 1878 | value or at a ';' (the group terminator). This is so that we can turn |
| 1879 | invalid mailboxes into InvalidMailbox tokens and continue parsing any |
| 1880 | remaining valid mailboxes. We also allow all mailbox entries to be null, |
| 1881 | and this condition is handled appropriately at a higher level. |
| 1882 | |
| 1883 | """ |
| 1884 | mailbox_list = MailboxList() |
| 1885 | while value and value[0] != ';': |
| 1886 | try: |
| 1887 | token, value = get_mailbox(value) |
| 1888 | mailbox_list.append(token) |
| 1889 | except errors.HeaderParseError: |
| 1890 | leader = None |
| 1891 | if value[0] in CFWS_LEADER: |
| 1892 | leader, value = get_cfws(value) |
| 1893 | if not value or value[0] in ',;': |
| 1894 | mailbox_list.append(leader) |
| 1895 | mailbox_list.defects.append(errors.ObsoleteHeaderDefect( |
| 1896 | "empty element in mailbox-list")) |
| 1897 | else: |
| 1898 | token, value = get_invalid_mailbox(value, ',;') |
| 1899 | if leader is not None: |
| 1900 | token[:0] = [leader] |
| 1901 | mailbox_list.append(token) |
| 1902 | mailbox_list.defects.append(errors.InvalidHeaderDefect( |
| 1903 | "invalid mailbox in mailbox-list")) |
| 1904 | elif value[0] == ',': |
| 1905 | mailbox_list.defects.append(errors.ObsoleteHeaderDefect( |
| 1906 | "empty element in mailbox-list")) |
| 1907 | else: |
| 1908 | token, value = get_invalid_mailbox(value, ',;') |
| 1909 | if leader is not None: |
| 1910 | token[:0] = [leader] |
| 1911 | mailbox_list.append(token) |
| 1912 | mailbox_list.defects.append(errors.InvalidHeaderDefect( |
| 1913 | "invalid mailbox in mailbox-list")) |
| 1914 | if value and value[0] not in ',;': |
| 1915 | # Crap after mailbox; treat it as an invalid mailbox. |
| 1916 | # The mailbox info will still be available. |
| 1917 | mailbox = mailbox_list[-1] |
| 1918 | mailbox.token_type = 'invalid-mailbox' |
| 1919 | token, value = get_invalid_mailbox(value, ',;') |
| 1920 | mailbox.extend(token) |
| 1921 | mailbox_list.defects.append(errors.InvalidHeaderDefect( |
| 1922 | "invalid mailbox in mailbox-list")) |
| 1923 | if value and value[0] == ',': |
| 1924 | mailbox_list.append(ListSeparator) |
| 1925 | value = value[1:] |
| 1926 | return mailbox_list, value |
| 1927 | |
| 1928 | |
| 1929 | def get_group_list(value): |
no test coverage detected
searching dependent graphs…