Mailbox, tell and read
Phil Mayes
Phil.Mayes at p98.f112.n480.z2.fidonet.org
Fri Jul 2 13:00:55 EDT 1999
More information about the Python-list mailing list
Fri Jul 2 13:00:55 EDT 1999
- Previous message (by thread): Python GUIs: Summary and Conclusion
- Next message (by thread): Mailbox, tell and read
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: "Phil Mayes" <nospam at bitbucket.com> Paul Prescod wrote in message <377AAE02.E8591727 at prescod.net>... >The mailbox message objects simulate a file interface by seeking through a >mailbox. A read() returns the entire message. It does this by seeking to >the start, reading to the message end, and returning the data. The problem >is that message offsets are derived by file.tell() which I presume is in >terms of bytes. But then it does a read() based on the offsets and read() >is in terms of characters. > >These don't match up on Windows because of CR/LF pairs. I think that the >right fix is to never use tell() and instead keep track of the location by >counting characters. Does that make sense? I am working with multiple mails in a single file, and found that using seek/tell on the file in text mode didn't allow me to extract a single mail, so I use binary, but I have to convert internally else quopri leaves =CRLF inside the string. Code fragment: # read the body from the mbx file with 'rb' to get the correct # amount of data in, then convert CRLF to LF else quopri fails. fmbx = open(mbxfile, 'rb') fmbx.seek(self._offbody) s = fmbx.read(self._offend - self._offbody) return string.replace(s, '\r\n', '\n') # runs in 2/3 the time of # ... joinfield/splitfield -- Phil Mayes pmayes AT olivebr DOT com
- Previous message (by thread): Python GUIs: Summary and Conclusion
- Next message (by thread): Mailbox, tell and read
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list