[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Nmh-workers] Attaching a zip file
From: |
Alexander Botero-Lowry |
Subject: |
Re: [Nmh-workers] Attaching a zip file |
Date: |
Wed, 13 Dec 2006 05:42:43 -0800 |
> ------- =_aaaaaaaaaa0
> Content-Type: text/plain; charset="us-ascii"
> Content-ID: <address@hidden>
>
> > > To attach a compressed tar file, say, /tmp/foobar.tgz, to an Email, I do
> > > something like:
> > >
> > > #application/octet-stream; \
> > > type=tar; x-conversion=gzip; \
> > > name=foobar.tgz /tmp/foobar.tgz
> > >
> > > Could somebody take pity on an old man and tell me what I would do to
> attach
> > > a zip file, say. /tmp/foobar.zip, to an Email?
> >
> > I'd just do
> >
> > #application/zip; name="foobar.zip" /tmp/foobar.zip
>
> i'll attach a script i use for forwarding attachments. it
> handles the common binary types i use, plain files, and mail
> messages, based on interpreting its arguments. it produces the
You should really just use file(1) here. It will give you mime-types
and sutible descriptions for free, and doesn't rely on file extensions.
My remime script http://people.freebsd.org/~alexbl/remime uses the libmagic
bindings for pytohn for the same effect. I've also attached it.
> it's far from perfect, i'm sure, but it saves me trying to remember how
> to compose mhbuild lines by hand.
I imagine a _lot_ of people have scripts like this :)
Alex
#!/usr/bin/env python
import sys, re, os
import magic
msg = ''
descr_ms = magic.open(magic.MAGIC_NONE)
descr_ms.load()
mime_ms = magic.open(magic.MAGIC_MIME)
mime_ms.load()
for a in open(sys.argv[1]):
if a.startswith('#remime: '):
filename = a[9:].strip()
if os.path.exists(filename):
a = '#%s; name="%s" <>[ %s ] %s\n' %
(mime_ms.file(filename), os.path.basename(filename), descr_ms.file(filename),
filename)
else:
a = '\n'
msg += a
msg_file = open(sys.argv[1], 'w')
msg_file.write(msg)
msg_file.close()
os.execvp('mhbuild', ('mhbuild', sys.argv[1]))