home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Neil's C++ Stuff
/
2002-11-php_neilstuff_com.zip
/
_qam.php
< prev
next >
Wrap
PHP Script
|
2001-02-27
|
5KB
|
229 lines
<?
global $page, $srcfile, $qsi;
$qsi = (int)$qsi;
$yr = (int)substr($page->id, 0, 4);
$mn = (int)substr($page->id, 4, 2);
if ($mn == 1)
$month = 'January';
else if ($mn == 2)
$month = 'February';
else if ($mn == 3)
$month = 'March';
else if ($mn == 4)
$month = 'April';
else if ($mn == 5)
$month = 'May';
else if ($mn == 6)
$month = 'June';
else if ($mn == 7)
$month = 'July';
else if ($mn == 8)
$month = 'August';
else if ($mn == 9)
$month = 'September';
else if ($mn == 10)
$month = 'October';
else if ($mn == 11)
$month = 'November';
else
$month = 'December';
$title = $month . ' ' . $yr . ' Mail';
class Message
{
var $iDay, $iHour, $iMinute;
var $sSubject;
var $sFrom;
var $sDate;
var $aText;
var $aType;
var $iLen;
function Message()
{
$this->aText = array();
$this->aType = array();
$this->iLen = 0;
}
}
$fp = @fopen($srcfile, "r");
if ($fp == false || $fp == null)
{
echo('Could not find mail archive for ' . $month . ' ' . $yr);
exit;
}
$i = -1;
$stat = -1;
$msg = array();
while (feof($fp) == false)
{
$line = fgets($fp, 4096);
if (substr($line,0,2) == '_[')
{
if ($stat == 3)
{
$msg[$i]->iLen++;
}
$i++;
$stat = 0;
$msg[$i] = new Message;
if ($line[2] == '0')
$msg[$i]->iDay = (int)$line[3];
else
$msg[$i]->iDay = (int)substr($line,2,2);
if ($line[5] == '0')
$msg[$i]->iHour = (int)$line[6];
else
$msg[$i]->iHour = (int)substr($line,5,2);
if ($line[8] == '0')
$msg[$i]->iMinute = (int)$line[9];
else
$msg[$i]->iMinute = (int)substr($line,8,2);
$m =& $msg[$i];
$m->sDate = $month . ' ' . $m->iDay;
if ($m->iDay == 1 || $m->iDay == 21 || $m->iDay == 31)
$m->sDate .= 'st';
else if ($m->iDay == 2 || $m->iDay == 22)
$m->sDate .= 'nd';
else if ($m->iDay == 3 || $m->iDay == 23)
$m->sDate .= 'rd';
else
$m->sDate .= 'th';
$m->sDate .= ', ' . $yr . ' / ';
if ($m->iHour > 12)
$m->sDate .= ($m->iHour-12);
else
$m->sDate .= $m->iHour;
$m->sDate .= ':';
if ($m->iMinute < 10)
$m->sDate .= '0';
$m->sDate .= $m->iMinute;
if ($m->iHour > 12)
$m->sDate .= 'pm';
else
$m->sDate .= 'am';
unset($m);
}
else if ($stat == 0)
{
$msg[$i]->sFrom = $line;
$stat = 1;
}
else if ($stat == 1)
{
$msg[$i]->sSubject = $line;
$stat = 2;
}
else if ($stat == 2 && substr($line,0,5) == '--q--')
{
$txt = '';
$stat = 3;
$msg[$i]->aType[$msg[$i]->iLen] = 'q';
$msg[$i]->aText[$msg[$i]->iLen] = '';
}
else if ($stat == 2 && substr($line,0,5) == '--a--')
{
$txt = '';
$stat = 3;
$msg[$i]->aType[$msg[$i]->iLen] = 'a';
$msg[$i]->aText[$msg[$i]->iLen] = '';
}
else if ($stat == 3)
{
if (substr($line,0,5) == '--a--')
{
$msg[$i]->iLen++;
$msg[$i]->aType[$msg[$i]->iLen] = 'a';
$msg[$i]->aText[$msg[$i]->iLen] = '';
}
else if (substr($line,0,5) == '--q--')
{
$msg[$i]->iLen++;
$msg[$i]->aType[$msg[$i]->iLen] = 'q';
$msg[$i]->aText[$msg[$i]->iLen] = '';
}
else
{
$msg[$i]->aText[$msg[$i]->iLen] .= str_replace(' ', ' ', str_replace(' ', ' ', htmlspecialchars($line))) . '<BR>';
}
}
//else
//{
// echo('ignoring "' . $line . '" (' . $stat . ')<BR>');
//}
}
fclose($fp);
echo('All "conversations" are broken into single blocks. The date shown is when I first received an email. The messages of the people writing me are in bold (i.e. "questions") and my answers are in plain text.<BR><BR>');
echo('<UL>');
if ($qsi > count($msg))
$qsi = 0;
$max = $qsi + 10;
if ($max > count($msg))
$max = count($msg);
for ($i = 0; $i < $qsi; $i += 10)
{
echo('<LI><A HREF="' . me() . '&qsi=' . $i . '">Page ' . (($i/10)+1) . '</A>');
}
for ($i = $qsi; $i < $max; $i++)
{
$m =& $msg[$i];
echo('<LI>' . $m->sDate . ' <A HREF="#' . $m->iDay . '.' . $m->iHour . '.' . $m->iMinute . '">' . $m->sSubject . '</A>');
unset($m);
}
for ($i = $qsi + 10; $i < count($msg); $i += 10)
{
echo('<LI><A HREF="' . me() . '&qsi=' . $i . '">Page ' . (($i/10)+1) . '</A>');
}
echo('</UL>');
for ($i = $qsi; $i < $max; $i++)
{
$m =& $msg[$i];
echo('<A NAME="' . $m->iDay . '.' . $m->iHour . '.' . $m->iMinute . '"></A><TABLE BGCOLOR=C0C0C0 BORDER=2 WIDTH=100% CELLSPACING=0 CELLPADDING=2><TR><TD COLSPAN=3 BGCOLOR=7F7FFF ALIGN=CENTER><FONT FACE="Primer Print" COLOR=000000 SIZE=+3><B>' . $m->sSubject . '</B></FONT></TD></TR>');
for ($x = 0; $x < count($m->aType); $x++)
{
if ($m->aType[$x] == 'q')
{
echo('<TR><TD BGCOLOR=C0C0C0 COLSPAN=3 ALIGN=LEFT><CODE><B>' . $m->aText[$x] . '</B></CODE></TD></TR>');
}
else
{
echo('<TR><TD BGCOLOR=C0C0C0 COLSPAN=3 ALIGN=LEFT><CODE>' . $m->aText[$x] . '</CODE></TD></TR>');
}
}
echo('<TR><TD ALIGN=CENTER BGCOLOR=C0C0C0>' . rndilnk() . '</TD><TD ALIGN=LEFT WIDTH=100% BGCOLOR=C0C0C0><FONT FACE="MS Sans Serif, Arial" SIZE=-2>' . $m->sDate . '</FONT></TD><TD ALIGN=RIGHT BGCOLOR=C0C0C0><IMG SRC="gfx/table/cornpull.gif"></TD></TR></TABLE><BR>');
unset($m);
}
?>