<?php
/**
 * $Horde: imp/test.php,v 1.22 2003/06/17 22:48:05 ericr Exp $
 *
 * Copyright 2002-2003 Brent J. Nordquist <bjn@horde.org>
 * Copyright 1999-2003 Charles J. Hagenbuch <chuck@horde.org>
 * Copyright 1999-2003 Jon Parise <jon@horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */


/* Initialize the Horde_Test:: class. */
if (!(@is_readable('../lib/Test.php'))) {
    echo 'ERROR: You must install Horde before running this script.';
    exit;
}
require_once '../lib/Test.php';
$horde_test = &new Horde_Test;

/* IMP version. */
$module = 'IMP';
require_once './lib/version.php';
$module_version = IMP_VERSION;

require TEST_TEMPLATES . 'header.inc';
require TEST_TEMPLATES . 'version.inc';

/* Display versions of other Horde applications. */
$app_list = array(
    'ingo'  =>  array(
        'error' => 'Ingo provides basic mail filtering capabilities to IMP.',
        'version' => '2.0'
    ),
    'turba' => array(
        'error' => 'Turba provides addressbook/contacts capabilities to IMP.',
        'version' => '2.0'
    )
);
$app_output = $horde_test->requiredAppCheck($app_list);

?>
<h1>Other Horde Applications</h1>
<ul>
    <?php echo $app_output ?>
</ul>
<?php

/* Display PHP Version information. */
$php_info = $horde_test->getPhpVersionInformation();
require TEST_TEMPLATES . 'php_version.inc';

/* PHP modules. */
$module_list = array(
    'imap' => array(
        'descrip' => 'IMAP Support',
        'error' => 'IMP requires the imap module to interact with the mail server.  It is required even if you only use pop3 access.'
    )
);

/* PHP settings. */
$setting_list = array(
    'file_uploads'  =>  array(
        'setting' => true,
        'error' => 'file_uploads must be enabled to use various features of IMP. See the INSTALL file for more information.'
    )
);

/* IMP configuration files. */
$file_list = array(
    'config/conf.php' => 'The file <code>./config/conf.php</code> appears to be missing. You must generate this file as an administrator via Horde.  See horde/docs/INSTALL.',
    'config/html.php' => 'The file <code>./config/html.php</code> appears to be missing. You probably just forgot to copy <code>./config/html.php.dist</code> over.',
    'config/menu.php' => null,
    'config/mime_drivers.php' => null,
    'config/prefs.php' => null,
    'config/servers.php' => null
);

/* Get the status output now. */
$module_output = $horde_test->phpModuleCheck($module_list);
$setting_output = $horde_test->phpSettingCheck($setting_list);
$file_output = $horde_test->requiredFileCheck($file_list);

?>

<h1>PHP Module Capabilities</h1>
<ul>
    <?php echo $module_output ?>
</ul>

<h1>Miscellaneous PHP Settings</h1>
<ul>
    <?php echo $setting_output ?>
</ul>

<h1>Required IMP Configuration Files</h1>
<ul>
    <?php echo $file_output ?>
</ul>

<h1>PHP IMAP Support Test</h1>
<?php

$server = isset($_POST['server']) ? $_POST['server'] : ''; // 'server.example.com';
$protocol = isset($_POST['protocol']) ? $_POST['protocol'] : ''; // 'imap';
$port = isset($_POST['port']) ? $_POST['port'] : ''; // '143';
$user   = isset($_POST['user']) ? $_POST['user'] : '';     // 'user';
$passwd = isset($_POST['passwd']) ? $_POST['passwd'] : ''; // 'password';

if (!empty($server) && !empty($user) && !empty($passwd)) {
    if (empty($protocol)) {
        $protocol = 'imap';
    }
    if (empty($port)) {
        $port = '143';
    }
    $mbname = '{' . $server . ':' . $port . '/' . $protocol . '}INBOX';
    echo 'server="', $server, '" user="', $user, '" mailbox="', $mbname, '"<br />';
    $mbox = @imap_open($mbname, $user, $passwd);
    if ($mbox) {
        $minfo = @imap_mailboxmsginfo($mbox);
        if ($minfo) {
            echo 'INBOX has ', $minfo->Nmsgs, ' messages (' . $minfo->Unread, ' new ', $minfo->Recent, ' recent)';
        } else {
            echo '<pre>'; var_dump(imap_errors()); echo '</pre>';
        }
        @imap_close($mbox);
    } else {
        echo '<pre>'; var_dump(imap_errors()); echo '</pre>';
    }
} else {
    ?>
<form name="form1" method="post" action="test.php">
<table>
<tr><td align="right">Server</td><td><input type="text" name="server" /></td></tr>
<tr><td align="right">Protocol</td><td><input type="text" name="protocol" /></td><td>(e.g. "imap" or "imap/notls")</td></tr>
<tr><td align="right">Port</td><td><input type="text" name="port" /></td><td>(defaults to "143")</td></tr>
<tr><td align="right">User</td><td><input type="text" name="user" /></td></tr>
<tr><td align="right">Password</td><td><input type="password" name="passwd" /></td></tr>
<tr><td></td><td><input type="submit" name="f_submit" value="Submit" /><input type="reset" name="f_reset" value="Reset" /></td></tr>
</table>
</form>
<?php } ?>

</td></tr>
</table>

<?php
require TEST_TEMPLATES . 'footer.inc';
