address = mailbox / group Note that counter-intuitively, an address can be either a single address or a list of addresses (a group). This is why the returned Address object has a 'mailboxes' attribute which treats a single address as a list of length one. When you need to differe
(value)
| 1994 | return group, value |
| 1995 | |
| 1996 | def get_address(value): |
| 1997 | """ address = mailbox / group |
| 1998 | |
| 1999 | Note that counter-intuitively, an address can be either a single address or |
| 2000 | a list of addresses (a group). This is why the returned Address object has |
| 2001 | a 'mailboxes' attribute which treats a single address as a list of length |
| 2002 | one. When you need to differentiate between to two cases, extract the single |
| 2003 | element, which is either a mailbox or a group token. |
| 2004 | |
| 2005 | """ |
| 2006 | # The formal grammar isn't very helpful when parsing an address. mailbox |
| 2007 | # and group, especially when allowing for obsolete forms, start off very |
| 2008 | # similarly. It is only when you reach one of @, <, or : that you know |
| 2009 | # what you've got. So, we try each one in turn, starting with the more |
| 2010 | # likely of the two. We could perhaps make this more efficient by looking |
| 2011 | # for a phrase and then branching based on the next character, but that |
| 2012 | # would be a premature optimization. |
| 2013 | address = Address() |
| 2014 | try: |
| 2015 | token, value = get_group(value) |
| 2016 | except errors.HeaderParseError: |
| 2017 | try: |
| 2018 | token, value = get_mailbox(value) |
| 2019 | except errors.HeaderParseError: |
| 2020 | raise errors.HeaderParseError( |
| 2021 | "expected address but found '{}'".format(value)) |
| 2022 | address.append(token) |
| 2023 | return address, value |
| 2024 | |
| 2025 | def get_address_list(value): |
| 2026 | """ address_list = (address *("," address)) / obs-addr-list |
no test coverage detected
searching dependent graphs…