[Zope-dev] RE: [Zope] change to MimeWriter to add "MIME-Version: 1.0"

Jay, Dylan djay@lucent.com
Thu, 7 Oct 1999 15:23:08 +1000


> -----Original Message-----
> From: Pate, Clarence T [mailto:Clarence.Pate@bridge.bellsouth.com]
> Sent: Thursday, October 07, 1999 04:45
> To: jason@mtear.com; michel@digicool.com; zope@zope.org
> Subject: RE: [Zope] change to MimeWriter to add "MIME-Version: 1.0"
> 

I'm also making changes to MimeTools. I've split the mime tag into two tags,
mime and boundary. This allows for the conditional inclusion of sub parts. I
am currently trying to allow variablized parameters to the tags (and not
having much luck!). I want to be able to say 
<dtml-boundary name="upload_file.filename()">
Anyone have any ideas?

 
> =->
> =->Note that Mimewriter is a standard python module, not a 
> part of Zope.
> =->You should submit your patch to the apropriate module 
> author or to the
> =->http://www.python.org/python-bugs section of the python site.
> =->
> =->Thanks for the patch!
> =->
> =->-Michel
> =->
> 
> Michael,
> 
> I sent a message to Guido, and he suggested something that 
> was much better (I
> really should not have bothered him with this minor problem.) 
>  All that was
> necessary is to change "MimeTools.py".  Basically, I added a 
> parameter to the
> mime tag, <!--#mime version=true-->.  Since I am not a python 
> programmer,
> somebody should verify that this does what I think it does!?!
> I have included the subset of MimeTools.py that I changed.
> 
> 
> 
>     name='mime'
>     blockContinuations=('boundary',)
>     encode=None
> """I added version=None.  I guess this is like a global variable.
>    I am not sure if this is necessary"""
>     version=None
> 
>     def __init__(self, blocks):
>         self.sections = []
> 
>         for tname, args, section in blocks:
> """I added the parameter version"""
>             args = parse_params(args, type=None, disposition=None,
>                                 encode=None, name=None, version=None)
> 
>             has_key=args.has_key
> 
>             if has_key('type'): 
>                 type = args['type']
>             else:
>                 type = 'application/octet-stream'
> 
>             if has_key('disposition'):
>                 disposition = args['disposition']
>             else:
>                 disposition = ''
> 
>             if has_key('encode'):
>                 encode = args['encode']
>             else:
>                 encode = 'base64'
> 
>             if has_key('name'):
>                 name = args['name']
>             else:
>                 name = ''
> """I added this. I believe it checks for any value, if no 
> value set to ''"""
>             if has_key('version'):
>                 version = args['version']
>             else:
>                 version = ''
> 
>             if encode not in \
>             ('base64', 'quoted-printable', 'uuencode', 'x-uuencode',
>              'uue', 'x-uue', '7bit'):
>                 raise MIMEError, (
>                     'An unsupported encoding was specified in tag')
> 
>             self.sections.append((type, disposition, encode, 
>                                   name, version,  section.blocks))
> 
> 
>     def render(self, md):
>         contents=[]
>         mw = MimeWriter(StringIO())
> 
> """I added this.  If version exists, add the header to 'outer'.
>    This only provides for version 1.0, maybe this should be a
>    variable that is actually passed if there are new future
>    version numbers. """
>         for x in self.sections:
>             t, d, e, n, v, b = x
>             if v:
>                 outer = mw.addheader("MIME-Version", "1.0", prefix=1)
>         outer = mw.startmultipartbody('mixed')
> 
> Thanks for the help!
> 
> Clarence T. Pate
> 
> 
>