On 18 Mag, 05:51, David <ww...@yahoo.com> wrote: > Hi, > > I am writing Python script to process e-mails in a user's mail > account. What I want to do is to update that e-mail's Status to 'R' > after processing it, however, the following script truncates old e- > mails even though it updates that e-mail's Status correctly. Anybody > knows how to fix this? > > Thanks so much. > > fp = '/var/spool/mail/' + user > mbox = mailbox.mbox(fp) > > for key, msg in mbox.iteritems(): > flags = msg.get_flags() > > if 'R' not in flags: > # now process the e-mail > # now update status > msg.add_flag('R' + flags) > mbox[key] = msg
I have no idea about your problem. However, I believe that the last statement "mbox[key] = msg" is not needed. The objects returned by dict.iteritems are not copies but the actual ones in the dictionary, so your msg.add_flag() already modifies the object in mbox. HTH Ciao ----- FB -- http://mail.python.org/mailman/listinfo/python-list