Barry Warsaw wrote: > I personally like this part of the API, and I think it's held up well under > years of use.
:-) msg[f] is indeed and really an elegant and understand-at-a-glance way to access headers. (Possible restriction: it would be graceful if it would return and take a list.) > Well, replace one header retaining original order is a bit difficult, but I've > rarely had to do that. [...] > I think it could too, by adding an index argument to .replace_header(), > and using .get_all() to get an ordered list of the headers of interest. ... and give me a way to also delete just one body of a field and i'll be lucky. Maybe simply 'Message._headers = {normalized_field = [bodies]}'? But, why not .delete_all_of(0, 2, 5), realized by a walk in equal spirit to .get_all(). (My thought was that a new Proxy class can be added very easily, requiring only one new method in Message and without affecting the remaining interface, whatever status David's local EMAIL 6 branch is currently in and whatever approach he will have chosen in the end. Anyway, and unless i missed something, this is the current way: def _bewitch_msg(self): """Handle Python 3.2.0/3.3a0 issue 11401 email/message.py error""" if sys.hexversion > 0x030300A1 or sys.hexversion > 0x030200F1: return for f in self._msg: had_repl = False new_ab = [] ab = self._msg.get_all(f) for b in ab: if not len(b): had_repl = True b = ' ' new_ab.append(b) if had_repl: del self._msg[f] for b in new_ab: self._msg[f] = b At best the very same could be achieved (faster and with smaller memory footprint): for p in self._msg.proxy_iter(): for (idx, body) in p: if not len(body): p[idx] = ' ' ) _______________________________________________ Email-SIG mailing list Email-SIG@python.org Your options: http://mail.python.org/mailman/options/email-sig/archive%40mail-archive.com