Forum OpenACS Q&A: Re: Parsing an incoming multi-part e-mail message

Posted by Matthew Walker on
I read my reply from earlier and it didn't make much sense to me so here's some code that works with the mime module from tcllib:

set mime [mime::initialize -string $msg]

set content [mime::getproperty $mime content]

if { [string first "multipart" $content] != -1 } {
    set parts [mime::getproperty $mime parts]
} else {
    set parts [list $mime]

foreach part $parts {
    switch [mime::getproperty $part content] {
        "text/plain" {
            set plain [mime::getbody $part]
        "text/html" {
            set html [mime::getbody $part]

It will recurse one level deep into multipart messages and try and find both the plain and html versions. It's possible that the message can be deeper than one level but I wouldn't think so for a reply to a forum posting (it's mainly spam trying to avoid filters where I've seen that).