• Publicity: Public Only All

account-email-procs.tcl

Render and send localized account email.

Location:
packages/acs-authentication/tcl/account-email-procs.tcl

Procedures in this file

Detailed information

[ hide source ] | [ make this the default ]

Content File Source

ad_library {
    Render and send localized account email.
}

namespace eval auth::email {}

d_proc -private auth::email::send {
    -template:required
    -user_id:required
    -to:required
    -default_from:required
    {-from ""}
    {-values {}}
} {
    Render an account email using the recipient's locale.
    The Tcl companion can set from_addr, subject and mime_type in the
    headers dictionary passed by reference. Use text/html for multipart
    delivery with a generated plain-text alternative.
    @param template Name of a Tcl/ADP pair in acs-authentication/lib/email.
    @param default_from Sender used when no override is configured.
    @param from Explicit sender override.
    @param values Dictionary of substitution values for the message catalogs.
} {
    set subsite_id [expr {[ns_conn isconnected] ? [ad_conn subsite_id] : [subsite::main_site_id]}]
    set locale [lang::user::locale -user_id $user_id -package_id $subsite_id]
    if {$from eq ""} {
        set from [parameter::get -package_id $subsite_id -parameter AccountEmailFrom -default ""]
    }
    if {$from eq ""} {
        set from $default_from
    }

    set headers [dict create from_addr $from mime_type text/plain]
    set body [template::adp_include /packages/acs-authentication/lib/email/$template \
                  [list locale $locale values $values &headers headers]]

    set from [dict get $headers from_addr]
    set subject [dict get $headers subject]
    set mime_type [dict get $headers mime_type]
    if {$from eq "" || [regexp {[\r\n]} $from] || [regexp {[\r\n]} $subject]} {
        error "Invalid account email headers"
    }
    if {$mime_type ni {text/plain text/html}} {
        error "Invalid account email content type"
    }

    acs_mail_lite::send -send_immediately -to_addr $to -from_addr $from \
        -subject $subject -body $body -mime_type $mime_type
}

# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: