Python mail truncate problem

D

David

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
 
B

bieffe62

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
 
D

David

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

thanks for your reply. If I delete "mbox[key] = msg", then the actual
files can not be updated for status.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top