acs_mail_lite::inbound_prioritize (public)
acs_mail_lite::inbound_prioritize \ [ -header_array_name header_array_name ] \ [ -size_chars size_chars ] [ -received_cs received_cs ] \ [ -subject subject ] [ -package_id package_id ] \ [ -party_id party_id ] [ -object_id object_id ]
Defined in packages/acs-mail-lite/tcl/email-inbound-procs.tcl
Returns a prioritization integer for assigning priority to an inbound email. Another proc processes in order of lowest number first. Returns empty string if input values from email are not expected types. Priority has 3 categories: high priority, normal priority, low priority as specified in acs_mail_lite::sched_parameters Expects parameters to be passed within an array, or individually. When passing via an array, parameter names have suffix "aml_". For example, size_chars becomes aml_size_chars. Array values take precedence, if they exist.
- Switches:
- -header_array_name (optional)
- -size_chars (optional)
- of email
- -received_cs (optional)
- seconds since epoch when email received
- -subject (optional)
- of email
- -package_id (optional)
- associated with email (if any)
- -party_id (optional)
- associated with email (if any)
- -object_id (optional)
- associated with email (if any)
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- acs_mail_lite_inbound_procs_check
Source code: if { $header_array_name ne "" } { set hn_list [list aml_size_chars aml_received_cs aml_subject aml_package_id aml_party_id aml_object_id ] upvar 1 $header_array_name h_arr foreach hn $hn_list { set vname [string range $hn 4 end] if { [info exists h_arr(${hn}) ] } { # set variable from array set ${vname} $h_arr(${hn}) } elseif { [set ${hn}] ne "" } { # set array's index same as variable set h_arr(${hn}) [set ${vname} ] } } } set priority_fine "" set size_error_p 0 # validate email inputs if { ! ([string is wideinteger -strict $size_chars] && $size_chars > 0) } { set size_error_p 1 ns_log Warning "acs_mail_lite::inbound_prioritize.283: size_chars '${size_chars}' is not a natural number." } set time_error_p 0 if { ! ([string is wideinteger -strict $received_cs] && $received_cs > 0) } { set time_error_p 1 ns_log Warning "acs_mail_lite::inbound_prioritize.289: received_cs '${received_cs}' is not a natural number." } # *_cs means clock time from epoch in seconds, # same as returned from tcl clock seconds array set params_arr [acs_mail_lite::sched_parameters] set priority 2 # Set general priority in order of least specific first if { $package_id ne "" } { if { $package_id in $params_arr(hpri_package_ids) } { set priority 1 } if { $package_id in $params_arr(lpri_package_ids) } { set priority 3 } } if { $party_id ne "" } { if { $party_id in $params_arr(hpri_party_ids) } { set priority 1 } if { $party_id in $params_arr(lpri_party_ids) } { set priority 3 } } if { [string match $params_arr(hpri_subject_glob) $subject] } { set priority 1 } if { [string match $params_arr(lpri_subject_glob) $subject] } { set priority 3 } if { $object_id ne "" } { if { $object_id in $params_arr(hpri_object_ids) } { set priority 1 } if { $object_id in $params_arr(lpri_object_ids) } { set priority 3 } } # quick math for arbitrary super max of maxes set su_max $params_arr(mpri_max) append su_max "00" set size_list [list $su_max] set ns_section_list [list nssock nssock_v4 nssock_v6] foreach section $ns_section_list { lappend size_list [ns_config -int -min 0 $section maxinput] } set size_max [f::lmax $size_list] # add granularity switch -exact $priority { 1 { set pri_min 0 set pri_max $params_arr(mpri_min) } 2 { set pri_min $params_arr(mpri_min) set pri_max $params_arr(mpri_max) } 3 { set pri_min $params_arr(mpri_max) set pri_max $size_max } default { ns_log Warning "acs_mail_lite::inbound_prioritize.305: Priority value not expected '${priority}'" } } ns_log Dev "inbound_prioritize: pri_max '${pri_max}' pri_min '${pri_min}'" set range [expr { $pri_max - $pri_min } ] # deviation_max = d_max set d_max [expr { $range / 2 } ] # midpoint = mp set mp [expr { $pri_min + $d_max } ] ns_log Dev "inbound_prioritize: range '${range}' d_max '${d_max}' mp '${mp}'" # number of variables in fine granularity calcs: # char_size, date timestamp set varnum 2 # Get most recent scan start time for reference to batch present time set start_cs [nsv_get acs_mail_lite si_start_t_cs] set dur_s [nsv_get acs_mail_lite si_dur_per_cycle_s] ns_log Dev "inbound_prioritize: start_cs '${start_cs}' dur_s '${dur_s}'" # Priority favors earlier reception, returns decimal -1. to 0. # for normal operation. Maybe -0.5 to 0. for most. if { $time_error_p } { set pri_t 0 } else { set pri_t [expr { ( $received_cs - $start_cs ) / ( 2. * $dur_s ) } ] } # Priority favors smaller message size. Returns decimal 0. to 1. # and for most, somewhere closer to perhaps 0. if { $size_error_p } { set pri_s [expr { ( $size_max / 2 ) } ] } else { set pri_s [expr { ( $size_chars / ( $size_max + 0. ) ) } ] } set priority_fine [expr { int( ( $pri_t + $pri_s ) * $d_max ) + $mp } ] ns_log Dev "inbound_prioritize: pri_t '${pri_t}' pri_s '${pri_s}'" ns_log Dev "inbound_prioritize: pre(max/min) priority_fine '${priority_fine}'" set priority_fine [f::min $priority_fine $pri_max] set priority_fine [f::max $priority_fine $pri_min] if { $header_array_name ne "" } { set h_arr(aml_priority) $priority_fine } return $priority_fineXQL Not present: PostgreSQL, Oracle Generic XQL file: packages/acs-mail-lite/tcl/email-inbound-procs.xql