diff -ruN ../aero_221/changes ./changes
--- ../aero_221/changes	2004-08-09 09:32:56.000000000 -0400
+++ ./changes	2004-09-09 20:15:37.000000000 -0400
@@ -114,3 +114,25 @@
 * Fixed some invalid HTML
 * Fixed sendmail options: a single dot on a line trucated qprint encoded
   messages
+
+Version 2.22lmb - Laird Bedore
+
+* Added support and configuration for SSL-encrypted IMAP servers
+* Fixed FORCE_FROM to work with qmail (added SERVER_SUFFIX explicit domain)
+* Fixed an infinite loop generated by some inline images
+* Fixed email links that contained a ">" at the end of them
+* Fixed some W3C-compatibility issues with font sizes
+* Fixed missing body style information (browser consistency improved)
+* Changed background color of table.main (the lines inbetween table cells)
+* Adjusted the layout to adjust to the size of the data first, then
+  adjust to the size of the screen afterwards
+* Tightened display padding in tables to fit better in small browser windows
+* Improved the bold-display of new messages
+* Shrunk date and size fields, forced them to display on a single line
+* Removed the display of the "To:" field in normal folders- it makes for
+  a real display nightmare when you receive mailing-list messages
+* Added option to force word-wrap when displaying plain text
+* Added option to display shorter email address field for addresses that
+  have the "personal name" defined
+* Added option to get rid of duplicate INBOX folder for some IMAP server
+  configurations
diff -ruN ../aero_221/config.inc ./config.inc
--- ../aero_221/config.inc	2003-11-12 05:16:32.000000000 -0500
+++ ./config.inc	2004-09-09 20:03:06.000000000 -0400
@@ -1,90 +1,110 @@
-<?php
-
-//    AeroMail - a web-based e-mail client written in PHP
-//    Copyright (C) 2000  Mark Cushman
-//
-//    This program is free software; you can redistribute it and/or modify
-//    it under the terms of the GNU General Public License as published by
-//    the Free Software Foundation; either version 2 of the License, or
-//    (at your option) any later version.
-//
-//    This program is distributed in the hope that it will be useful,
-//    but WITHOUT ANY WARRANTY; without even the implied warranty of
-//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//    GNU General Public License for more details.
-//
-//    You should have received a copy of the GNU General Public License
-//    along with this program; if not, write to the Free Software
-//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-//-----------------------
-// server config section
-//-----------------------
-
-// controls the name at the top of the window
-define('PROG_NAME', "Aeromail");
-
-// directory for folders to be stored - applies to UWash servers only
-// if server type is Cyrus, this var is not used
-define('PROG_DIR', "~/");
-
-// this is the server name or ip address of the IMAP server
-define('IMAP_SERVER', "localhost");
-
-// server type should either be "Cyrus" or "UWash"
-define('IMAP_SERVER_TYPE', "UWash");
-
-// tcp port where the IMAP server is running - default is 143
-define('IMAP_PORT', "143");
-
-// url to redirect to when a user clicks on cancel when loggin in
-define('SERVER_REDIR', "http://aeromail.nicolaas.net/");
-
-// default number of messages to display per screen
-define('MSG_COUNT', 25);
-
-// should AeroMail decide what the user's e-mail address is, or should
-// AeroMail let sendmail and genericstable figure it out (0=no 1=yes)
-define('FORCE_FROM', 1);
-
-//-----------------------
-// extra features
-//-----------------------
-
-// include possibility to make, delete and use folders.
-// set to 0 if you simply want to read and answer mail, e.g. when you
-// use POP at home and this when on the move.
-define('USE_FOLDERS', 1);
-
-// default folder to store sent messages in
-// set to 0 to disable sent mail storage
-define('SENT_MAIL', "Sent mail");
-
-// default folder to store deleted messages in
-// set to 0 to disable deleted mail storage
-define('TRASH', "Trash");
-
-// spam blacklists
-// colon-separated list of spam blacklisters or open relay blacklisters.
-// Keep the list short, and put the fast ones first.
-// set to 0 if you don't want probable spam marked
-//define('SPAM_BLACKLISTS', "bl.spamcop.net:list.dsbl.org:dnsbl.njabl.org:blackholes.five-ten-sg.com:dialups.visi.com:relays.ordb.org:blackholes.mail-abuse.org:dialups.mail-abuse.org:relays.mail-abuse.org");
-define('SPAM_BLACKLISTS', "bl.spamcop.net:list.dsbl.org:dnsbl.njabl.org");
-
-//------------------------
-// user interface section
-//------------------------
-
-// change the path to this file to the desired theme file
-include("themes/default.theme.inc");
-// Set this to your template file
-define('HTML_TEMPLATE', "themes/default.template.inc");
-
-//------------------
-// language section
-//------------------
-
-// change the path to this file to the desired language file
-include("lang/en.lang.inc");
-
-?>
+<?php
+
+//    AeroMail - a web-based e-mail client written in PHP
+//    Copyright (C) 2000  Mark Cushman
+//
+//    This program is free software; you can redistribute it and/or modify
+//    it under the terms of the GNU General Public License as published by
+//    the Free Software Foundation; either version 2 of the License, or
+//    (at your option) any later version.
+//
+//    This program is distributed in the hope that it will be useful,
+//    but WITHOUT ANY WARRANTY; without even the implied warranty of
+//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//    GNU General Public License for more details.
+//
+//    You should have received a copy of the GNU General Public License
+//    along with this program; if not, write to the Free Software
+//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+//-----------------------
+// server config section
+//-----------------------
+
+// controls the name at the top of the window
+define('PROG_NAME', "Aeromail");
+
+// directory for folders to be stored - applies to UWash servers only
+// if server type is Cyrus, this var is not used
+define('PROG_DIR', "~/");
+
+// this is the server name or ip address of the IMAP server
+define('IMAP_SERVER', "localhost");
+
+// server type should either be "Cyrus" or "UWash"
+define('IMAP_SERVER_TYPE', "UWash");
+
+// tcp port where the IMAP server is running - default is 143, SSL is 993
+define('IMAP_PORT', "143");
+
+// IMAP options may be necessary when connecting to an SSL-enabled server
+define('IMAP_OPTS', "");
+//define('IMAP_OPTS', "/imap");
+//define('IMAP_OPTS', "/imap/ssl");
+//define('IMAP_OPTS', "/imap/ssl/novalidate-cert");
+
+// url to redirect to when a user clicks on cancel when loggin in
+define('SERVER_REDIR', "http://aeromail.nicolaas.net/");
+
+// default number of messages to display per screen
+define('MSG_COUNT', 25);
+
+// should AeroMail decide what the user's e-mail address is, or should
+// AeroMail let sendmail and genericstable figure it out (0=no 1=yes)
+define('FORCE_FROM', 1);
+
+// If you are using the force_from, define a server suffix.
+define('SERVER_SUFFIX',"mydomain.com");
+
+// should AeroMail force word-wrap when displaying plaintext messages?
+// 0 to disable. Default is 81 characters.
+define('WRAP_AT_COLUMN',81);
+
+// When displaying a folder list, should we display both the "personal"
+// name and the email address when available, or just the personal name?
+define('DISPLAY_FULL_ADDR',0);
+
+// If you see two INBOX's in your folder list, change the line below to 1.
+define('NO_INBOX_EXPLICIT',0);
+
+//-----------------------
+// extra features
+//-----------------------
+
+// include possibility to make, delete and use folders.
+// set to 0 if you simply want to read and answer mail, e.g. when you
+// use POP at home and this when on the move.
+define('USE_FOLDERS', 1);
+
+// default folder to store sent messages in
+// set to 0 to disable sent mail storage
+define('SENT_MAIL', "Sent mail");
+
+// default folder to store deleted messages in
+// set to 0 to disable deleted mail storage
+define('TRASH', "Trash");
+
+// spam blacklists
+// colon-separated list of spam blacklisters or open relay blacklisters.
+// Keep the list short, and put the fast ones first.
+// set to 0 if you don't want probable spam marked
+//define('SPAM_BLACKLISTS', "bl.spamcop.net:list.dsbl.org:dnsbl.njabl.org:blackholes.five-ten-sg.com:dialups.visi.com:relays.ordb.org:blackholes.mail-abuse.org:dialups.mail-abuse.org:relays.mail-abuse.org");
+define('SPAM_BLACKLISTS', "bl.spamcop.net:list.dsbl.org:dnsbl.njabl.org");
+
+//------------------------
+// user interface section
+//------------------------
+
+// change the path to this file to the desired theme file
+include("themes/default.theme.inc");
+// Set this to your template file
+define('HTML_TEMPLATE', "themes/default.template.inc");
+
+//------------------
+// language section
+//------------------
+
+// change the path to this file to the desired language file
+include("lang/en.lang.inc");
+
+?>
diff -ruN ../aero_221/folder.php ./folder.php
--- ../aero_221/folder.php	2004-05-21 12:01:49.000000000 -0400
+++ ./folder.php	2004-09-09 20:04:11.000000000 -0400
@@ -1,131 +1,131 @@
-<?php   
-    Header("Cache-Control: no-cache");
-    Header("Pragma: no-cache");
-    Header("Expires: Sat, Jan 01 2000 01:01:01 GMT");
-
-    include("global.inc");
-
-function content()
-{    
-
-    content_start();
-    header_start();
-    header_left();
-    global $user;
-    echo L_FOLDERS . " - $user - " . PROG_NAME;
-      
-    header_left_right_end();
-    header_right();
-
-    global $folder;
-?>
-    <form action="index.php" method="get">
-    <input type="hidden" name="folder" value="<?php echo $folder ?>">
-    <input type="submit" value="<?php echo L_GO_BACK_BTN ?>">
-    </form>
-<?php
-    header_left_right_end();
-    header_end();
-    body_start();
-    title_start();
-    title_left();    
-    echo L_FOLDER_NAME;
-    title_left_end();
-    title_left('width="20%"');
-    echo L_NUM_MESSAGES;
-    title_left_end();
-    title_end();
-
-    global $mailbox;
-    global $name, $action;
-
-    $folder_str = construct_folder_str($name);
-    if($action == "create")
-    {
-        imap_createmailbox($mailbox, IMAP_STR . "$folder_str");
-    }
-    if($action == "delete")
-    {
-        imap_deletemailbox($mailbox, IMAP_STR . "$folder_str");
-    }
-    $mailboxes = imap_listmailbox($mailbox, IMAP_STR, FILTER. "*");
-    if($mailboxes)
-    {
-        sort($mailboxes);
-        $first = "rowoff";
-        $second = "rowon";
-        if (FILTER != "INBOX")
-        {
-            body_row('class="rowon"');
-            body_left();
-            echo "<a href=\"index.php?folder=INBOX\">INBOX</a>";
-            body_left_end();
-            body_left();
-            echo imap_num_msg($mailbox);
-            body_left_end();
-            body_row_end();
-            $first = "rowon";
-            $second = "rowoff";
-        }
-        for ($i = 0; $i < count($mailboxes); $i++)
-        {
-            $bg = (($i + 1)/2 == floor(($i + 1)/2)) ? $first : $second;
-            imap_reopen($mailbox, $mailboxes[$i]);
-            $nm = substr($mailboxes[$i], strrpos($mailboxes[$i], "}") + 1, strlen($mailboxes[$i]));
-            body_row('class="' . $bg . '"');
-            body_left();
-            if ($nm != "INBOX")
-            {
-                $nm = deconstruct_folder_str($nm);
-            }
-
-            $url_nm = urlencode($nm);
-
-            echo "<a href=\"index.php?folder=$url_nm\">$nm</a>";
-            body_left_end();
-            body_left();
-            echo imap_num_msg($mailbox);
-            body_left_end();
-            body_row_end();
-        }
-    }
-    else
-    {
-        body_row('class="rowon"');
-        body_left();
-        echo "<a href=\"index.php?folder=INBOX\">INBOX</a>";
-        body_left_end();
-        body_left();
-        echo imap_num_msg($mailbox);
-        body_left_end();
-        body_row_end();
-    }
-    imap_close($mailbox);
-    body_end();
-
-    header_start();
-    header_left('colspan="2"');
-    ?>
-
-<form action="folder.php" method="get">
-<select name="action">
-<option value="create"><?php echo L_FOLDER_CREATE ?>
-<option value="delete"><?php echo L_FOLDER_DELETE ?>
-</select> <label for="name"><?php echo L_NAMED ?></label>
-<input type="text" name="name" id="name"><input type="hidden" name="folder" value="<?php echo $folder ?>">
-<input type="submit" value="<?php echo L_SUBMIT_BTN ?>">
-</form>
-
-
-<?php
-    header_left_right_end();
-    header_end();
-    content_end();
-}
-
-
-
-/* MAIN */
-include(HTML_TEMPLATE);
- 
-?>
+<?php   
+    Header("Cache-Control: no-cache");
+    Header("Pragma: no-cache");
+    Header("Expires: Sat, Jan 01 2000 01:01:01 GMT");
+
+    include("global.inc");
+
+function content()
+{    
+
+    content_start();
+    header_start();
+    header_left();
+    global $user;
+    echo L_FOLDERS . " - $user - " . PROG_NAME;
+      
+    header_left_right_end();
+    header_right();
+
+    global $folder;
+?>
+    <form action="index.php" method="get">
+    <input type="hidden" name="folder" value="<?php echo $folder ?>">
+    <input type="submit" value="<?php echo L_GO_BACK_BTN ?>">
+    </form>
+<?php
+    header_left_right_end();
+    header_end();
+    body_start();
+    title_start();
+    title_left();    
+    echo L_FOLDER_NAME;
+    title_left_end();
+    title_left('width="20%"');
+    echo L_NUM_MESSAGES;
+    title_left_end();
+    title_end();
+
+    global $mailbox;
+    global $name, $action;
+
+    $folder_str = construct_folder_str($name);
+    if($action == "create")
+    {
+        imap_createmailbox($mailbox, IMAP_STR . "$folder_str");
+    }
+    if($action == "delete")
+    {
+        imap_deletemailbox($mailbox, IMAP_STR . "$folder_str");
+    }
+    $mailboxes = imap_listmailbox($mailbox, IMAP_STR, FILTER. "*");
+    if($mailboxes)
+    {
+        sort($mailboxes);
+        $first = "rowoff";
+        $second = "rowon";
+        if (FILTER != "INBOX" && NO_INBOX_EXPLICIT != 1)
+        {
+            body_row('class="rowon"');
+            body_left();
+            echo "<a href=\"index.php?folder=INBOX\">INBOX</a>";
+            body_left_end();
+            body_left();
+            echo imap_num_msg($mailbox);
+            body_left_end();
+            body_row_end();
+            $first = "rowon";
+            $second = "rowoff";
+        }
+        for ($i = 0; $i < count($mailboxes); $i++)
+        {
+            $bg = (($i + 1)/2 == floor(($i + 1)/2)) ? $first : $second;
+            imap_reopen($mailbox, $mailboxes[$i]);
+            $nm = substr($mailboxes[$i], strrpos($mailboxes[$i], "}") + 1, strlen($mailboxes[$i]));
+            body_row('class="' . $bg . '"');
+            body_left();
+            if ($nm != "INBOX")
+            {
+                $nm = deconstruct_folder_str($nm);
+            }
+
+            $url_nm = urlencode($nm);
+
+            echo "<a href=\"index.php?folder=$url_nm\">$nm</a>";
+            body_left_end();
+            body_left();
+            echo imap_num_msg($mailbox);
+            body_left_end();
+            body_row_end();
+        }
+    }
+    else
+    {
+        body_row('class="rowon"');
+        body_left();
+        echo "<a href=\"index.php?folder=INBOX\">INBOX</a>";
+        body_left_end();
+        body_left();
+        echo imap_num_msg($mailbox);
+        body_left_end();
+        body_row_end();
+    }
+    imap_close($mailbox);
+    body_end();
+
+    header_start();
+    header_left('colspan="2"');
+    ?>
+
+<form action="folder.php" method="get">
+<select name="action">
+<option value="create"><?php echo L_FOLDER_CREATE ?>
+<option value="delete"><?php echo L_FOLDER_DELETE ?>
+</select> <label for="name"><?php echo L_NAMED ?></label>
+<input type="text" name="name" id="name"><input type="hidden" name="folder" value="<?php echo $folder ?>">
+<input type="submit" value="<?php echo L_SUBMIT_BTN ?>">
+</form>
+
+
+<?php
+    header_left_right_end();
+    header_end();
+    content_end();
+}
+
+
+
+/* MAIN */
+include(HTML_TEMPLATE);
+ 
+?>
diff -ruN ../aero_221/global.inc ./global.inc
--- ../aero_221/global.inc	2004-08-09 09:33:10.000000000 -0400
+++ ./global.inc	2004-09-09 20:06:54.000000000 -0400
@@ -1,624 +1,674 @@
-<?php
-
-// shouldn't have to modify anything in this file...
-define('VERSION', "AeroMail 2.21");
-
-include("config.inc");
-
-define('FILTER', IMAP_SERVER_TYPE == "Cyrus" ? "INBOX" : PROG_DIR);
-define('IMAP_STR', "{".IMAP_SERVER.":".IMAP_PORT."}");
-
-function mailbox_log_in( $folder )
-{
-    global $user, $pass;
-    error_reporting(error_reporting() - 2);
-
-    $folder = $folder == "INBOX" ? "INBOX" : construct_folder_str($folder);
-    $mbox = imap_open(IMAP_STR . "$folder", $user , $pass);
-
-    error_reporting(error_reporting() + 2);
-    return $mbox;
-}
-
-function construct_folder_str( $folder )
-{
-    // Cyrus style: INBOX.Junque
-    // UWash style: ./aeromail/Junque
-
-    $folder_str = IMAP_SERVER_TYPE == "Cyrus" ? "INBOX." . $folder : PROG_DIR . $folder;
-    return $folder_str;
-}
-
-function deconstruct_folder_str( $folder )
-{
-    // Cyrus style: INBOX.Junque
-    // UWash style: ./aeromail/Junque
-
-    $srch_str = IMAP_SERVER_TYPE == "Cyrus" ? "INBOX." : PROG_DIR;
-
-    $folder_str = substr($folder, strlen($srch_str), strlen($folder));
-
-    return $folder_str;
-}
-
-function removecrlf($string)
-{
-    return strtr($string, "\015\012", "  ");
-}
-
-function decode_header_string($hed_str)
-{
-    $output = "";
-              
-    if($hed_str)
-    {
-        $element=imap_mime_header_decode($hed_str);
-        for($i=0; $i < count($element); $i++) {
-            if ($element[$i]->charset == "default")
-                $output .= $element[$i]->text;
-            else
-            {
-                $output .= make_utf8($element[$i]->text, $element[$i]->charset);
-            }
-        }
-    }
-    return $output;
-}
-
-function make_address_list($header_arr)
-{
-    $out = array();
-    if (is_array($header_arr) && count($header_arr)) 
-    {
-        foreach ($header_arr as $adr)
-        {
-            $out[] = imap_rfc822_write_address($adr->mailbox, $adr->host, $adr->personal);
-        }
-    }
-    return $out;
-}
-
-function make_formaddress_list($header_arr)
-{
-    $list = make_address_list($header_arr);
-    $l = array();
-    foreach ($list as $adr)
-    {
-        $l[] = htmlentities(decode_header_string($adr));
-    }
-    return implode(", ", $l);
-}
-
-
-function make_clickable_list($header_arr, $folder)
-{    
-    $list = make_address_list($header_arr);
-    $l = array();
-    foreach ($list as $adr)
-    {
-        $l[] = "<a href=\"compose.php?folder="
-            . urlencode($folder) 
-            . "&amp;to=" . urlencode($adr) . "\">"
-            .  htmlspecialchars(decode_header_string($adr))
-            . "</a>";
-    }
-    return implode(", ", $l);
-}
-
-function list_folders( $mailbox )
-{
-    $mailboxes = imap_listmailbox($mailbox, IMAP_STR, FILTER . "*");
-    if($mailboxes)
-    {
-        sort($mailboxes);
-        $num_boxes = count($mailboxes);
-        if (FILTER != "INBOX") { echo "<option>INBOX"; }
-        for ($index = 0; $index < $num_boxes; $index++)
-        {
-            $nm = substr($mailboxes[$index], strrpos($mailboxes[$index], "}") + 1, strlen($mailboxes[$index]));
-            echo "<option>";
-            if ($nm != "INBOX")
-            {
-                echo deconstruct_folder_str($nm);
-            }
-            else
-            {
-                echo "INBOX";
-            }
-            echo "\n";
-        }
-    }
-    else
-    {
-        echo "<option>INBOX";
-    }
-}
-
-function get_mime_type($de_part)
-{
-    switch ($de_part->type)
-    {
-        case TYPETEXT:      $mime_type = "text"; break;
-        case TYPEMULTIPART: $mime_type = "multipart"; break;
-        case TYPEMESSAGE:   $mime_type = "message"; break;
-        case TYPEAPPLICATION:   $mime_type = "application"; break;
-        case TYPEAUDIO:     $mime_type = "audio"; break;
-        case TYPEIMAGE:     $mime_type = "image"; break;
-        case TYPEVIDEO:     $mime_type = "video"; break;
-        case TYPEMODEL:     $mime_type = "model"; break;
-        default:        $mime_type = "unknown";
-    }
-    return $mime_type;
-}
-
-function get_mime_encoding($de_part)
-{
-    switch ($de_part->encoding)
-    {
-        case ENCBASE64:         $mime_encoding = "base64"; break;
-        case ENCQUOTEDPRINTABLE:    $mime_encoding = "qprint"; break;
-        case ENCOTHER:          $mime_encoding = "other"; break;
-        default:            $mime_encoding = "other";
-    }
-    return $mime_encoding;
-}
-
-function get_charset($de_part)
-{
-    $charset = "US-ASCII";
-    for ($i = 0; $i < count($de_part->parameters); $i++)
-    {
-        $param = $de_part->parameters[$i];
-        if ($param->attribute == "CHARSET")
-        {
-            $charset = $param->value;
-        }
-    }
-    return $charset;
-}
-
-
-function make_utf8($str, $charset)
-{
-    /* Try, but at least return something! */
-    if (function_exists('iconv')) 
-    {
-        if (!$charset)
-            $charset="US-ASCII";
-        $charset = strtoupper($charset);
-        /* Do some processing to catch sloppy charsets */
-        $charset = ereg_replace("^WINDOWS-", "CP", $charset);
-        /* Found in the wild: "CHINESEBIG5" */
-        $charset = ereg_replace("^CHINESE", "", $charset);
-        $out = iconv($charset, "UTF-8", $str);
-        if ($out)
-            return $out;
-    }
-    return $str;
-}
-
-
-function get_att_name($de_part)
-{
-    $att_name = 0;
-    $att_filename = "Unknown";
-    for ($i = 0; $i < count($de_part->parameters); $i++)
-    {
-        $param = $de_part->parameters[$i];
-        if ($param->attribute == "NAME")
-        {
-            $att_name = $param->value;
-        }
-    }
-    for ($i = 0; $i < count($de_part->dparameters); $i++)
-    {
-        $param = $de_part->dparameters[$i];
-        if ($param->attribute == "FILENAME")
-        {
-            $att_filename = $param->value;
-        }
-    }
-    if ($att_name)
-        return $att_name;
-    else
-        return $att_filename;
-}
-
-function attach_display($de_part, $part_no)
-{
-    global $mailbox, $folder, $msgnum;
-    $mime_type = get_mime_type($de_part);
-    $mime_encoding = get_mime_encoding($de_part);
-
-    $att_name = get_att_name($de_part);
-    $url_att_name = urlencode($att_name);
-
-    $jnk = "<a href=\"get_attach.php?folder=$folder&amp;msgnum=$msgnum&amp;part_no=$part_no";
-    $jnk .= "&amp;type=$mime_type&amp;subtype=$de_part->subtype&amp;name=$url_att_name&amp;encoding=$mime_encoding";
-    $jnk .= "\">$att_name</a>";
-    return $jnk;
-}
-
-/* imap_qprint doesn't handle soft returns correctly */
-function my_imap_qprint($dsp)
-{
-    $dsp = str_replace("=\r\n", "", $dsp);
-    $dsp = imap_qprint($dsp);
-    return $dsp;
-}
-
-function enriched_to_html($dsp)
-{
-    // Convert to HMTL
-    /* Double << is <. Using &lt; makes sure it is no longer taken
-       as a command start, as & will become $amp; Later we replace 
-       &amp;lt; with &lt; */ 
-    $dsp = str_replace("<<", "&lt;", $dsp);
-    $dsp = htmlspecialchars($dsp);
-    // Simple ones
-    $dsp = eregi_replace("&lt;bold&gt;", "<b>", $dsp);
-    $dsp = eregi_replace("&lt;/bold&gt;", "</b>", $dsp);
-    $dsp = eregi_replace("&lt;italic&gt;", "<i>", $dsp);
-    $dsp = eregi_replace("&lt;/italic&gt;", "</i>", $dsp);
-    $dsp = eregi_replace("&lt;underline&gt;", "<u>", $dsp);
-    $dsp = eregi_replace("&lt;/underline&gt;", "</u>", $dsp);
-    $dsp = eregi_replace("&lt;fixed&gt;", "<tt>", $dsp);
-    $dsp = eregi_replace("&lt;/fixed&gt;", "</tt>", $dsp);
-    $dsp = eregi_replace("&lt;smaller&gt;", "<small>", $dsp);
-    $dsp = eregi_replace("&lt;/smaller&gt;", "</small>", $dsp);
-    $dsp = eregi_replace("&lt;bigger&gt;", "<big>", $dsp);
-    $dsp = eregi_replace("&lt;/bigger&gt;", "</big>", $dsp);
-    $dsp = eregi_replace("&lt;center&gt;", "<div align=\"center\">", $dsp);
-    $dsp = eregi_replace("&lt;/center&gt;", "</div>", $dsp);
-    $dsp = eregi_replace("&lt;flushleft&gt;", "<div align=\"left\">", $dsp);
-    $dsp = eregi_replace("&lt;/flushleft&gt;", "</div>", $dsp);
-    $dsp = eregi_replace("&lt;flushright&gt;", "<div align=\"right\">", $dsp);
-    $dsp = eregi_replace("&lt;/flushright&gt;", "</div>", $dsp);
-    $dsp = eregi_replace("&lt;flushboth&gt;", "<div align=\"justify\">", $dsp);
-    $dsp = eregi_replace("&lt;/flushboth&gt;", "</div>", $dsp);
-    /* nofill -> pre. TODO: Within this block, no newline replacing 
-       should be done. */
-    $dsp = eregi_replace("&lt;nofill&gt;", "<pre>", $dsp);
-    $dsp = eregi_replace("&lt;/nofill&gt;", "</pre>", $dsp);
-    /* Paraindent -> blockquote
-       Not entriely correct: there is a param telling what kind
-       of indenting to do, which we don't support.
-       Another thing: My params cannot contain an & char, which
-       might be a problem.
-     */
-    $dsp = eregi_replace("&lt;paraindent&gt;&lt;param&gt;[^&]*&lt;/param&gt;", "<blockquote>", $dsp);
-    $dsp = eregi_replace("&lt;/paraindent&gt;", "</blockquote>", $dsp);
-    /* Excerpt can optionally have a param telling where excerpt 
-       comes from. */
-    $dsp = eregi_replace("&lt;excerpt&gt;&lt;param&gt;([^&]*)&lt;/param&gt;", "<hr><br>\\\\1<blockquote>", $dsp);
-    $dsp = eregi_replace("&lt;excerpt&gt;", "<hr><blockquote>", $dsp);
-    $dsp = eregi_replace("&lt;/excerpt&gt;", "</blockquote>", $dsp);
-    /* Lang: Language is ignored */
-    $dsp = eregi_replace("&lt;lang&gt;&lt;param&gt;[^&]*&lt;/param&gt;", "", $dsp);
-    $dsp = eregi_replace("&lt;/lang&gt;", "", $dsp);
-    /* FontFamily */
-    $dsp = eregi_replace("&lt;fontfamily&gt;&lt;param&gt;([^&]*)&lt;/param&gt;", "<font face=\"\\\\1\">", $dsp);
-    $dsp = eregi_replace("&lt;/fontfamily&gt;", "</font>", $dsp);
-    /* color */
-    while (eregi("&lt;color&gt;&lt;param&gt;([^&]*)&lt;/param&gt;", $dsp, $regs))
-    {
-        // regs[1] = xxxx,yyyy,zzzz or colorname
-        $c = explode(",", $regs[1]);
-        if (count($c) == 1)
-            $color = $c[0];
-        else
-        {
-            // First 2 chars of 4char hex string is string /256
-            $color = "#" . 
-                substr($c[0], 0, 2) . 
-                substr($c[1], 0, 2) . 
-                substr($c[2], 0, 2);
-        }
-        $dsp = eregi_replace("&lt;color&gt;&lt;param&gt;[^&]*&lt;/param&gt;", "<font color=\"$color\">", $dsp);
-    }
-    $dsp = eregi_replace("&lt;/color&gt;", "</font>", $dsp);
-    /* Now remove any unrecognised <param>s */
-    $dsp = eregi_replace("&lt;param&gt;[^&]*&lt;/param&gt;", "", $dsp);
-    /* And last, remove any unknown tags */
-    $dsp = eregi_replace("&lt;[^&]*&gt;", "", $dsp);
-    /* Now finish the work on << */
-    $dsp = eregi_replace("&amp;lt;", "&lt;", $dsp);
-    /* Do the newlines */
-    while (ereg("\n\n", $dsp))
-        $dsp = ereg_replace("\n\n", "<br>\n", $dsp);
-    while (ereg("\r\n\r\n", $dsp))
-        $dsp = ereg_replace("\r\n\r\n", "<br>\r\n", $dsp);
-    /* text/enriched must start with filled text according to RFC */
-    $dsp = "<div align=\"justify\">$dsp</div>";
-    return $dsp;
-}
-
-function make_safe_html($dsp)
-{
-    $hidetag = array (
-        '!doctype',
-        'html',
-        'head',
-        'meta',
-        'body'
-    );
-    foreach ($hidetag as $tag)
-    {
-        $dsp = eregi_replace("<\\s*(/?)\\s*$tag([^>]*)>",
-                             "<!-- \\1$tag\\2 -->", $dsp);
-    }
-    $hideelt = array (
-        'title',
-        'style'
-    );
-    foreach ($hideelt as $tag)
-    {
-        $dsp = eregi_replace("<\\s*$tag([^>]*)>",
-                             "<!-- $tag\\1>", $dsp);
-        $dsp = eregi_replace("<\\s*/\\s*$tag([^>]*)>",
-                             "</$tag\\1 -->", $dsp);
-    }
-    return $dsp;
-}
-
-function do_inline_display($msgnum, $part_no, $encoding, $charset, $type, $safe = 0)
-{
-    global $mailbox, $msgnum;
-    global $folder;
-
-    /* $safe means: Safe to display in an HTML form. 
-       not safe is largely unchanged. */
-
-    $dsp = imap_fetchbody($mailbox, $msgnum, $part_no);
-    if ($encoding == "base64") {
-        $dsp = imap_base64($dsp);
-    }
-    if ($encoding == "qprint") {
-        $dsp = my_imap_qprint($dsp);
-    }
-    if (!$safe)
-    {
-        /* Done, no further processing. */
-        echo $dsp;
-    }
-    else
-    {
-        $dsp = make_utf8($dsp, $charset);
-        if (strtolower($type) == "text/plain")
-        {
-            /* For text/plain we assume the user took care of line breaks;
-             */
-            $dsp = htmlspecialchars($dsp);
-            $dsp = make_clickable($dsp);
-            echo "<pre>$dsp</pre>";
-        }
-        else if (strtolower($type) == "text/enriched")
-        {
-            $dsp = enriched_to_html($dsp);
-            echo $dsp;
-        }
-        else if (strtolower($type) == "text/html")
-        {
-            $struct = imap_fetchstructure($mailbox, $msgnum);
-            while (ereg("cid:([^\"]*)", $dsp, $regs))
-            {
-                $dsp = ereg_replace("cid:" . $regs[1], cid_name($struct, $regs[1]), $dsp);
-            }
-            $dsp = make_safe_html($dsp);
-            echo $dsp;
-        }
-        else
-        {
-            /* For unknown types, we just display exactly as sent, so here
-               we do use <pre>. */
-            $dsp = htmlspecialchars($dsp);
-            echo "<pre>\n$dsp</pre>\n";
-        }
-    }
-}
-
-function inline_display($de_part, $part_no)
-{
-    global $mailbox, $msgnum, $folder;
-    
-    
-    $mime_type = get_mime_type($de_part);
-    $type = $mime_type . "/" . $de_part->subtype;
-    $mime_encoding = get_mime_encoding($de_part);
-    $charset = get_charset($de_part);
-
-    /* Default, simple mail */
-    if (strtolower($type) == "text/plain")
-    {
-        $ret = 1;
-    }
-    /* Smart types we know of */
-    elseif ((strtolower($type) == "text/enriched") or
-            (strtolower($type) == "text/html"))
-    {
-        output_bound(L_MIME_SECTION . ":" , "$mime_type/$de_part->subtype");
-        $ret = 1;
-    }
-    /* All other types: return 0 as we don't know whether we displayed 
-       anything useful for the user. */
-    else
-    {
-        output_bound(L_MIME_SECTION .  ":" , "$mime_type/$de_part->subtype");
-        $ret = 0;
-    }
-    /* This is not really useful
-    print "<p><a href=\"view_inline.php?folder=" . urlencode($folder) 
-                . "&amp;msgnum=$msgnum"
-                . "&amp;part_no=$part_no"
-                . "&amp;encoding=" . urlencode($mime_encoding)
-                . "&amp;charset=" . urlencode($charset)
-                . "&amp;type=" . urlencode($type)
-                . "\">" . L_MESSAGE . "</a></p>\n";
-    */                
-    
-    /* Embedded objects have a fixed height, which means embedded scrolbars.
-       That's not worth it.
-    print "<object "
-                . "data=\"view_inline.php?folder=" . urlencode($folder) 
-                . "&amp;msgnum=$msgnum"
-                . "&amp;part_no=$part_no"
-                . "&amp;encoding=" . urlencode($mime_encoding)
-                . "&amp;charset=" . urlencode($charset)
-                . "&amp;type=" . urlencode($type)
-                . "\" width=\"100%\">\n";
-    */                
-
-    do_inline_display($msgnum, $part_no, $mime_encoding,
-                      $charset, $type, 1);
-    /*
-    echo "</object>\n";
-    */
-    return $ret;
-}
-
-function output_bound($title, $str)
-{
-    body_left_end();
-    body_row_end();
-
-    title_start();
-    title_left();
-    echo $title;
-    title_left_end();
-    title_data();
-    echo $str;
-    title_data_end();
-    body_row('class="rowon"');
-    body_left('colspan="2"');
-}
-
-
-function cid_name($struct, $cid_to_find, $numprefix="")
-{
-    global $folder, $msgnum;
-    global $cidsdone;
-    $name = "";
-    $numparts = !$struct->parts ? "1" : count($struct->parts);
-    for($i = 0; $i < $numparts; $i++)
-    {
-        $part = !$struct->parts[$i] ? $part = $struct : $part = $struct->parts[$i];
-
-        if ($part->parts)
-        {
-            $subpartnum = $i + 1;
-            $name .= cid_name($part, $cid_to_find, $numprefix . $subpartnum . ".");
-            if ($name)
-            {
-                return $name;
-            }
-        }
-        else
-        {
-            $cid = $part->ifid ? $part->id : "";
-            if ($cid == $cid_to_find || $cid == "<$cid_to_find>")
-            {
-                $subpartnum = $i + 1;
-                $att_name = get_att_name($part);
-                $name .= "view_image.php?folder=" . $folder 
-                    . "&amp;msgnum=$msgnum&amp;part_no=" . $numprefix
-                    . $subpartnum
-                    . "&amp;type=$part->subtype&amp;name=$att_name";
-                $cidsdone[$cid] = 1;
-                return $name;
-            }
-        }
-    }
-    // Not found, leave it as it is
-    return $cid_to_find;
-}
-
-/* ciddone is set for an inline image that is processed. If the image data 
-   appears later in the message, it doesn't have to be displayed again.
-   This is not entirely correct, because when the image data appears first, 
-   it is displayed, and again later as inline.
-*/
-function ciddone($part)
-{
-    global $cidsdone;
-    $cid = $part->ifid ? $part->id : "";
-    if ($cid == "")
-        return 0;
-    return $cidsdone[$cid];
-}
-
-function image_display($folder, $msgnum, $de_part, $part_no, $att_name)
-{
-    output_bound(L_IMAGE . ":" , $att_name);
-    echo "\n<img src=\""; 
-    echo "view_image.php?folder=" . urlencode($folder) . "&amp;msgnum=$msgnum&amp;part_no=$part_no";
-    echo "&amp;type=$de_part->subtype&amp;name=$att_name\">\n<br>\n";
-}
-
-// function make_clickable ripped off from PHPWizard.net
-// http://www.phpwizard.net/phpMisc/
-// modified to make mailto: addresses compose in AeroMail
-
-function make_clickable($text)
-{
-    global $folder;
-    $ret = eregi_replace( "([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
-        "<a href=\"\\1://\\2\\3\" target=\"_new\">\\1://\\2\\3</a>", $text);
-    $ret = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))",
-        "<a href=\"compose.php?folder=" . urlencode($folder) . "&amp;to=\\1\">\\1</a>", $ret);
-    return($ret);
-}
-
-
-function self_with_param($paramname, $value)
-{
-    global $HTTP_SERVER_VARS;
-    $url = $HTTP_SERVER_VARS["REQUEST_URI"];
-    /* first strip out the old value of $paramname */
-    $url = ereg_replace("\&$paramname=[^&]*", "", $url);
-    $url = ereg_replace("$paramname=[^&]*\&", "", $url);
-    $url = ereg_replace("\?$paramname=[^&]*", "", $url);
-    /* Then insert the new one */
-    /* Note: $value != "" is FALSE when $value is the string "0". You gotta 
-       love PHP... */
-    if ($value != "" or $value == "0")
-    {
-        if (strpos($url, "?"))
-            $url .= "&";
-        else
-            $url .= "?";
-        $url .= "$paramname=$value";
-    }
-    return htmlspecialchars($url);
-}
-
-function login_prompt()
-{
-    Header("WWW-Authenticate: Basic realm=\"" . PROG_NAME . "\"");
-    Header("HTTP/1.0 401 Unauthorized");
-    echo "<meta HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL= " . SERVER_REDIR . "\">";
-    exit;
-}
-
-include('layout.inc');
-
-if ((!$PHP_AUTH_USER) or (!$PHP_AUTH_PW) or ($time > time()))
-{
-    login_prompt();
-} 
-else
-{ 
-    if($PHP_AUTH_USER && $PHP_AUTH_PW)
-    {
-        $user = $PHP_AUTH_USER;
-        $pass = $PHP_AUTH_PW;
-        $folder = !$folder ? "INBOX" : $folder;
-        $mailbox = mailbox_log_in($folder);
-
-        if(!$mailbox)
-        {
-            login_prompt();
-        }
-    }
-} 
-
-?>
+<?php
+
+// shouldn't have to modify anything in this file...
+define('VERSION', "AeroMail 2.22");
+
+include("config.inc");
+
+define('FILTER', IMAP_SERVER_TYPE == "Cyrus" ? "INBOX" : PROG_DIR);
+define('IMAP_STR', "{".IMAP_SERVER.":".IMAP_PORT.IMAP_OPTS."}");
+
+function mailbox_log_in( $folder )
+{
+    global $user, $pass;
+    error_reporting(error_reporting() - 2);
+
+    $folder = $folder == "INBOX" ? "INBOX" : construct_folder_str($folder);
+    $mbox = imap_open(IMAP_STR . "$folder", $user , $pass);
+
+    error_reporting(error_reporting() + 2);
+    return $mbox;
+}
+
+function construct_folder_str( $folder )
+{
+    // Cyrus style: INBOX.Junque
+    // UWash style: ./aeromail/Junque
+
+    $folder_str = IMAP_SERVER_TYPE == "Cyrus" ? "INBOX." . $folder : PROG_DIR . $folder;
+    return $folder_str;
+}
+
+function deconstruct_folder_str( $folder )
+{
+    // Cyrus style: INBOX.Junque
+    // UWash style: ./aeromail/Junque
+
+    $srch_str = IMAP_SERVER_TYPE == "Cyrus" ? "INBOX." : PROG_DIR;
+
+    $folder_str = substr($folder, strlen($srch_str), strlen($folder));
+
+    return $folder_str;
+}
+
+function removecrlf($string)
+{
+    return strtr($string, "\015\012", "  ");
+}
+
+function decode_header_string($hed_str)
+{
+    $output = "";
+              
+    if($hed_str)
+    {
+        $element=imap_mime_header_decode($hed_str);
+        for($i=0; $i < count($element); $i++) {
+            if ($element[$i]->charset == "default")
+                $output .= $element[$i]->text;
+            else
+            {
+                $output .= make_utf8($element[$i]->text, $element[$i]->charset);
+            }
+        }
+    }
+    return $output;
+}
+
+function make_address_list($header_arr)
+{
+    $out = array();
+    if (is_array($header_arr) && count($header_arr)) 
+    {
+        foreach ($header_arr as $adr)
+        {
+            $out[] = imap_rfc822_write_address($adr->mailbox, $adr->host, $adr->personal);
+        }
+    }
+    return $out;
+}
+
+function make_formaddress_list($header_arr)
+{
+    $list = make_address_list($header_arr);
+    $l = array();
+    foreach ($list as $adr)
+    {
+        $l[] = htmlentities(decode_header_string($adr));
+    }
+    return implode(", ", $l);
+}
+
+
+function make_clickable_list($header_arr, $folder)
+{    
+    $list = make_address_list($header_arr);
+    $l = array();
+    foreach ($list as $adr)
+    {
+	if (DISPLAY_FULL_ADDR)
+	  $linkdisplay = htmlspecialchars(decode_header_string($adr));
+	else
+	  $linkdisplay = strip_tags(str_replace("\"","",$adr));
+        $l[] = "<a href=\"compose.php?folder="
+            . urlencode($folder) 
+            . "&amp;to=" . urlencode($adr) . "\">"
+            .  $linkdisplay . "</a>";
+    }
+    return implode(", ", $l);
+}
+
+function list_folders( $mailbox )
+{
+    $mailboxes = imap_listmailbox($mailbox, IMAP_STR, FILTER . "*");
+    if($mailboxes)
+    {
+        sort($mailboxes);
+        $num_boxes = count($mailboxes);
+        if (FILTER != "INBOX" && NO_INBOX_EXPLICIT != 1) { echo "<option>INBOX"; }
+        for ($index = 0; $index < $num_boxes; $index++)
+        {
+            $nm = substr($mailboxes[$index], strrpos($mailboxes[$index], "}") + 1, strlen($mailboxes[$index]));
+            echo "<option>";
+            if ($nm != "INBOX")
+            {
+                echo deconstruct_folder_str($nm);
+            }
+            else
+            {
+                echo "INBOX";
+            }
+            echo "\n";
+        }
+    }
+    else
+    {
+        echo "<option>INBOX";
+    }
+}
+
+function get_mime_type($de_part)
+{
+    switch ($de_part->type)
+    {
+        case TYPETEXT:      $mime_type = "text"; break;
+        case TYPEMULTIPART: $mime_type = "multipart"; break;
+        case TYPEMESSAGE:   $mime_type = "message"; break;
+        case TYPEAPPLICATION:   $mime_type = "application"; break;
+        case TYPEAUDIO:     $mime_type = "audio"; break;
+        case TYPEIMAGE:     $mime_type = "image"; break;
+        case TYPEVIDEO:     $mime_type = "video"; break;
+        case TYPEMODEL:     $mime_type = "model"; break;
+        default:        $mime_type = "unknown";
+    }
+    return $mime_type;
+}
+
+function get_mime_encoding($de_part)
+{
+    switch ($de_part->encoding)
+    {
+        case ENCBASE64:         $mime_encoding = "base64"; break;
+        case ENCQUOTEDPRINTABLE:    $mime_encoding = "qprint"; break;
+        case ENCOTHER:          $mime_encoding = "other"; break;
+        default:            $mime_encoding = "other";
+    }
+    return $mime_encoding;
+}
+
+function get_charset($de_part)
+{
+    $charset = "US-ASCII";
+    for ($i = 0; $i < count($de_part->parameters); $i++)
+    {
+        $param = $de_part->parameters[$i];
+        if ($param->attribute == "CHARSET")
+        {
+            $charset = $param->value;
+        }
+    }
+    return $charset;
+}
+
+
+function make_utf8($str, $charset)
+{
+    /* Try, but at least return something! */
+    if (function_exists('iconv')) 
+    {
+        if (!$charset)
+            $charset="US-ASCII";
+        $charset = strtoupper($charset);
+        /* Do some processing to catch sloppy charsets */
+        $charset = ereg_replace("^WINDOWS-", "CP", $charset);
+        /* Found in the wild: "CHINESEBIG5" */
+        $charset = ereg_replace("^CHINESE", "", $charset);
+        $out = iconv($charset, "UTF-8", $str);
+        if ($out)
+            return $out;
+    }
+    return $str;
+}
+
+
+function get_att_name($de_part)
+{
+    $att_name = 0;
+    $att_filename = "Unknown";
+    for ($i = 0; $i < count($de_part->parameters); $i++)
+    {
+        $param = $de_part->parameters[$i];
+        if ($param->attribute == "NAME")
+        {
+            $att_name = $param->value;
+        }
+    }
+    for ($i = 0; $i < count($de_part->dparameters); $i++)
+    {
+        $param = $de_part->dparameters[$i];
+        if ($param->attribute == "FILENAME")
+        {
+            $att_filename = $param->value;
+        }
+    }
+    if ($att_name)
+        return $att_name;
+    else
+        return $att_filename;
+}
+
+function attach_display($de_part, $part_no)
+{
+    global $mailbox, $folder, $msgnum;
+    $mime_type = get_mime_type($de_part);
+    $mime_encoding = get_mime_encoding($de_part);
+
+    $att_name = get_att_name($de_part);
+    $url_att_name = urlencode($att_name);
+
+    $jnk = "<a href=\"get_attach.php?folder=$folder&amp;msgnum=$msgnum&amp;part_no=$part_no";
+    $jnk .= "&amp;type=$mime_type&amp;subtype=$de_part->subtype&amp;name=$url_att_name&amp;encoding=$mime_encoding";
+    $jnk .= "\">$att_name</a>";
+    return $jnk;
+}
+
+/* imap_qprint doesn't handle soft returns correctly */
+function my_imap_qprint($dsp)
+{
+    $dsp = str_replace("=\r\n", "", $dsp);
+    $dsp = imap_qprint($dsp);
+    return $dsp;
+}
+
+function enriched_to_html($dsp)
+{
+    // Convert to HMTL
+    /* Double << is <. Using &lt; makes sure it is no longer taken
+       as a command start, as & will become $amp; Later we replace 
+       &amp;lt; with &lt; */ 
+    $dsp = str_replace("<<", "&lt;", $dsp);
+    $dsp = htmlspecialchars($dsp);
+    // Simple ones
+    $dsp = eregi_replace("&lt;bold&gt;", "<b>", $dsp);
+    $dsp = eregi_replace("&lt;/bold&gt;", "</b>", $dsp);
+    $dsp = eregi_replace("&lt;italic&gt;", "<i>", $dsp);
+    $dsp = eregi_replace("&lt;/italic&gt;", "</i>", $dsp);
+    $dsp = eregi_replace("&lt;underline&gt;", "<u>", $dsp);
+    $dsp = eregi_replace("&lt;/underline&gt;", "</u>", $dsp);
+    $dsp = eregi_replace("&lt;fixed&gt;", "<tt>", $dsp);
+    $dsp = eregi_replace("&lt;/fixed&gt;", "</tt>", $dsp);
+    $dsp = eregi_replace("&lt;smaller&gt;", "<small>", $dsp);
+    $dsp = eregi_replace("&lt;/smaller&gt;", "</small>", $dsp);
+    $dsp = eregi_replace("&lt;bigger&gt;", "<big>", $dsp);
+    $dsp = eregi_replace("&lt;/bigger&gt;", "</big>", $dsp);
+    $dsp = eregi_replace("&lt;center&gt;", "<div align=\"center\">", $dsp);
+    $dsp = eregi_replace("&lt;/center&gt;", "</div>", $dsp);
+    $dsp = eregi_replace("&lt;flushleft&gt;", "<div align=\"left\">", $dsp);
+    $dsp = eregi_replace("&lt;/flushleft&gt;", "</div>", $dsp);
+    $dsp = eregi_replace("&lt;flushright&gt;", "<div align=\"right\">", $dsp);
+    $dsp = eregi_replace("&lt;/flushright&gt;", "</div>", $dsp);
+    $dsp = eregi_replace("&lt;flushboth&gt;", "<div align=\"justify\">", $dsp);
+    $dsp = eregi_replace("&lt;/flushboth&gt;", "</div>", $dsp);
+    /* nofill -> pre. TODO: Within this block, no newline replacing 
+       should be done. */
+    $dsp = eregi_replace("&lt;nofill&gt;", "<pre>", $dsp);
+    $dsp = eregi_replace("&lt;/nofill&gt;", "</pre>", $dsp);
+    /* Paraindent -> blockquote
+       Not entriely correct: there is a param telling what kind
+       of indenting to do, which we don't support.
+       Another thing: My params cannot contain an & char, which
+       might be a problem.
+     */
+    $dsp = eregi_replace("&lt;paraindent&gt;&lt;param&gt;[^&]*&lt;/param&gt;", "<blockquote>", $dsp);
+    $dsp = eregi_replace("&lt;/paraindent&gt;", "</blockquote>", $dsp);
+    /* Excerpt can optionally have a param telling where excerpt 
+       comes from. */
+    $dsp = eregi_replace("&lt;excerpt&gt;&lt;param&gt;([^&]*)&lt;/param&gt;", "<hr><br>\\\\1<blockquote>", $dsp);
+    $dsp = eregi_replace("&lt;excerpt&gt;", "<hr><blockquote>", $dsp);
+    $dsp = eregi_replace("&lt;/excerpt&gt;", "</blockquote>", $dsp);
+    /* Lang: Language is ignored */
+    $dsp = eregi_replace("&lt;lang&gt;&lt;param&gt;[^&]*&lt;/param&gt;", "", $dsp);
+    $dsp = eregi_replace("&lt;/lang&gt;", "", $dsp);
+    /* FontFamily */
+    $dsp = eregi_replace("&lt;fontfamily&gt;&lt;param&gt;([^&]*)&lt;/param&gt;", "<font face=\"\\\\1\">", $dsp);
+    $dsp = eregi_replace("&lt;/fontfamily&gt;", "</font>", $dsp);
+    /* color */
+    while (eregi("&lt;color&gt;&lt;param&gt;([^&]*)&lt;/param&gt;", $dsp, $regs))
+    {
+        // regs[1] = xxxx,yyyy,zzzz or colorname
+        $c = explode(",", $regs[1]);
+        if (count($c) == 1)
+            $color = $c[0];
+        else
+        {
+            // First 2 chars of 4char hex string is string /256
+            $color = "#" . 
+                substr($c[0], 0, 2) . 
+                substr($c[1], 0, 2) . 
+                substr($c[2], 0, 2);
+        }
+        $dsp = eregi_replace("&lt;color&gt;&lt;param&gt;[^&]*&lt;/param&gt;", "<font color=\"$color\">", $dsp);
+    }
+    $dsp = eregi_replace("&lt;/color&gt;", "</font>", $dsp);
+    /* Now remove any unrecognised <param>s */
+    $dsp = eregi_replace("&lt;param&gt;[^&]*&lt;/param&gt;", "", $dsp);
+    /* And last, remove any unknown tags */
+    $dsp = eregi_replace("&lt;[^&]*&gt;", "", $dsp);
+    /* Now finish the work on << */
+    $dsp = eregi_replace("&amp;lt;", "&lt;", $dsp);
+    /* Do the newlines */
+    while (ereg("\n\n", $dsp))
+        $dsp = ereg_replace("\n\n", "<br>\n", $dsp);
+    while (ereg("\r\n\r\n", $dsp))
+        $dsp = ereg_replace("\r\n\r\n", "<br>\r\n", $dsp);
+    /* text/enriched must start with filled text according to RFC */
+    $dsp = "<div align=\"justify\">$dsp</div>";
+    return $dsp;
+}
+
+function make_safe_html($dsp)
+{
+    $hidetag = array (
+        '!doctype',
+        'html',
+        'head',
+        'meta',
+        'body'
+    );
+    foreach ($hidetag as $tag)
+    {
+        $dsp = eregi_replace("<\\s*(/?)\\s*$tag([^>]*)>",
+                             "<!-- \\1$tag\\2 -->", $dsp);
+    }
+    $hideelt = array (
+        'title',
+        'style'
+    );
+    foreach ($hideelt as $tag)
+    {
+        $dsp = eregi_replace("<\\s*$tag([^>]*)>",
+                             "<!-- $tag\\1>", $dsp);
+        $dsp = eregi_replace("<\\s*/\\s*$tag([^>]*)>",
+                             "</$tag\\1 -->", $dsp);
+    }
+    return $dsp;
+}
+
+function do_inline_display($msgnum, $part_no, $encoding, $charset, $type, $safe = 0)
+{
+    global $mailbox, $msgnum;
+    global $folder;
+
+    /* $safe means: Safe to display in an HTML form. 
+       not safe is largely unchanged. */
+
+    $dsp = imap_fetchbody($mailbox, $msgnum, $part_no);
+    if ($encoding == "base64") {
+        $dsp = imap_base64($dsp);
+    }
+    if ($encoding == "qprint") {
+        $dsp = my_imap_qprint($dsp);
+    }
+    if (!$safe)
+    {
+        /* Done, no further processing. */
+        echo $dsp;
+    }
+    else
+    {
+        $dsp = make_utf8($dsp, $charset);
+        if (strtolower($type) == "text/plain")
+        {
+            /* For text/plain we exhibit the line break behavior defined
+               in the config.inc 
+             */
+            if (WRAP_AT_COLUMN)
+              $dsp = forcelinebreaks($dsp,WRAP_AT_COLUMN);
+            $dsp = htmlspecialchars($dsp);
+            $dsp = make_clickable($dsp);
+            echo "<pre>$dsp</pre>";
+        }
+        else if (strtolower($type) == "text/enriched")
+        {
+            $dsp = enriched_to_html($dsp);
+            echo $dsp;
+        }
+        else if (strtolower($type) == "text/html")
+        {
+            $struct = imap_fetchstructure($mailbox, $msgnum);
+            while (ereg("cid:([^\"]*)", $dsp, $regs))
+            {
+                /* WARNING: MAKE SURE you quotemeta() on $regs[1]. They can
+		    (and often do) contain $ characters.
+                */
+                $dsp = ereg_replace("cid:" . quotemeta($regs[1]), cid_name($struct, $regs[1]), $dsp);
+            }
+            $dsp = make_safe_html($dsp);
+            echo $dsp;
+        }
+        else
+        {
+            /* For unknown types, we just display exactly as sent, so here
+               we do use <pre>. */
+            $dsp = htmlspecialchars($dsp);
+            echo "<pre>\n$dsp</pre>\n";
+        }
+    }
+}
+
+function inline_display($de_part, $part_no)
+{
+    global $mailbox, $msgnum, $folder;
+    
+    
+    $mime_type = get_mime_type($de_part);
+    $type = $mime_type . "/" . $de_part->subtype;
+    $mime_encoding = get_mime_encoding($de_part);
+    $charset = get_charset($de_part);
+
+    /* Default, simple mail */
+    if (strtolower($type) == "text/plain")
+    {
+        $ret = 1;
+    }
+    /* Smart types we know of */
+    elseif ((strtolower($type) == "text/enriched") or
+            (strtolower($type) == "text/html"))
+    {
+        output_bound(L_MIME_SECTION . ":" , "$mime_type/$de_part->subtype");
+        $ret = 1;
+    }
+    /* All other types: return 0 as we don't know whether we displayed 
+       anything useful for the user. */
+    else
+    {
+        output_bound(L_MIME_SECTION .  ":" , "$mime_type/$de_part->subtype");
+        $ret = 0;
+    }
+    /* This is not really useful
+    print "<p><a href=\"view_inline.php?folder=" . urlencode($folder) 
+                . "&amp;msgnum=$msgnum"
+                . "&amp;part_no=$part_no"
+                . "&amp;encoding=" . urlencode($mime_encoding)
+                . "&amp;charset=" . urlencode($charset)
+                . "&amp;type=" . urlencode($type)
+                . "\">" . L_MESSAGE . "</a></p>\n";
+    */                
+    
+    /* Embedded objects have a fixed height, which means embedded scrolbars.
+       That's not worth it.
+    print "<object "
+                . "data=\"view_inline.php?folder=" . urlencode($folder) 
+                . "&amp;msgnum=$msgnum"
+                . "&amp;part_no=$part_no"
+                . "&amp;encoding=" . urlencode($mime_encoding)
+                . "&amp;charset=" . urlencode($charset)
+                . "&amp;type=" . urlencode($type)
+                . "\" width=\"100%\">\n";
+    */                
+
+    do_inline_display($msgnum, $part_no, $mime_encoding,
+                      $charset, $type, 1);
+    /*
+    echo "</object>\n";
+    */
+    return $ret;
+}
+
+function output_bound($title, $str)
+{
+    body_left_end();
+    body_row_end();
+
+    title_start();
+    title_left();
+    echo $title;
+    title_left_end();
+    title_data();
+    echo $str;
+    title_data_end();
+    body_row('class="rowon"');
+    body_left('colspan="2"');
+}
+
+
+function cid_name($struct, $cid_to_find, $numprefix="")
+{
+    global $folder, $msgnum;
+    global $cidsdone;
+    $name = "";
+    $numparts = !$struct->parts ? "1" : count($struct->parts);
+    for($i = 0; $i < $numparts; $i++)
+    {
+        $part = !$struct->parts[$i] ? $part = $struct : $part = $struct->parts[$i];
+
+        if ($part->parts)
+        {
+            $subpartnum = $i + 1;
+            $name .= cid_name($part, $cid_to_find, $numprefix . $subpartnum . ".");
+            if ($name)
+            {
+                return $name;
+            }
+        }
+        else
+        {
+            $cid = $part->ifid ? $part->id : "";
+            if ($cid == $cid_to_find || $cid == "<$cid_to_find>")
+            {
+                $subpartnum = $i + 1;
+                $att_name = get_att_name($part);
+                $name .= "view_image.php?folder=" . $folder 
+                    . "&amp;msgnum=$msgnum&amp;part_no=" . $numprefix
+                    . $subpartnum
+                    . "&amp;type=$part->subtype&amp;name=$att_name";
+                $cidsdone[$cid] = 1;
+                return $name;
+            }
+        }
+    }
+    // Not found, leave it as it is
+    return $cid_to_find;
+}
+
+/* ciddone is set for an inline image that is processed. If the image data 
+   appears later in the message, it doesn't have to be displayed again.
+   This is not entirely correct, because when the image data appears first, 
+   it is displayed, and again later as inline.
+*/
+function ciddone($part)
+{
+    global $cidsdone;
+    $cid = $part->ifid ? $part->id : "";
+    if ($cid == "")
+        return 0;
+    return $cidsdone[$cid];
+}
+
+function image_display($folder, $msgnum, $de_part, $part_no, $att_name)
+{
+    output_bound(L_IMAGE . ":" , $att_name);
+    echo "\n<img src=\""; 
+    echo "view_image.php?folder=" . urlencode($folder) . "&amp;msgnum=$msgnum&amp;part_no=$part_no";
+    echo "&amp;type=$de_part->subtype&amp;name=$att_name\">\n<br>\n";
+}
+
+// function make_clickable ripped off from PHPWizard.net
+// http://www.phpwizard.net/phpMisc/
+// modified to make mailto: addresses compose in AeroMail
+
+function make_clickable($text)
+{
+    global $folder;
+    $ret = eregi_replace( "([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
+        "<a href=\"\\1://\\2\\3\" target=\"_new\">\\1://\\2\\3</a>", $text);
+    $ret = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]&^>&^<]*)([[:alnum:]-]))",
+        "<a href=\"compose.php?folder=" . urlencode($folder) . "&amp;to=\\1\">\\1</a>", $ret);
+    return($ret);
+}
+
+
+function self_with_param($paramname, $value)
+{
+    global $HTTP_SERVER_VARS;
+    $url = $HTTP_SERVER_VARS["REQUEST_URI"];
+    /* first strip out the old value of $paramname */
+    $url = ereg_replace("\&$paramname=[^&]*", "", $url);
+    $url = ereg_replace("$paramname=[^&]*\&", "", $url);
+    $url = ereg_replace("\?$paramname=[^&]*", "", $url);
+    /* Then insert the new one */
+    /* Note: $value != "" is FALSE when $value is the string "0". You gotta 
+       love PHP... */
+    if ($value != "" or $value == "0")
+    {
+        if (strpos($url, "?"))
+            $url .= "&";
+        else
+            $url .= "?";
+        $url .= "$paramname=$value";
+    }
+    return htmlspecialchars($url);
+}
+
+function forcelinebreaks($dsp,$charcount) {
+  /*  lastLB = last-known line break (absolute position)
+      nextSP = next-known space, if any (relative to lastLB)
+      nextLB = next-known line break, if any (relative to lastLB)
+      walkback = the last space prior to the $charcount position
+  */
+    $lastLB = 0;
+    $dsptemp = "";
+    for ($n = 0; $n < strlen($dsp); $n++) {
+        if (strcmp(substr($dsp,$n,1), "\n") == 0)
+          $lastLB = $n;
+        $nextSP = strpos(substr($dsp,$lastLB)," ");
+        $nextLB = strpos(substr($dsp,$lastLB),"\n");
+        if (($nextSP > $charcount) && ($nextLB > $charcount)) {
+            // Jmp ahead to the next space or newline.
+            if ($nextSP > $nextLB) {
+                # closest is newline. go there.
+                $dsptemp .= substr($dsp,$n,$nextLB + 1);
+                $lastLB = $nextLB + $n;
+                $n = $lastLB + 1;
+            } else {
+                # closest is space. go there.
+                $dsptemp .= substr($dsp,$n,$nextSP) . "\n";
+                $lastLB = $nextSP + $n;
+                $n = $lastLB;
+            } // end if nextSP > nextLB
+        } else if ($nextSP < 1) {
+            // do nothing (don't walk back!). just keep walking the string.
+        } else if ($n - $lastLB > $charcount) {
+            // walk backwards on the string to the last space
+            $walkback = strrpos(substr($dsp,$lastLB,$charcount)," ");
+            $curpos = $lastLB + $walkback;
+            $dsptemp = substr($dsptemp,0,$curpos) . "\n";
+            $lastLB = $curpos + 1;
+            $n = $lastLB;
+        } // end if nextSP > charcount          
+        $dsptemp .= substr($dsp,$n,1);
+    } // end for n < strlen($dsp)
+    return $dsptemp;
+} // End function forcelinebreaks
+
+function login_prompt()
+{
+    Header("WWW-Authenticate: Basic realm=\"" . PROG_NAME . "\"");
+    Header("HTTP/1.0 401 Unauthorized");
+    echo "<meta HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL= " . SERVER_REDIR . "\">";
+    exit;
+}
+
+include('layout.inc');
+
+if ((!$PHP_AUTH_USER) or (!$PHP_AUTH_PW) or ($time > time()))
+{
+    login_prompt();
+} 
+else
+{ 
+    if($PHP_AUTH_USER && $PHP_AUTH_PW)
+    {
+        $user = $PHP_AUTH_USER;
+        $pass = $PHP_AUTH_PW;
+        $folder = !$folder ? "INBOX" : $folder;
+        $mailbox = mailbox_log_in($folder);
+
+        if(!$mailbox)
+        {
+            login_prompt();
+        }
+    }
+} 
+
+?>
diff -ruN ../aero_221/index.php ./index.php
--- ../aero_221/index.php	2004-04-20 03:18:13.000000000 -0400
+++ ./index.php	2004-09-04 18:48:12.000000000 -0400
@@ -234,22 +234,23 @@
         if ($sort == 100 + SORTFROM)
             echo "<img src=\"images/descending.gif\" alt=\"v\" width=\"8\" height=\"8\" border=\"0\">";
         title_left_end();
-    }
-    title_left();
-    echo "<a href=\"";
-    if ($sort == SORTTO)
-        $s = 100 + SORTTO;
-    else
-        $s = SORTTO;
-    echo self_with_param("sort", $s);
-    echo "\">";
-    echo L_TO_HDR;
-    echo "&nbsp;";
-    if ($sort == SORTTO)
-        echo "<img src=\"images/ascending.gif\" alt=\"^\" width=\"8\" height=\"8\" border=\"0\">";
-    if ($sort == 100 + SORTTO)
-        echo "<img src=\"images/descending.gif\" alt=\"v\" width=\"8\" height=\"8\" border=\"0\">";
-    title_left_end();
+    } else {
+        title_left();
+        echo "<a href=\"";
+        if ($sort == SORTTO)
+            $s = 100 + SORTTO;
+        else
+            $s = SORTTO;
+        echo self_with_param("sort", $s);
+        echo "\">";
+        echo L_TO_HDR;
+        echo "&nbsp;";
+        if ($sort == SORTTO)
+            echo "<img src=\"images/ascending.gif\" alt=\"^\" width=\"8\" height=\"8\" border=\"0\">";
+        if ($sort == 100 + SORTTO)
+            echo "<img src=\"images/descending.gif\" alt=\"v\" width=\"8\" height=\"8\" border=\"0\">";
+        title_left_end();
+    } // end else on if !issentmail for heading
     title_left();
     echo "<a href=\"";
     if ($issentmail)
@@ -400,29 +401,33 @@
         echo "</a>$attach\n";
         if ($possible_spam)
             print "<br><font color=\"red\"><small>($ret)</small></font>";
-        if ($msg->Unseen)
+        if ($msg->Unseen == 'U' || $msg->Recent == 'N')
             print "</b>";
         body_left_end();
         if(!$issentmail)
         {
             body_left();
-            if($msg->from)
+            if($msg->from) {
+                if ($msg->Unseen == 'U' || $msg->Recent == 'N')
+                  print "<b>";
                 echo make_clickable_list($msg->from, $folder);
-            else
+            } else
                 echo L_NO_FROM;
             body_left_end();
+        } else {
+            // Hide To: field unless displaying the sent items folder.
+            body_left();
+            if ($msg->to)
+                echo make_clickable_list($msg->to, $folder);
+            else
+                echo L_NO_TO;
+            body_left_end();
         }
-        body_left();
-        if ($msg->to)
-            echo make_clickable_list($msg->to, $folder);
-        else
-            echo L_NO_TO;
+        body_left('class="row-small"');
+        echo "<nobr>".date(L_DATE_FORMAT, $msg->udate)."</nobr>";
         body_left_end();
-        body_left();
-        echo date(L_DATE_FORMAT, $msg->udate);
-        body_left_end();
-        body_left();
-        echo "$size\n";
+        body_left('class="row-small"');
+        echo "<nobr>$size</nobr>\n";
         body_left_end();
         body_row_end();
     }
diff -ruN ../aero_221/layout.inc ./layout.inc
--- ../aero_221/layout.inc	2003-10-22 08:38:32.000000000 -0400
+++ ./layout.inc	2004-09-04 15:18:27.000000000 -0400
@@ -1,167 +1,167 @@
-<?php
-
-function content_start()
-{
-?>
-<table class="main" cellpadding="0" cellspacing="0" width="100%">
-<?php
-//<tr><td>
-}
-
-function header_start()
-{
-?>
-  <tr><td class="header">
-    <table border="0" cellpadding="5" cellspacing="1" width="100%">
-      <tr>
-<?php
-}
-
-function header_left()
-{
-?>    
-    <td class="header" width="100%"><b>
-<?php
-}
-
-function header_right()
-{
-?>    
-    <td align="right" class="header"><b>
-<?php
-}
-
-function header_left_right_end()
-{
-?>
-    </b></td>
-<?php
-}
-
-function header_end()
-{
-?>    
-      </tr>
-    </table>
-  </td></tr>
-<?php
-}
-
-function title_start()
-{
-?>
-  <tr>
-<?php
-}
-
-function title_left($att="")
-{
-?>
-        <th class="title" <?php echo $att ?>>
-<?php
-}
-function title_left_end()
-{
-?>
-        </th>
-<?php
-}
-
-function title_data()
-{
-?>
-        <td class="title">
-<?php
-}
-
-function title_data_end()
-{
-?>
-        </td>
-<?php
-}
-
-function title_end()
-{
-?>
-    </tr>
-<?php
-}
-
-function body_start()
-{
-?>
-  <tr><td>
-    <table border="0" cellpadding="5" cellspacing="1" width="100%">
-<?php
-}
-
-function body_compose_start()
-{
-?>
-  <tr><td>
-    <table border="0" cellpadding="1" cellspacing="1" width="100%">
-<?php
-}
-
-function body_row($att="")
-{
-?>
-    <tr <?php echo $att ?>>
-<?php
-}
-
-function body_left($att="")
-{
-?>
-    <td <?php echo $att ?>>
-<?php
-}
-
-function body_left_end()
-{
-?>
-    </td>
-<?php
-}
-
-function body_row_end()
-{
-?>
-    </tr>
-<?php
-}
-
-
-function body_end()
-{
-?>
-    </table>
-    </td></tr>
-<?php
-}
-
-function content_end()
-{
-version();
-//</td></tr>
-?>
-</table>
-<?php
-}
-
-
-function style()
-{
-    include("style.php");
-}
-
-
-function version()
-{
-?>
-    <tr><td class="version"><?php echo VERSION ?></td></tr>
-<?php
-}
-
-?>
+<?php
+
+function content_start()
+{
+?>
+<table class="main" cellpadding="0" cellspacing="0">
+<?php
+//<tr><td>
+}
+
+function header_start()
+{
+?>
+  <tr><td class="header">
+    <table border="0" cellpadding="3" cellspacing="1" width="100%">
+      <tr>
+<?php
+}
+
+function header_left()
+{
+?>    
+    <td class="header" width="100%"><b>
+<?php
+}
+
+function header_right()
+{
+?>    
+    <td align="right" class="header"><b>
+<?php
+}
+
+function header_left_right_end()
+{
+?>
+    </b></td>
+<?php
+}
+
+function header_end()
+{
+?>    
+      </tr>
+    </table>
+  </td></tr>
+<?php
+}
+
+function title_start()
+{
+?>
+  <tr>
+<?php
+}
+
+function title_left($att="")
+{
+?>
+        <th class="title" <?php echo $att ?>>
+<?php
+}
+function title_left_end()
+{
+?>
+        </th>
+<?php
+}
+
+function title_data()
+{
+?>
+        <td class="title">
+<?php
+}
+
+function title_data_end()
+{
+?>
+        </td>
+<?php
+}
+
+function title_end()
+{
+?>
+    </tr>
+<?php
+}
+
+function body_start()
+{
+?>
+  <tr><td>
+    <table border="0" cellpadding="3" cellspacing="1" width="100%">
+<?php
+}
+
+function body_compose_start()
+{
+?>
+  <tr><td>
+    <table border="0" cellpadding="1" cellspacing="1" width="100%">
+<?php
+}
+
+function body_row($att="")
+{
+?>
+    <tr <?php echo $att ?>>
+<?php
+}
+
+function body_left($att="")
+{
+?>
+    <td <?php echo $att ?>>
+<?php
+}
+
+function body_left_end()
+{
+?>
+    </td>
+<?php
+}
+
+function body_row_end()
+{
+?>
+    </tr>
+<?php
+}
+
+
+function body_end()
+{
+?>
+    </table>
+    </td></tr>
+<?php
+}
+
+function content_end()
+{
+version();
+//</td></tr>
+?>
+</table>
+<?php
+}
+
+
+function style()
+{
+    include("style.php");
+}
+
+
+function version()
+{
+?>
+    <tr><td class="version"><?php echo VERSION ?></td></tr>
+<?php
+}
+
+?>
diff -ruN ../aero_221/send_message.php ./send_message.php
--- ../aero_221/send_message.php	2004-08-09 09:26:24.000000000 -0400
+++ ./send_message.php	2004-09-04 18:53:02.000000000 -0400
@@ -1,105 +1,111 @@
-<?php   
-
-    include("global.inc");
-
-    function mailfrom($fromaddress, $body, $headers)
-    {
-        // -t means get To, CC and BCC from message
-        // -i means ignore single dots on line, read till EOF
-        // -f forces fromaddress
-        $fp = popen("/usr/sbin/sendmail -t -i -f" . $fromaddress, "w");
-
-        fputs($fp, $headers);
-        fputs($fp, $body);
-        fputs($fp, "\r\n");
-
-        pclose($fp);
-    }
-
-    /* A boundary must be unlikely to appear in the body. "=_" can never
-       occur in qprint or bas64 encoded parts. The user could still type
-       this, but '=' is converted in qprint and will never appear
-       in bas64 except in the end.
-    */
-    $boundary = "=_Message-Boundary_=";
-
-    //$mailheaders  = "From: $user$SERVER_SUFFIX\r\n";
-    //$mailheaders .= "Reply-To: $user$SERVER_SUFFIX\r\n";
-
-    $to = stripslashes($to);
-    $mailheaders = "To: ".removecrlf($to)."\n";
-    $cc = stripslashes($cc);
-    $mailheaders .= "Cc: ".removecrlf($cc)."\n";
-
-    $mailheaders .= "X-Mailer: " . VERSION . "\r\n";
-
-    $msg_body = stripslashes($body);
-    $msg_body = imap_8bit($msg_body);
-
-    if (( $attach != "none" ) && ( $attach != "" ) and (is_uploaded_file($attach)))
-    {
-        $file = fopen($attach, "r");
-        $contents = fread($file, $attach_size);
-        $encoded_attach = chunk_split(base64_encode($contents));
-        fclose($file);
-        
-        $mailheaders .= "MIME-version: 1.0\r\n";
-        $mailheaders .= "Content-type: multipart/mixed; ";
-        $mailheaders .= "boundary=\"$boundary\"\r\n";
-        $mailheaders .= "Content-transfer-encoding: 7BIT\r\n";
-        $mailheaders .= "X-attachments: $attach_name\r\n";
-
-        $body_top = "--$boundary\r\n";
-        $body_top .= "Content-type: text/plain; charset=UTF-8\r\n";
-        $body_top .= "Content-transfer-encoding: quoted-printable\r\n";
-        $body_top .= "Content-description: Mail message body\r\n\r\n";
-
-        $msg_body = $body_top . $msg_body;
-
-        $msg_body .= "\r\n\r\n--$boundary\r\n";
-        $msg_body .= "Content-type: $attach_type; name=\"$attach_name\"\r\n";       
-        $msg_body .= "Content-Transfer-Encoding: BASE64\r\n";
-        $msg_body .= "Content-disposition: attachment; filename=\"$attach_name\"\r\n\r\n";
-        $msg_body .= "$encoded_attach\r\n";
-        $msg_body .= "--$boundary--\r\n";
-    }
-    else
-    {
-        $mailheaders .= "MIME-version: 1.0\r\n";
-        $mailheaders .= "Content-type: text/plain; charset=UTF-8\r\n";
-        $mailheaders .= "Content-transfer-encoding: quoted-printable\r\n";
-    }
-
-    $mailheaders .= "Subject: " . removecrlf(stripslashes($subject)) . "\r\n\r\n";
-
-    $from_user = FORCE_FROM ? "$user@" . IMAP_SERVER : $user;
-
-    mailfrom($from_user, $msg_body, $mailheaders);
-
-    // add message to the sent mail folder
-    if(is_string(SENT_MAIL))
-    {
-        $mailbox = mailbox_log_in(SENT_MAIL);
-        $snt_folder = construct_folder_str(SENT_MAIL);
-
-        if(imap_last_error())
-        {
-            //if there was an error, it was because there was no sent mail folder
-            //we'll just create one here, then re-login
-
-            imap_createmailbox($mailbox, IMAP_STR . "$snt_folder");
-            $mailbox = mailbox_log_in(SENT_MAIL);
-        }
-
-        $waxer = imap_append($mailbox, IMAP_STR. "$snt_folder", "From: $user@" . IMAP_SERVER . "\r\n" . $mailheaders . $msg_body);
-    }
-
-    if ($msgnum != "")
-    {
-        header("Location: message.php?folder=" . $folder . "&msgnum=" . $msgnum);  
-    }
-    else
-    {
-        header("Location: index.php?folder=" . $folder);  
-    }
-?>
+<?php   
+
+    include("global.inc");
+
+    function mailfrom($fromaddress, $body, $headers)
+    {
+        // -t means get To, CC and BCC from message
+        // -i means ignore single dots on line, read till EOF
+        // -f forces fromaddress
+        $fp = popen("/usr/sbin/sendmail -t -i -f" . $fromaddress, "w");
+
+        fputs($fp, $headers);
+        fputs($fp, $body);
+        fputs($fp, "\r\n");
+
+        pclose($fp);
+    }
+
+    /* A boundary must be unlikely to appear in the body. "=_" can never
+       occur in qprint or bas64 encoded parts. The user could still type
+       this, but '=' is converted in qprint and will never appear
+       in bas64 except in the end.
+    */
+    $boundary = "=_Message-Boundary_=";
+    $mailheaders = "";
+
+    if (FORCE_FROM) {
+        $mailheaders .= "From: $user@".SERVER_SUFFIX."\r\n";
+        //$mailheaders .= "Reply-To: $user@".SERVER_SUFFIX."\r\n";
+    }
+
+    $to = stripslashes($to);
+    $mailheaders .= "To: ".removecrlf($to)."\n";
+    $cc = stripslashes($cc);
+    $mailheaders .= "Cc: ".removecrlf($cc)."\n";
+
+    $mailheaders .= "X-Mailer: " . VERSION . "\r\n";
+
+    $msg_body = stripslashes($body);
+    $msg_body = imap_8bit($msg_body);
+
+    if (( $attach != "none" ) && ( $attach != "" ) and (is_uploaded_file($attach)))
+    {
+        $file = fopen($attach, "r");
+        $contents = fread($file, $attach_size);
+        $encoded_attach = chunk_split(base64_encode($contents));
+        fclose($file);
+        
+        $mailheaders .= "MIME-version: 1.0\r\n";
+        $mailheaders .= "Content-type: multipart/mixed; ";
+        $mailheaders .= "boundary=\"$boundary\"\r\n";
+        $mailheaders .= "Content-transfer-encoding: 7BIT\r\n";
+        $mailheaders .= "X-attachments: $attach_name\r\n";
+
+        $body_top = "--$boundary\r\n";
+        $body_top .= "Content-type: text/plain; charset=UTF-8\r\n";
+        $body_top .= "Content-transfer-encoding: quoted-printable\r\n";
+        $body_top .= "Content-description: Mail message body\r\n\r\n";
+
+        $msg_body = $body_top . $msg_body;
+
+        $msg_body .= "\r\n\r\n--$boundary\r\n";
+        $msg_body .= "Content-type: $attach_type; name=\"$attach_name\"\r\n";       
+        $msg_body .= "Content-Transfer-Encoding: BASE64\r\n";
+        $msg_body .= "Content-disposition: attachment; filename=\"$attach_name\"\r\n\r\n";
+        $msg_body .= "$encoded_attach\r\n";
+        $msg_body .= "--$boundary--\r\n";
+    }
+    else
+    {
+        $mailheaders .= "MIME-version: 1.0\r\n";
+        $mailheaders .= "Content-type: text/plain; charset=UTF-8\r\n";
+        $mailheaders .= "Content-transfer-encoding: quoted-printable\r\n";
+    }
+
+    $mailheaders .= "Subject: " . removecrlf(stripslashes($subject)) . "\r\n\r\n";
+
+    $from_user = FORCE_FROM ? "$user@" . SERVER_SUFFIX : $user;
+
+    mailfrom($from_user, $msg_body, $mailheaders);
+
+    // add message to the sent mail folder
+    if(is_string(SENT_MAIL))
+    {
+        $mailbox = mailbox_log_in(SENT_MAIL);
+        $snt_folder = construct_folder_str(SENT_MAIL);
+
+        if(imap_last_error())
+        {
+            //if there was an error, it was because there was no sent mail folder
+            //we'll just create one here, then re-login
+
+            imap_createmailbox($mailbox, IMAP_STR . "$snt_folder");
+            $mailbox = mailbox_log_in(SENT_MAIL);
+        }
+
+        if (FORCE_FROM)
+            $waxer = imap_append($mailbox, IMAP_STR. "$snt_folder", "From: $user@" . SERVER_SUFFIX . "\r\n" . $mailheaders . $msg_body);
+        else
+            $waxer = imap_append($mailbox, IMAP_STR. "$snt_folder", "From: $user@" . IMAP_SERVER . "\r\n" . $mailheaders . $msg_body);
+    }
+
+    if ($msgnum != "")
+    {
+        header("Location: message.php?folder=" . $folder . "&msgnum=" . $msgnum);  
+    }
+    else
+    {
+        header("Location: index.php?folder=" . $folder);  
+    }
+?>
diff -ruN ../aero_221/style.php ./style.php
--- ../aero_221/style.php	2003-10-21 08:03:36.000000000 -0400
+++ ./style.php	2004-09-04 15:23:14.000000000 -0400
@@ -1,52 +1,56 @@
-<style type="text/css">
-    a {color: <?php echo COLOR_LINK ?> }
-    a:active {color: <?php echo COLOR_ALINK ?> }
-    a.msg {text-decoration: none; color: <?php echo COLOR_NUM_LINK ?>}
-    form {
-        display: inline;
-    }
-
-    table.main {
-        background-color: <?php echo COLOR_BG ?>; 
-        color: <?php echo COLOR_FONT ?>;
-        font-family: <?php echo FONT ?>;
-        border: thin solid <?php echo COLOR_BG ?>;
-    }
-/*td { border: thin solid red; }
-table { border: thin solid yellow; }*/
-    td.header {
-        background-color: <?php echo COLOR_HEAD ?>;
-        color: <?php echo COLOR_FONT_HEAD ?>;
-        font-weight: bold;               
-    }
-    th.title {
-        background-color: <?php echo COLOR_TITLE ?>;
-        color: <?php echo COLOR_FONT_TITLE ?>;
-        font-weight: bold;               
-        font-size: smaller;
-        text-align: left;
-    }
-    td.title {
-        background-color: <?php echo COLOR_ROW_ON ?>;
-        font-size: smaller;
-        width: 80%;
-    }
-    tr.rowoff {
-        background-color: <?php echo COLOR_ROW_OFF ?>;
-        font-size: smaller;
-    }
-    tr.rowon {
-        background-color: <?php echo COLOR_ROW_ON ?>;
-        font-size: smaller;
-    }
-    td.body {
-        background-color: <?php echo COLOR_ROW_ON ?>;
-    }
-    td.version {
-        background-color: <?php echo COLOR_BG ?>; 
-        color: <?php echo COLOR_FONT ?>;
-        font-size: xx-small;
-        font-style: italic;
-        text-align: center;
-    }
-</style>
+<style type="text/css">
+    body {margin-top: 11; background-color: <?php echo COLOR_BG ?>; color: <?php echo COLOR_FONT ?> }
+    a {color: <?php echo COLOR_LINK ?> }
+    a:active {color: <?php echo COLOR_ALINK ?> }
+    a.msg {text-decoration: none; color: <?php echo COLOR_NUM_LINK ?>}
+    form {
+        display: inline;
+    }
+
+    table.main {
+        background-color: <?php echo COLOR_HEAD ?>; 
+        color: <?php echo COLOR_FONT ?>;
+        font-family: <?php echo FONT ?>;
+        border: thin solid <?php echo COLOR_BG ?>;
+    }
+/*td { border: thin solid red; }
+table { border: thin solid yellow; }*/
+    td.header {
+        background-color: <?php echo COLOR_HEAD ?>;
+        color: <?php echo COLOR_FONT_HEAD ?>;
+        font-weight: bold;               
+    }
+    th.title {
+        background-color: <?php echo COLOR_TITLE ?>;
+        color: <?php echo COLOR_FONT_TITLE ?>;
+        font-weight: bold;               
+        font-size: small;
+        text-align: left;
+    }
+    td.title {
+        background-color: <?php echo COLOR_ROW_ON ?>;
+        font-size: small;
+        width: 80%;
+    }
+    tr.rowoff {
+        background-color: <?php echo COLOR_ROW_OFF ?>;
+        font-size: small;
+    }
+    tr.rowon {
+        background-color: <?php echo COLOR_ROW_ON ?>;
+        font-size: small;
+    }
+    td.row-small {
+        font-size: x-small;
+    }
+    td.body {
+        background-color: <?php echo COLOR_ROW_ON ?>;
+    }
+    td.version {
+        background-color: <?php echo COLOR_BG ?>; 
+        color: <?php echo COLOR_FONT ?>;
+        font-size: xx-small;
+        font-style: italic;
+        text-align: center;
+    }
+</style>
diff -ruN ../aero_221/themes/blackandblue.theme.inc ./themes/blackandblue.theme.inc
--- ../aero_221/themes/blackandblue.theme.inc	1969-12-31 19:00:00.000000000 -0500
+++ ./themes/blackandblue.theme.inc	2004-09-04 15:37:34.000000000 -0400
@@ -0,0 +1,35 @@
+<?php
+
+//----------------------------
+// Default theme include file
+//----------------------------
+
+// font(s) used in AeroMail
+define('FONT', "verdana,arial,helvetica");
+
+// font color
+define('COLOR_FONT', "#FFFFFF");
+
+// background color
+define('COLOR_BG', "#000000");
+
+// color for the header
+define('COLOR_HEAD', "#505090");
+define('COLOR_FONT_HEAD', "#ffffff");
+
+// color for field titles
+define('COLOR_TITLE', "#303050");
+
+// color for colored row
+define('COLOR_ROW_ON', "#202020");
+
+// color for uncolored row
+define('COLOR_ROW_OFF', "#000000");
+
+// link colors
+define('COLOR_LINK', "#dddddd");
+define('COLOR_VLINK', "#999999");
+define('COLOR_ALINK', "#ffffff");
+define('COLOR_NUM_LINK', "#dddddd");
+
+?>
diff -ruN ../aero_221/themes/default.template.inc ./themes/default.template.inc
--- ../aero_221/themes/default.template.inc	2003-10-21 08:03:32.000000000 -0400
+++ ./themes/default.template.inc	2004-09-04 15:35:51.000000000 -0400
@@ -1,14 +1,14 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-    <head>
-        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-        <title>
-            AeroMail
-        </title>
-        <?php style() ?>
-    </head>
-
-    <body>
-        <?php content(); ?>
-    </body>
-</html>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+        <title>
+            <?php echo PROG_NAME ?>
+        </title>
+        <?php style() ?>
+    </head>
+
+    <body>
+        <?php content(); ?>
+    </body>
+</html>
