[plug] MIME Types by file contents
Bernd Felsche
bernie at innovative.iinet.net.au
Tue Jul 6 20:07:40 WST 2004
On Tuesday 06 July 2004 13:53, Craig Ringer wrote:
> Bernd Felsche wrote:
> > I get a bunch of errors like:
> > bernie at pinion:~> python bin/maildoc.py bernie < z25
> > Traceback (most recent call last):
> > File "bin/maildoc.py", line 143, in ?
> > if __name__ == '__main__': main()
> > File "bin/maildoc.py", line 140, in main
> > os.popen("/usr/sbin/sendmail -t","w").write(message.as_string())
> > File
> > "/var/tmp/python-2.2.2-build//usr/lib/python2.2/email/Message.py", line
[snip]
> > whenever I feed it a saved news item. It'll probably hiccup on email as
> > well.
> >
> > See the attached bugfest for details.
> A heads-up on said "bugfest" - you've mixed space and tab indenting.
> This is probably unwise. If you drop this in your .vimrc (if you use
> vim), it'll display tabs and trailing spaces:
>
> set listchars=tab:>-,trail:+
Except I don't want it to work that way for everything. :-)
I might get smart and load the syntax, etc files for Python.
> ... really handy for this sort of thing.
Or I could just set vim not to replace spaces with tabes when
increasing indent levels.
> I'm going to make a guess at what the problem you're having is, based on
> that info you found and the code in build_message(). I suspect the email
> package is being confused by the content-type of message/* because it
Once I hard-coded that maintype as 'text' instead of 'message'
doc_part = MIMEBase('text','news')
and comment out the other code
# if doc_type[0] == 'data':
# doc_part = MIMEBase(doc_type[0],'')
# else:
# doc_part = MIMEBase(doc_type[0],doc_type[1])
it doesn't complain.
> expects a Message object for that content-type. If you look at
> Generator._dispatch, you'll see:
Yes indeed. It does look like that.. but
> doc_part = MIMEMessage(doc_data, doc_type[1])
won't work because the stuff isn't really a message.
I finally changed the MIMEBase definition to force 'text' instead of
'message' if that is the maintype.
if doc_type[0] == 'data':
doc_part = MIMEBase(doc_type[0],'')
elif doc_type[0] == 'message':
doc_part = MIMEBase('text',doc_type[1])
else:
doc_part = MIMEBase(doc_type[0],doc_type[1])
Now much happier.
And having thrown a collection of various crud at the procedure, it
seems to have encoded stuff well.
--
/"\ Bernd Felsche - Innovative Reckoning, Perth, Western Australia
\ / ASCII ribbon campaign | I'm a .signature virus!
X against HTML mail | Copy me into your ~/.signature
/ \ and postings | to help me spread!
More information about the plug
mailing list