Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMAP4 missing support for starttls #48721

Closed
lmctv mannequin opened this issue Nov 30, 2008 · 16 comments
Closed

IMAP4 missing support for starttls #48721

lmctv mannequin opened this issue Nov 30, 2008 · 16 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@lmctv
Copy link
Mannequin

lmctv mannequin commented Nov 30, 2008

BPO 4471
Nosy @gpshead, @pitrou, @giampaolo, @lmctv
Files
  • imaplib.rst.patch
  • imaplib_01_SSL_refactor.diff
  • imaplib_02_shutdown.diff
  • imaplib_03_starttls.diff
  • test_imapnet.py
  • imaptls.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:

    assignee = None
    closed_at = <Date 2010-11-12.18:49:46.440>
    created_at = <Date 2008-11-30.16:33:15.420>
    labels = ['type-feature', 'library']
    title = 'IMAP4 missing support for starttls'
    updated_at = <Date 2010-11-12.18:49:46.439>
    user = 'https://github.com/lmctv'

    bugs.python.org fields:

    activity = <Date 2010-11-12.18:49:46.439>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-11-12.18:49:46.440>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2008-11-30.16:33:15.420>
    creator = 'lcatucci'
    dependencies = []
    files = ['12171', '12193', '12194', '12195', '12963', '19562']
    hgrepos = []
    issue_num = 4471
    keywords = ['patch']
    message_count = 16.0
    messages = ['76641', '76644', '76714', '76718', '76752', '80960', '80972', '80974', '80981', '81326', '82984', '83079', '120902', '120903', '120904', '121053']
    nosy_count = 5.0
    nosy_names = ['gregory.p.smith', 'janssen', 'pitrou', 'giampaolo.rodola', 'lcatucci']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue4471'
    versions = ['Python 3.2']

    @lmctv
    Copy link
    Mannequin Author

    lmctv mannequin commented Nov 30, 2008

    In the enclosed patch, there are three changes:

    1. Support starttls on IMAP4 connections
    2. Rework of the IMAP_SSL, to replace home-grown file-like
      methods with proper ones from ssl module's makefile();
    3. Properly shutdown sockets at close() time to avoid server-side pile-up

    @lmctv lmctv mannequin added the stdlib Python modules in the Lib dir label Nov 30, 2008
    @lmctv
    Copy link
    Mannequin Author

    lmctv mannequin commented Nov 30, 2008

    the needed changes to library documentation if the patch is accepted

    @vstinner
    Copy link
    Member

    vstinner commented Dec 1, 2008

    Same comments than issue bpo-4473:

    • you might split your patch into smaller patches
    • Do you really need to keep a reference to the "raw" socket?
    • I don't understand what is sock.shutdown(SHUT_RDWR). When is it
      needed? Does it change the behaviour?

    Oh, another comment:

    • When I fixed poplib/imaplib in py3k, I created a _create_socket()
      method which to factorize the "classic" class and the SSL class. The
      classic class uses socket.create_connection() which supports IPv4 and
      IPv6 (and maybe other protocols) whereas the SSL version reimplements
      create_connection(): "for ... in getaddrinfo...". So you may reuse
      this idea for in your SSL refactoring (for POP3 and IMAP4).

    @lmctv
    Copy link
    Mannequin Author

    lmctv mannequin commented Dec 2, 2008

    As in bpo-4473: if needed, I'll redo the patch into a small
    series. I've cut and pasted the following.

    As for the shutdown before close, it's needed to let the server know
    we are leaving, instead of waiting until socket timeout. This is the
    reason I need to keep the reference to the wrapped socket.

    You don't usually configure maildrop servers to limit the number/rate of
    connects as you do on smtp servers; still, you could get into problems
    with stateful firewalls or the like.

    As for the last comment, I'll gladly look at your changes and try to
    copy^H^H^H^Hbackport them.

    @lmctv
    Copy link
    Mannequin Author

    lmctv mannequin commented Dec 2, 2008

    As requested, I've split the patch into three parts: the first one does
    just refactor IMAP4_SSL, the second is really a one liner for shutting
    down the socket before closing it, and the thirs does introduce the
    starttls method in IMAP4.

    @janssen
    Copy link
    Mannequin

    janssen mannequin commented Feb 2, 2009

    Lorenzo, do we have test cases for this? I think you should try to add
    some test cases. We may need to set up some test mail servers on
    python.org to accommodate such tests.

    @lmctv
    Copy link
    Mannequin Author

    lmctv mannequin commented Feb 2, 2009

    Thanks for following-up, Bill.

    While I fully understand the need for unit-testing, I don't have the
    guts to start writing a dummy imap server from scratch.

    I tested my changes on a couple of servers I manage, one running
    uw-imapd and the other running cyrus imapd; still, I don't think unit
    tests could rely on a "real" server. On the other hand, I don't think a
    python.org hosted test server would be a very wise choice: even if we
    found some dummy all-data-in-memory server, I fear the ssl/tls load on
    the server.

    @gpshead
    Copy link
    Member

    gpshead commented Feb 2, 2009

    For network tests like this where it is useful to test against external
    servers, could we just pick few known external servers that are unlikely
    to every go away?

    imap.gmail.com:993 for instance? (i don't know enough about imap to
    know if it supports what we need to test, I'll leave that up to you to
    determine :)

    Picking another host or two from other big ISPs would also be wise in
    order to test multiple server implementations.

    Once that is done, the tests that connect to external servers should be
    put in their own file marked as requiring the network resource. Similar
    to how its done in Lib/test/test_urllib2net.py.

    @lmctv
    Copy link
    Mannequin Author

    lmctv mannequin commented Feb 2, 2009

    I just found out that the gmail servers don't support connections on
    the standard pop3/imapv4 ports, but only on the SSL wrapped ones.

    I'm unsure if cmu.edu anonymous imap server admin's would be happy with
    their server becoming python's official imap/pop testing playground;
    still, I just verified it does support TLS upgrades both for pop3 and imap
    and anonymous (read-only) logins.

    I think I could cook-up something.

    @lmctv
    Copy link
    Mannequin Author

    lmctv mannequin commented Feb 7, 2009

    As the tests are new, I hope sending the real file is the right way to
    proceed.

    @janssen
    Copy link
    Mannequin

    janssen mannequin commented Mar 1, 2009

    Why can't we use python.org for tests? Do we need IMAP/POP servers
    running? Let's send some mail to pydotorg to get that set up.

    @janssen
    Copy link
    Mannequin

    janssen mannequin commented Mar 3, 2009

    I brought this up on pydotorg, and Barry suggests that someone put
    together a Twisted environment which could be downloaded and run locally
    on the test machine. It would provide IMAP and POP servers, perhaps
    NNTP and others as well. Now, all we need is someone to make that
    happen :-).

    @pitrou
    Copy link
    Member

    pitrou commented Nov 9, 2010

    I've committed some of the remote tests in r86380, which also helped me fix a bug in login() in 3.x.

    @pitrou
    Copy link
    Member

    pitrou commented Nov 9, 2010

    The shutdown change was committed in r86383.

    @pitrou
    Copy link
    Member

    pitrou commented Nov 9, 2010

    Here is an updated STARTTLS patch for py3k.

    @pitrou pitrou added the type-feature A feature request or enhancement label Nov 9, 2010
    @pitrou
    Copy link
    Member

    pitrou commented Nov 12, 2010

    The starttls patch has been committed in r86431. Thank you very much for writing the initial patch.

    @pitrou pitrou closed this as completed Nov 12, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants