ad_parse_incoming_email (public)

 ad_parse_incoming_email message

Defined in packages/acs-tcl/tcl/html-email-procs.tcl

Takes an incoming message and splits it into parts. The main goal of this proc is to return something that can be stuffed into the database somewhere, such as a forum message. Since we aggressively filter HTML, the HTML tags are stripped out of the returned content. The message may have only plain text, plain text and HTML, or plain text and something else (Apple Mail uses text/enhanced, for example). To make our lives simpler we support only text/html as a special case; in all other cases the plain text is returned.

Parameters:
message

Partial Call Graph (max 5 caller/called nodes):
%3 notification::email::load_qmail_mail_queue notification::email::load_qmail_mail_queue (private) ad_parse_incoming_email ad_parse_incoming_email notification::email::load_qmail_mail_queue->ad_parse_incoming_email parse_incoming_email parse_incoming_email (public, deprecated) parse_incoming_email->ad_parse_incoming_email ad_html_to_text ad_html_to_text (public) ad_parse_incoming_email->ad_html_to_text mime::finalize mime::finalize ad_parse_incoming_email->mime::finalize mime::getbody mime::getbody ad_parse_incoming_email->mime::getbody mime::getproperty mime::getproperty ad_parse_incoming_email->mime::getproperty mime::initialize mime::initialize ad_parse_incoming_email->mime::initialize

Testcases:
No testcase defined.
Source code:
    if { [catch {set mime [mime::initialize -string $message]} err ] } {
        ns_log error "parse_incoming_email: could not parse message; error was $err"
        return ""
    }
    set content [mime::getproperty $mime content]

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

    # Expand any first-level multipart/alternative children.
    set expanded_parts [list]
    foreach part $parts {
        catch {mime::getproperty $part content} this_content
        if { $this_content eq "multipart/alternative"} {
            foreach child_part [mime::getproperty $part parts] {
                lappend expanded_parts $child_part
            }
        } else {
            lappend expanded_parts $part
        }
    }

    foreach part $expanded_parts {
        catch {mime::getproperty $part content} this_content
        switch -- $this_content {
            "text/plain" {
                if { ![info exists plain] } {
                    set plain [mime::getbody $part]
                }
            }
            "text/html" {
                if { ![info exists html] } {
                    set html [mime::getbody $part]
                }
            }
        }
    }

    if { [info exists plain] } {
        set body $plain
    } elseif { [info exists html] } {
        set body [ad_html_to_text -- $html]
    } else {
        set body $message
    }

    mime::finalize $mime -subordinates all
    return $body
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: