ad_build_mime_message (public)
ad_build_mime_message text_body html_body [ charset ]
Defined in packages/acs-tcl/tcl/html-email-procs.tcl
Composes multipart/alternative email containing plain text and html versions of the message, parses out the headers we need, constructs an array and returns it to the caller. This proc is based on ad_html_sendmail, written by Doug Harris at the World Bank.
- Parameters:
- text_body (required)
- html_body (required)
- charset (optional, defaults to
"UTF-8"
)- Returns:
- ns_set containing MIME-Version, Content-ID, Content-Type, and body
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- ad_build_mime_message
Source code: # convert text to charset set encoding [ns_encodingforcharset $charset] if {[lsearch [encoding names] $encoding] != -1} { set html_body [encoding convertto $encoding $html_body] set text_body [encoding convertto $encoding $text_body] } else { ns_log error "ad_html_sendmail: unknown charset passed in ($charset)" } # build body ## JCD: I fail to see why you would want both a base64 and a quoted-printable ## version of html part of this email. I am removing the base64 version. ## set base64_html_part [mime::initialize -canonical text/html -param [list charset $charset] -encoding base64 -string $html_body] set html_part [mime::initialize -canonical text/html -param [list charset $charset] -encoding quoted-printable -string $html_body] set text_part [mime::initialize -canonical text/plain -param [list charset $charset] -encoding quoted-printable -string $text_body] set multi_part [mime::initialize -canonical multipart/alternative -parts [list $text_part $html_part]] # this gives us a complete mime message, minus the headers because # we don't pass any in. This code is designed to send a fully-formed # message out through an SMTP socket, but we're not doing that so we # have to hijack the process a bit. set mime_body [mime::buildmessage $multi_part] # mime-encode the periods at the beginning of a line in the # message text or they are lost. Most noticeable when the line # is broken within a URL regsub {^\.} $mime_body {=2E} mime_body # the first three lines of the message are special; we need to grab # the info, add it to the message headers, and discard the lines set lines [split $mime_body \n] set message_data [ns_set create] # get mime version regexp {MIME-Version: (.*)} [lindex $lines 0] junk mime_version ns_set put $message_data MIME-Version $mime_version # the content id regexp {Content-ID: (.*)} [lindex $lines 1] junk content_id ns_set put $message_data Content-ID $content_id # and the content type and boundary regexp {Content-Type: (.*)} [lindex $lines 2] junk content_type set content_type "$content_type\n[lindex $lines 3]" ns_set put $message_data Content-Type $content_type # the rest of the lines form the message body. We strip off the last # line, which is the last boundary, because acs_mail_lite::send seems to be # adding another one on for us. ## JCD: not anymore. maybe an AOLserver 3.3 bug? removing the clipping. ns_set put $message_data body [join [lrange $lines 4 end] \n] return $message_dataXQL Not present: Generic, PostgreSQL, Oracle