classification
Title: POP3 missing support for starttls
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: giampaolo.rodola, janssen, jcea, lcatucci
Priority: normal Keywords: patch

Created on 2008-11-30 16:39 by lcatucci, last changed 2011-03-14 12:09 by jcea.

Files
File name Uploaded Description Edit
poplib.rst.patch lcatucci, 2008-11-30 16:46
poplib_02_sock_shutdown.diff lcatucci, 2008-12-02 12:28
poplib_03_SSL_refactor.diff lcatucci, 2008-12-02 12:28
poplib_04_STLS.diff lcatucci, 2008-12-02 12:29
poplib_01_CAPA.diff lcatucci, 2008-12-02 14:26
test_popnet.py lcatucci, 2009-02-07 00:25
test_popnet.py lcatucci, 2009-02-07 01:04
Messages (13)
msg76643 - (view) Author: Lorenzo M. Catucci (lcatucci) Date: 2008-11-30 16:39
In the enclosed patch, there are four changes 
1. add support for the optional CAPA pop command, since it is needed
   for starttls support discovery
2. add support for the STLS pop command
3. replace home-grown file-like methods and replace them with ssl
   socket's makefile() in POP3_SSL
4. Properly shutdown sockets at close() time to avoid server-side pile-up
msg76645 - (view) Author: Lorenzo M. Catucci (lcatucci) Date: 2008-11-30 16:46
The needed changes to documentation if the patch gets accepted
msg76713 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2008-12-01 23:00
You might split your patch into smaller patches, example:
  * patch 1: implement CAPA method
  * patch 2: POP3_SSL refatoring
  * patch 3: stls() method

Comments:
- Do you really need to keep a reference to the "raw" socket 
(self._sock) for a SSL connection?
- I don't understand what is sock.shutdown(SHUT_RDWR). When is it 
needed? Does it change the behaviour?
- Could you write a method to parse the capabilities because I hate 
long lambda function. You may write doctest for the new method :-)
msg76717 - (view) Author: Lorenzo M. Catucci (lcatucci) Date: 2008-12-01 23:50
I understand the need to keep things simple, but this time the split
seemed a bit overkill. If needed, I'll redo the patch into a small
series. Thinking of it... I was unsure if it really made sense to split
out smtp/pop/imap patches instead of sending them all at once... :-)

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 forewalls or the like.
msg76719 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2008-12-02 00:05
> As for the shutdown before close, it's needed to let the server know
> we are leaving, instead of waiting until socket timeout.

Extracts of an UNIX FAQ [1]:
"Generally the difference between close() and shutdown() is: close() 
closes the socket id for the process but the connection is still 
opened if another process shares this socket id."

"i have noticed on some (mostly non-unix) operating systems though a 
close by all processes (threads) is not enough to correctly flush 
data, (or threads) is not. A shutdown must be done, but on many 
systems it is superfulous."

So shutdown() is useless on most OS, but it looks like it's better to 
use it ;-)

> This is the reason I need to keep the reference to the wrapped 
socket.

You don't need to do that. The wrapper already calls shutdown() of the 
parent socket (see Lib/ssl.py).

[1] http://www.developerweb.net/forum/archive/index.php/t-2940.html
msg76734 - (view) Author: Lorenzo M. Catucci (lcatucci) Date: 2008-12-02 12:31
I'm reasonably sure Victor is right about the original socket being
unneeded. How does the series look now?
msg76735 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2008-12-02 12:44
"lst[1:] if len(lst)>1 else []" is useless, lst[1:] alone does the 
same :-) So it can be simplify to:
  def _parsecap(line):
     lst = line.split()
     return lst[0], lst[1:]

You might add a real example in the capa() docstring.

About poplib_02_sock_shutdown.diff: I'm not sure that poplib is the 
right place to fix the issue... if there is really an issue. Why not 
calling shutdown directly in socket.close()? :-)

You removed self._sock, nice.
msg76744 - (view) Author: Lorenzo M. Catucci (lcatucci) Date: 2008-12-02 14:26
Changed CAPA as requested: now there is a proper docstring, and the
useless if ... else ... is gone.
msg76745 - (view) Author: Lorenzo M. Catucci (lcatucci) Date: 2008-12-02 14:31
As for the shutdown/close comment, I think there could be cases
where you are going to close but don't want to shutdown: e.g. you might
close a dup-ed socket, but the other owner would want to continue
working with his copy of the socket.
msg81327 - (view) Author: Lorenzo M. Catucci (lcatucci) Date: 2009-02-07 00:49
There is a problem I forgot to state with test_anonlogin:
since I try and test both SSL and starttls, the DoS checker at cmu kicks
in and refuse the login attempt in PopSSLTest. Since I'd rather avoid
cheating, I'm leaning to try logging in as SomeUser, and expecting a
failure in both cases. Comments?
msg81330 - (view) Author: Lorenzo M. Catucci (lcatucci) Date: 2009-02-07 01:04
I'm enclosing the expected-failure version of test_popnet. It's much
simpler to talk and comment about something you can see!
msg91094 - (view) Author: Jesús Cea Avión (jcea) * (Python committer) Date: 2009-07-30 13:24
How is going? Any hope for 2.7/3.2?
msg100776 - (view) Author: Jesús Cea Avión (jcea) * (Python committer) Date: 2010-03-10 01:07
Ping...

Any hope for 2.7/3.2?
History
Date User Action Args
2011-03-14 12:09:29jceasetnosy: jcea, janssen, giampaolo.rodola, lcatucci
versions: + Python 3.3, - Python 2.7, Python 3.2
2010-03-12 19:13:38pitrousetversions: + Python 2.7, Python 3.2
nosy: + janssen

priority: normal
type: enhancement
stage: patch review
2010-03-10 01:07:59jceasetmessages: + msg100776
2009-07-30 13:24:23jceasetmessages: + msg91094
2009-07-30 13:19:56jceasetnosy: + jcea
2009-02-08 22:02:17hayposetnosy: - haypo
2009-02-07 01:04:17lcatuccisetfiles: + test_popnet.py
messages: + msg81330
2009-02-07 00:49:21lcatuccisetmessages: + msg81327
2009-02-07 00:26:20lcatuccisetcomponents: + Library (Lib)
2009-02-07 00:25:03lcatuccisetfiles: + test_popnet.py
2008-12-02 14:31:03lcatuccisetmessages: + msg76745
2008-12-02 14:26:45lcatuccisetfiles: - poplib_01_CAPA.diff
2008-12-02 14:26:25lcatuccisetfiles: + poplib_01_CAPA.diff
messages: + msg76744
2008-12-02 12:44:18hayposetmessages: + msg76735
2008-12-02 12:31:55lcatuccisetmessages: + msg76734
2008-12-02 12:29:21lcatuccisetfiles: - poplib.py.patch
2008-12-02 12:29:10lcatuccisetfiles: + poplib_04_STLS.diff
2008-12-02 12:28:52lcatuccisetfiles: + poplib_03_SSL_refactor.diff
2008-12-02 12:28:36lcatuccisetfiles: + poplib_02_sock_shutdown.diff
2008-12-02 12:28:17lcatuccisetfiles: + poplib_01_CAPA.diff
2008-12-02 00:05:08hayposetmessages: + msg76719
2008-12-01 23:50:35lcatuccisetmessages: + msg76717
2008-12-01 23:00:08hayposetnosy: + haypo
messages: + msg76713
2008-12-01 21:44:16giampaolo.rodolasetnosy: + giampaolo.rodola
2008-11-30 16:46:17lcatuccisetfiles: + poplib.rst.patch
messages: + msg76645
2008-11-30 16:39:02lcatuccicreate