acs_mail_lite::inbound_queue_insert (private)

 acs_mail_lite::inbound_queue_insert \
    [ -headers_arr_name headers_arr_name ] \
    [ -parts_arr_name parts_arr_name ] [ -priority priority ] \
    [ -aml_email_id aml_email_id ] [ -section_ref section_ref ] \
    [ -struct_list struct_list ] [ -error_p error_p ]

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

Adds a new, actionable incoming email to the queue for prioritized processing. Returns aml_email_id if successful, otherwise empty string.

Switches:
-headers_arr_name (optional)
-parts_arr_name (optional)
-priority (optional)
-aml_email_id (optional)
-section_ref (optional)
-struct_list (optional)
-error_p (optional, defaults to "0")

Partial Call Graph (max 5 caller/called nodes):
%3 acs_mail_lite::imap_check_incoming acs_mail_lite::imap_check_incoming (private) acs_mail_lite::inbound_queue_insert acs_mail_lite::inbound_queue_insert acs_mail_lite::imap_check_incoming->acs_mail_lite::inbound_queue_insert acs_mail_lite::maildir_check_incoming acs_mail_lite::maildir_check_incoming (private) acs_mail_lite::maildir_check_incoming->acs_mail_lite::inbound_queue_insert acs_mail_lite::parse_email_address acs_mail_lite::parse_email_address (private) acs_mail_lite::inbound_queue_insert->acs_mail_lite::parse_email_address acs_mail_lite::sched_parameters acs_mail_lite::sched_parameters (public) acs_mail_lite::inbound_queue_insert->acs_mail_lite::sched_parameters db_dml db_dml (public) acs_mail_lite::inbound_queue_insert->db_dml db_nextval db_nextval (public) acs_mail_lite::inbound_queue_insert->db_nextval db_transaction db_transaction (public) acs_mail_lite::inbound_queue_insert->db_transaction

Testcases:
No testcase defined.
Source code:
    upvar 1 $headers_arr_name h_arr
    upvar 1 $parts_arr_name p_arr

    set id ""
    # This should remain general enough to import
    # email regardless of its source.

    # Email should already be parsed and in a transferable format
    # in passed arrays

    # Array content corresponds to these tables:

    #   h_arr($name) $value         acs_mail_lite_ie_headers
    #       Some indexes match fields of table acs_mail_lite_from_external:
    #   h_arr(aml_email_id)
    #   h_arr(aml_to_addrs)     to_email_addrs
    #   h_arr(aml_from_addrs)   from_email_addrs
    #   h_arr(aml_priority)     priority
    #   h_arr(aml_subject)      email subject (normalized index reference).
    #   h_arr(aml_msg_id)       email message-id or msg-id's cross-reference
    #                           see acs_mail_lite_msg_id_map.msg_id
    #   h_arr(aml_size_chars)   size_chars
    #   h_arr(aml_processed_p)  processed_p

    #   p_arr($section_id,<field>)  acs_mail_lite_ie_parts (content of a part)
    #   p_arr($section_id,nv_list)  acs_mail_lite_part_nv_pairs
    #   p_arr(section_id_list) list of section_ids
    #
    #
    # where index is section_id based on section_ref, and
    # where top most section_ref is a natural number as
    # there may be more than one tree.
    #
    # Specifically,
    # for p_arr, content is p_arr($section_id,content)
    #            c_type is p_arr($section_id,c_type)
    #            filename is p_arr($section_id,filename)
    #            c_filepathname is p_arr($section_id,c_filepathname)
    #



    if { !$error_p } {

        # email goes into queue tables:

        # This data is expected to be available at same moment

        db_transaction {
            set id [db_nextval acs_mail_lite_in_id_seq]

            # acs_mail_lite_ie_headers
            set h_names_list [array names h_arr]
            set to_email_addrs ""
            set from_email_addrs ""
            set subject ""
            set msg_id ""
            set size_chars ""
            set received_cs ""
            # sub set of header names
            foreach h_name $h_names_list {
                set h_value $h_arr(${h_name})
                switch -nocase -- $h_name {
                    x-openacs-from -
                    aml_from_addrs -
                    from {
                        if { ![info exists h_arr(aml_from_addrs)] } {
                            set fr_addrs [acs_mail_lite::parse_email_address  -email $h_value ]
                            set h_arr(aml_from_addrs) $fr_addrs
                        } else {
                            set fr_addrs $h_arr(aml_from_addrs)
                        }
                    }
                    x-openacs-to -
                    aml_to_addrs -
                    to {
                        if { ![info exists h_arr(aml_to_addrs)] } {
                            set h_quoted [ns_quotehtml $h_value]
                            set h_arr(aml_to) $h_quoted
                            set to_addrs [acs_mail_lite::parse_email_address  -email $h_quoted ]
                            set h_arr(aml_to_addrs) $to_addrs
                        } else {
                            set to_addrs $h_arr(aml_to_addrs)
                        }
                    }
                    aml_msg_id {
                        set msg_id $h_value
                    }
                    x-openacs-subject -
                    aml_subject -
                    subject {
                        set subject $h_value
                    }
                    x-openacs-size -
                    aml_size_chars -
                    size {
                        if { ![info exists h_arr(aml_size_chars) ] } {
                            if { [string is wideinteger -strict $h_value] } {
                                set size_chars $h_value
                            }
                        } else {
                            set size_chars $h_arr(ams_size_chars)
                        }
                    }
                    aml_received_cs {
                        set received_cs $h_value
                    }
                    aml_priority {
                        set priority $h_value
                    }
                }

                if { $priority eq "" } {
                    set priority [dict get  [acs_mail_lite::sched_parameters] mpri_max]
                }

                db_dml acs_mail_lite_ie_headers_w1 {
                    insert into acs_mail_lite_ie_headers
                    (aml_email_id,h_name,h_value)
                    values (:id,:h_name,:h_value)
                }
            }

            # acs_mail_lite_from_external
            set false 0
            #set processed_p 0
            #set release_p 0
            db_dml acs_mail_lite_from_external_w1 {
                insert into acs_mail_lite_from_external
                (aml_email_id,
                 priority,
                 to_email_addrs,
                 from_email_addrs,
                 subject,
                 msg_id,
                 size_chars,
                 received_cs,
                 processed_p,
                 release_p)
                values (:id,
                        :priority,
                        :to_addrs,
                        :fr_addrs,
                        :subject,
                        :msg_id,
                        :size_chars,
                        :received_cs,
                        :false,
                        :false)
            }



            set parts_list [list c_type filename content c_filepathname]
            foreach section_id $p_arr(section_id_list) {

                # acs_mail_lite_ie_parts
                foreach p $parts_list {
                    set $p ""
                    if { [info exists p_arr(${section_id},${p}) ] } {
                        set $p $p_arr(${section_id},${p})
                    }
                }
                db_dml acs_mail_lite_ie_parts_w1 {
                    insert into acs_mail_lite_ie_parts
                    (aml_email_id,
                     section_id,
                     c_type,
                     filename,
                     content,
                     c_filepathname)
                    values
                    (:id,
                     :section_id,
                     :c_type,
                     :filename,
                     :content,
                     :c_filepathname)
                }

                # acs_mail_lite_ie_part_nv_pairs
                foreach {p_name p_value} $p_arr(${section_id},nv_list) {
                    db_dml acs_mail_lite_ie_part_mv_pairs_w1 {
                        insert into acs_mail_lite_ie_part_nv_pairs
                        (aml_email_id,
                         section_id,
                         p_name,
                         p_value)
                        values
                        (:id,
                         :section_id,
                         :p_name,
                         :p_value)
                    }
                }
            }


        } on_error {
            ns_log Error "acs_mail_lite::inbound_queue_insert  Unable to insert email. Headers: '[array get h_arr]' Error: ${errmsg}"

        }
    }
    return $id
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: