On 01 Oct 08:55, Mark Rogers wrote:
On 30/09/10 18:41, Ted Harding wrote:
It seems Mark wants to set bit 4 to 0, presumably whatever the first 3 bits may be. Is that correct?
That is correct.
The 0009 -> 0008 replacement is fine as far as it goes but it misses all the ones that have other bits set; deleting the status means that there's more rubbish to sort through but at least avoids missing anything.
Also, Mark, how many of the bits would be 1 in this? Since bit 4 can be 1, and bits 1, 2, 3 could be 0 or 1, you could be up to 0015 on those 4 bits alone. Will you be using higher-order bits as well? E.g. with bit 5 in play, you can go up to 0031, with bit 6 up to 0063, etc.
In principle any could be set, although I did grep | sort | uniq the X-Mozilla-Status line and (from memory) there were only about 12 variations in total.
Or is that 4-digit number really in hex? So it could have value 000F, 00BF, 0ABF, ...
Yes, it would be hex.
In principle, your task can be dome in 'awk', but the details would depend on the answers to these questions!
I'd be interested in how to do it in awk purely as an exercise to improve my awk skills, but the actual need has passed by deleting all the status lines. I do still have a backup file to test any theories on though!
Was this an mbox format mailbox perchance? If so then the following would do the job...
--- Begin Python Script --- #!/usr/bin/python
import mailbox
# open and lock the mailbox... mb = mailbox.mbox("/path/to/mbox") mb.lock()
# iterate through the messages for (key,message) in mb.iteritems(): if message.has_key('X-Mozilla-Status'): old_status = message['X-Mozilla-Status'] try: # parse the hex status in to a value we can bitmask old_status_int = int(old_status, 16) except: print "Failed parsing %s" %(old_status) continue del message['X-Mozilla-Status'] # bit mask off the 4th bit. new_status_int = old_status_int & 0xfff7 # make it a 'hex' string without the leading 0x new_status = "%04x" %(new_status_int) message['X-Mozilla-Status'] = str(new_status) # write the new message mb.update(((key, message),)) print "Updated message index: %d" %(key)
mb.flush() mb.unlock() mb.close() --- End Python Script ---
All of the stuff there is in the default libraries of any recent python.
Cheers,