acs_mail_lite::inbound_queue_pull (private)

 acs_mail_lite::inbound_queue_pull

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

Identifies and processes highest priority inbound email.

Partial Call Graph (max 5 caller/called nodes):
%3 acs_mail_lite::bounce_ministry acs_mail_lite::bounce_ministry (private) acs_mail_lite::inbound_queue_pull_one acs_mail_lite::inbound_queue_pull_one (private) acs_object::object_p acs_object::object_p (public) apm_package_id_from_key apm_package_id_from_key (public) callback callback (public) acs_mail_lite::inbound_queue_pull acs_mail_lite::inbound_queue_pull acs_mail_lite::inbound_queue_pull->acs_mail_lite::bounce_ministry acs_mail_lite::inbound_queue_pull->acs_mail_lite::inbound_queue_pull_one acs_mail_lite::inbound_queue_pull->acs_object::object_p acs_mail_lite::inbound_queue_pull->apm_package_id_from_key acs_mail_lite::inbound_queue_pull->callback

Testcases:
No testcase defined.
Source code:


    # Get scheduling parameters
    set start_cs [clock seconds]
    # The value of si_dur_per_cycle_s is used
    # to keep about 1 inbound_queue_pull active at a time.
    # This is an artificial limit.
    # For parallel processing of queue, remove this
    # scheduling check, and query the queue with each iteration.
    # That is, query the queue before processing
    # each inbound email to avoid collision of attempts
    # to process email more than once.
    set si_dur_per_cycle_s  [nsv_get acs_mail_lite si_dur_per_cycle_s ]
    set stop_cs [expr { $start_cs + int( $si_dur_per_cycle_s * .8 ) } ]
    set aml_package_id [apm_package_id_from_key "acs-mail-lite"]
    # ct = count
    set pull_ct 0
    # sort only what we need. Process in 20 email chunks
    set email_max_ct 20
    set pull_p 1
    while { $pull_p && [clock seconds ] < $stop_cs } {

        # ols = ordered lists
        set chunk_ols [db_list acs_mail_lite_from_external_rN {
            select aml_email_id from acs_mail_lite_from_external
            where processed_p <>'1'
            and release_p <>'1'
            order by priority
            fetch next :email_max_ct rows only}]

        set chunk_len [llength $chunk_ols]
        if { $chunk_len < 1} {
            set pull_p 0
        }
        set i 0
        while { $i < $chunk_len && $pull_p && [clock seconds ] < $stop_cs } {
            array unset h_arr
            array unset p_arr
            set error_p 0
            set aml_email_id [lindex $chunk_ols $i]
            acs_mail_lite::inbound_queue_pull_one  -h_array_name h_arr  -p_array_name p_arr  -aml_email_id $aml_email_id

            set processed_p 0
            set bounced_p [acs_mail_lite::bounce_ministry]
            if { !$bounced_p } {

                # following from acs_mail_lite::load_mail
                set pot_object_id [lindex [split $h_arr(aml_to_addrs) "@"] 0]
                ##code  OpenACS Developers:
                # object_id@domain is unconventional
                # and may break if someone
                # uses an email beginning with a number.
                # Also, 'from' header could be spoofed..
                # This practice should be deprecated in favor of signed
                # acs_mail_lite::unique_id_create.
                # For emails originating elsewhere, another authentication
                # method, such as a pre-signed unique-id in message
                # content could be added as well.
                # For now, we warn whenever this is used.
                if { [string is integer -strict $pot_object_id] } {
                    if { [acs_object::object_p -id h_arr(aml_object_id)] } {
                        ns_log Warning "acs_mail_lite::inbound_queue_pull  Accepted insecure email object_id '${pot_object_id}'  array get h_arr '[array get h_arr]'. See code comments."
                        callback -catch acs_mail_lite::incoming_object_email  -array h_arr  -object_id $pot_object_id
                        set processed_p 1
                    }
                }
                if { !$processed_p } {
                    # Execute all callbacks for this email

                    # Forums uses callbacks via notifications
                    # See callback
                    # acs_mail_lite::incoming_email -imp notifications
                    # in notifications/tcl/notification-callback-procs.tcl
                    # and
                    # notification::reply::get
                    #  in forums/tcl/forum-reply-procs.tcl
                    #  which is defined in file:
                    # notifications/tcl/notification-reply-procs.tcl

                    #Callback acs_mail_lite::incoming_email bounces everything
                    # with a user_id.
                    # Its useful code has been added to
                    # acs_mail_lite::bounce_ministry.
                    # A new callback intended to be compatible with
                    # notification::reply::get (if possible) is invoked here
                    if { ![info exists h_arr(aml_package_id) ] } {
                        set h_arr(aml_package_id) $aml_package_id
                    }
                    set status [callback -catch acs_mail_lite::email_inbound  -header_array_name h_arr  -parts_array_name p_arr  -package_id $h_arr(aml_package_id)  -object_id $h_arr(aml_object_id)  -party_id $h_arr(aml_party_id)  -other $h_arr(aml_other)  -datetime_cs $h_arr(aml_datetime_cs)]

                    if {"0" in $status} {
                        set error_p 1
                    }
                }
            }

            # Email is removed from queue when
            # set acs_mail_lite_from_external.processed_p 1.
            # Do not release if there was an error.
            # set acs_mail_lite_from_external.release_p !$error_p
            set not_error_p [expr { ! $error_p } ]
            db_dml acs_mail_lite_from_external_wproc {
                update acs_mail_lite_from_external
                set processed_p='1'
                and release_p=:not_error_p
                where acs_email_id=:acs_email_id
            }

            incr i
        }

    }

   return 1
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: