acs_mail_lite::imap_conn_go (private)

 acs_mail_lite::imap_conn_go [ -conn_id conn_id ] [ -host host ] \
    [ -password password ] [ -port port ] [ -timeout timeout ] \
    [ -user user ] [ -flags flags ] [ -name_mb name_mb ] \
    [ -default_to_inbox_p default_to_inbox_p ] \
    [ -default_box_name default_box_name ]

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

Verifies connection (connId) is established. Tries to establish a connection if it doesn't exist. If mailbox doesn't exist, tries to find an inbox at root of tree or as close as possible to it. If -host parameter is supplied, will try connection with supplied params. Defaults to use connection info provided by parameters via acs_mail_lite::imap_conn_set.

Switches:
-conn_id (optional)
-host (optional)
-password (optional)
-port (optional)
Ignored for now. SSL automatically switches port.
-timeout (optional)
-user (optional)
-flags (optional)
-name_mb (optional)
-default_to_inbox_p (optional, defaults to "0")
If set to 1 and name_mb not found, assigns an inbox if found.
-default_box_name (optional, defaults to "inbox")
Set if default name for default_to_inbox_p should be something other than inbox.
Returns:
connectionId or empty string if unsuccessful.
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_mail_lite_inbound_procs_check acs_mail_lite_inbound_procs_check (test acs-mail-lite) acs_mail_lite::imap_conn_go acs_mail_lite::imap_conn_go test_acs_mail_lite_inbound_procs_check->acs_mail_lite::imap_conn_go acs_mail_lite::imap_conn_set acs_mail_lite::imap_conn_set (private) acs_mail_lite::imap_conn_go->acs_mail_lite::imap_conn_set acs_mail_lite::imap_mailbox_join acs_mail_lite::imap_mailbox_join (public) acs_mail_lite::imap_conn_go->acs_mail_lite::imap_mailbox_join acs_mail_lite::imap_check_incoming acs_mail_lite::imap_check_incoming (private) acs_mail_lite::imap_check_incoming->acs_mail_lite::imap_conn_go

Testcases:
acs_mail_lite_inbound_procs_check
Source code:
    # imap_conn_go = icg
    # imap_conn_set = ics
    if { $host eq "" } {
        set default_conn_set_p 1
        set ics_list [acs_mail_lite::imap_conn_set ]
        foreach {n v} $ics_list {
            set $n "${v}"
            ns_log Dev "acs_mail_lite::imap_conn_go.596. set ${n} '${v}'"
        }
    } else {
        set default_conn_set_p 0
    }

    set fl_list [split $flags " "]

    set connected_p 0
    set prior_conn_exists_p 0

    if { $conn_id ne "" } {
        # list {id opentime accesstime mailbox} ...
        set id ""
        set opentime ""
        set accesstime ""
        set mailbox ""

        set sessions_list [ns_imap sessions]
        set s_len [llength $sessions_list]
        ns_log Dev "acs_mail_lite::imap_conn_go.612:  sessions_list '${sessions_list}'"
        # Example session_list as val0 val1 val2 val3 val4 val5 val6..:
        #'40 1501048046 1501048046 {{or97.net:143/imap/tls/user="testimap1"}<no_mailbox>}
        # 39 1501047978 1501047978 {{or97.net:143/imap/tls/user="testimap1"}<no_mailbox>}'
        set i 0
        while { $i < $s_len && $id ne $conn_id }  {
            set s_list [lindex $sessions_list 0]
            set id [lindex $s_list 0]
            if { $id eq $conn_id } {
                set prior_conn_exists_p 1
                lassign $s_list . opentime accesstime mailbox
            }
            incr i
        }
        if { $prior_conn_exists_p eq 0 } {
            ns_log Warning "acs_mail_lite::imap_conn_go.620:  Session broken? conn_id '${conn_id}' not found."
        }
    }

    if { $prior_conn_exists_p } {
        # Test connection.
        # status_flags = sf
        if { [catch { set sf_list [ns_imap status $conn_id ] } err_txt ] } {
            ns_log Warning "acs_mail_lite::imap_conn_go.624  Error connection conn_id '${conn_id}' unable to get status. Broken?  Set to retry. Error is: ${err_txt}"
            set prior_conn_exists_p 0
        } else {
            set connected_p 1
            ns_log Dev "acs_mail_lite::imap_conn_go.640: fl_list '${fl_list}'"
        }
    }

    if { !$prior_conn_exists_p && $host ne "" } {
        if { "ssl" in $fl_list } {
            set ssl_p 1
        } else {
            set ssl_p 0
        }
        set mb [acs_mail_lite::imap_mailbox_join  -host $host  -name $name_mb  -ssl_p $ssl_p]
        if { "novalidatecert" in $fl_list } {
            if { [catch { set conn_id [ns_imap open  -novalidatecert  -mailbox "${mb}"  -user $user  -password $password]  } err_txt ]  } { ns_log Warning "acs_mail_lite::imap_conn_go.653  Error attempting ns_imap open. Error is: '${err_txt}'"
            } else {
                set connected_p 1
                ns_log Dev "acs_mail_lite::imap_conn_go.662:  new session conn_id '${conn_id}'"
            }
        } else {
            if { [catch { set conn_id [ns_imap open  -mailbox "${mb}"  -user $user  -password $password]  } err_txt ]  } { ns_log Warning "acs_mail_lite::imap_conn_go.653  Error attempting ns_imap open. Error is: '${err_txt}'"
            } else {
                set connected_p 1
                ns_log Dev "acs_mail_lite::imap_conn_go.675:  new session conn_id '${conn_id}'"
            }
        }

    }
    if { !$connected_p } {
        set conn_id ""
    } else {
        # Check if mailbox exists.
        set status_nv_list [ns_imap status $conn_id]
        array set stat_arr $status_nv_list
        set stat_n_list [array get names stat_arr]
        set msg_idx [lsearch -nocase -exact $stat_n_list "messages"]
        if { $msg_idx < 0 } {
            set mb_exists_p 0
            ns_log Warning "acs_mail_lite::imap_conn_go.723  mailbox name '${name_mb}' not found."
            # top level = t
            set t_list [ns_imap list $conn_id $host {%}]
            ns_log Notice "acs_mail_lite::imap_conn_go.725  available top level mailbox names '${t_list}'"
            if { [llength $t_list < 2] && !$default_to_inbox_p } {
                # Provide more hints.
                set t_list [ns_imap list $conn_id $host {*}]
                ns_log Notice "acs_mail_lite::imap_conn_go.727  available mailbox names '${t_list}'"
            }
        } else {
            set mb_exists_p 1
        }

        if { !$mb_exists_p && $default_to_inbox_p } {
            set mb_default ""
            set idx [lsearch -exact -nocase $t_list "${default_box_name}"]
            if { $idx < 0 } {
                set idx [lsearch -glob -nocase $t_list "${default_box_name}*"]
            }
            if { $idx < 0 } {
                set idx [lsearch -glob -nocase $t_list "*${default_box_name}*"]
            }
            if { $idx < 0 } {
                set t_list [ns_imap list $conn_id $mailbox_host {*}]
                set idx_list  [lsearch -glob -nocase $t_list "*${default_box_name}*"]
                set i_pos_min 999
                # find inbox closest to tree root
                foreach mb_q_idx $idx_list {
                    set mb_q [lindex $tv_list $mb_q_idx]
                    set i_pos [string first ${default_box_name}  [string tolower $mb_q]]
                    if { $idx < 0 || $i_pos < $i_pos_min } {
                        set i_pos_min $i_pos
                        set idx $mb_q_idx
                    }
                }

            }
            # choose a box closest to tree root.
            if { $idx > -1 } {
                set mb_default [lindex $t_list $idx]
                if { $default_conn_set_p } {
                    ns_log Notice "acs_mail_lite::imap_conn_go.775  Setting default mailbox.name to '${mb_default}'"
                    acs_mail_lite::imap_conn_set -name_mb $mb_default
                }
                set mb [acs_mail_lite::imap_mailbox_join  -host $host  -name $name_mb  -ssl_p $ssl_p]
                if { "novalidatecert" in $fl_list } {
                    set conn_id [ns_imap reopen  -novalidatecert  -mailbox "${mb}"  -user $user  -password $password]
                } else {
                    set conn_id [ns_imap open  -mailbox "${mb}"  -user $user  -password $password]
                }
            }
        }

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