python / cpython

The Python programming language
https://www.python.org
Other
63.44k stars 30.38k forks source link

smtplib does not fully support IPv6 in EHLO #47711

Open 02595635-67bd-49b1-bb7e-0decc940a690 opened 16 years ago

02595635-67bd-49b1-bb7e-0decc940a690 commented 16 years ago
BPO 3461
Nosy @warsaw, @giampaolo, @bitdancer
Files
  • python_smtplib.patch
  • smtplib.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['type-bug', '3.8', 'expert-email', '3.10', 'library', '3.9'] title = 'smtplib does not fully support IPv6 in EHLO' updated_at = user = 'https://bugs.python.org/dmorr' ``` bugs.python.org fields: ```python activity = actor = 'iritkatriel' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)', 'email'] creation = creator = 'dmorr' dependencies = [] files = ['11000', '17863'] hgrepos = [] issue_num = 3461 keywords = ['patch'] message_count = 7.0 messages = ['70372', '109271', '109288', '109414', '109422', '110133', '110137'] nosy_count = 4.0 nosy_names = ['barry', 'giampaolo.rodola', 'dmorr', 'r.david.murray'] pr_nums = [] priority = 'normal' resolution = None stage = 'test needed' status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue3461' versions = ['Python 3.8', 'Python 3.9', 'Python 3.10'] ```

    02595635-67bd-49b1-bb7e-0decc940a690 commented 16 years ago

    On an IPv6-only machine, smtplib does not send an IPv6 address in the EHLO. It sends "EHLO [0.0.0.0]" instead. For example, on a v6-only network with stateless autoconfiguration enabled (a common configuration), smtplib will show this error.

    Further, SMTP's __init__() method tries to determine the value of EHLO parameter before the socket is established. But it can't know what value to use before the socket is setup (e.g., should it use a hostname, a v4 address literal, or a v6 address literal).

    The attached patch moves the self.local_hostname processing into the connect() method, and updates it to use IPv6-aware resolver interfaces.

    83d2e70e-e599-4a04-b820-3814bbdb9bef commented 14 years ago

    I intended testing this but the patch file appears to have a dangling else at the bottom, or am I missing something?

    02595635-67bd-49b1-bb7e-0decc940a690 commented 14 years ago

    You're right. My mistake when I made the patch. I've attached a new one without the trailing else

    83d2e70e-e599-4a04-b820-3814bbdb9bef commented 14 years ago

    Ran test_smtplib.py for Python 2.7 and 3.1.2 on Windows Vista all tests passed.

    bitdancer commented 14 years ago

    The patch still needs unit tests.

    02595635-67bd-49b1-bb7e-0decc940a690 commented 14 years ago

    I'm not sure how to best write a unit test for this. The patch should only be invoked if the client doesn't have a name-served hostname and has IPv6 enabled. Also, there are several IPv4-isms in the smtplib tests.

    giampaolo commented 14 years ago

    You might want to take a look at Lib/test/test_ftplib.py which contains IPv6 tests including the necessary logic to decide whether or not running them.