Location: PHPKode > projects > phlyMail Lite > phlymail/handlers/core/setup.php
<?php
/**
 * mod.setup.php -> FrontEnd User Setup
 * @package phlyMail Nahariya 4.0+ Default Branch
 * @subpackage Core Handler
 * @subpackage Setup
 * @copyright 2001-2010 phlyLabs, Berlin (http://phlylabs.de)
 * @version 4.6.3 2010-11-08
 */
// Only valid within phlyMail
if (!defined('_IN_PHM_')) die();

$link_base = PHP_SELF.'?load=setup&handler=core&'.give_passthrough(1).'&mode=';
$mode = (isset($_REQUEST['mode'])) ? $_REQUEST['mode'] : false;
$save_handler = 'email';

// Prevent operations the user is not allowed to do
if (in_array($mode, array('addalias', 'editalias', 'dropalias', 'queryaliases', 'adduhead', 'edituhead', 'dropuhead', 'queryuheads'
                ,'addsignature', 'editsignature', 'dropsignature', 'getsignature', 'querysignatures', 'saveprofileorder'))
        && !$_SESSION['phM_privs']['all'] && !$_SESSION['phM_privs']['email_add_profile'] && !$_SESSION['phM_privs']['email_edit_profile']) {
    sendJS(array(), 1, 1);
}

if ('addalias' == $mode) {
    $sig = !strlen($_REQUEST['signature']) ? null : intval($_REQUEST['signature']);
    $DB->add_alias($_SESSION['phM_uid'], $_REQUEST['id'], $_REQUEST['email'], $_REQUEST['real_name'], $sig, $_REQUEST['sendvcf']);
    $mode = 'queryaliases';
}
if ('editalias' == $mode) {
    $sig = !strlen($_REQUEST['signature']) ? null : intval($_REQUEST['signature']);
    $DB->update_alias($_SESSION['phM_uid'], $_REQUEST['aid'], $_REQUEST['email'], $_REQUEST['real_name'], $sig, $_REQUEST['sendvcf']);
    $mode = 'queryaliases';
}
if ('dropalias' == $mode) {
    $DB->delete_alias($_SESSION['phM_uid'], $_REQUEST['aid']);
    $mode = 'queryaliases';
}
if ('queryaliases' == $mode ) {
    $data = $DB->get_accdata($_SESSION['phM_uid'], '', $_REQUEST['id']);
    sendJS(array('alias' => $data['aliases']), 1, 1);
}

if ('adduhead' == $mode) {
    $hkey = preg_replace('![^\x21-\x39\x3B-\x7e]!', '', $_REQUEST['hkey']);
    $hval = preg_replace('!\r|\n!', '', $_REQUEST['hval']);
    $DB->add_uhead($_SESSION['phM_uid'], $_REQUEST['id'], $hkey, $hval);
    $mode = 'queryuheads';
}

if ('edituhead' == $mode) {
    $hkey = preg_replace('![^\x21-\x39\x3B-\x7e]!', '', $_REQUEST['hkey']);
    $hval = preg_replace('!\r|\n!', '', $_REQUEST['hval']);
    $DB->update_uhead($_SESSION['phM_uid'], $_REQUEST['id'], $_REQUEST['ohkey'], $hkey, $hval);
    $mode = 'queryuheads';
}

if ('dropuhead' == $mode) {
    $DB->delete_uhead($_SESSION['phM_uid'], $_REQUEST['id'], $_REQUEST['hkey']);
    $mode = 'queryuheads';
}

if ('queryuheads' == $mode ) {
    $return = array();
    $data = $DB->get_accdata($_SESSION['phM_uid'], '', $_REQUEST['id']);
    if (!isset($data['userheaders']) || !is_array($data['userheaders'])) $data['userheaders'] = array();
    foreach ($data['userheaders'] as $hkey => $hval) $return[] = array('hval' => $hval, 'hkey' => $hkey);
    sendJS(array('uhead' => $return), 1, 1);
}

if ('addsignature' == $mode) {
    $sig = phm_stripslashes($_REQUEST['signature']);
    $sig_html = phm_stripslashes($_REQUEST['signature_html']);
    if ($sig_html == '<br />') $sig_html = '';
    $DB->add_signature($_SESSION['phM_uid'], $_REQUEST['title'], $sig, $sig_html);
    $mode = 'querysignatures';
}

if ('editsignature' == $mode) {
    $sig = phm_stripslashes($_REQUEST['signature']);
    $sig_html = phm_stripslashes($_REQUEST['signature_html']);
    if ($sig_html == '<br />') $sig_html = '';
    $DB->update_signature($_SESSION['phM_uid'], $_REQUEST['id'], $_REQUEST['title'], $sig, $sig_html);
    $mode = 'querysignatures';
}

if ('dropsignature' == $mode) {
    $DB->delete_signature($_SESSION['phM_uid'], $_REQUEST['id']);
    $mode = 'querysignatures';
}

if ('getsignature' == $mode) {
    $sig = $DB->get_signature($_SESSION['phM_uid'], $_REQUEST['id']);
    sendJS(array('signature' => $sig['signature'], 'signature_html' => $sig['signature_html']), 1, 1);
}

if ('querysignatures' == $mode ) {
    $return = array();
    $data = $DB->get_signature_list($_SESSION['phM_uid']);
    foreach ($data as $id => $signature) {
        $return[] = array('id' => $id, 'title' => $signature['title'] ? $signature['title'] : $WP_msg['undef']);
    }
    sendJS(array('signatures' => $return), 1, 1);
}

if ('saveprofileorder' == $mode) {
    $DB->reorder_accounts($_SESSION['phM_uid'], $_REQUEST['id']);
    sendJS(array('done' => 1), 1, 1);
}

if ('general' == $mode && ($_SESSION['phM_privs']['all'] || $_SESSION['phM_privs']['core_setup_settings'])) {
    $userdata = $DB->get_usrdata($_SESSION['phM_uid']);
    if (isset($_REQUEST['whattodo']) && 'save' == $_REQUEST['whattodo']) {
        $GlChFile = $DB->get_usr_choices($_SESSION['phM_uid']);
        $tokens = array
        		('theme_name', 'language', 'receipt_out', 'send_html', 'sms_sender', 'pagesize'
        		,'newmail_showalert', 'newmail_playsound', 'newmail_soundfile', 'pop3fetch_login'
        		,'folders_usepreview', 'plaintext_fontface', 'plaintext_fontsize', 'showattachmentinline'
        		,'mdn_behaviour', 'logout_emptytrash', 'logout_emptyjunk', 'email_preferred_part'
        		,'timezone', 'automarkread', 'reply_samewin', 'teletype', 'answer_style'
        		,'sentfolder_sms', 'replysamefolder', 'parsesmileys', 'parseformat', 'email_collapse_threads'
        		,'logout_showprompt', 'fax_sender', 'fax_sender_name', 'sentfolder_fax', 'fax_status_email'
        		);
        $tokval = array
                (isset($_REQUEST['skin']) ? $_REQUEST['skin'] : -1
                ,isset($_REQUEST['lang']) ? $_REQUEST['lang'] : -1
                ,isset($_REQUEST['receiptout']) ? $_REQUEST['receiptout'] : -1
                ,isset($_REQUEST['sendhtml']) ? $_REQUEST['sendhtml'] : -1
                ,isset($_REQUEST['smssender']) ? $_REQUEST['smssender'] : -1
                ,isset($_REQUEST['pagesize']) ? $_REQUEST['pagesize'] : 150
                ,isset($_REQUEST['alertmail']) ? $_REQUEST['alertmail'] : -1
                ,isset($_REQUEST['soundmail']) ? $_REQUEST['soundmail'] : -1
                ,isset($_REQUEST['soundname']) && $_REQUEST['soundname'] ? $_REQUEST['soundname'] : -1
                ,isset($_REQUEST['fetchlogin']) ? $_REQUEST['fetchlogin'] : -1
                ,isset($_REQUEST['usepreview']) ? $_REQUEST['usepreview'] : -1
                ,isset($_REQUEST['fontface']) ? $_REQUEST['fontface'] : -1
                ,isset($_REQUEST['fontsize']) ? $_REQUEST['fontsize'] : -1
                ,isset($_REQUEST['showattachmentinline']) ? $_REQUEST['showattachmentinline'] : -1
                ,isset($_REQUEST['mdn_behaviour']) ? $_REQUEST['mdn_behaviour'] : -1
                ,isset($_REQUEST['emptytrash']) ? $_REQUEST['emptytrash'] : -1
                ,isset($_REQUEST['emptyjunk']) ? $_REQUEST['emptyjunk'] : -1
                ,isset($_REQUEST['email_preferred_part']) ? $_REQUEST['email_preferred_part'] : 'html'
                ,isset($_REQUEST['timezone']) ? $_REQUEST['timezone'] : -1
                ,isset($_REQUEST['automarkread']) ? intval($_REQUEST['automarkread_time']) : 0
                ,isset($_REQUEST['answersamewin']) ? $_REQUEST['answersamewin'] : 0
                ,isset($_REQUEST['teletype']) ? 'sys' : 'pro'
                ,isset($_REQUEST['answer_style']) && $_REQUEST['answer_style'] == 'tofu' ? 'tofu' : 'default'
                ,isset($_REQUEST['sentfolder_sms']) ? $_REQUEST['sentfolder_sms'] : 0
                ,isset($_REQUEST['replysamefolder']) ? $_REQUEST['replysamefolder'] : -1
                ,isset($_REQUEST['parsesmileys']) ? $_REQUEST['parsesmileys'] : 0
                ,isset($_REQUEST['parseformat']) ? $_REQUEST['parseformat'] : 0
                ,isset($_REQUEST['collapse_threads']) ? $_REQUEST['collapse_threads'] : 0
                ,isset($_REQUEST['logout_showprompt']) ? $_REQUEST['logout_showprompt'] : 0
                ,isset($_REQUEST['faxsender']) ? $_REQUEST['faxsender'] : -1
                ,isset($_REQUEST['faxsendername']) ? $_REQUEST['faxsendername'] : ''
                ,isset($_REQUEST['sentfolder_fax']) ? $_REQUEST['sentfolder_fax'] : 0
                ,isset($_REQUEST['faxstatusemail']) ? $_REQUEST['faxstatusemail'] : ''
                );
        // Checkbox settings may be unset.
        $tokcheck = array (0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1);
        foreach ($tokens as $k => $v) {
            if ($tokval[$k] == -1) {
                if (!$tokcheck[$k]) continue;
                $tokval[$k] = '';
            }
            $GlChFile['core'][$tokens[$k]] = $tokval[$k];
        }
        if (isset($_REQUEST['loginfolder'])) {
            if (!$_REQUEST['loginfolder']) {
                $GlChFile['core']['login_handler'] = $GlChFile['core']['login_folder'] = false;
            } elseif (preg_match('!^([a-z_]+)\:\:(root|[0-9]+)$!i', $_REQUEST['loginfolder'], $found)) {
                $GlChFile['core']['login_handler'] = $found[1];
                $GlChFile['core']['login_folder'] = $found[2];
            }
        }
        if ($_REQUEST['pw'] != '') {
            if ($_REQUEST['pw'] != $_REQUEST['pw2']) {
                $WP_return = $WP_msg['SuPW1notPW2'];
            } else {
                // Tell backend API about password change
                require_once($_PM_['path']['admin'].'/lib/configapi.class.php');
                $cAPI = new configapi($_PM_);
                $cAPI->edit_user($_SESSION['phM_uid'], $_SESSION['phM_username'], $_REQUEST['pw'], '', $_SESSION['phM_username']);
                unset($cAPI);
            }
        }
        // Check validity of given SMS sender
        if (isset($_REQUEST['smssender']) && $_REQUEST['smssender']) {
            require_once($_PM_['path']['msggw'].'/'.$_PM_['core']['sms_use_gw'].'/phm_shortmessage.php');
            $GW = new phm_shortmessage($_PM_['path']['conf'].'/msggw.'.$_PM_['core']['sms_use_gw'].'.ini.php', 1, 1);
            $out = $GW->wash_input(array('from' => $_REQUEST['smssender']));
            if (!is_array($out)) $WP_return = $WP_msg['ESMSFormat'];
        }
        // Check validity of given SMS sender number
        if (isset($_REQUEST['faxsender']) && $_REQUEST['faxsender']) {
            require_once($_PM_['path']['msggw'].'/'.$_PM_['core']['sms_use_gw'].'/phm_shortmessage.php');
            $GW = new phm_shortmessage($_PM_['path']['conf'].'/msggw.'.$_PM_['core']['sms_use_gw'].'.ini.php', 1, 1);
            $out = $GW->wash_input(array('to' => $_REQUEST['faxsender'])); // Make sure, this really is a phone number
            if (!is_array($out)) $WP_return = $WP_msg['EFaxFormat'];
        }
        // User might switch the Teletype setting, this is held in the session in parallel
        if (isset($_SESSION['phM_tt'])) $_SESSION['phM_tt'] = $GlChFile['core']['teletype'];

        if (!isset($WP_return)) {
            if ($_REQUEST['externalemail'] != $userdata['externalemail']) {
                // Tell backend API about change of external email
                require_once($_PM_['path']['admin'].'/lib/configapi.class.php');
                $cAPI = new configapi($_PM_);
                $cAPI->edit_user($_SESSION['phM_uid'], $_SESSION['phM_username'], $_REQUEST['pw'], $_REQUEST['externalemail'], '');
                unset($cAPI);
                $userdata['externalemail'] = $_REQUEST['externalemail'];
            }
            if ($_REQUEST['pw'] && $_REQUEST['pw']) $userdata['password'] = $_REQUEST['pw'];
            $userdata['uid'] = $_SESSION['phM_uid'];
            $DB->upd_user($userdata);
            $WP_return = $DB->set_usr_choices($_SESSION['phM_uid'], $GlChFile) ? $WP_msg['optssaved'] : $WP_msg['optsnosave'];
        }
        header('Location: '.$link_base.'general&WP_return='.urlencode($WP_return));
        exit();
    }
    $data = $DB->get_usrdata($_SESSION['phM_uid']);
    $tpl = new fxl_cached_template($_PM_['path']['frontend'].'/templates/setup.general.tpl', $_PM_['path']['tplcache'].'setup.general.tpl');
    if ($_SESSION['phM_privs']['all'] || $_SESSION['phM_privs']['core_change_theme']) {

        $themeEngine = trim(file_get_contents($_PM_['path']['conf'].'/theme.engine'));

        $t_ht = $tpl->get_block('has_themes');
        $d_ = opendir($_PM_['path']['theme_dir']);
        while (false !== ($skinname = readdir($d_))) {
            if ($skinname == '.' || $skinname == '..') continue;
            if (!is_dir($_PM_['path']['theme_dir'].'/'.$skinname)) continue;
            if (!file_exists($_PM_['path']['theme_dir'].'/'.$skinname.'/main.tpl')) continue;
            if (!file_exists($_PM_['path']['theme_dir'].'/'.$skinname.'/choices.ini.php')) continue;
            // Read theme's chocies
            $thChoi = parse_ini_file($_PM_['path']['theme_dir'].'/'.$skinname.'/choices.ini.php'); // Parse
            if (!isset($thChoi['engine']) || $thChoi['engine'] != $themeEngine) { // Has engine setting and version matches?
                continue; // This theme ought to be imcompatible
            }
            $skins[] = $skinname;
        }
        closedir($d_);
        sort($skins);
        $t_s = $t_ht->get_block('skinline');
        foreach ($skins as $skinname) {
            $t_s->assign('skinname', $skinname);
            if ($skinname == $_PM_['core']['theme_name']) $t_s->assign_block('sel');
            $t_ht->assign('skinline', $t_s);
            $t_s->clear();
        }
        $t_ht->assign('msg_optskin', $WP_msg['opttheme']);
        $tpl->assign('has_themes', $t_ht);
    }

    $tpl->assign(array
            ('target_link' => htmlspecialchars($link_base.'general&whattodo=save')
            ,'link_base' => $link_base
            ,'WP_return' => isset($_REQUEST['WP_return']) ? $_REQUEST['WP_return'] : ''
            ,'msg_optlang' => $WP_msg['optlang']
            ,'msg_opttele' => $WP_msg['opttele']
            ,'msg_optcopybox' => $WP_msg['optcopybox']
            ,'msg_optreceipt' => $WP_msg['optreceipt']
            ,'msg_mdnbehaviour' => $WP_msg['optmdnbehaviour']
            ,'msg_pagesize' => $WP_msg['optpagesize']
            ,'msg_txt_prop' => $WP_msg['txt_prop']
            ,'msg_txt_syst' => $WP_msg['txt_syst']
            ,'msg_save' => $WP_msg['save']
            ,'msg_cancel' => $WP_msg['cancel']
            ,'msg_newpw' => $WP_msg['sysnewpass']
            ,'msg_newpw2' => $WP_msg['syspass2']
            ,'msg_sendhtml' => $WP_msg['EmailSendHTML']
            ,'msg_alertnewmail' => $WP_msg['newmail_showalert']
            ,'msg_alertnewmail_popup' => $WP_msg['newmail_alertpopup']
            ,'msg_alertnewmail_sound' => $WP_msg['newmail_alertsound']
            ,'msg_fetchlogin' => $WP_msg['newmail_fetchlogin']
            ,'msg_usepreview' => $WP_msg['folders_use_preview']
            ,'msg_fontface' => $WP_msg['PlaintextFontstyle']
            ,'msg_showattinline' => $WP_msg['showattachmentinline']
            ,'msg_onlogout' => $WP_msg['onLogout']
            ,'msg_emptytrash' => $WP_msg['ActionEmptyTrash']
            ,'msg_emptyjunk' => $WP_msg['ActionEmptyJunk']
            ,'standard' => $WP_msg['Standard']
            ,'msg_pinboard' => $WP_msg['CorePinboard']
            ,'msg_preferredmailpart' => $WP_msg['optpreferred']
            ,'msg_timezone' => $WP_msg['TimeZone']
            ,'msg_automarkread1' => $WP_msg['AutoMarkRead']
            ,'msg_automarkread2' => $WP_msg['AutoMarkRead2']
            ,'msg_answersamewin' => $WP_msg['ReplyInSameWin']
            ,'msg_teletype' => $WP_msg['TeletypeFont']
            ,'msg_sigpos' => $WP_msg['SigPos']
            ,'msg_sigtop' => $WP_msg['SigTop']
            ,'msg_sigbottom' => $WP_msg['SigBottom']
            ,'msg_loginfolder' => $WP_msg['LoginFolder']
            ,'msg_onlogin' => $WP_msg['onLogin']
            ,'msg_sentfolder_sms' => $WP_msg['CoreSentFolderSMS']
            ,'msg_replysamefolder' => $WP_msg['StoreReplySameFolder']
            ,'msg_parsesmileys' => $WP_msg['ParseSmileys']
            ,'msg_parseformat' => $WP_msg['ParsePlaintextFormats']
            ,'msg_collapse_threads' => $WP_msg['EmailCollapseThreads']
            ,'msg_externalemail' => $WP_msg['sysextemail']
            ,'msg_showprompt' => $WP_msg['onLogoutShowPrompt']
            ,'fontsize' => isset($_PM_['core']['plaintext_fontsize']) ? $_PM_['core']['plaintext_fontsize'] : '12'
            ,'pagesize' => $_PM_['core']['pagesize']
            ,'externalemail' => $userdata['externalemail']
            ,'msg_sentfolder_fax' => $WP_msg['CoreSentFolderFax']
            ));
    if (isset($_PM_['core']['sms_feature_active']) && $_PM_['core']['sms_feature_active']) {
        $tpl->fill_block('smssender', array
                ('msg_smssender' => $WP_msg['SMSSender']
                ,'sms_sender' => isset($_PM_['core']['sms_sender']) ? $_PM_['core']['sms_sender'] : ''
                ));
    }
    if ((isset($_PM_['core']['fax_default_active']) && $_PM_['core']['fax_default_active'])
            || (isset($_PM_['core']['fax_active']) && $_PM_['core']['fax_active'])) {
        $tpl->fill_block('faxsender', array
                ('msg_faxsender' => $WP_msg['FaxSender']
                ,'msg_faxsendername' => $WP_msg['FaxSenderName']
                ,'msg_faxstatusemail' => $WP_msg['FaxStatusEmailTo']
                ,'fax_sender' => isset($_PM_['core']['fax_sender']) ? $_PM_['core']['fax_sender'] : ''
                ,'fax_sender_name' => isset($_PM_['core']['fax_sender_name']) ? $_PM_['core']['fax_sender_name'] : ''
                ,'fax_status_email' => isset($_PM_['core']['fax_status_email']) ? $_PM_['core']['fax_status_email'] : ''
                ));
    }
    if (isset($_PM_['core']['answer_style']) && $_PM_['core']['answer_style'] == 'tofu') {
        $tpl->assign_block('answer_style_tofu');
    } else {
        $tpl->assign_block('answer_style_default');
    }
    // Allow selection of login folder
    if (!isset($_PM_['core']['login_handler'])) $_PM_['core']['login_handler'] = '';
    if (!isset($_PM_['core']['login_folder'])) $_PM_['core']['login_folder'] = '';

    if (!isset($_PM_['core']['sentfolder_sms'])) $_PM_['core']['sentfolder_sms'] = 0;
    $t_lifo = $tpl->get_block('loginfolder');
    $t_smsfo = $tpl->get_block('sentfolder_sms');
    $t_faxfo = $tpl->get_block('sentfolder_fax');
    foreach ($_SESSION['phM_uniqe_handlers'] as $type => $data) {
        if (!file_exists($_PM_['path']['handler'].'/'.basename($type).'/api.php')) continue;
        require_once($_PM_['path']['handler'].'/'.basename($type).'/api.php');
        if (!in_array('give_folderlist', get_class_methods('api_'.$type))) continue;
        // Denote the handler the following structure belongs to
        $t_lifo->assign(array
                ('id' => '" style="color:darkgray;" disabled="disabled'
                ,'name' => phm_entities($data['i18n'])
                ));
        $tpl->assign('loginfolder', $t_lifo);
        $t_lifo->clear();
        // Actual folder structure output
        $clsnam = 'api_'.$type;
        $API = new $clsnam($_PM_, $_SESSION['phM_uid']);
        foreach ($API->give_folderlist() as $k => $v) {
            $lvl_space = str_repeat('&nbsp;', ($v['level']+1)*2);
            $t_lifo->assign(array
                    ('id' => (!$v['has_items']) ? '" style="color:darkgray;" disabled="disabled' : $type.'::'.$k
                    ,'name' => $lvl_space.phm_entities($v['foldername'])
                    ));
            if ($_PM_['core']['login_handler'] == $type && $_PM_['core']['login_folder'] == $k) $t_lifo->assign_block('sel');
            $tpl->assign('loginfolder', $t_lifo);
            $t_lifo->clear();
            // While filling login folder also fill sent SMS default folder
            if ($type == 'email') {
                $lvl_space = str_repeat('&nbsp;', ($v['level'])*2);
                $t_smsfo->assign(array
                        ('id' => (!$v['has_items']) ? '" style="color:darkgray;" disabled="disabled' : $k
                        ,'name' => $lvl_space.phm_entities($v['foldername'])
                        ));
                if ($_PM_['core']['sentfolder_sms'] == $k) $t_smsfo->assign_block('sel');
                $tpl->assign('sentfolder_sms', $t_smsfo);
                $t_smsfo->clear();
                $t_faxfo->assign(array
                        ('id' => (!$v['has_items']) ? '" style="color:darkgray;" disabled="disabled' : $k
                        ,'name' => $lvl_space.phm_entities($v['foldername'])
                        ));
                if ($_PM_['core']['sentfolder_fax'] == $k) $t_faxfo->assign_block('sel');
                $tpl->assign('sentfolder_fax', $t_faxfo);
                $t_faxfo->clear();
            }
        }
    }
    $langs = $langnames = array();
    $d_ = opendir($_PM_['path']['message']);
    while (false !== ($langname = readdir($d_))) {
        if ($langname == '.' || $langname == '..') continue;
        if (!preg_match('/\.php$/i', trim($langname))) continue;
        preg_match
                ('!\$WP_msg\[\'language_name\'\]\ \=\ \'([^\']+)\'!'
                ,file_get_contents($_PM_['path']['message'].'/'.$langname)
                ,$found
                );
        $langname = preg_replace('/\.php$/i', '', trim($langname));
        $langs[] = $found[1];
        $langnames[] = $langname;
    }
    closedir($d_);
    array_multisort($langs, SORT_ASC, $langnames);
    $t_s = $tpl->get_block('langline');
    foreach($langs as $id => $langname) {
        $t_s->assign(array('id' => $langnames[$id], 'langname' => $langname));
        if ($langnames[$id] == $_PM_['core']['language']) $t_s->assign_block('sel');
        $tpl->assign('langline', $t_s);
        $t_s->clear();
    }
    $myfonts = $_PM_['path']['conf'].'/global.fontlist.phml';
    if (file_exists($myfonts) && is_readable($myfonts)) {
    	$t_ff = $tpl->get_block('fontface');
    	foreach (file($myfonts) as $line) {
    		$line = trim($line);
    		if (!$line) continue;
    		if ($line{0} == '#') continue;
    		if (preg_match('![^-a-zA-Z0-9,\s]!', $line)) continue;
    		$t_ff->assign('face', $line);
    		if (isset($_PM_['core']['plaintext_fontface']) && $_PM_['core']['plaintext_fontface'] == $line) $t_ff->assign_block('sel');
    		$tpl->assign('fontface', $t_ff);
    		$t_ff->clear();
    	}
    } else {
    	$tpl->fill_block('fontface', 'face', 'Arial, Helvetica, Verdana, sans-serif');
    }
    $d_ = opendir($_PM_['path']['frontend'].'/sounds');
    while (false !== ($skinname = readdir($d_))) {
        if ($skinname == '.' || $skinname == '..') continue;
        if (!preg_match('!\.(mp3|phsnd)$!', $skinname)) continue;
        $sounds[] = $skinname;
    }
    closedir($d_);
    sort($sounds);
    $t_s = $tpl->get_block('soundnames');
    foreach ($sounds as $skinname) {
        $t_s->assign('name', $skinname);
        if (isset($_PM_['core']['newmail_soundfile']) && $skinname == $_PM_['core']['newmail_soundfile']) $t_s->assign_block('sel');
        $tpl->assign('soundnames', $t_s);
        $t_s->clear();
    }

    $myzones = $_PM_['path']['conf'].'/timezonedb.phml';
    if (file_exists($myzones) && is_readable($myzones)) {
    	$t_ff = $tpl->get_block('timezone');
    	foreach (file($myzones) as $line) {
    		$line = trim($line);
    		if (!$line) continue;
    		if ($line{0} == '#') continue;
    		if (preg_match('![^-a-zA-Z0-9_\+\/,\s]!', $line)) continue;
    		$t_ff->assign(array('zone' => $line, 'zonename' => str_replace('_', ' ', $line)));
    		if (date_default_timezone_get() == $line) $t_ff->assign_block('sel');
            $tpl->assign('timezone', $t_ff);
            $t_ff->clear();
    	}
    } else {
    	$tpl->fill_block('timezone', array('zone' => 'Europe/Berlin', 'zonename' => 'Europe/Berlin'));
    }

    if (!isset($_PM_['core']['mdn_behaviour'])) $_PM_['core']['mdn_behaviour'] = 'none';
    $t_mdn = $tpl->get_block('mdnline');
    foreach (array('none' => 'optmdnbeha_never', 'ask' => 'optmdnbeha_ask', 'always' => 'optmdnbeha_send') as $behaviour => $message) {
        $t_mdn->assign(array('behaviour' => $behaviour, 'behaviourname' => $WP_msg[$message]));
        if ($_PM_['core']['mdn_behaviour'] == $behaviour) $t_mdn->assign_block('sel');
        $tpl->assign('mdnline', $t_mdn);
        $t_mdn->clear();
    }
    if (!isset($_PM_['core']['email_preferred_part'])) $_PM_['core']['email_preferred_part'] = 'html';
    $t_epp = $tpl->get_block('mailpreferredpart');
    foreach (array('html' => 'optpreferred_html', 'text' => 'optpreferred_text') as $part => $message) {
        $t_epp->assign(array('part' => $part, 'partname' => $WP_msg[$message]));
        if ($_PM_['core']['email_preferred_part'] == $part) $t_epp->assign_block('sel');
        $tpl->assign('mailpreferredpart', $t_epp);
        $t_epp->clear();
    }
    if (isset($_PM_['core']['receipt_out']) && $_PM_['core']['receipt_out']) $tpl->assign_block('receipt');
    if (isset($_PM_['core']['folders_usepreview']) && $_PM_['core']['folders_usepreview']) $tpl->assign_block('preview');
    if (isset($_PM_['core']['newmail_showalert']) && $_PM_['core']['newmail_showalert']) $tpl->assign_block('alertmail');
    if (isset($_PM_['core']['newmail_playsound']) && $_PM_['core']['newmail_playsound']) $tpl->assign_block('soundmail');
    if (isset($_PM_['core']['pop3fetch_login']) && $_PM_['core']['pop3fetch_login']) $tpl->assign_block('fetchlogin');
    if (isset($_PM_['core']['send_html']) && $_PM_['core']['send_html']) $tpl->assign_block('sendhtml');
    if (isset($_PM_['core']['showattachmentinline']) && $_PM_['core']['showattachmentinline']) $tpl->assign_block('showattachmentinline');
    if (isset($_PM_['core']['logout_emptytrash']) && $_PM_['core']['logout_emptytrash']) $tpl->assign_block('emptytrash');
    if (isset($_PM_['core']['logout_emptyjunk']) && $_PM_['core']['logout_emptyjunk']) $tpl->assign_block('emptyjunk');
    if (!isset($_PM_['core']['logout_showprompt']) || $_PM_['core']['logout_showprompt']) $tpl->assign_block('logoutshowprompt');
    if (isset($_PM_['core']['reply_samewin']) && $_PM_['core']['reply_samewin']) $tpl->assign_block('answersamewin');
    if (isset($_PM_['core']['teletype']) && $_PM_['core']['teletype'] == 'sys') $tpl->assign_block('teletype');
    if (isset($_PM_['core']['automarkread']) && $_PM_['core']['automarkread']) {
        $tpl->assign_block('automarkread');
        $tpl->assign('automarkread_time', intval($_PM_['core']['automarkread']));
    } else {
        $tpl->assign('automarkread_time', 0);
    }
    if (isset($_PM_['core']['replysamefolder']) && $_PM_['core']['replysamefolder']) $tpl->assign_block('replysamefolder');
    if (!isset($_PM_['core']['parsesmileys']) || $_PM_['core']['parsesmileys']) $tpl->assign_block('parsesmileys');
    if (!isset($_PM_['core']['parseformat']) || $_PM_['core']['parseformat']) $tpl->assign_block('parseformat');
    if (isset($_PM_['core']['email_collapse_threads']) && $_PM_['core']['email_collapse_threads']) $tpl->assign_block('collapse_threads');
}

if (($mode == 'saveold' && ($_SESSION['phM_privs']['all'] || $_SESSION['phM_privs']['email_edit_profile']) )
        || ($mode == 'savenew' && ($_SESSION['phM_privs']['all'] || $_SESSION['phM_privs']['email_add_profile']))) {
    $acctype = isset($_REQUEST['acctype']) ? $_REQUEST['acctype'] : 'pop3';
    $userdata = $DB->get_usrdata($_SESSION['phM_uid']);
    $error = '';
    $account = (isset($_REQUEST['account'])) ? $_REQUEST['account'] : false;
    if ('' == $_REQUEST['popname'])   $error .= $WP_msg['enterProfname'].LF;
    if ('' == $_REQUEST['popserver']) $error .= ($acctype == 'imap' ? 'IMAP' : 'POP3').': '.$WP_msg['enterPOPserver'].LF;
    if ('' == $_REQUEST['popuser'])   $error .= ($acctype == 'imap' ? 'IMAP' : 'POP3').': '.$WP_msg['enterPOPuser'].LF;
    if ('saveold' == $mode) {
        $check_accid = $DB->checkfor_accname($userdata['username'], $_REQUEST['popname']);
        if (isset($check_accid) && $account != $check_accid && $check_accid != '') {
            $error .= $account.'/'.$check_accid.': '.$WP_msg['SuPrfExists'];
        }
    } else {
        if ($DB->checkfor_accname($userdata['username'], $_REQUEST['popname'])) $error .= $WP_msg['SuPrfExists'];
    }
    if (!$error) {
        if ('savenew' == $mode) {
            $account = $DB->add_account(array
                    ('uid' => $_SESSION['phM_uid']
                    ,'accname' => $_REQUEST['popname']
                    ,'checkevery' => $_REQUEST['checkevery']
                    ,'be_checkevery' => isset($_REQUEST['be_checkevery']) ? $_REQUEST['be_checkevery'] : '0'
                    ,'accid' => $DB->get_maxaccid($_SESSION['phM_uid'])
                    ,'checkspam' => isset($_REQUEST['checkspam']) ? $_REQUEST['checkspam'] : 0
                    ,'acctype' => $acctype
                    ,'sig_on' => isset($_REQUEST['sig_on']) ? $_REQUEST['sig_on'] : 0
                    ,'popserver' => $_REQUEST['popserver']
                    ,'popport' => $_REQUEST['popport']
                    ,'popuser' => $_REQUEST['popuser']
                    ,'poppass' => $_REQUEST['poppass']
                    ,'popnoapop' => isset($_REQUEST['popapop']) ? $_REQUEST['popapop'] : '0'
                    ,'popsec' => isset($_REQUEST['popsec']) && $_REQUEST['popsec'] == '1' ? 'AUTO' : 'none'
                    ,'leaveonserver' => isset($_REQUEST['leaveonserver']) ? $_REQUEST['leaveonserver'] : 0
                    ,'localkillserver' => isset($_REQUEST['localkillserver']) ? $_REQUEST['localkillserver'] : 0
                    ,'onlysubscribed' => isset($_REQUEST['onlysubscribed']) ? $_REQUEST['onlysubscribed'] : 0
                    ,'cachetype' => isset($_REQUEST['cachetype']) ? $_REQUEST['cachetype'] : 'struct'
                    ,'imapprefix' => isset($_REQUEST['imapprefix']) ? $_REQUEST['imapprefix'] : ''
                    ,'checkspam' => isset($_REQUEST['checkspam']) ? $_REQUEST['checkspam'] : 0
                    ,'inbox' => isset($_REQUEST['inbox']) ? $_REQUEST['inbox'] : '0'
                    ,'sent' => isset($_REQUEST['sent_objects']) ? $_REQUEST['sent_objects'] : '0'
                    ,'drafts' => isset($_REQUEST['drafts']) ? $_REQUEST['drafts'] : '0'
                    ,'templates' => isset($_REQUEST['templates']) ? $_REQUEST['templates'] : '0'
                    ,'junk' => isset($_REQUEST['junk']) ? $_REQUEST['junk'] : '0'
                    ,'waste' => isset($_REQUEST['waste']) ? $_REQUEST['waste'] : '0'
                    ,'real_name' => $_REQUEST['real_name']
                    ,'address' => $_REQUEST['address']
                    ,'smtpafterpop' => isset($_REQUEST['smtpafterpop']) ? $_REQUEST['smtpafterpop'] : 0
                    ,'smtpsec' => isset($_REQUEST['smtpsec']) && $_REQUEST['smtpsec'] == '1' ? 'AUTO' : 'none'
                    ,'smtpserver' => $_REQUEST['smtp_host']
                    ,'smtpport' => $_REQUEST['smtp_port']
                    ,'smtpuser' => $_REQUEST['smtp_user']
                    ,'smtppass' => $_REQUEST['smtp_pass']
                    ,'signature' => $_REQUEST['signature']
                    ,'sendvcf' => $_REQUEST['sendvcf']
                    ));
            if ($account) {
                // Attempting to create the imapbox entry in the indexer via API call
                if ('imap' == $acctype) {
                    $profile = $DB->get_profile_from_accid($_SESSION['phM_uid'], $account);
                    require_once($_PM_['path']['handler'].'/email/api.php');
                    $API = new api_email($_PM_, $_SESSION['phM_uid']);
                    $API->create_imapbox((($_REQUEST['popname']) ? $_REQUEST['popname'] : $_REQUEST['popserver'].' IMAP'), $profile);
                    unset($API);
                }
            }
        }
        if ('saveold' == $mode) {
            if (!$DB->upd_account(array
                    ('uid' => $_SESSION['phM_uid']
                    ,'accid' => $account
                    ,'accname' => $_REQUEST['popname']
                    ,'checkevery' => $_REQUEST['checkevery']
                 	,'be_checkevery' => isset($_REQUEST['be_checkevery']) ? $_REQUEST['be_checkevery'] : '0'
                    ,'checkspam' => isset($_REQUEST['checkspam']) ? $_REQUEST['checkspam'] : 0
                    ,'acctype' => isset($_REQUEST['acctype']) ? $_REQUEST['acctype'] : 'pop3'
                    ,'sig_on' => isset($_REQUEST['sig_on']) ? $_REQUEST['sig_on'] : 0
                    ,'popserver' => $_REQUEST['popserver']
                    ,'popport' => $_REQUEST['popport']
                    ,'popuser' => $_REQUEST['popuser']
                    ,'poppass' => $_REQUEST['poppass']
                    ,'popnoapop' => isset($_REQUEST['popapop']) ? $_REQUEST['popapop'] : '0'
                    ,'popsec' => isset($_REQUEST['popsec']) && $_REQUEST['popsec'] == '1' ? 'AUTO' : 'none'
                    ,'leaveonserver' => isset($_REQUEST['leaveonserver']) ? $_REQUEST['leaveonserver'] : 0
                    ,'localkillserver' => isset($_REQUEST['localkillserver']) ? $_REQUEST['localkillserver'] : 0
                    ,'onlysubscribed' => isset($_REQUEST['onlysubscribed']) ? $_REQUEST['onlysubscribed'] : 0
                    ,'cachetype' => isset($_REQUEST['cachetype']) ? $_REQUEST['cachetype'] : 'struct'
                    ,'imapprefix' => /*isset($_REQUEST['imapprefix']) ? $_REQUEST['imapprefix'] : */ '' // Not yet supported
                    ,'checkspam' => isset($_REQUEST['checkspam']) ? $_REQUEST['checkspam'] : 0
                 	,'inbox' => isset($_REQUEST['inbox']) ? $_REQUEST['inbox'] : '0'
                    ,'sent' => isset($_REQUEST['sent_objects']) ? $_REQUEST['sent_objects'] : '0'
                    ,'drafts' => isset($_REQUEST['drafts']) ? $_REQUEST['drafts'] : '0'
                    ,'templates' => isset($_REQUEST['templates']) ? $_REQUEST['templates'] : '0'
                    ,'junk' => isset($_REQUEST['junk']) ? $_REQUEST['junk'] : '0'
                    ,'waste' => isset($_REQUEST['waste']) ? $_REQUEST['waste'] : '0'
                    ,'real_name' => $_REQUEST['real_name']
                    ,'address' => $_REQUEST['address']
                    ,'smtpafterpop' => isset($_REQUEST['smtpafterpop']) ? $_REQUEST['smtpafterpop'] : 0
                    ,'smtpsec' => isset($_REQUEST['smtpsec']) && $_REQUEST['smtpsec'] == '1' ? 'AUTO' : 'none'
                    ,'smtpserver' => $_REQUEST['smtp_host']
                    ,'smtpport' => $_REQUEST['smtp_port']
                    ,'smtpuser' => $_REQUEST['smtp_user']
                    ,'smtppass' => $_REQUEST['smtp_pass']
                    ,'signature' => $_REQUEST['signature']
                    ,'sendvcf' => $_REQUEST['sendvcf']
                    ))) {
                $error .= $WP_msg['optsnosave'];
            } else {
                if ('imap' == $acctype) {
                    require_once($_PM_['path']['handler'].'/email/api.php');
                    $API = new api_email($_PM_, $_SESSION['phM_uid']);
                    $profile = $DB->get_profile_from_accid($_SESSION['phM_uid'], $account);
                    $folder = $API->get_system_folder('imapbox', $profile, false);
                    if (!$folder) {
                        // Attempting to create the imapbox entry in the indexer via API call in case it does not exist (this should NOT happen)
                        $API->create_imapbox((($_REQUEST['popname']) ? $_REQUEST['popname'] : $_REQUEST['popserver'].' IMAP'), $profile);
                    } else {
                        // Update the name according to what the user entered for it
                        $API->rename_imapbox($folder['idx'], (($_REQUEST['popname']) ? $_REQUEST['popname'] : $_REQUEST['popserver'].' IMAP'));
                    }
                    unset($API);
                }
            }
        }
    }
    if ($error) {
        sendJS(array('error' => $error), 1, 1);
    } else {
        $account = $DB->get_profile_from_accid($_SESSION['phM_uid'], $account);
        sendJS(array('profsaved' => intval($account), 'mode' => $mode, 'profname' => $_REQUEST['popname']), 1, 1);
    }
}

if ('kill' == $mode && ($_SESSION['phM_privs']['all'] || $_SESSION['phM_privs']['email_delete_profile'])) {
    $account = (isset($_REQUEST['account'])) ? (int) $_REQUEST['account'] : false;
    if (false !== $account) {
        $accdata = $DB->get_accdata($_SESSION['phM_uid'], $_SESSION['phM_username'], $account);
        $profile = $DB->get_profile_from_accid($_SESSION['phM_uid'], $account);
        if ($accdata['acctype'] == 'imap') {
            require_once($_PM_['path']['handler'].'/email/api.php');
            $API = new api_email($_PM_, $_SESSION['phM_uid']);
            $API->drop_imapbox($profile);
            unset($API);
        }
        $DB->delete_account($_SESSION['phM_username'], $account);
    }
    sendJS(array('profsaved' => $account, 'mode' => $mode), 1, 1);
}

if ($mode == 'setdefacc' && ($_SESSION['phM_privs']['all'] || $_SESSION['phM_privs']['email_edit_profile'])) {
    $GlChFile = $DB->get_usr_choices($_SESSION['phM_uid']);
    if (isset($_REQUEST['def_prof'])) $GlChFile['core']['default_profile'] = $_REQUEST['def_prof'];
    $WP_return = ($DB->set_usr_choices($_SESSION['phM_uid'], $GlChFile)) ? $WP_msg['optssaved'] : $WP_msg['optsnosave'];
    header('Location: '.$link_base.'profiles');
    exit;
}

if ($mode == 'profiles' && ($_SESSION['phM_privs']['all'] || $_SESSION['phM_privs']['email_add_profile'] || $_SESSION['phM_privs']['email_edit_profile'])) {
    $tpl = new fxl_cached_template($_PM_['path']['frontend'].'/templates/core.listprofiles.tpl', $_PM_['path']['tplcache'].'core.listprofiles.tpl');
    $acclist = $DB->get_accidx($_SESSION['phM_uid'], $_SESSION['phM_username']);
    $counter = sizeof($acclist);
    if ($counter > 0 && is_array($acclist)) {
        $t_b = $tpl->get_block('menline');
        foreach ($acclist as $k => $v) {
            $pd = array_merge
                    ($DB->get_accdata($_SESSION['phM_uid'], $_SESSION['phM_username'], $k)
                    ,$DB->get_popconnect($_SESSION['phM_uid'], $_SESSION['phM_username'], $k)
                    );
            $t_b->assign(array('profilenm' => $acclist[$k], 'id' => $k, 'msg_del' => $WP_msg['del']));
            if (isset($pd['acctype']) && $pd['acctype'] == 'pop3') {
                $t_b->assign_block('acctype_pop3');
            } elseif (isset($pd['acctype']) && $pd['acctype'] == 'imap') {
                $t_b->assign_block('acctype_imap');
            }
            $tpl->assign('menline', $t_b);
            $t_b->clear();
            $defacc[$k] = $acclist[$k]; // Save data for default account selection below
        }
    }
    // Selection of default account
    if (isset($defacc) && !empty($defacc)) {
        $t_da = $tpl->get_block('profline');
        foreach ($defacc as $k => $v) {
            $t_da->assign(array('id' => $k, 'name' => $v));
            if (isset($_PM_['core']['default_profile']) && $_PM_['core']['default_profile'] == $k) $t_da->assign_block('sel');
            $tpl->assign('profline', $t_da);
            $t_da->clear();
        }
    }
    $save_handler_path = $_PM_['path']['handler'].'/'.$save_handler.'/api.php';
    $save_class = 'api_'.$save_handler;
    require_once($save_handler_path);
    $API = new $save_class($_PM_, $_SESSION['phM_uid']);
    $t_inb = $tpl->get_block('inboxline');
    foreach ($API->give_folderlist() as $id => $data) {
        $lvl_space = ($data['level'] > 0) ? str_repeat('&nbsp;', $data['level'] * 2) : '';
        $t_inb->assign(array
                ('id' => (!$data['has_items']) ? '" style="color:darkgray;" disabled="disabled' : $id
                ,'name' => $lvl_space . phm_entities($data['foldername'])
                ));
        $tpl->assign('inboxline', $t_inb);
        $t_inb->clear();
    }
    /** Maybe later again, not sensible right now
    $t_ctl = $tpl->get_block('cacheline');
    foreach (array('struct' => $WP_msg['IMAPFetchHeaders'], 'full' => $WP_msg['IMAPFetchFull']) as $k => $v) {
        $t_ctl->assign(array('id' => $k, 'name' => htmlspecialchars($v)));
        $tpl->assign('cacheline', $t_ctl);
        $t_ctl->clear();
    }*/
    // Tell the frontend, whether SSL is compiled in for transparent SSL support in POP3 / SMTP / IMAP
    if (function_exists('extension_loaded') && extension_loaded('openssl')) {
        $tpl->assign_block('ssl_available');
    }
    if ($_SESSION['phM_privs']['all'] || $_SESSION['phM_privs']['email_add_profile']) {
        $tpl->assign_block('may_add_profile');
    }
    $tpl->assign(array
            ('msg_profile' => $WP_msg['ProfileName']
            ,'msg_addacct' => $WP_msg['addacct']
            ,'addlink' => htmlspecialchars($link_base.'add')
            ,'kill_request' => $WP_msg['deleAccount']
            ,'form_target' => htmlspecialchars($link_base.'setdefacc')
            ,'msg_defacc' => $WP_msg['default_account']
            ,'about_defacc' => str_replace('$1', $WP_msg['notdef'], $WP_msg['about_defacc'])
            ,'msg_notdef' => $WP_msg['notdef']
            ,'editlink' => $link_base.'loadprofile&account='
            ,'delelink' => $link_base.'kill&account='
            ,'savelink' => $link_base
            ,'getaliasesurl' => $link_base.'queryaliases'
            ,'addaliaslink' => $link_base.'addalias'
            ,'editaliaslink' => $link_base.'editalias'
            ,'dropaliaslink' => $link_base.'dropalias'
            ,'getsignaturesurl' => $link_base.'querysignatures'
            ,'getsignatureurl' => $link_base.'getsignature'
            ,'addsignaturelink' => $link_base.'addsignature'
            ,'editsignaturelink' => $link_base.'editsignature'
            ,'dropsignaturelink' => $link_base.'dropsignature'
            ,'getuheadsurl' => $link_base.'queryuheads'
            ,'adduheadlink' => $link_base.'adduhead'
            ,'edituheadlink' => $link_base.'edituhead'
            ,'dropuheadlink' => $link_base.'dropuhead'
            ,'saveordersurl' => $link_base.'saveprofileorder'
            ,'msg_popserver' => $WP_msg['popserver']
            ,'msg_popport' => $WP_msg['popport']
            ,'msg_popuser' => $WP_msg['popuser']
            ,'msg_poppass' => $WP_msg['poppass']
            ,'msg_email' => $WP_msg['email']
            ,'msg_realname' => $WP_msg['realname']
            ,'msg_fetchevery' => $WP_msg['popfetchevery']
            ,'msg_fetchfrontend' => $WP_msg['popfetchfrontend']
            ,'msg_fetchbackend' => $WP_msg['popfetchbackend']
            ,'msg_leaveonserver' => $WP_msg['popleaveonserver']
            ,'msg_popapop' => $WP_msg['popapop']
            ,'msg_auto' => $WP_msg['auto']
            ,'msg_no' => $WP_msg['no']
            ,'msg_checkspam' => $WP_msg['ProfileCheckSPAM']
            ,'msg_sigon' => $WP_msg['sigOn']
            ,'msg_dele' => $WP_msg['del']
            ,'msg_save' => $WP_msg['save']
            ,'msg_cancel' => $WP_msg['cancel']
            ,'msg_smtphost' => $WP_msg['optsmtphost']
            ,'msg_smtpport' => $WP_msg['optsmtpport']
            ,'msg_smtpuser' => $WP_msg['optsmtpuser']
            ,'msg_smtppass' => $WP_msg['optsmtppass']
            ,'copy_smtp' => $WP_msg['copy_smtp']
            ,'copy_pop3' => $WP_msg['copy_pop3']
            ,'msg_aliases' => $WP_msg['AliasesDefined']
            ,'msg_addalias' => $WP_msg['AddAlias']
            ,'e_enterprofname' => $WP_msg['enterProfname']
            ,'e_enterpopserver' => $WP_msg['enterPOPserver']
            ,'e_enterpopuser' => $WP_msg['enterPOPuser']
            ,'e_enteremail' => $WP_msg['SuDefineAEmail']
            ,'msg_reallydropalias' => $WP_msg['ReallyDropAlias']
            ,'msg_cachetype' => $WP_msg['IMAPFetchtype']
            ,'theme_path' => $_PM_['path']['theme']
            ,'passthrough_2' => give_passthrough(2)
            ,'passthrough' => give_passthrough(1)
            ,'msg_generic' => $WP_msg['General']
            ,'msg_various' => $WP_msg['Various']
            ,'msg_aliases' => $WP_msg['Aliases']
            ,'msg_onlysubscribed' => $WP_msg['ImapOnlySubscribed']
            ,'msg_showprefix' => $WP_msg['ImapOnlyWithPrefix']
            ,'about_uheaders' => $WP_msg['UHeadAbout']
            ,'msg_hkey' => $WP_msg['UHeadHKey']
            ,'msg_hval' => $WP_msg['UHeadHVal']
            ,'msg_uhead' => $WP_msg['UHeadReiter']
            ,'msg_adduhead' => $WP_msg['UHeadAdd']
            ,'e_enterhkey' => $WP_msg['UHeadEEnterKey']
            ,'msg_reallydropuhead' => $WP_msg['UHeadReallyDrop']
            ,'msg_nossl_pop3' => $WP_msg['ENoSSLAvailablePOP3']
            ,'msg_nossl_smtp' => $WP_msg['ENoSSLAvailableSMTP']
            ,'msg_inboxfolder' => $WP_msg['EmailInboxFolder']
            ,'msg_sentfolder' => $WP_msg['EmailSentObjectsFolder']
            ,'msg_draftsfolder' => $WP_msg['EmailDraftsFolder']
            ,'msg_templatesfolder' => $WP_msg['EmailTemplatesFolder']
            ,'msg_junkfolder' => $WP_msg['EmailJunkFolder']
            ,'msg_wastefolder' => $WP_msg['EmailWasteFolder']
            ,'msg_defaultfolder' => $WP_msg['EmailDefaultFolder']
            ,'msg_addsig' => $WP_msg['SignatureAdd']
            ,'msg_editsig' => $WP_msg['SignatureEdit']
            ,'msg_delesig' => $WP_msg['SignatureDele']
            ,'q_reallydelesig' => $WP_msg['QSignatureDele']
            ,'msg_sigtitle' => $WP_msg['BPlateName']
            ,'msg_folders' => $WP_msg['Folders']
            ,'msg_localkillserver' => $WP_msg['poplocalkillserver']
            ,'msg_sigval_txt' => $WP_msg['SigvalText']
            ,'msg_sigval_html' => $WP_msg['SigvalHTML']
            ,'msg_signature' => $WP_msg['sig']
            ,'msg_sendvcf' => $WP_msg['VCFsend']
            ,'msg_vcf_none' => $WP_msg['VCFsendNone']
            ,'msg_vcf_default' => $WP_msg['VCFsendDefault']
            ,'msg_vcf_priv' => $WP_msg['VCFsendPriv']
            ,'msg_vcf_busi' => $WP_msg['VCFsendBusi']
            ,'msg_vcf_all' => $WP_msg['VCFsendAll']
            ,'msg_sig_default' => $WP_msg['SigSendDefault']
            ,'msg_sig_none' => $WP_msg['SigSendNone']
            ));
}

if ($mode == 'loadprofile' && ($_SESSION['phM_privs']['all'] || $_SESSION['phM_privs']['email_edit_profile'])) {
    $acclist = $DB->get_accidx($_SESSION['phM_uid'], $_SESSION['phM_username']);
    $accdata = $DB->get_accdata($_SESSION['phM_uid'], $_SESSION['phM_username'], $_REQUEST['account']);
    $out = $pd = array();
    if (is_array($accdata)) {
        $pd = array_merge_recursive($accdata
                ,$DB->get_popconnect($_SESSION['phM_uid'], $_SESSION['phM_username'], $_REQUEST['account'])
                ,$DB->get_smtpconnect($_SESSION['phM_uid'], $_SESSION['phM_username'], $_REQUEST['account'])
                );
        $pd['profilename'] = $acclist[$_REQUEST['account']];
        unset($accdata);
    }
    $out = array();
    foreach (array('profilename' => 'profilename', 'acctype' => 'acctype', 'smtp_host' => 'smtpserver'
            ,'smtp_port' => 'smtpport', 'smtp_user' => 'smtpuser', 'smtp_pass' => 'smtppass'
            ,'smtpafterpop' => 'smtpafterpop', 'checkevery' => 'checkevery', 'be_checkevery' => 'be_checkevery'
            ,'leaveonserver' => 'leaveonserver', 'localkillserver' => 'localkillserver', 'inbox' => 'inbox'
            ,'sent_objects' => 'sent', 'junk' => 'junk', 'waste' => 'waste', 'drafts' => 'drafts'
            ,'templates' => 'templates', 'cachetype' => 'cachetype', 'popserver' => 'popserver'
            ,'popport' => 'popport', 'popuser' => 'popuser', 'poppass' => 'poppass', 'popapop' => 'popnoapop'
            ,'address' => 'address', 'real_name' => 'real_name', 'signature' => 'signature', 'sig_on' => 'sig_on'
            ,'checkspam' => 'checkspam', 'onlysubscribed' => 'onlysubscribed', 'imapprefix' => 'imapprefix'
            ,'popsec' => 'popsec', 'smtpsec' => 'smtpsec', 'sendvcf' => 'sendvcf') as $k => $v) {
        $out[$k] = isset($pd[$v]) ? (is_array($pd[$v]) ? $pd[$v][0] : $pd[$v]) : '';
    }
    sendJS(array('profile' => $out), 1, 1);
}
?>
Return current item: phlyMail Lite