// cjh: put this in for 2.0 beta, but make on a per-mail basis instead of per-mailbox

######################################
### Display "To" instead of "From" ###
######################################


/* I did experience that it is quite annoying to see the From address
 * eg. in your sent mail box - you'd like to see the from address there
 * instead.
 * Well, this little patch does this.
 * The following variable definitions were added to the config file:
 *  - $default->show_to_in_sent
 *  - $default->sent_boxes	(Array)
 * eg.:
    $default->show_to_in_sent           = true;
    $default->sent_boxes                = array("sent","Mail/sent","Sent");
 * One file was added:
 * templates/mailbox.php3-message_headers-sent.inc
 * This file is base on templates/mailbox.php3-message_headers.inc
 * The only differnce is that "from" was replaced with "to".
 *
 * This solution is not ideal - I'd prefer if  this was decided on a 
 * per mail basis - ie. as pine does this. Maybe later ... (do have
 * some ideas how this could be done if an LDAP server is available ..)
 *
 * The changes below have to be applied to mailbox.php3 (ca. line 205):
*/


/* This is the original version: */
  require( "$default->include_dir/mailbox.php3-navbar1.inc");
  require( "$default->include_dir/mailbox.php3-actions.inc");
  require( "$default->include_dir/mailbox.php3-message_headers.inc");



/* The new version: *
 * These lines do simply change the file to be included
 * Additionally, a counter is initialized showing whether we are in a
 * sent mail folder. This counter will be reused later on.
*/

  require( "$default->include_dir/mailbox.php3-navbar1.inc");
  require( "$default->include_dir/mailbox.php3-actions.inc");


if  ( $default->show_to_in_sent ) {
   $is_sentbox = 0;
   while (list( $sent_count, $sent_entry ) = each( $default->sent_boxes ))
{
      if ( "$current_mbox" == "$sent_entry" ) {
          $is_sentbox = ++$is_sentbox;
      }
   }
   if ( $is_sentbox ) {
      require(
"$default->include_dir/mailbox.php3-message_headers-sent.inc");
   } else {
      require( "$default->include_dir/mailbox.php3-message_headers.inc");
   }
} else {
   require( "$default->include_dir/mailbox.php3-message_headers.inc");
}



/* Some lines below, something like the following in included in the
 * original version:
*/

    $frm = chop(htmlspecialchars(decode_mime_string($h->fromaddress)));
    $sub = chop(htmlspecialchars(decode_mime_string($h->subject)));
    $dat = chop(substr(htmlspecialchars($h->date), 0, 11));   




/* The new version follows: */


if  ( $default->show_to_in_sent ) { 
   if ( $is_sentbox ) {
      $frm = chop(htmlspecialchars(decode_mime_string($h->toaddress)));
   } else {
       $frm = chop(htmlspecialchars(decode_mime_string($h->fromaddress)));
   }   
}
    
    
$sub = chop(htmlspecialchars(decode_mime_string($h->subject)));
$dat = chop(substr(htmlspecialchars($h->date), 0, 11));   
