acs_mail_lite::imap_email_parse (private)

 acs_mail_lite::imap_email_parse [ -headers_arr_name headers_arr_name ] \
    [ -parts_arr_name parts_arr_name ] [ -conn_id conn_id ] \
    [ -msgno msgno ] [ -struct_list struct_list ] \
    [ -section_ref section_ref ] [ -error_p error_p ]

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

Parse an email from an imap connection into array array_name for adding to queue via acs_mail_lite::inbound_queue_insert Parsed data is set in headers and parts arrays in calling environment. struct_list expects output list from ns_imap struct conn_id msgno

Switches:
-headers_arr_name
(optional)
-parts_arr_name
(optional)
-conn_id
(optional)
-msgno
(optional)
-struct_list
(optional)
-section_ref
(optional)
-error_p
(defaults to "0") (optional)

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::imap_email_parse acs_mail_lite::imap_email_parse acs_mail_lite::imap_check_incoming->acs_mail_lite::imap_email_parse _ _ (public) acs_mail_lite::imap_email_parse->_ acs_mail_lite::sched_parameters acs_mail_lite::sched_parameters (public) acs_mail_lite::imap_email_parse->acs_mail_lite::sched_parameters acs_mail_lite::section_id_of acs_mail_lite::section_id_of (private) acs_mail_lite::imap_email_parse->acs_mail_lite::section_id_of acs_root_dir acs_root_dir (public) acs_mail_lite::imap_email_parse->acs_root_dir

Testcases:
No testcase defined.
Source code:
    # Put email in a format usable for
    # acs_mail_lite::inbound_queue_insert to insert into queue

    # for format this proc is to generate.

    # Due to the hierarchical nature of email and ns_imap struct
    # this proc is recursive.
    upvar 1 $headers_arr_name h_arr
    upvar 1 $parts_arr_name p_arr
    upvar 1 __max_txt_bytes __max_txt_bytes
    set has_parts_p 0
    set section_n_v_list [list ]
    if { ![info exists __max_txt_bytes] } {
        set sp_list [acs_mail_lite::sched_parameters]
        set __max_txt_bytes [dict get $sp_list max_blob_chars]
    }
    if { !$error_p } {

        if { [string range $section_ref 0 0] eq "." } {
            set section_ref [string range $section_ref 1 end]
        }
        ns_log Dev "acs_mail_lite::imap_email_parse.706  msgno '${msgno}' section_ref '${section_ref}'"

        # Assume headers and names are unordered

        foreach {n v} $struct_list {
            if { [string match {part.[0-9]*} $n] } {
                set has_parts_p 1
                set subref $section_ref
                append subref [string range $n 4 end]
                acs_mail_lite::imap_email_parse  -headers_arr_name h_arr  -parts_arr_name p_arr  -conn_id $conn_id  -msgno $msgno  -struct_list $v  -section_ref $subref
            } else {
                switch -exact -nocase -- $n {
                    bytes {
                        set bytes $v
                    }
                    disposition.filename {
                        regsub -all -nocase -- {[^0-9a-zA-Z\-.,\_]} $v {_} v
                        set filename $v
                    }
                    type {
                        set type $v
                    }

                    default {
                        # do nothing
                    }
                }
                if { $section_ref eq "" } {
                    set h_arr(${n}${v}
                } else {
                    lappend section_n_v_list ${n} ${v}
                }
            }
        }

        if { $section_ref eq "" && !$has_parts_p } {
            # section_ref defaults to '1'
            set section_ref "1"
        }

        set section_id [acs_mail_lite::section_id_of $section_ref]
        ns_log Dev "acs_mail_lite::imap_email_parse.746  msgno '${msgno}' section_ref '${section_ref}' section_id '${section_id}'"

        # Add content of an email part
        set p_arr(${section_id},nv_list) $section_n_v_list
        set p_arr(${section_id},c_type) $type
        lappend p_arr(section_id_list) ${section_id}

        if { [info exists bytes]
             && $bytes > $__max_txt_bytes
             && ![info exists filename]
         } {
            set filename "blob.txt"
        }

        if { [info exists filename ] } {
            set filename2 [clock microseconds]
            append filename2 "-" $filename
            set filepathname [file join [acs_root_dir]  acs-mail-lite  $filename2 ]
            set p_arr(${section_id},filename) $filename
            set p_arr(${section_id},c_filepathname) $filepathname
            if { $filename eq "blob.txt" } {
                ns_log Dev "acs_mail_lite::imap_email_parse.775  ns_imap body '${conn_id}' '${msgno}' '${section_ref}'  -file '${filepathname}'"
                ns_imap body $conn_id $msgno ${section_ref}  -file $filepathname
            } else {
                ns_log Dev "acs_mail_lite::imap_email_parse.780  ns_imap body '${conn_id}' '${msgno}' '${section_ref}'  -file '${filepathname}' -decode"

                ns_imap body $conn_id $msgno ${section_ref}  -file $filepathname  -decode
            }
        } elseif$section_ref ne "" } {
            # text content
            set p_arr(${section_id},content) [ns_imap body $conn_id $msgno $section_ref]
            ns_log Dev "acs_mail_lite::imap_email_parse.792  text content '${conn_id}' '${msgno}' '${section_ref}'  $p_arr(${section_id},content)'"

        } else {
            set p_arr(${section_id},content) ""
            # The content for this case
            # has been verified to be redundant.
            # It is mostly the last section/part of message.
            #
            # If diagnostics urge examining these cases,
            # Set debug_p 1 to allow the following code to
            # to compress a message to recognizable parts without
            # flooding the log.
            set debug_p 0
            if { $debug_p } {
                set msg_txt [ns_imap text $conn_id $msgno ]
                # 72 character wide lines * x lines
                set msg_start_max [expr { 72 * 20 } ]
                set msg_txtb [string range $msg_txt 0 $msg_start_max]
                set msg_len [string length $msg_txt]
                if { $msg_len > $msg_start_max + 400 } {
                    set msg_txte [string range $msg_txt end-$msg_start_max end]
                } elseif$msg_len > $msg_start_max + 144 } {
                    set msg_txte [string range $msg_txt end-144 end]
                } else {
                    set msg_txte ""
                }
                ns_log Dev "acs_mail_lite::imap_email_parse.818 IGNORED  ns_imap text '${conn_id}' '${msgno}' '${section_ref}' \n  msg_txte '${msg_txte}'"
            } else {
                ns_log Dev "acs_mail_lite::imap_email_parse.822 ignored  ns_imap text '${conn_id}' '${msgno}' '${section_ref}'"
            }
        }

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