acs_mail_lite::unique_id_parse (private)

 acs_mail_lite::unique_id_parse -message_id message_id

Defined in packages/acs-mail-lite/tcl/email-inbound-procs.tcl

Parses a message-id compatible reference created by acs_mail_lite::unique_id_create. Returns package_id, party_id, object_id, other, datetime_cs in a name value list. datetime_cs is approximate system time in seconds from epoch when header was created.

Switches:
-message_id (required)
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_mail_lite_inbound_procs_check acs_mail_lite_inbound_procs_check (test acs-mail-lite) acs_mail_lite::unique_id_parse acs_mail_lite::unique_id_parse test_acs_mail_lite_inbound_procs_check->acs_mail_lite::unique_id_parse acs_mail_lite::address_domain acs_mail_lite::address_domain (private) acs_mail_lite::unique_id_parse->acs_mail_lite::address_domain ad_verify_signature ad_verify_signature (public) acs_mail_lite::unique_id_parse->ad_verify_signature ad_verify_signature_with_expr ad_verify_signature_with_expr (public) acs_mail_lite::unique_id_parse->ad_verify_signature_with_expr db_list_of_lists db_list_of_lists (public) acs_mail_lite::unique_id_parse->db_list_of_lists acs_mail_lite::inbound_email_context acs_mail_lite::inbound_email_context (private) acs_mail_lite::inbound_email_context->acs_mail_lite::unique_id_parse

Testcases:
acs_mail_lite_inbound_procs_check
Source code:
    if { [string match "<*>" $message_id] } {
        # remove quote which is not part of message id according to RFCs
        set message_id [string range $message_id 1 end-1]
    }
    set return_list [list ]
    lassign $return_list package_id party_id object_id other datetime_cs

    set last_at_idx [string last "@" $message_id]

    set domain [string range $message_id $last_at_idx+1 end]
    set unique_part [string range $message_id 0 $last_at_idx-1]
    set first_dash_idx [string first "-" $unique_part]

    if { $first_dash_idx > -1 } {
        # message-id is signed.
        ns_log Dev "acs_mail_lite::unique_id_parse message_id '${message_id}'"
        set unique_id [string range $unique_part 0 $first_dash_idx-1]
        set signature [string range $unique_part $first_dash_idx+1 end]
        set sign_list [split $signature "-+"]

        if { [llength $sign_list] == 3 } {
            # signature is in good form
            # Use the signature's delimiter instead of param IncomingMaxAge
            # so that this works even if there is a change in param value
            #set aml_package_id /apm_package_id_from_key "acs-mail-lite"/
            #set max_age /parameter::get -parameter "IncomingMaxAge"  #                 -package_id $aml_package_id /
            #ns_log Dev "acs_mail_lite::unique_id_parse max_age '${max_age}'"
            # if max_age is "" or "0" delim is "-".
            #    See acs_mail_lite::unique_id_create
            if { [string first "-" $signature] } {
                # A max_age of 0 or '' expires instantly.
                # User expects signature to not expire.
                set expiration_cs [ad_verify_signature $unique_id $sign_list]
            } else {

                set expiration_cs [ad_verify_signature_with_expr $unique_id $sign_list]
            }
            if { $expiration_cs > 0 } {
                set p_lists [db_list_of_lists  acs_mail_lite_send_msg_id_map_r1all {
                                     select package_id,
                                     party_id,
                                     object_id,
                                     other,
                                     datetime_cs
                                     from acs_mail_lite_send_msg_id_map
                                     where msg_id=:unique_part } ]
                set p_list [lindex $p_lists 0]

                lassign $p_list package_id party_id object_id other datetime_cs
            } else {
                ns_log Dev "acs_mail_lite::unique_id_parse unverified signature unique_id '${unique_id}' signature '${sign_list}' expiration_cs '${expiration_cs}'"
            }
            set bounce_domain [acs_mail_lite::address_domain]
            if { $bounce_domain ne $domain } {
                ns_log Warning "acs_mail_lite::unique_id_parse  message_id '${message_id}' is not from '@${bounce_domain}'"
            }
        } else {
            ns_log Dev "acs_mail_lite::unique_id_parse  not in good form signature '${signature}'"
        }
    } else {
        set unique_id $unique_part
        set uid_list [split $unique_id "."]
        if { [llength $uid_list] == 3 } {
            # assume from a mime::uniqueID
            set date_time_cs [lindex $uid_list 1]
        } else {
            set date_time_cs ""
        }

    }
    set r_list [list  package_id $package_id  party_id $party_id  object_id $object_id  other $other  datetime_cs $datetime_cs ]
    return $r_list
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-mail-lite/tcl/email-inbound-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: