<?php
//****************************************************************************************
// Copyright (C) 2000 Koen de Boeve
//
// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// Version : MyPhPim-01.05
// Author : Koen de Boeve
// Contact: hide@address.com
//****************************************************************************************
include "conf/global_conf.inc";
session_start();
$db = new DB;
$html = new HtmlCl;
$form = new FormCl;
$imap = new ImapCl;
$userdata = $db->Fetch_login ( $user, $choosehost );
$login = $userdata[0];
$pass = $userdata[1];
$proto = $userdata[2];
$host = $userdata[3];
$port = $userdata[4];
$query = "SELECT user_id FROM users WHERE user='$user'";
$result = $db->query ( $query );
$user_id = $db->result ( $result, 0, "user_id" );
$html->HtmlHeader ( '','' );
$mbox = $imap->InitFolder ( $host, $port, $proto, $login, $pass, $folder);
$nummesg = $imap->nummesg ( $mbox );
$numrecent = $imap->numrecent ( $mbox );
$header = $imap->FetchHeader ( $mbox, $msgno );
$tmp = $imap->FetchHeaderData ( $header, "FROM" );
$numfrom = count ( $tmp );
$end = $numfrom - 1;
echo "<table border=0 cellspacing=0 cellpadding=0 width=100%><tr bgcolor=lightgrey><td>";
echo "<font size=-1>\n";
for ( $i = 0; $i < $numfrom; $i++ ) {
$from->address = $imap->ConvertEnc ( $from->address );
$from = $tmp[$i];
$query = "SELECT email FROM addresses WHERE email='$from->address' AND owner=$user_id";
$result = $db->query ( $query );
$numrows = $db->numrows ( $result );
if ( $numrows != 0 ) {
if ( $i == 0 ) {
echo "<b>From:</b> $from->name <a CLASS=blue href=main.php3?menu=compose&to=$from->address> <$from->address></a>\n";
if ( $i == $end ) { echo ""; }
} else if ( $i == $end ) {
echo ", $from->name <a CLASS=blue href=main.php3?menu=compose&to=$from->address> <$from->address></a>\n";
} else {
echo ", $from->name <a CLASS=blue href=main.php3?menu=compose&to=$from->address> <$from->address></a>\n";
}
} else {
if ( $i == 0 ) {
echo "<b>From:</b> $from->name <a CLASS=blue href='javascript: DoWhatWithemail ( \"$from->address\" )'> <$from->address></a>\n";
if ( $i == $end ) { echo ""; }
} else if ( $i == $end ) {
echo ", $from->name <a CLASS=blue href='javascript: DoWhatWithemail ( \"$from->address\" )'> <$from->address></a>\n";
} else {
echo ", $from->name <a CLASS=blue href='javascript: DoWhatWithemail ( \"$from->address\" )'> <$from->address></a>\n";
}
}
}
$tmp = $imap->FetchHeaderData ( $header, "TO" );
$numto = count ( $tmp );
$end = $numto - 1;
if ( $numto != 0 ) {
echo "</font></td></tr><tr bgcolor=lightgrey><td><font size=-1>";
for ( $i = 0; $i < $numto; $i++ ) {
$to->address = $imap->ConvertEnc ( $to->address );
$to = $tmp[$i];
$query = "SELECT email FROM addresses WHERE email='$to->address' AND owner=$user_id";
$result = $db->query ( $query );
$numrows = $db->numrows ( $result );
if ( $numrows != 0 ) {
if ( $i == 0 ) {
echo "<b>To: </b>$to->name <a CLASS=blue href=main.php3?menu=compose&to=$to->address> <$to->address></a>\n";
if ( $i == $end ) { echo "\n"; }
} else if ( $i == $end ) {
echo ", $to->name <a CLASS=blue href=main.php3?menu=compose&to=$to->address> <$to->address></a>\n";
} else {
echo ", $to->name <a CLASS=blue href=main.php3?menu=compose&to=$to->address> <$to->address></a>\n";
}
} else {
if ( $i == 0 ) {
echo "<b>To: </b>$to->name <a CLASS=blue href='javascript: DoWhatWithemail ( \"$to->address\" )'> <$to->address></a>\n";
if ( $i == $end ) { echo "\n"; }
} else if ( $i == $end ) {
echo ", $to->name <a CLASS=blue href='javascript: DoWhatWithemail ( \"$to->address\" )'> <$to->address></a>\n";
} else {
echo ", $to->name <a CLASS=blue href='javascript: DoWhatWithemail ( \"$to->address\" )'> <$to->address></a>\n";
}
}
}
}
$tmp = $imap->FetchHeaderData ( $header, "CC" );
$numcc = count ( $tmp );
if ( $numcc != 0 ) {
echo "</font></td></tr><tr bgcolor=lightgrey><td><font size=-1>";
$end = $numcc - 1;
for ( $i = 0; $i < $numcc; $i++ ) {
if ( is_array ( $tmp ) ) {
$cc = $tmp[$i];
} else {
$cc = $tmp;
}
$cc->address = $imap->ConvertEnc ( $cc->address );
if ( $i == 0 ) {
echo "<b>Cc: </b>$cc->name <a CLASS=blue href=main.php3?menu=compose&to=$cc->address> <$cc->address></a>\n";
if ( $i == $end ) { echo "\n"; }
} else if ( $i == $end ) {
echo ", $cc->name <a CLASS=blue href=main.php3?menu=compose&to=$cc->address> <$cc->address></a>\n";
} else {
echo ", $cc->name <a CLASS=blue href=main.php3?menu=compose&to=$cc->address> <$cc->address></a>\n";
}
}
}
$date = $imap->FetchHeaderData ( $header, "DATE" );
$subject = $imap->FetchHeaderData ( $header, "SUBJECT" );
$subject = $imap->ConvertEnc ( $subject );
$flag = $imap->FetchHeaderData ( $header, "FLAGS" );
echo "</font></td></tr><tr bgcolor=lightgrey><td><font size=-1>";
echo "<b>Date: </b>$date\n";
echo "</font></td></tr><tr bgcolor=lightgrey><td><font size=-1>";
echo "<b>Subject: </b></font><font size=-1 color=green><b>$subject</b></font>\n";
echo "</font></td></tr></table><br>";
$this_part = imap_fetchstructure ( $mbox, $msgno );
echo "<table border=0 cellspacing=0 cellpadding=0 width=100%>";
$imap->FetchParts ( $mbox, $folder, $msgno,$this_part, "1" );
echo "</table>";
$imap->close ( $mbox );
echo "<hr noshade>\n";
$html->HtmlFooter ();
?>