[Python-bugs-list] Re: A little bug in the ._test of the mailbox module (PR#135)

Leroy.Regis@iupchbio.univ-nantes.fr Leroy.Regis@iupchbio.univ-nantes.fr
Mon, 13 Dec 1999 10:04:13 -0500 (EST)


On 03 12 1999, you wrote :
> 
> I cannot reproduce this problem.
> 
> I don't know what's in the test.py file.  Perhaps you are not using the
> mailbox module right?
> 
> > This is due to the line 258 of mailbox.py. In this line we've got "msg.fp =
> > None"
> > (I can't understan why...)
> 
> This line is there because otherwise you would have as many open files
> as you inspect messages -- remember that a mailbox can have thousands
> of messages and you can't have that many open files.  There should be
> no need to use the file after reading the headers.
> 
> 
> Unless you show sample code that elicits this problem I'm going to categorize
> this as a use error, because I cannot reproduce it given your information.
> 
> Sorry,
> 
> --Guido van Rossum


Excuse me but I don't think this is a user bug!
Maybe I haven't said enought the first time.
Excuse me for that and please take a look at theses explainations.
Here 's the code of my test program (mymbxtest.py):

#! /usr/bin/python
import mailbox
mb = mailbox._test()

And here is the way to obtain the bug:

[root@banquise]# ./mymbxtest.py
Mailbox /var/spool/mail/toto has 0 messages:

[root@banquise]# ./mymbxtest.py /var/spool/mail/facteur
Mailbox /var/spool/mail/facteur has 7 messages:
Mail System Internal   26 Nov 1999 16:26:   DON'T DELETE THIS MESSAGE -- F
root <root@banquise.   23 Nov 1999 16:02:   retest pour facteur
root <root@banquise.   23 Nov 1999 16:30:   un autre encore
Mail Delivery Subsys   23 Nov 1999 17:38:   Postmaster notify: Host unknow
Mail Delivery Subsys   24 Nov 1999 16:01:   Postmaster notify: Host unknow
Mailer-Daemon (Mail	26 Nov 1999 11:51:   Postmaster notify: User unknow
Mailer-Daemon (Mail    13 Dec 1999 09:00:   Postmaster notify: Cannot send

[root@banquise]# ./mymbxtest.py /var/spool/mail/facteur 2
Message 2 body:
Traceback (innermost last):
  File "./mymbxtest.py", line 3, in ?
    mb = mailbox._test()
  File "/usr/lib/python1.5/mailbox.py", line 263, in _test
    msg.rewindbody()
  File "/usr/lib/python1.5/rfc822.py", line 104, in rewindbody
    self.fp.seek(self.startofbody)
AttributeError: 'None' object has no attribute 'seek'
-----------------------------------------------------------------------------
As we can see in this part of the mailbox module
the user of the _test part of the module can use
a second arg to read the a message.

if len(args) > 1:
                num = string.atoi(args[1])
                print 'Message %d body:'%num
                msg = msgs[num-1]
                msg.rewindbody() 
                sys.stdout.write(msg.fp.read())

Here is what I call a bug.
Because to use the rfc822 rewindbody() we've got to
have a valid Fp, not 'None'.
This bug is a little bug for two reasons:
- this is only a _test proc, is aim is just to inspire you.
- it's a bug in the way we use the rf822 module not the mailbox module.

I understand that we can't keep all the fp opened on messages.
But if we want to read it with rfc822 we've got to open it before.
It's maybe possible to open it jsut before the Msg.rewindbody() and
to close it after.
 
Thanks for your response, I'm glad to have your name in my mailbox.

---
||fatal comprehension error - THC00:00 - no-sens - main-reboot
||neurone overflow at 00:00 ____________________________ ____
| _|_|_|  _|_|_|  _|_|_|_| |    {%p#  #£)k  {8°p}k-    _|____|___
| _|   _| _|      _|        leroy@staps.univ-nantes.fr |___|_|_|
| _|_|_|  _|_|    _|  _|_|_|   objo-admin-system           | | |
| _|   _| _|      _|    _|  leroy@iupchbio.univ-nantes.fr _|_|__\
| _|    _|_|_|_|_|_|_|_|_| |_______________________________||___|