[Pymilter] something odd I've noticed about the milter supplied wrapper to e-mail module

Stuart D. Gathman stuart at bmsi.com
Wed Apr 21 18:08:44 EDT 2004


On Wed, 21 Apr 2004, Eric S. Johansson wrote:

> code of mine which had worked using the standard e-mail module is now 
> causing errors because automatic conversion to string type is not 
> happening with the milter wrapped email module.  End result is a need to 
> sprinkle str() every time I try to assign an integer or a float to a 
> header.
> 
> any ideas why this is happening?

class MimeMessage(Message):

  def __setitem__(self, name, value):
      rc = Message.__setitem__(self,name,value)
      self.modified = True 
      if self.headerchange: self.headerchange(self,name,value)
      return rc

I call the parent setitem, but use the original value to pass on
(to sendmail through the headerchange hook).

If there was a simple way to retrieve the value just stored, we could
pass that on to sendmail instead.  Unfortunately, it is tricky to find
the value we just stored when there are multiple headers with the same name.
(I think the one we just stored would be the last in the list, but I'm
not sure.)

The other option is to duplicate the string conversion.  If wrapping with
str() is all that is required, that is probably simplest:

class MimeMessage(Message):

  def __setitem__(self, name, value):
      rc = Message.__setitem__(self,name,value)
      self.modified = True 
      if self.headerchange: self.headerchange(self,name,str(value))
      return rc

-- 
			Stuart D. Gathman <stuart at bmsi.com>
      Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
      "Very few of our customers are going to have a pure Unix
      or pure Windows environment." - Dennis Oldroyd, Microsoft Corporation




More information about the Pymilter mailing list