acs_mail_lite::maildir_check_incoming (private)

 acs_mail_lite::maildir_check_incoming

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

Checks for new, actionable incoming email via Postfix MailDir standards. Email is actionable if it is identified by acs_mail_lite::email_type. When actionable, email is buffered in table acs_mail_lite_from_external and callbacks are triggered.

See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 acs_mail_lite::email_type acs_mail_lite::email_type (public) acs_mail_lite::inbound_cache_hit_p acs_mail_lite::inbound_cache_hit_p (private) acs_mail_lite::inbound_email_context acs_mail_lite::inbound_email_context (private) acs_mail_lite::inbound_prioritize acs_mail_lite::inbound_prioritize (public) acs_mail_lite::inbound_queue_insert acs_mail_lite::inbound_queue_insert (private) acs_mail_lite::maildir_check_incoming acs_mail_lite::maildir_check_incoming acs_mail_lite::maildir_check_incoming->acs_mail_lite::email_type acs_mail_lite::maildir_check_incoming->acs_mail_lite::inbound_cache_hit_p acs_mail_lite::maildir_check_incoming->acs_mail_lite::inbound_email_context acs_mail_lite::maildir_check_incoming->acs_mail_lite::inbound_prioritize acs_mail_lite::maildir_check_incoming->acs_mail_lite::inbound_queue_insert

Testcases:
No testcase defined.
Source code:
    set error_p 0
    set mail_dir_fullpath [acs_mail_lite::mail_dir]
    if { $mail_dir_fullpath ne "" } {


        set newdir [file join $mail_dir_fullpath new "*"]
        set curdir [file join $mail_dir_fullpath cur "."]

        set messages_list [glob -nocomplain $newdir]

        # only one of acs_mail_lite::maildir_check_incoming process at a time.
        set cycle_start_cs [clock seconds]
        nsv_lappend acs_mail_lite sj_actives_list $cycle_start_cs
        set sj_actives_list [nsv_get acs_mail_lite sj_actives_list]
        ns_log Notice "acs_mail_lite::maildir_check_incoming.37. start  sj_actives_list '${sj_actives_list}'"

        set active_cs [lindex $sj_actives_list end]
        set concurrent_ct [llength $sj_actives_list]
        # pause is in seconds
        set pause_s 10
        set pause_ms [expr { $pause_s * 1000 } ]
        while { $active_cs eq $cycle_start_cs
                && $concurrent_ct > 1
            } {
            set sj_actives_list [nsv_get acs_mail_lite sj_actives_list]
            set active_cs [lindex $sj_actives_list end]
            set concurrent_ct [llength $sj_actives_list]
            ns_log Notice "acs_mail_lite::maildir_check_incoming.1198.  pausing ${pause_s} seconds for prior invoked processes to stop.  sj_actives_list '${sj_actives_list}'"
            after $pause_ms
        }

        if { $active_cs eq $cycle_start_cs } {

            set aml_package_id [apm_package_id_from_key "acs-mail-lite"]
            set filter_proc [parameter::get -parameter "IncomingFilterProcName"  -package_id $aml_package_id]
            #
            # Iterate through emails
            #
            foreach msg $messages_list {
                set error_p [acs_mail_lite::maildir_email_parse  -headers_arr_name hdrs_arr  -parts_arr_name parts_arr  -message_fpn $msg]
                if { $error_p } {
                    ns_log Notice "acs_mail_lite::maildir_check_incoming  could not process message file '${msg}'. Messaged moved to MailDir/cur/."
                    # Move the message into MailDir/cur for other mail reader
                    file copy -- $msg $curdir
                    file delete -- $msg

                } else {
                    # process email

                    set uid $hdrs_arr(uid)
                    set uidvalidity [file mtime $mail_dir_fullpath]
                    set processed_p [acs_mail_lite::inbound_cache_hit_p  $uid  $uidvalidity  $mail_dir_fullpath ]

                    if { !$processed_p } {

                        set type [acs_mail_lite::email_type  -header_arr_name hdrs_arr ]

                        set headers_list [array names hdrs_arr]
                        # Create some standardized header indexes aml_*
                        # with corresponding values
                        set size_idx [lsearch -nocase -exact  $headers_list size]
                        set sizen [lindex $headers_list $size_idx]
                        if { $sizen ne "" } {
                            set hdrs_arr(aml_size_chars) $hdrs_arr(${sizen})
                        } else {
                            set hdrs_arr(aml_size_chars) ""
                        }

                        if { [info exists hdrs_arr(received_cs)] } {
                            set hdrs_arr(aml_received_cs) $hdrs_arr(received_cs)
                        } else {
                            set hdrs_arr(aml_received_cs) ""
                        }

                        set su_idx [lsearch -nocase -exact  $headers_list subject]
                        if { $su_idx > -1 } {
                            set sun [lindex $headers_list $su_idx]
                            set hdrs_arr(aml_subject) [ns_quotehtml $hdrs_arr(${sun})]
                        } else {
                            set hdrs_arr(aml_subject) ""
                        }

                        set to_idx [lsearch -nocase -exact  $headers_list to]
                        if { ${to_idx} > -1 } {
                            set ton [lindex $headers_list $to_idx]
                            set hdrs_arr(aml_to) [ns_quotehtml $hdrs_arr(${ton}) ]
                        } else {
                            set hdrs_arr(aml_to) ""
                        }

                        acs_mail_lite::inbound_email_context  -header_array_name hdrs_arr  -header_name_list $headers_list

                        acs_mail_lite::inbound_prioritize  -header_array_name hdrs_arr

                        if { [string match {[a-z]*_[a-z]*} $filter_proc] } {
                            set hdrs_arr(aml_package_ids_list) [ad_safe_eval ${filter_proc}]
                        }

                        set id [acs_mail_lite::inbound_queue_insert  -parts_arr_name parts_arr  -headers_arr_name hdrs_arr  -error_p $error_p ]
                        ns_log Notice "acs_mail_lite::maildir_check_incoming  inserted to queue aml_email_id '${id}'"
                    }

                    # Move the message into MailDir/cur for other mail handling
                    file copy -- $msg $curdir
                    file delete -- $msg
                }
            }
        }
        # remove active_cs from sj_actives_list
        set sj_idx [lsearch -integer -exact $sj_actives_list $cycle_start_cs]
        # We call nsv_get within nsv_set to reduce chances of dropping
        # a new list entry.
        nsv_set acs_mail_lite sj_actives_list  [lreplace [nsv_get acs_mail_lite sj_actives_list] $sj_idx $sj_idx]
        ns_log Notice "acs_mail_lite::maildir_check_incoming.199. stop  sj_actives_list '${sj_actives_list}'"
        ns_log Dev "acs_mail_lite::maildir_check_incoming.200. nsv_get  acs_mail_lite sj_actives_list '[nsv_get acs_mail_lite sj_actives_list]'"
    }
    # end if !$error

    return 1
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: