<?php	// TWIG		Module Framework Processor ?>
<?php

 $version = "0.1.8";

 // Set up database fu
 $dbconfigfile="config/dbconfig.inc";
 if (is_readable($dbconfigfile)) {
  include($dbconfigfile);
  if (!$dbconfig["sqltype"]) { $dbconfig["sqltype"] = "mysql"; }
  include("features/" . $dbconfig["sqltype"] . ".db.inc");
 }

 include("features/common.inc");	// Common Functions
 include("config/config.inc");		// Global Configuration Variables

 // Tell browsers not to cache us.
 Header("Pragma: no-cache");
 Header("Expires: Tue Jan 26 09:38:24 EST 1999");

 $baseurl=$basedir . "/index.php3"; 

 // Very tacky argument parser
 // This was originally part of another program, and it somehow carried
 // over to here.  Please bear with it.
 $tacked = ereg_replace("^/","",$PATH_INFO);
 if (ereg("/",$tacked)) {
  list ($command, $mailbox, $path, $path2, $path3) = explode("/",$tacked);
  $mailbox = ereg_replace("!","/",$mailbox);
  if ($path2) { $path .= "/$path2"; }
  if ($path3) { $path .= "/$path3"; }
  $path = urldecode($path);
 }
 // If this is being called wrong, redirect to where we think it should go
 if (!$command) { $command = "default"; }
 if (!$mailbox) { $mailbox = "INBOX"; }
 if ($newmailbox) { $mailbox = $newmailbox; }

 // Set default IMAP parameters
 if (!$imap_server) { $imap_server = "localhost"; }
 if (!$imap_port) { $imap_port = "143"; } 

 // Authenticate the user and open their mailbox for reading
 $mbox=twig_auth("TWIG",$logout);
 // Massage the mailbox variable
 $mailbox=MailboxEncode($mailbox);

 $sorted[0]=1;

 // Set Preferences if necessary
 include("features/prefs.inc");
 if ($updated[prefs]) {
  PutPref("realname",$prefs["realname"]);
  PutPref("replyto",$prefs["replyto"]);
  PutPref("signature",$prefs["signature"]);
  PutPref("linewrap",$prefs["linewrap"]);
  PutPref("pagesize",$prefs["pagesize"]);
 }

 // allow for large attachment sending (only works if not in safe mode)
 if ($command == "compose") {
  @set_time_limit(3000); // they can upload for 5 hours
 }

 // Set group info
 include("features/groups.inc");

?>
<html>
<head><title><?php echo $pagetitle[$command]?></title></head>

<!-- TWIG <?php echo $version?>

<?php include("CREDITS")?>

-->

<?php
 include("config/header.inc");
 include("features/twig.header.inc");
 if (!$disabled[$command]) { include("features/$command.feature"); }
 include("features/twig.footer.inc");
 include("config/footer.inc");
?>
</html>
