How to program round this poplib error?
cl at isbd.net
cl at isbd.net
Thu Mar 10 09:09:50 EST 2016
Jon Ribbens <jon+usenet at unequivocal.co.uk> wrote:
> On 2016-03-10, cl at isbd.net <cl at isbd.net> wrote:
> > # Read each message into a string and then parse with the email module, if
> > # there's an error retrieving the message then just throw it away
> > #
> > try:
> > popmsg = pop3.retr(i+1)
> > except:
> > pop3.dele(i+1)
> > continue
> >
> > The trouble is that the error is (presumably) some sort of buffer size
> > limitation in pop3.dele(). If I trap the error then I still can't get
> > rid of the rogue E-Mail and, more to the point, I can't even identify
> > it so that the trap could report the error and tell me which message
> > was causing it.
>
> You really, really should not be using bare "except:".
> Always specify which exceptions you are trying to catch.
>
Yes, I know, but it doesn't really relate to the problem does it.
> In this case, I think there are two problems. Firstly, I think
> whoever implemented poplib mis-read the POP3 specification, as
> they are applying the line-length limit to not just the POP3
> commands and responses, but the email contents too.
>
> Secondly, you are just trying to carry on with the POP3 connection
> after it has thrown an exception. You can't do that, because you
> don't know what the problem was. My guess would be that what you
> are mostly seeing is a line in the email content that is over 2kB,
> which causes 'retr' to throw a "line too long" exception.
>
> You then blindly throw a "DELE" at the server, and when you try to
> read the response to that command it throws another "line too long"
> exception because (a) the server's actually still in the middle of
> sending the email contents and (b) there's a bug in the SSL poplib
> which means once it's thrown "line too long" it will keep doing so
> repeatedly.
>
> So what I think you need to do is:
>
> (a) after your "import poplib" add "poplib._MAXLINE = 10*1024*1024"
> or somesuch (i.e. increase it a lot),
>
Ah, that's a much better way of doing it than actually changing the
code, thank you.
> (b) get rid of your "except:" and work out what you really meant,
> checking what the error returned was before blindly throwing
> commands at a POP3 server in an unknown state. You may well
> need to disconnect and reconnect before continuing - or indeed
> you may well not need to catch any exception at all at this
> point after doing (a).
Yes, hopefully the exception will go away.
Thank you again.
--
Chris Green
·
More information about the Python-list
mailing list