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

Collapse
Posted by Matthew Walker on
You should be able to pass the MIME message to initialize and have it parse out all the parts and then use getproperty to find the one you want and getbody to retrieve it. You may also want to look at the mime module on tcllib, this has a few more capabilities.
Collapse
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).