Logo Search packages:      
Sourcecode: egroupware version File versions  Download package

mail_msg_base::begin_request ( args_array ) [inherited]

begin_request initializes EVERYTHING, do not forget to call end_session before you leave this transaction.

Parameters:
$args_arrayMay be phased out, but right now the most used param is "do_login" => True
Author:
Angles the who enchalada happens here. Recently only class msg_bootstrap calls this directly.

do_login if False prevents even trying to login this is for preferences pages or other pages where we may not need nor want a mailserver login BUT we still want the prefs handling and other functions available in the msg class. Note that caching can eliminate the need for some logins, but that is a different issue. do_login set to False will disallow testing cache (which may itself require a login) or trying to login anyway.

Definition at line 842 of file class.mail_msg_base.inc.php.

References mail_msg_base::db_defang_decode(), mail_msg_base::db_defang_encode(), mail_msg_base::decrypt_email_passwd(), mail_msg_base::end_request(), and mail_msg_base::prep_folder_out().

            {
                  if ($this->debug_logins > 0) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): ENTERING'.'<br>'); } 
                  if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): feed var args_array[] DUMP:', $args_array); }
                  
                  // Grab GPC vars, after we get an acctnum, we'll put them in the appropriate account's "args" data
                  // issue?: which acctnum arg array would this be talking to when we inquire about "already_grab_class_args_gpc"?
                  if ( ($this->get_isset_arg('already_grab_class_args_gpc'))
                  && ((string)$this->get_arg_value('already_grab_class_args_gpc') != '') )
                  {
                        // somewhere, there's already been a call to grab_class_args_gpc(), do NOT re-run
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): "already_grab_class_args_gpc" is set, do not re-grab<br>'); }
                        if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): "already_grab_class_args_gpc" pre-existing $this->get_all_args() DUMP:', $this->get_all_args()); } 
                        $got_args=array();
                  }
                  else
                  {
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): "already_grab_class_args_gpc" is NOT set, call grab_class_args_gpc() now<br>'); }
                        $got_args=array();
                        $got_args = $this->grab_class_args_gpc();
                  }
                  
                  // FIND THE "BEST ACCTNUM" and set it
                  if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): about to call:  get_best_acctnum($args_array, $got_args) <br>'); }
                  $acctnum = $this->get_best_acctnum($args_array, $got_args);
                  if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): "get_best_acctnum" returns $acctnum ['.$acctnum.']<br>'); }
                  if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): * * * *SETTING CLASS ACCTNUM* * * * by calling $this->set_acctnum('.serialize($acctnum).')<br>'); }
                  $this->set_acctnum($acctnum);
                  
                  // SET GOT_ARGS TO THAT ACCTNUM
                  // use that acctnum to set "got_args" to the appropiate acctnum
                  if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): about to call: $this->set_arg_array($got_args); <br>'); }
                  $this->set_arg_array($got_args, $acctnum);
                  if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): post set_arg_array $this->get_all_args() DUMP:', $this->get_all_args()); } 
                  
                  // Initialize Internal Args
                  if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): about to call: "init_internal_args_and_set_them('.$acctnum.')"<br>'); }
                  $this->init_internal_args_and_set_them($acctnum);
                  
                  if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): POST "grab_class_args_gpc", "get_best_acctnum", and "init_internal_args_and_set_them" : this->get_all_args() DUMP:', $this->get_all_args()); } 
                  
                  // (chopped out the re-use existing object code - never worked right, maybe later...)
                  
                  // ----  Things To Be Done Whether You Login Or Not  -----
                  
                  // UNDER DEVELOPMEMT - backwards_compat with sessions_db where php4 sessions are not being used
                  // ALSO UNDER DEVELOPMENT - using private table for anglemail
                  if (($GLOBALS['phpgw_info']['server']['sessions_type'] == 'db')
                  || ($this->use_private_table == True))
                  {
                        // REF_SESSION should not really be in $_SESSION namespace so RE-CREATE all this outside of php4 sessions
                        $this->so->prep_db_session_compat('begin_request LINE '.__LINE__);
                  }
                  
                  
                  if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): about to handle email preferences and setup extra accounts<br>'); } 
                  // ----  Obtain Preferences Data  ----
                  
                  /*
                  // CAPABILITY: caching the prefs data
                  // data we need to DB save to cache final processed prefs
                  $this->unprocessed_prefs
                  $this->raw_filters
                  $this->ex_accounts_count
                  $this->extra_accounts
                  $this->extra_and_default_acounts
                  $this->a[X]->prefs
                  // where X is the account number, we can use "set_pref_array(array_data, acctnum) for each account
                  
                  // ok lets make an array to hold this data in the DB
                  $cached_prefs = array();
                  $cached_prefs['unprocessed_prefs'] = array();
                  $cached_prefs['raw_filters'] = array();
                  $cached_prefs['ex_accounts_count'] = '0';
                  $cached_prefs['extra_accounts'] = array();
                  $cached_prefs['extra_and_default_acounts'] = array();
                  $cached_prefs['a'] = array();
                  */
                  // ---- GET FROM CACHE THE COMPLETED PREF DATA
                  //$this->use_cached_prefs = True;
                  //$this->use_cached_prefs = False;
                  if ($this->use_cached_prefs == False)
                  {
                        $cached_prefs = $this->nothing;
                  }
                  else
                  {
                        /*
                        // data we need to DB save to cache final processed prefs
                        $this->unprocessed_prefs
                        $this->raw_filters
                        $this->ex_accounts_count
                        $this->extra_accounts
                        $this->extra_and_default_acounts
                        $this->a[X]->['prefs']
                        // where X is the account number, we can use "set_pref_array(array_data, acctnum) for each account
                        
                        // ok this is what we should get from the DB storage (we use appsession for now) 
                        $cached_prefs = array();
                        $cached_prefs['unprocessed_prefs'] = array();
                        $cached_prefs['raw_filters'] = array();
                        $cached_prefs['ex_accounts_count'] = '0';
                        $cached_prefs['extra_accounts'] = array();
                        $cached_prefs['extra_and_default_acounts'] = array();
                        $cached_prefs['a'] = array();
                        */
                        // get the data from appsession, we use compression to avoid problems unserializing
                        $my_location = '0;cached_prefs';
                        $cached_prefs = $this->so->so_appsession_passthru($my_location);
                        if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): raw $cached_prefs as returned from cache DUMP:', $cached_prefs); } 
                        if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): raw serialized $cached_prefs is '.htmlspecialchars(serialize($cached_prefs)).'<br>'); } 
                  }
                  
                  // ok if we actually got cached_prefs then maybe we can use them 
                  if (($this->use_cached_prefs == True)
                  && ((string)$cached_prefs != $this->nothing)
                  && (is_array($cached_prefs))
                  && (isset($cached_prefs['extra_and_default_acounts'])))
                  {
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): raw $cached_prefs deemed to actually have usable data, so process it<br>'); } 
                        // UN-defang the filters
                        // NO remember that filters are left in defang (htmlquotes encoded) form
                        // UNTIL they are going to be used, then bofilters defangs them
                        //for ($x=0; $x < count($cached_prefs['raw_filters']); $x++)
                        //{
                        //    $cached_prefs['raw_filters'][$x]['filtername'] = $this->db_defang_decode($cached_prefs['raw_filters'][$x]['filtername']);
                        //    $cached_prefs['raw_filters'][$x]['source_accounts']['folder'] = $this->db_defang_decode($cached_prefs['raw_filters'][$x]['source_accounts']['folder']);
                        //    for ($y=0; $y < count($cached_prefs['raw_filters']['matches']); $y++)
                        //    {
                        //          $cached_prefs['raw_filters'][$x]['matches'][$y]['matchthis']
                        //                = $this->db_defang_decode($cached_prefs['raw_filters'][$x]['matches'][$y]['matchthis']);
                        //    }
                        //    for ($y=0; $y < count($cached_prefs['raw_filters']['actions']); $y++)
                        //    {
                        //          $cached_prefs['raw_filters'][$x]['actions'][$y]['folder']
                        //                = $this->db_defang_decode($cached_prefs['raw_filters'][$x]['actions'][$y]['folder']);
                        //    }
                        //}
                        // UN-defang the rest of the prefs that may need it
                        $defang_these = array();
                        $defang_these[0] = 'passwd';
                        $defang_these[1] = 'email_sig';
                        $defang_these[2] = 'trash_folder_name';
                        $defang_these[3] = 'sent_folder_name';
                        $defang_these[4] = 'userid';
                        $defang_these[5] = 'address';
                        $defang_these[6] = 'mail_folder';
                        $defang_these[7] = 'fullname';
                        $defang_these[8] = 'account_name';
                        $loops = count($cached_prefs['extra_and_default_acounts']);
                        for ($i=0; $i < $loops; $i++)
                        {
                              for ($x=0; $x < count($defang_these); $x++)
                              {
                                    $defang_word = $defang_these[$x];
                                    if (isset($cached_prefs['a'][$i]['prefs'][$defang_word]))
                                    {
                                          $cached_prefs['a'][$i]['prefs'][$defang_word]
                                                = $this->db_defang_decode($cached_prefs['a'][$i]['prefs'][$defang_word]);
                                    }
                              }
                        }
                        if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): retrieved $cached_prefs AFTER UN-defang DUMP:', $cached_prefs); } 
                        // lets fill the data
                        $this->unprocessed_prefs = $cached_prefs['unprocessed_prefs'];
                        $this->raw_filters = $cached_prefs['raw_filters'];
                        $this->ex_accounts_count = $cached_prefs['ex_accounts_count'];
                        $this->extra_accounts = $cached_prefs['extra_accounts'];
                        $this->extra_and_default_acounts = $cached_prefs['extra_and_default_acounts'];
                        $loops = count($this->extra_and_default_acounts);
                        for ($i=0; $i < $loops; $i++)
                        {
                              $this->set_pref_array($cached_prefs['a'][$i]['prefs'], $i);
                        }
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): successfully retrieved and applied $cached_prefs<br>'); } 
                  }
                  //$allow_prefs_shortcut = True;
                  //$allow_prefs_shortcut = False;
                  //if ((is_array($GLOBALS['phpgw_info']['user']['preferences']['email']) == True)
                  //&& ($allow_prefs_shortcut == True))
                  //{
                  //    if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): prefs array already created by the API, NOT calling "create_email_preferences"<br>'); } 
                  //    $this->unprocessed_prefs = array();
                  //    $this->unprocessed_prefs['email'] = array();
                  //    $this->unprocessed_prefs['email'] = $GLOBALS['phpgw_info']['user']['preferences']['email'];
                  //    if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): did NOT call create_email_preferences, prefs were already available in $GLOBALS["phpgw_info"]["user"]["preferences"]["email"] <br>'); } 
                  //}
                  else
                  {
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $cached_prefs either disabled or no data was cached<br>'); } 
                        // make this empty without question, since cached prefs were not recovered
                        $cached_prefs = array();
                        // IT SEEMS PREFS FOR ACCT 0 NEED TO RUN THRU THIS TO FILL "Account Name" thingy
                        // obtain the preferences from the database, put them in $this->unprocessed_prefs, note THIS GETS ALL PREFS for some reason, not just email prefs?
                        if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): BEFORE processing email prefs, GLOBALS[phpgw_info][user][preferences][email] DUMP:', $GLOBALS['phpgw_info']['user']['preferences']['email']); } 
                        
                        //$this->unprocessed_prefs = $GLOBALS['phpgw']->preferences->create_email_preferences();
                        $tmp_email_only_prefs = array();
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): calling create_email_preferences, may be time consuming<br>'); } 
                        $tmp_email_only_prefs = $GLOBALS['phpgw']->preferences->create_email_preferences();
                        // clean "unprocessed_prefs" so all prefs oher than email are NOT included 
                        $this->unprocessed_prefs = array();
                        $this->unprocessed_prefs['email'] = array();
                        $this->unprocessed_prefs['email'] = $tmp_email_only_prefs['email'];
                        $tmp_email_only_prefs = array();
                        unset($tmp_email_only_prefs);
                        //if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): AFTER "create_email_preferences" GLOBALS[phpgw_info][user][preferences] DUMP<pre>'; print_r($GLOBALS['phpgw_info']['user']['preferences']); echo '</pre>'); } 
                        
                        // BACKWARDS COMPAT for apps that have no clue what multiple accounts are about
                        // fill email's $GLOBALS['phpgw_info']['user']['preferences'] with the data for backwards compatibility (we don't use that)
                        // damn, where did email's prefs get filled already? Where are they getting filled, anyway do not re-fill if not needed
                        // NO - IT IS POSSIBLE THIS MAY NOT CATCH ALL PREF CHANGES IN CORNER CASES
                        if (is_array($GLOBALS['phpgw_info']['user']['preferences']['email']) == False)
                        {
                              //$GLOBALS['phpgw_info']['user']['preferences'] = $this->unprocessed_prefs;
                              $GLOBALS['phpgw_info']['user']['preferences']['email'] = array();
                              $GLOBALS['phpgw_info']['user']['preferences']['email'] = $this->unprocessed_prefs['email'];
                        }
                        //echo 'dump3 <pre>'; print_r($GLOBALS['phpgw_info']['user']['preferences']); echo '</pre>';
                        // BUT DO NOT put unneeded stuff in there, [ex_accounts] and [filters] multilevel arrays 
                        // are not needed for mackward compat, we need them internally but external apps do not use this raw data
                        //if (isset($GLOBALS['phpgw_info']['user']['preferences']['email']['ex_accounts']))
                        //{
                        //    $GLOBALS['phpgw_info']['user']['preferences']['email']['ex_accounts'] = array();
                        //    unset($GLOBALS['phpgw_info']['user']['preferences']['email']['ex_accounts']);
                        //}
                        //if (isset($GLOBALS['phpgw_info']['user']['preferences']['email']['filters']))
                        //{
                        //    $GLOBALS['phpgw_info']['user']['preferences']['email']['filters'] = array();
                        //    unset($GLOBALS['phpgw_info']['user']['preferences']['email']['filters']);
                        //}
                        if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): AFTER backwards_compat and cleaning GLOBALS[phpgw_info][user][preferences] DUMP:', $GLOBALS['phpgw_info']['user']['preferences']); } 
                  
                  
                        // first, put the filter data from prefs in a holding var for use by the filters class if needed
                        // raw filters array for use by the filters class, we just put the data here, that is all, while collecting other prefs
                        $this->raw_filters = array();
                        if ((isset($this->unprocessed_prefs['email']['filters']))
                        && (is_array($this->unprocessed_prefs['email']['filters'])))
                        {
                              $this->raw_filters = $this->unprocessed_prefs['email']['filters'];
                              // not get that out of "unprocessed_prefs" because it is not needed there any more
                              $this->unprocessed_prefs['email']['filters'] = array();
                              unset($this->unprocessed_prefs['email']['filters']);
                        }
                        //if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): put filter data in $this->raw_filters DUMP<pre>'; print_r($this->raw_filters); echo '</pre>'); } 
                        
                        // second, set the prefs for the default, base acct 0, BUT do not give it data it does not need
                        // we already got "filters" out of "unprocessed_prefs", so when setting acct0 prefs, do not give it the "ex_accounts" array
                        $acct0_prefs_cleaned = array();
                        $acct0_prefs_cleaned = $this->unprocessed_prefs;
                        if ((isset($acct0_prefs_cleaned['email']['ex_accounts']))
                        && (is_array($acct0_prefs_cleaned['email']['ex_accounts'])))
                        {
                              $acct0_prefs_cleaned['email']['ex_accounts'] = array();
                              unset($acct0_prefs_cleaned['email']['ex_accounts']);
                        }
                        // now we can use that to set the prefs for the base account
                        
                        // ---  process pres for in multi account enviornment ---
                        // for our use, put prefs in a class var to be accessed thru OOP-style access calls in mail_msg_wrapper
                        // since we know these prefs to be the  top level prefs, for the default email account, force them into acctnum 0
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): putting top level, default account, pref data in acct 0 with $this->set_pref_array($acct0_prefs_cleaned[email], 0); <br>'); } 
                        if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $acct0_prefs_cleaned[email] DUMP:', $acct0_prefs_cleaned['email']); } 
                        //$this->set_pref_array($this->unprocessed_prefs['email'], 0);
                        $this->set_pref_array($acct0_prefs_cleaned['email'], 0);
                        $acct0_prefs_cleaned = array();
                        unset($acct0_prefs_cleaned);
                        
                        
                        // ===  EXTRA ACCOUNTS  ===
                        // they are located in an array based at $this->unprocessed_prefs['email']['ex_accounts'][]
                        // determine what extra accounts have been defined
                        // note: php3 DOES have is_array(), ok to use it here
                        if ((isset($this->unprocessed_prefs['email']['ex_accounts']))
                        && (is_array($this->unprocessed_prefs['email']['ex_accounts'])))
                        {
                              $this->ex_accounts_count = count($this->unprocessed_prefs['email']['ex_accounts']);
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $this->unprocessed_prefs[email][ex_accounts] is set and is_array, its count: $this->ex_accounts_count: ['.$this->ex_accounts_count.']<br>'); }
                              if ($this->debug_logins > 2) { $this->dbug->out('$this->unprocessed_prefs[email][ex_accounts] DUMP:', $this->unprocessed_prefs['email']['ex_accounts']); }
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): about to process extra account data ; $this->ex_accounts_count: ['.$this->ex_accounts_count.']<br>'); }
                              // note: extra accounts lowest possible value = 1, NOT 0
                              // also, $key, although numbered integers, may not be conticuous lowest to highest (may be empty or missing elements inbetween)
                        
                              // ---- what accounts have some data defined
                              // array_extra_accounts[X]['acctnum'] : integer
                              // array_extra_accounts[X]['status'] string = "enabled" | "disabled" | "empty"
                              //while(list($key,$value) = each($this->unprocessed_prefs['email']['ex_accounts']))
                              while(list($key,$value) = each($this->unprocessed_prefs['email']['ex_accounts']))
                              {
                                    if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): inside loop: for each $this->unprocessed_prefs[email][ex_accounts] ; $key: ['.serialize($key).'] $value DUMP:', $value); } 
                                    // if we are here at all then this array item must have some data defined
                                    $next_pos = count($this->extra_accounts);
                                    $this->extra_accounts[$next_pos] = array();
                                    $this->extra_accounts[$next_pos]['acctnum'] = (int)$key;
                                    // ----  is this account "enabled", "disabled" or is this array item "empty"
                                    // first, see if it has essential data, if not, it's an empty array item
                                    if ( (!isset($this->unprocessed_prefs['email']['ex_accounts'][$key]['fullname']))
                                    || (!isset($this->unprocessed_prefs['email']['ex_accounts'][$key]['email_sig']))
                                    || (!isset($this->unprocessed_prefs['email']['ex_accounts'][$key]['layout'])) )
                                    {
                                          // this account lacks essential data needed to describe an account, it must be an "empty" element
                                          if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): inside loop: account ['.$key.'] is *empty*: $this->unprocessed_prefs[email][ex_accounts]['.$key.']: ['.serialize($this->unprocessed_prefs['email']['ex_accounts'][$key]).']<br>'); } 
                                          $this->extra_accounts[$next_pos]['status'] = 'empty';
                                    }
                                    // ... so the account is not empty ...
                                    elseif ( (isset($this->unprocessed_prefs['email']['ex_accounts'][$key]['ex_account_enabled']))
                                    && ((string)$this->unprocessed_prefs['email']['ex_accounts'][$key]['ex_account_enabled'] != ''))
                                    {
                                          // this account is defined AND enabled, 
                                          if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): inside loop: account ['.$key.'] is *enabled*: $this->unprocessed_prefs[email][ex_accounts]['.$key.'][ex_account_enabled]:  ['.serialize($this->unprocessed_prefs['email']['ex_accounts'][$key]['ex_account_enabled']).']<br>'); } 
                                          $this->extra_accounts[$next_pos]['status'] = 'enabled';
                                    }
                                    else
                                    {
                                          // this account is defined BUT not enabled
                                          if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): inside loop: account ['.$key.'] is *disabled*: $this->unprocessed_prefs[email][ex_accounts]['.$key.'][ex_account_enabled]:  ['.serialize($this->unprocessed_prefs['email']['ex_accounts'][$key]['ex_account_enabled']).']<br>'); } 
                                          $this->extra_accounts[$next_pos]['status'] = 'disabled';
                                    }
                                    
                                    // IF ENABLED, then 
                                    if ($this->extra_accounts[$next_pos]['status'] == 'enabled')
                                    {
                                          // PROCESS EXTRA ACCOUNT PREFS
                                          // run thru the create prefs function requesting this particular acctnum
                                          // fills in certain missing data, and does some sanity checks, and any data processing that may be necessary
                                          $sub_tmp_prefs = array();
                                          // we "fool" create_email_preferences into processing extra account info as if it were top level data
                                          // by specifing the secong function arg as the integer of this particular enabled account
                                          $this_ex_acctnum = $this->extra_accounts[$next_pos]['acctnum'];
                                          if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): CALLING create_email_preferences("", $this_ex_acctnum) for specific account, where $this_ex_acctnum: ['.serialize($this_ex_acctnum).'] <br>'); }
                                          $sub_tmp_prefs = $GLOBALS['phpgw']->preferences->create_email_preferences('', $this_ex_acctnum);
                                          // now put these processed prefs in the correct location  in our prefs array
                                          $this->set_pref_array($sub_tmp_prefs['email'], $this_ex_acctnum);
                                    }
                              }
                              // extra_and_default_acounts is the same as above but has default account inserted at position zero
                              $this->extra_and_default_acounts = array();
                              // first put in the default account
                              $this->extra_and_default_acounts[0]['acctnum'] = 0;
                              $this->extra_and_default_acounts[0]['status'] = 'enabled';
                              // now add whetever extra accounts we processed above
                              $loops = count($this->extra_accounts);
                              for ($i=0; $i < $loops; $i++)
                              {
                                    $this->extra_and_default_acounts[$i+1]['acctnum'] = $this->extra_accounts[$i]['acctnum'];
                                    $this->extra_and_default_acounts[$i+1]['status'] = $this->extra_accounts[$i]['status'];
                              }
                              if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $this->extra_accounts DUMP:', $this->extra_accounts); } 
                              if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $this->extra_and_default_acounts DUMP:', $this->extra_and_default_acounts); } 
                        }
                        else
                        {
                              $this->ex_accounts_count = 0;
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $this->unprocessed_prefs[email][ex_accounts] NOT set or NOT is_array, $this->ex_accounts_count: ['.$this->ex_accounts_count.']<br>'); } 
                        }
                        // if NO extra accounts axist, we STILL need to put the default account inextra_and_default_acounts
                        // extra_and_default_acounts will not have been handled whatsoever if no extra accounts exist
                        // so make sure the default account is there
                        if (count($this->extra_and_default_acounts) == 0)
                        {
                              $this->extra_and_default_acounts = array();
                              // first put in the default account
                              $this->extra_and_default_acounts[0]['acctnum'] = 0;
                              $this->extra_and_default_acounts[0]['status'] = 'enabled';
                        }
                        // -end- extra account init handling
                  }
                  
                  //if ($this->debug_logins > 2) { echo 'mail_msg.begin_request('.__LINE__.'): POST create_email_preferences GLOBALS[phpgw_info][user][preferences][email] dump:<pre>'; print_r($GLOBALS['phpgw_info']['user']['preferences']['email']) ; echo '</pre>';}
                  //if ($this->debug_logins > 2) { echo 'mail_msg.begin_request('.__LINE__.'): POST create_email_preferences $this->get_all_prefs() dump:<pre>'; print_r($this->get_all_prefs()) ; echo '</pre>';}
                  if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): POST create_email_preferences direct access dump of $this->a DUMP:', $this->a); } 
                  //if ($this->debug_logins > 2) { echo 'mail_msg.begin_request('.__LINE__.'):  preferences->create_email_preferences called, GLOBALS[phpgw_info][user][preferences] dump:<pre>'; print_r($GLOBALS['phpgw_info']['user']['preferences']) ; echo '</pre>';}
                  //if ($this->debug_logins > 2) { echo 'mail_msg.begin_request('.__LINE__.'):  preferences->create_email_preferences called, GLOBALS[phpgw_info][user] dump:<pre>'; print_r($GLOBALS['phpgw_info']['user']) ; echo '</pre>';}
                  //if ($this->debug_logins > 2) { echo 'mail_msg.begin_request('.__LINE__.'): preferences->create_email_preferences called, GLOBALS[phpgw_info] dump:<pre>'; print_r($GLOBALS['phpgw_info']) ; echo '</pre>';}
                  //if ($this->debug_logins > 2) { echo 'mail_msg.begin_request('.__LINE__.'): preferences->create_email_preferences called, GLOBALS[phpgw] dump:<pre>'; print_r($GLOBALS['phpgw']) ; echo '</pre>';}
                  
                  // ---- CACHE THE COMPLETED PREF DATA
                  if (($this->use_cached_prefs == True)
                  && (!$cached_prefs))
                  {
                        // for whever reason we did not get any data from the stored prefs
                        /*
                        // data we need to DB save to cache final processed prefs
                        $this->unprocessed_prefs
                        $this->raw_filters
                        $this->ex_accounts_count
                        $this->extra_accounts
                        $this->extra_and_default_acounts
                        $this->a[X]->['prefs']
                        // where X is the account number, we can use "set_pref_array(array_data, acctnum) for each account
                        */
                        // ok lets make an array to hold this data in the DB
                        $cached_prefs = array();
                        $cached_prefs['unprocessed_prefs'] = array();
                        $cached_prefs['raw_filters'] = array();
                        $cached_prefs['ex_accounts_count'] = '0';
                        $cached_prefs['extra_accounts'] = array();
                        $cached_prefs['extra_and_default_acounts'] = array();
                        $cached_prefs['a'] = array();
                        // lets fill the data
                        $cached_prefs['unprocessed_prefs'] = $this->unprocessed_prefs;
                        $cached_prefs['raw_filters'] = $this->raw_filters;
                        // defang the filters
                        // NO remember bofilters defangs, htmlquotes encodes, the filters FOR US
                        // they are stored in the preferences DB already in defanged state
                        // we never need to degang or UN-defang filters 
                        // because bofilters handles ALL that for us
                        //for ($x=0; $x < count($cached_prefs['raw_filters']); $x++)
                        //{
                        //    $cached_prefs['raw_filters'][$x]['filtername'] = $this->db_defang_encode($cached_prefs['raw_filters'][$x]['filtername']);
                        //    $cached_prefs['raw_filters'][$x]['source_accounts']['folder'] = $this->db_defang_encode($cached_prefs['raw_filters'][$x]['source_accounts']['folder']);
                        //    for ($y=0; $y < count($cached_prefs['raw_filters']['matches']); $y++)
                        //    {
                        //          $cached_prefs['raw_filters'][$x]['matches'][$y]['matchthis']
                        //                = $this->db_defang_encode($cached_prefs['raw_filters'][$x]['matches'][$y]['matchthis']);
                        //    }
                        //    for ($y=0; $y < count($cached_prefs['raw_filters']['actions']); $y++)
                        //    {
                        //          $cached_prefs['raw_filters'][$x]['actions'][$y]['folder']
                        //                = $this->db_defang_encode($cached_prefs['raw_filters'][$x]['actions'][$y]['folder']);
                        //    }
                        //}
                        $cached_prefs['ex_accounts_count'] = $this->ex_accounts_count;
                        $cached_prefs['extra_accounts'] = $this->extra_accounts;
                        $cached_prefs['extra_and_default_acounts'] = $this->extra_and_default_acounts;
                        $cached_prefs['a'] = array();
                        $defang_these = array();
                        $defang_these[0] = 'passwd';
                        $defang_these[1] = 'email_sig';
                        $defang_these[2] = 'trash_folder_name';
                        $defang_these[3] = 'sent_folder_name';
                        $defang_these[4] = 'userid';
                        $defang_these[5] = 'address';
                        $defang_these[6] = 'mail_folder';
                        $defang_these[7] = 'fullname';
                        $defang_these[8] = 'account_name';
                        $loops = count($this->extra_and_default_acounts);
                        for ($i=0; $i < $loops; $i++)
                        {
                              $cached_prefs['a'][$i] = array();
                              $cached_prefs['a'][$i]['prefs'] = array();
                              $cached_prefs['a'][$i]['prefs'] = $this->a[$i]['prefs'];
                              // defang
                              for ($x=0; $x < count($defang_these); $x++)
                              {
                              $defang_word = $defang_these[$x];
                                    if (isset($cached_prefs['a'][$i]['prefs'][$defang_word]))
                                    {
                                          $cached_prefs['a'][$i]['prefs'][$defang_word]  = $this->db_defang_encode($cached_prefs['a'][$i]['prefs'][$defang_word]);
                                    }
                              }
                        }
                        // just use account 0 for this eventhough the prefs are for every account
                        $my_location = '0;cached_prefs';
                        if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): POST create_email_preferences we made the $cached_prefs for storage DUMP:', $cached_prefs); } 
                        $this->so->so_appsession_passthru($my_location, $cached_prefs);
                  }
                  
                  // EXTREME CACHING ADJUSTMENTS
                  // now we have preferences we know if we have pop3 or not
                  // POP3 does not support UID therefor we must verify msgball list every page view
                  // session_cache_extreme allows for testing msgball list validity only one time per page view
                  // whereas NO session_cache_extreme does not have this code so that is WAY SLOW 
                  // checking like 5 times per page view because builtin php-imap uses a timestamp for "uidvalidity"
                  // note that with pop3 Sockets I use mailbox SIZE as a standin for "uidvalidity" 
                  // what this adds up to is keep session_cache_extreme True but reduce timestamp_age_limit to 10 seconds
                  // but doing this also required this change:
                  // IN WRAPPERS we set "big move" to 0 if pop3 is in use 
                  // this resets cache for ANY move or delete thus hopefully fixing header body misalign problem
                  if (stristr($this->get_pref_value('mail_server_type', $acctnum), 'pop3'))
                  {
                        $this->timestamp_age_limit = 10;
                        if ($this->debug_logins > 0 || $this->debug_session_caching > 0) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): pop3 (any) in use, so FORCE change $this->timestamp_age_limit to ['.serialize($this->timestamp_age_limit).'] <br>'); }
                  }
                  
                  // ---- SET important class vars  ----
                  $this->att_files_dir = $GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$GLOBALS['phpgw_info']['user']['sessionid'];
                  
                  // and.or get some vars we will use later in this function
                  $mailsvr_callstr = $this->get_arg_value('mailsvr_callstr');
                  if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $mailsvr_callstr '.$mailsvr_callstr.'<br>'); }
                  
                  // set class var "$this->cache_mailsvr_data" based on prefs info
                  // FIXME: why have this in 2 places, just keep it in prefs (todo)
                  // THIS IS DEPRECIATED but may be used again in the future.
                  if ((isset($this->cache_mailsvr_data_disabled))
                  && ($this->cache_mailsvr_data_disabled == True))
                  {
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): OLD DEFUNCT OPTION folder cache DISABLED, $this->cache_mailsvr_data_disabled = '.serialize($this->cache_mailsvr_data_disabled).'<br>'); }
                        $this->cache_mailsvr_data = False;
                  }
                  elseif (($this->get_isset_pref('cache_data'))
                  && ($this->get_pref_value('cache_data') != ''))
                  {
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): OLD DEFUNCT OPTION folder cache is enabled in user prefs'.'<br>'); }
                        $this->cache_mailsvr_data = True;
                  }
                  else
                  {
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): OLD DEFUNCT OPTION folder cache is NOT enabled in user prefs'.'<br>'); }
                        $this->cache_mailsvr_data = False;
                  }
                  
                  // ----  Should We Login  -----
                  $local_bootstrap = '';
                  if (defined("BS_LOGIN_NOT_SPECIFIED") == False)
                  {
                        // this puts the defines in our namespace
                        //$GLOBALS['phpgw']->msg->dbug->out('mail_msg.begin_request('.__LINE__.'): get_defined_constants DUMP:', get_defined_constants());
                        $local_bootstrap = CreateObject('email.msg_bootstrap');
                  }
                  // $args_array[do_login] and $args_array[do_login_ex] are set in bootstrap and fed into here
                  if (!isset($args_array['do_login']))
                  {
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $args_array[do_login] was NOT set, so we set it to default value "FALSE"'.'<br>'); }
                        $args_array['do_login'] = False;
                  }
                  // ---- newer 3 way do_login_ex value from the bootstrap class
                  if (!isset($args_array['do_login_ex']))
                  {
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $args_array[do_login_ex] not set, getting default from a temp local bootstrap object'.'<br>'); }
                        // that means somewhere the bootstrap class has been run
                        if (is_object($local_bootstrap) == False)
                        {
                              $local_bootstrap = CreateObject('email.msg_bootstrap');
                        }
                        $local_bootstrap->set_do_login($args_array['do_login'], 'begin_request line('.__LINE__.')');
                        $args_array['do_login_ex'] = $local_bootstrap->get_do_login_ex();
                        $local_bootstrap = '';
                        unset($local_bootstrap);
                  }
                  // cleanup
                  $local_bootstrap = '';
                  unset($local_bootstrap);
                  if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $args_array[] DUMP ['.serialize($args_array).']'.'<br>'); }
                  
                  /*
                  // ----  Are We In Newsmode Or Not  -----
                  // FIXME: !!! this needs better handling
                  if ((isset($args_array['newsmode']))
                  && (($args_array['newsmode'] == True) || ($args_array['newsmode'] == "on")))
                  {
                        $args_array['newsmode'] = True;
                        $this->set_arg_value('newsmode', True);
                        $this->set_pref_value('mail_server_type', 'nntp');
                  }
                  else
                  {
                        $args_array['newsmode'] = False;
                        $this->set_arg_value('newsmode', False);
                  }
                  */
                  
                  // Browser Detection =FUTURE=
                  // 0 = NO css ; 1 = CSS supported ; 2 = text only
                  // currently not implemented, use default 0 (NO CSS support in browser)
                  $this->browser = 0;
                  //$this->browser = 1;
                  
                  // ----  Process "sort" "order" and "start" GPC args (if any) passed to the script  -----
                  // these args are so fundamental, they get stored in their own class vars
                  // no longer referenced as args after this
                  // requires args saved to $this->a[$this->acctnum]['args'], only relevant if you login
                  $this->fill_sort_order_start();
                  
                  // ----  Things Specific To Loging In, and Actually Logging In  -----
                  // $args_array['folder'] gets prep_folder_in and then is stored in class var $this->get_arg_value('folder')
                  
                  // test for previous login, meaning we have all the cached data we need
                  //if (($args_array['do_login'] == True)
                  
                  /*!
                  @capability do_login if False prevents even trying to login
                  @abstract this is for preferences pages or other pages where we may 
                  not need nor want a mailserver login BUT we still want the prefs handling and 
                  other functions available in the msg class. Note that caching can eliminate 
                  the need for some logins, but that is a different issue. do_login set to 
                  False will disallow testing cache (which may itself require a login) or trying to login 
                  anyway.
                  */
                  
                  
                  // test for previous login, meaning we have all the cached data we need
                  if (($args_array['do_login_ex'] >= BS_LOGIN_ONLY_IF_NEEDED)
                  && ($this->session_cache_enabled == True)
                  && ($this->session_cache_extreme == True))
                  {
                        // IF we already have a cached_folder_list, we DO NOT NEED to immediately log in
                        // if and when a login is required, calls to "ensure_stream_and_folder" will take care of that login
                        // actually, we could even test the L1 class cashed folder_list first, that is a sure sign we have the data
                        // note _direct_access_arg_value returns NULL (nothing) if that arg is not set
                        $L1_cached_folder_list = $this->_direct_access_arg_value('folder_list', $acctnum);
                        if ($this->debug_logins > 1) { $this->dbug->out('begin_request: LINE '.__LINE__.' check for $L1_cached_folder_list DUMP:', $L1_cached_folder_list); } 
                        if ((isset($L1_cached_folder_list) == False)
                        || (!$L1_cached_folder_list))
                        {
                              $appsession_cached_folder_list = $this->read_session_cache_item('folder_list', $acctnum);
                              if ($this->debug_logins > 1) { $this->dbug->out('begin_request: LINE '.__LINE__.' check for $appsession_cached_folder_list DUMP:', $appsession_cached_folder_list); } 
                              // while we are here, if we got a folder list now put it in L1 cache so no more aueries to the DB
                              // but only if it a new style, full folder_list including the folder_short elements
                              if (isset($appsession_cached_folder_list[0]['folder_short']))
                              {
                                    // cache the result in "Level 1 cache" class object var
                                    if (($this->debug_logins > 1) || ($this->debug_args_special_handlers > 1)) { $this->dbug->out('begin_request: LINE '.__LINE__.' while we are here, put folder_list into Level 1 class var "cache" so no more queries to DB for this<br>'); } 
                                    $this->set_arg_value('folder_list', $appsession_cached_folder_list, $acctnum);
                              }
                        }
                        else
                        {
                              // we have L1 data, no need to query the database
                              $appsession_cached_folder_list = $L1_cached_folder_list;
                        }
                        if (($L1_cached_folder_list)
                        || ($appsession_cached_folder_list))
                        {
                              // in this case, extreme caching is in use, AND we already have cached data, so NO NEED TO LOGIN
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): session extreme caching IS in use, AND we have a cached "folder_list", which means should also have all necessary cached data, so NO LOGIN NEEDED<br>'); }           
                              $decision_to_login = False;
                              
                              // get a few more things that we would otherwise get during the login code (which we'll be skiping)
                              // "get_best_folder_arg" should also verify the folder name and fix any fldball or msgball if unverified.
                              $processed_folder_arg = $this->get_best_folder_arg($args_array, $got_args, $acctnum);
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): session extreme caching IS in use, Login may NOT occur, so about to issue: $this->set_arg_value("folder", '.$processed_folder_arg.', '.serialize($acctnum).')<br>'); }
                              $this->set_arg_value('folder', $processed_folder_arg, $acctnum);
                              if ( $this->get_isset_pref('userid')
                              && ($this->get_pref_value('userid') != ''))
                              {
                                    $user = $this->get_pref_value('userid');
                                    if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): session extreme caching IS in use, Login may NOT occur, so about to issue: $this->set_arg_value("mailsvr_account_username", '.$user.', '.serialize($acctnum).')<br>'); }
                                    $this->set_arg_value('mailsvr_account_username', $user, $acctnum);
                              }
                        }
                        else
                        {
                              // in this case, extreme caching is in use, HOWEVER we do not have necessary cached data, so WE NEED A LOGIN
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): session extreme caching IS in use, but we do NOT have a cached "folder_list", meaning we probably do NOT have any cached data, so we NEED A LOGIN, allow it if requested<br>'); } 
                              $decision_to_login = True;
                        }
                  }
                  elseif ($args_array['do_login_ex'] == BS_LOGIN_NEVER)
                  {
                        // whether or not extreme caching is on, if  "BS_LOGIN_NEVER" then we DO NOT login
                        $decision_to_login = False;
                        
                        // get a few more things that we would otherwise get during the login code (which we'll be skiping)
                        // "get_best_folder_arg" should also verify the folder name and fix any fldball or msgball if unverified.
                        // NOTE THIS CAN CAUSE A LOGIN ATTEMPT IF CERTAIN ARGS (like fldball and msgball) REQUIRE LOOKUP VERIFY that pref folder in may do
                        // so BS_LOGIN_NEVER is really never ONLY WHEN folder args that do not ever need a lookup are not passed
                        // a. INBOX will not cause a lookup, for example
                        // b. params like "target_fldball" are not verified in "get_best_folder_arg" so no lookup possibility there
                        // c. maybe other ways to avaoid but I can not think of them right now
                        // but params such as fldball and msgball, whether fed in "_fake_uri" or not, WILL need a lookup in "get_best_folder_arg"
                        // the lookup only needs a login if the folder list is not available in cache
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): we are NOT allowed to log in (see code this line) but we still need to call $this->get_best_folder_arg , be aware that function sometimes can trigger a login on a folder lookup, see comments there<br>'); }
                        $processed_folder_arg = $this->get_best_folder_arg($args_array, $got_args, $acctnum);
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): we are NOT allowed to log in (see code this line) but we still need to get this info, so about to issue: $this->set_arg_value("folder", '.$processed_folder_arg.', '.serialize($acctnum).')<br>'); }
                        $this->set_arg_value('folder', $processed_folder_arg, $acctnum);
                        if ( $this->get_isset_pref('userid')
                        && ($this->get_pref_value('userid') != ''))
                        {
                              $user = $this->get_pref_value('userid');
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): we are NOT allowed to log in (see code this line) but we still need to get this info, so about to issue: $this->set_arg_value("mailsvr_account_username", '.$user.', '.serialize($acctnum).')<br>'); }
                              $this->set_arg_value('mailsvr_account_username', $user, $acctnum);
                        }
                  }
                  /*
                  elseif ($args_array['do_login_ex'] == BS_LOGIN_ONLY_IF_NEEDED)
                  {
                        // if extreme is on and "BS_LOGIN_ONLY_IF_NEEDED" then that's taken care of above, 
                        // therefor
                        // * if we are here then caching is NOT on
                        // * we are told a login is "not 100% necessary"
                        // in that case we'll pass thru this function without logging in
                        // and rely on the rest of the code to open a stream if it is needed
                        $decision_to_login = False;
                        
                        // get a few more things that we would otherwise get during the login code (which we'll be skiping)
                        $processed_folder_arg = $this->get_best_folder_arg($args_array, $got_args, $acctnum);
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg: begin_request ('.__LINE__.'): we are NOT allowed to log in (see code this line) but we still need to get this info, so about to issue: $this->set_arg_value("folder", '.$processed_folder_arg.', '.serialize($acctnum).')<br>'); }
                        $this->set_arg_value('folder', $processed_folder_arg, $acctnum);
                        if ( $this->get_isset_pref('userid')
                        && ($this->get_pref_value('userid') != ''))
                        {
                              $user = $this->get_pref_value('userid');
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg: begin_request ('.__LINE__.'): we are NOT allowed to log in (see code this line) but we still need to get this info, so about to issue: $this->set_arg_value("mailsvr_account_username", '.$user.', '.serialize($acctnum).')<br>'); }
                              $this->set_arg_value('mailsvr_account_username', $user, $acctnum);
                        }
                  }
                  */
                  else
                  {
                        // extreme caching and logins handled above in the first if .. then
                        // if we are here, generally we are allowed to login
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): session extreme caching is NOT in use, any begin_request logins ARE allowed <br>'); }   
                        $decision_to_login = True;
                  }
                  
                  if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): <u>maybe about to enter login sequence</u>, $args_array[]: ['.serialize($args_array).'] ; $decision_to_login ['.serialize($decision_to_login).'] <br>'); } 
                  
                  // now actually use that test result
                  if ($decision_to_login == True)
                  {
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): entered and starting login sequence <br>'); }            
                        
                        //  ----  Get Email Password
                        if ($this->get_isset_pref('passwd') == False)
                        {
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): this->a[$this->acctnum][prefs][passwd] NOT set, fallback to $GLOBALS[phpgw_info][user][passwd]'.'<br>'); }
                              // DO NOT alter the password and put that altered password BACK into the preferences array
                              // why not? used to have a reason, but that was obviated, no reason at the moment
                              //$this->set_pref_value('passwd',$GLOBALS['phpgw_info']['user']['passwd']);
                              //$this->a[$this->acctnum]['prefs']['passwd'] = $GLOBALS['phpgw_info']['user']['passwd'];
                              $pass = $GLOBALS['phpgw_info']['user']['passwd'];
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): pass grabbed from GLOBALS[phpgw_info][user][passwd] = '.htmlspecialchars(serialize($pass)).'<br>'); }
                        }
                        else
                        {
                              // DO NOT alter the password and do NOT put that altered password BACK into the preferences array
                              // keep the one in GLOBALS in encrypted form if possible ????
                              $pass = $this->get_pref_value('passwd');
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): pass from prefs: already defanged for us, but still encrypted <pre>'.$pass.'</pre><br>'."\r\n"); }
                              // IMPORTANT: (this note on "defanging" still valid as of Jan 24, 2002
                              // the last thing you do before saving to the DB is "de-fang"
                              // so the FIRST thing class prefs does when reading from the db MUST be to "UN-defang", and that IS what happens there
                              // so by now phpgwapi/class.preferences has ALREADY done the "de-fanging"
                              $pass = $this->decrypt_email_passwd($pass);
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): pass from prefs: decrypted: <pre>'.$pass.'</pre><br>'."\r\n"); }
                        }
                        // ----  ISSET CHECK for userid and passwd to avoid garbage logins  ----
                        if ( $this->get_isset_pref('userid')
                        && ($this->get_pref_value('userid') != '')
                        && (isset($pass))
                        && ($pass != '') )
                        {
                              $user = $this->get_pref_value('userid');
                        }
                        else
                        {
                              // FIXME make this use an official error function
                              // problem - invalid or nonexistant info for userid and/or passwd
                              //if ($this->debug_logins > 0) {
                                    echo 'mail_msg.begin_request('.__LINE__.'): ERROR: userid or passwd empty'."<br>\r\n"
                                          .' * * $this->get_pref_value(userid) = '
                                                .$this->get_pref_value('userid')."<br>\r\n"
                                          .' * * if the userid is filled, then it must be the password that is missing'."<br>\r\n"
                                          .' * * tell your admin if a) you have a custom email password or not when reporting this error'."<br>\r\n";
                              //}
                              if ($this->debug_logins > 0) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): LEAVING with ERROR: userid or passwd empty<br>'); } 
                              return False;
                        }
                        
                        // ----  Create email server Data Communication Class  ----
                        // 1st arg to the constructor is the "mail_server_type"
                        // we feed from here because when there are multiple mail_msg objects
                        // we need to make sure we load the appropriate type dcom class
                        // which that class may not know which accounts prefs to use, so tell it here
                        
                        //$this->a[$this->acctnum]['dcom'] = CreateObject("email.mail_dcom",$this->get_pref_value('mail_server_type'));
                        
                        // ----  php3 compatibility  ----
                        // make a "new" holder object to hold the dcom object
                        // remember, by now we have determined an acctnum
                        $this_server_type = $this->get_pref_value('mail_server_type');
                        // ok, now put that object into the array
                        //$this_acctnum = $this->get_acctnum();
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): creating new dcom_holder at $GLOBALS[phpgw_dcom_'.$acctnum.'] = new mail_dcom_holder'.'<br>'); }
                        $GLOBALS['phpgw_dcom_'.$acctnum] = new mail_dcom_holder;
                        $GLOBALS['phpgw_dcom_'.$acctnum]->dcom = CreateObject("email.mail_dcom", $this_server_type);
                        // initialize the dcom class variables
                        $GLOBALS['phpgw_dcom_'.$acctnum]->dcom->mail_dcom_base();
                        
                        // ----  there are 2 settings from this mail_msg object we need to pass down to the child dcom object:  ----
                        // (1)  Do We Use UTF7 encoding/decoding of folder names
                        if (($this->get_isset_pref('enable_utf7'))
                        && ($this->get_pref_value('enable_utf7')))
                        {
                              $GLOBALS['phpgw_dcom_'.$acctnum]->dcom->enable_utf7 = True;
                        }
                        // (2)  Do We Force use of msg UID's
                        if ($this->force_msg_uids == True)
                        {
                              $GLOBALS['phpgw_dcom_'.$acctnum]->dcom->force_msg_uids = True;
                        }
                        
                        //@set_time_limit(60);
                        // login to INBOX because we know that always(?) should exist on an imap server and pop server
                        // after we are logged in we can get additional info that will lead us to the desired folder (if not INBOX)
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): about to call dcom->open: $GLOBALS["phpgw_dcom_".$acctnum('.$acctnum.')]->dcom->open('.$mailsvr_callstr."INBOX".', '.$user.', '.$pass.', )'.'<br>'); }
                        if ($this->debug_logins > 0) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): <font color="red">MAIL SERVER COMMAND</font>'.'<br>'); } 
                        $mailsvr_stream = $GLOBALS['phpgw_dcom_'.$acctnum]->dcom->open($mailsvr_callstr."INBOX", $user, $pass, '');
                        $pass = '';
                        //@set_time_limit(0);
                        
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): open returns $mailsvr_stream = ['.serialize($mailsvr_stream).']<br>'); } 
                        
                        // Logged In Success or Faliure check
                        if ( (!isset($mailsvr_stream))
                        || ($mailsvr_stream == '') )
                        {
                              // set the "mailsvr_stream" to blank so all will know the login failed
                              $this->set_arg_value('mailsvr_stream', '');
                              if ($this->debug_logins > 0) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): LEAVING with ERROR: failed to open mailsvr_stream : '.$mailsvr_stream.'<br>'); } 
                              // we return false, but SHOULD WE ERROR EXIT HERE?
                              return False;
                        }
                        
                        // SUCCESS - we are logged in to the server, at least we got to "INBOX"
                        $this->set_arg_value('mailsvr_stream', $mailsvr_stream, $acctnum);
                        $this->set_arg_value('mailsvr_account_username', $user, $acctnum);
                        // BUT if "folder" != "INBOX" we still have to "reopen" the stream to that "folder"
                        
                        // ----  Get additional Data now that we are logged in to the mail server  ----
                        // namespace is often obtained by directly querying the mailsvr
                        $mailsvr_namespace = $this->get_arg_value('mailsvr_namespace');
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $mailsvr_namespace: '.serialize($mailsvr_namespace).'<br>'); }
                        $mailsvr_delimiter = $this->get_arg_value('mailsvr_delimiter');
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): $mailsvr_delimiter: '.serialize($mailsvr_delimiter).'<br>'); }
                        
                        
                        // FIND FOLDER VALUE
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): <b> *** FIND FOLDER VALUE *** </b><br>'); }
                        // get best available, most legit, folder value that we can find, and prep it in
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): about to call: "get_best_folder_arg($args_array, $got_args, $acctnum(='.$acctnum.'))"<br>'); }
                        // "get_best_folder_arg" should also verify the folder name and fix any fldball or msgball if unverified.
                        $processed_folder_arg = $this->get_best_folder_arg($args_array, $got_args, $acctnum);
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): "get_best_folder_arg" returns $processed_folder_arg ['.htmlspecialchars(serialize($processed_folder_arg)).']<br>'); }
                        
                        // ---- Switch To Desired Folder If Necessary  ----
                        if ($processed_folder_arg == 'INBOX')
                        {
                              // NO need to switch to another folder
                              // put this $processed_folder_arg in arg "folder", replacing any unprocessed value that may have been there
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): NO need to switch folders, about to issue: $this->set_arg_value("folder", '.$processed_folder_arg.', '.serialize($acctnum).')<br>'); }
                              $this->set_arg_value('folder', $processed_folder_arg, $acctnum);
                        }
                        else
                        {
                              // switch to the desired folder now that we are sure we have it's official name
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): need to switch folders (reopen) from INBOX to $processed_folder_arg: '.$processed_folder_arg.'<br>'); } 
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): about to issue: $GLOBALS[phpgw_dcom_'.$acctnum.']->dcom->reopen('.$mailsvr_stream.', '.$mailsvr_callstr.$processed_folder_arg,', )'.'<br>'); } 
                              //$did_reopen = $tmp_a['dcom']->reopen($mailsvr_stream, $mailsvr_callstr.$processed_folder_arg, '');
                              if ($this->debug_logins > 0) { $this->dbug->out('mail_msg: begin_request('.__LINE__.'): <font color="red">MAIL SERVER COMMAND</font>'.'<br>'); } 
                              $did_reopen = $GLOBALS['phpgw_dcom_'.$acctnum]->dcom->reopen($mailsvr_stream, $mailsvr_callstr.$processed_folder_arg, '');
                              if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): reopen returns: '.serialize($did_reopen).'<br>'); } 
                              // error check
                              if ($did_reopen == False)
                              {
                                    if ($this->debug_logins > 0) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): LEAVING with re-open ERROR, closing stream, FAILED to reopen (change folders) $mailsvr_stream ['.$mailsvr_stream.'] INBOX to ['.$mailsvr_callstr.$processed_folder_arg.'<br>'); } 
                                    // log out since we could not reopen, something must have gone wrong
                                    $this->end_request();
                                    return False;
                              }
                              else
                              {
                                    if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): Successful switch folders (reopen) from (default initial folder) INBOX to ['.$processed_folder_arg.']<br>'); } 
                                    // put this $processed_folder_arg in arg "folder", since we were able to successfully switch folders
                                    if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): switched folders (via reopen), about to issue: $this->set_arg_value("folder", '.$processed_folder_arg.', $acctnum(='.$acctnum.'))<br>'); }
                                    $this->set_arg_value('folder', $processed_folder_arg, $acctnum);
                              }
                        }
                        
                        // now we have folder, sort and order, make a URI for auto-refresh use
                        // we can NOT put "start" in auto refresh or user may not see the 1st index page on refresh
                        $this_index_refresh_uri = 
                              'menuaction=email.uiindex.index'
                              .'&fldball[folder]='.$this->prep_folder_out()
                              .'&fldball[acctnum]='.$this->get_acctnum()
                              .'&sort='.$this->get_arg_value('sort')
                              .'&order='.$this->get_arg_value('order');
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): about to call $this->set_arg_value(index_refresh_uri, $this_index_refresh_uri, $acctnum(='.$acctnum.')); ; where $this_index_refresh_uri: '.htmlspecialchars($this_index_refresh_uri).'<br>'); }
                        $this->set_arg_value('index_refresh_uri', $this_index_refresh_uri, $acctnum);
                        
                        if ($this->debug_logins > 2) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): about to leave, direct access dump of $this->a  DUMP:', $this->a); } 
                        if ($this->debug_logins > 0) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): LEAVING, success'.'<br>'); } 
                        // returning this is vestigal, not really necessary, but do it anyway
                        // it's importance is that it returns something other then "False" on success
                        return $this->get_arg_value('mailsvr_stream', $acctnum);
                  }
                  else
                  {
                        // EXPERIMENTAL since we did not login can we still get a good refresh URI?
                        // now we have folder, sort and order, make a URI for auto-refresh use
                        // we can NOT put "start" in auto refresh or user may not see the 1st index page on refresh
                        $this_index_refresh_uri = 
                              'menuaction=email.uiindex.index'
                              .'&fldball[folder]='.$this->prep_folder_out()
                              .'&fldball[acctnum]='.$this->get_acctnum()
                              .'&sort='.$this->get_arg_value('sort')
                              .'&order='.$this->get_arg_value('order');
                        if ($this->debug_logins > 1) { $this->dbug->out('mail_msg.begin_request('.__LINE__.'): about to call $this->set_arg_value(index_refresh_uri, $this_index_refresh_uri, $acctnum(='.$acctnum.')); ; where $this_index_refresh_uri: '.htmlspecialchars($this_index_refresh_uri).'<br>'); }
                        $this->set_arg_value('index_refresh_uri', $this_index_refresh_uri, $acctnum);
                        
                        //if ($this->debug_logins > 1) { $this->dbug->out('mail_msg: begin_request ('.__LINE__.'): LEAVING, we were NOT allowed to, $args_array[do_login]: ['.serialize($args_array['do_login']).'] if TRUE, then we must return *something* so calling function does NOT think error, so return $args_array[do_login] <br>'); } 
                        //return $args_array['do_login'];
                        if ($this->debug_logins > 0) { $this->dbug->out('mail_msg: begin_request ('.__LINE__.'): LEAVING, we did NOT login, see above debug output, $args_array[do_login]: ['.serialize($args_array['do_login']).'] if TRUE, then we must return *something* so calling function does NOT think error, so return TRUE (what impact does this have??) <br>'); } 
                        return True;
                  }
            }

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index