Update of /cvsroot/meshdb/src/mailt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27166 Modified Files: Tag: leonard-dev mail.inc subjects.php util.c util.h view.c Added Files: Tag: leonard-dev style.css Log Message: A fairly large overhaul of the mail system. * added a sample style.css sheet * introduced lots of HTML class attributes (for css) * refactored the PHP so it is easier to maintain * corrected the way findhdr() is used --- NEW FILE: style.css --- body { color: black; background: white; font-family: sans-serif; } a:hover { background: #d0d0ff; } table.header { border: thin black solid; } table.header .email { font-family: monospace; font-style: italic; } span.indent1 { color: #004000; } span.indent2 { color: #004040; } span.indent3 { color: #000040; } span.indent4 { color: #400040; } span.indent5 { color: #400000; } span.indent6 { color: #404000; } table.envelope { background: #f0fff0; border-collapse: collapse; } table.envelope th { border-right: thin green solid; text-align: right; } table.envelope th , table.envelope td { vertical-align: top; } div.navigation, p.killed, p.messageid { font-size: smaller; } div.navigation a:hover { background: #d0d0ff; } div.navigation a, div.navigation span { padding-left: 1ex; padding-right: 1ex; } div.navigation a { border: thin blue solid; text-decoration: none; } div.navigation span { border: thin #c0c0c0 solid; color: grey } div.navigation { padding-bottom: 1ex; } pre { border-top: thin solid #c0c0c0; border-bottom: thin solid #c0c0c0; } p.killed, p.messageid { padding-left: 1ex; padding-right: 1ex; } p.killed { background: #ffd0d0; border: thin red solid; } p.messageid { background: #d0d0d0; border: thin black solid; } ul.thread { font-size: small; } ul.thread .shortdate { font-size: smaller; } ul.thread .author { font-style: italic; } /* The calendar group */ div.calendar { display: block; float: right; text-align: center; } /* The year-month index */ table.bymonth { font-size: xx-small; border-collapse: collapse; background: #e8e8ff; border: 1px #c0c0e0 solid; color: grey; } table.bymonth td { padding: 0 0 0 0.5ex ; } table.bymonth th { padding: 0 0.5ex 0 0; border-right: 1px #c0c0e0 solid; } table.bymonth a { text-decoration: none; } /* The day calendar */ table.byday { background: #f0f0f0; border: none; border-collapse: collapse; } table.byday td { vertical-align: top; } table.onemonth { font-size: x-small; border: thin solid white; border-collapse: collapse; } table.onemonth td { padding: 0 0 0 0; text-align: right } table.onemonth th { font-weight: normal; padding: 0 0 0 0; } table.onemonth tr.nav { background: #e8e8e8; } table.onemonth tr.weekday { background: #e0e0e0; } table.onemonth a { text-decoration: none; } table.onemonth td.mark { background: yellow; } table.onemonth td.dimmed { color: white; } table.onemonth td a:hover { background: blue; color: white; } /* The title */ h1 { font-size: 120%; background: #f8f8f8; border-bottom: thin solid #e0e0e0; border-top: thin solid #e0e0e0; } Index: mail.inc =================================================================== RCS file: /cvsroot/meshdb/src/mailt/mail.inc,v retrieving revision 1.1.1.1.2.1 retrieving revision 1.1.1.1.2.2 diff -u -d -r1.1.1.1.2.1 -r1.1.1.1.2.2 --- mail.inc 8 Nov 2004 12:55:34 -0000 1.1.1.1.2.1 +++ mail.inc 1 May 2005 12:28:27 -0000 1.1.1.1.2.2 @@ -8,11 +8,11 @@ * program reports, ideally when it is run on the same host * as the web server. */ - $FMT = "Lhdrlen/Lbodylen/Lpos/Ldate/a40from" - ."/a60subject/Lparent/Lchild/Lsibling/Lflags"; - $FMT0 = "Lsize/Lversion/Lend/Ldate/a40ign4" - ."/a60ign5/Lmsgs/Lchild/Lign8/Lflags"; - $FMTSZ = 132; + $FMT = "Lhdrlen/Lbodylen/Lposhi/Lposlo/Ldate/a40from" + ."/a60subject/Lparent/Lchild/Lsibling/nflags"; + $FMT0 = "Lsize/Lversion/Lendhi/Lendlo/Ldate/a40ign4" + ."/a60ign5/Lmsgs/Lchild/Lign8/nflags"; + $FMTSZ = 136; $KILLED = 1; /* off_t is a 64-bit value. (php probably doesnt handle it) */ @@ -52,8 +52,11 @@ function getmsg($o, $i) { global $FMT, $FMT0, $FMTSZ; $i = intval($i); - if ($i < 1 || $i >= $o["m0"]["msgs"]) - die("bad message ID ".$i); + if ($i < 1 || $i >= $o["m0"]["msgs"]) { + $bt = debug_backtrace(); + die("bad message ID ".$i." from " + .($bt[0]["file"]).":".($bt[0]["line"])); + } $m = unpack($FMT, substr($o["idx"], $FMTSZ * $i, $FMTSZ)); /* $m["pos"] = quad($m["poslo"], $m["poshi"]); */ $m["o"] = $o; Index: subjects.php =================================================================== RCS file: /cvsroot/meshdb/src/mailt/subjects.php,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -d -r1.2.2.1 -r1.2.2.2 --- subjects.php 8 Nov 2004 13:21:26 -0000 1.2.2.1 +++ subjects.php 1 May 2005 12:28:27 -0000 1.2.2.2 @@ -1,264 +1,350 @@ -<html> -<body> -<h1>Mail archive index</h1> <? - /* $Id$ */ + +/* $Id$ */ include("mail.inc"); +$title = "Subject index"; $self = "subjects.php"; -$viewcgi = "../cgi-bin/view-list.cgi"; +#$viewcgi = "../cgi-bin/view-list.cgi"; $viewcgi = "msg"; # relies on a .htaccess file to redirect - $o = openmbox("mbox"); $msgs = $o["msgs"]; -?> - -<h1>Messages by month</h1> -<table> -<? -$MONTHS = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); $first_m = getmsg($o, 1); $last_m = getmsg($o, $msgs - 1); -$first_t = localtime($first_m["date"], true); -$last_t = localtime($last_m["date"] + 1, true); -for ($y = $first_t["tm_year"]; $y <= $last_t["tm_year"]; $y++) { - $s = sprintf("%04d%02d%02d", $y+1900, 1, 1); - $f = sprintf("%04d%02d%02d", $y+1900+1, 1, 0); -?> - <tr><th><a href="<?="$self?$s-$f"?>"><?=$y+1900?></a></th> -<? - for ($m = 0; $m < 12; $m++) { - echo "<td>"; - $havemail = false; - $t1 = mktime(0,0,0,$m+1,1,$y); - $i = findmsgbydate($o, $t1); /* Find first mail after that date */ - $havemail = false; - while ($i < $msgs) { /* Skip killed msgs at start of month */ - $msg = getmsg($o, $i); - if (iskilled($m)) - $i++; - else - break; - } - if ($i < $msgs) { /* Check first mail within the month */ - $msg_t = localtime($msg["date"], true); - if ($msg_t["tm_mon"] == $m) - $havemail = true; +/* Helper functions: */ + +/* Recursively prints the subject tree for messages in the range [ilo,ihi) */ +function echomsgtree($o, $i, $ilo, $ihi, $dosib) { + global $o, $viewcgi; + $m = getmsg($o, $i); + print "<li id=\"m$i\">" + ."<span class=\"shortdate\">" + .strftime("%e %b", $m["date"]) + ."</span> " + ."<span class=\"author\">" + .htmlspecialchars($m["from"]) + ."</span> " + ."<a class=\"subject\" href=\"$viewcgi/$i\">" + .htmlspecialchars($m["subject"]) + ."</a>" + ."</li>\n"; + $c = $m["child"]; + if ($c && $ilo <= $c && $c < $ihi) { + print "<ul>\n"; + echomsgtree($o, $c, $ilo, $ihi, 1); + print "</ul>\n"; + } + if ($dosib) { + $s = $m["sibling"]; + if ($s && $ilo <= $s && $s < $ihi) + echomsgtree($o, $s, $ilo, $ihi, 1); + } +} + +/* Prints an entire messae tree */ +function show_message_tree($start_t, $finish_t) { + global $o; + /* Show message threads, within the date range */ + $ilo = findmsgbydate($o, $start_t); + $ihi = findmsgbydate($o, $finish_t); + print "<ul class=\"thread\">\n"; + for ($i = $ilo; $i < $ihi; $i++) { + $m = getmsg($o, $i); + if (iskilled($m)) continue; + $pi = $m["parent"]; + if ($pi) { + $mp = getmsg($o, $pi); + if ($mp["date"] < $start_t) + $pi = 0; } - if ($havemail) { - $s = sprintf("%04d%02d%02d", $y+1900, $m+1, 1); - $f = sprintf("%04d%02d%02d", $y+1900, $m+2, 0); - echo "<a href=\"$self?$s-$f\">".$MONTHS[$m]."</a>"; - } else - echo $MONTHS[$m]; - echo "</td>"; + if ($pi == 0) + echomsgtree($o, $i, $ilo, $ihi, 0); } -?> - </tr> -<? } ?> -</table> + print "</ul>\n"; +} -<? +/* + * Convert a date of the form "YYYYMMDD" into a time_t. + * Special times of the form ".NNN" return the time_t of a single message. + */ +function parsetime($t) { + global $o; + if (substr($t, 0, 1) == ".") { + $id = intval(substr($t, 1)); + $m = getmsg($o, $id); + if ($m) + return $m["date"]; + die("invalid message id $t"); + } - /* function to recursively print a thread */ - function echomsgtree($o, $i, $ilo, $ihi, $dosib) { - global $KILLED, $viewcgi; - $m = getmsg($o, $i); - echo "<li id=\"m$i\"> ".strftime("%e %b", $m["date"]). " ". - htmlspecialchars($m["from"]).", ". - "<a href=\"$viewcgi/$i\">". - htmlspecialchars($m["subject"]). - "</a>". - "</li>\n"; - $c = $m["child"]; - if ($c && $ilo <= $c && $c < $ihi) { - echo "<ul>\n"; - echomsgtree($o, $c, $ilo, $ihi, 1); - echo "</ul>\n"; - } - if ($dosib) { - $s = $m["sibling"]; - if ($s && $ilo <= $s && $s < $ihi) - echomsgtree($o, $s, $ilo, $ihi, 1); - } - } + return mktime(0,0,0, + intval(substr($t, 4, 2)), + intval(substr($t, 6, 2)), + intval(substr($t, 0, 4)), + -1); +} - function parsetime($t) { - if (substr($t, 0, 1) == ".") { - global $o; - $id = intval(substr($t, 1)); - $m = getmsg($o, $id); - if ($m) - return $m["date"]; - die("invalid message id $t"); - } +/* + * Generate a 'Year/Month' table, that shows the span of the entire + * archive. It looks like this: + * + * 2004 Jan Feb Mar Apr May Jun Aug Sep Oct Nov Dec + * 2005 Jan Feb Mar Apr May Jun Aug Sep Oct Nov Dec + * 2006 Jan Feb Mar Apr May Jun Aug Sep Oct Nov Dec + * + * We make the month names and year numbers hyperlinks to display + * month-only or year-only ranges, respectively. + */ +function show_bymonth_table() +{ + global $o, $last_m, $first_m, $msgs; - return mktime(0,0,0, - intval(substr($t, 4, 2)), - intval(substr($t, 6, 2)), - intval(substr($t, 0, 4)), - -1); - } + $MONTHS = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); - /* - * figure out the range of dates to display, query string is - * of the found [YYYYMMDD]-[YYYYMMDD] - */ + /* Determine the dates of the first and last messages in + * the entire archive */ + $first_t = localtime($first_m["date"], true); + $last_t = localtime($last_m["date"] + 1, true); - if ($_SERVER[QUERY_STRING] == "") { - $start_t = mktime(0,0,0,date("m"), 1, date("Y")); - $finish_t= mktime(0,0,0,date("m")+1, 1, date("Y")) - 1; - } else { - list($start, $finish) = explode("-", $_SERVER[QUERY_STRING], 2); + print "<table class=\"bymonth\">\n"; + for ($y = $first_t["tm_year"]; $y <= $last_t["tm_year"]; $y++) { + print "<tr>"; - if ($start == "") $start_t = $first_m["date"]; - else $start_t = parsetime($start); + /* The year portion */ + $year = $y + 1900; + $s = sprintf("%04d%02d%02d", $year, 1, 1); + $f = sprintf("%04d%02d%02d", $year+1, 1, 0); + $yearuri = "$self?$s-$f"; + print "<th><a href=\"$yearuri\">$year</a></th>\n" ; - if ($finish == "") $finish_t = $last_m["date"] + 1; - else $finish_t = parsetime($finish) - + 24*60*60 - 1; - } + for ($m = 0; $m < 12; $m++) { + /* The month portion - find when it starts */ + $monthname = $MONTHS[$m]; + $t1 = mktime(0,0,0,$m+1,1,$y); + $i = findmsgbydate($o, $t1); -?> - <h1>Messages from <?=strftime("%a %b %e %Y", $start_t)?> - - <?=strftime("%a %b %e %Y", $finish_t - 1)?></h1> + /* Skip killed msgs at start of month */ + while ($i < $msgs) { + $msg = getmsg($o, $i); + if (iskilled($m)) + $i++; + else + break; + } + /* Are there any messages inside this month range? */ + $havemail = false; + if ($i < $msgs) { /* Check first mail within the month */ + $msg_t = localtime($msg["date"], true); + if ($msg_t["tm_mon"] == $m) + $havemail = true; + } -<? - /* print a month table */ + /* Print the month name, and hyperlink if it has content */ + print "<td>"; + if ($havemail) { + $s = sprintf("%04d%02d%02d", $y+1900, $m+1, 1); + $f = sprintf("%04d%02d%02d", $y+1900, $m+2, 0); + $monthuri = "$self?$s-$f"; + print "<a href=\"$monthuri\">$monthname</a>"; + } else + print $monthname; + print "</td>\n"; + } /* for $m */ + print "</tr>\n"; + } /* for $y */ + print "</table>\n"; +} - $endmonth = date("n", $finish_t); - $endyear = date("Y", $finish_t); - $nmonths = 0; +/* + * Print a table of month tables, each month showing the days + * in that month, hyperlinked to the URI which displays just that day. + */ +function show_byday_table($start_t, $finish_t) +{ + global $o; + $endmonth = date("n", $finish_t); + $endyear = date("Y", $finish_t); + $nmonths = 0; + $month = date("n", $start_t); + $year = date("Y", $start_t); - $month = date("n", $start_t); - $year = date("Y", $start_t); + $NCOLS = 4; - $NCOLS = 4; + while (1) { + if ($year > $endyear || + ($year == $endyear && $month > $endmonth)) + break; - while (1) { - if ($year > $endyear || - ($year == $endyear && $month > $endmonth)) - break; + $tlo = mktime(0,0,0,$month,1,$year-1900); + $thi = mktime(0,0,0,$month+1,1,$year-1900); + $ilo = findmsgbydate($o, $tlo); + $ihi = findmsgbydate($o, $thi); - $tlo = mktime(0,0,0,$month,1,$year-1900); - $thi = mktime(0,0,0,$month+1,1,$year-1900); - $ilo = findmsgbydate($o, $tlo); - $ihi = findmsgbydate($o, $thi); + /* The month range */ + $s = sprintf("%04d%02d%02d", $year, $month, 1); + $f = sprintf("%04d%02d%02d", $year, $month+1, 0); + /* Compute URIs for the month navigation */ + $prev_month_uri = "$self?" . sprintf("%04d%02d01-%04d%02d00", + $month == 1 ? $year - 1 : $year, + $month == 1 ? 12 : $month - 1, + $year, + $month); + $this_month_uri = "$self?$s-$f"; + $this_month_name = strftime("%b", $tlo); + $this_year_uri = "$self?" . sprintf("%04d0101-%04d0100", + $year, $year + 1); + $next_month_uri = "$self?".sprintf("%04d%02d01-%04d%02d00", + $year, $month + 1, $year,$month + 2); - if ($nmonths == 0) - echo "<table border>"; - if ($nmonths % $NCOLS == 0) - echo "<tr>"; + if ($nmonths == 0) echo "<table class=\"byday\">"; + if ($nmonths % $NCOLS == 0) echo "<tr>"; - $s = sprintf("%04d%02d%02d", $year, $month, 1); - $f = sprintf("%04d%02d%02d", $year, $month+1, 0); -?> -<td> -<table> - <tr> - <td><a href="<?="$self?".sprintf("%04d%02d01-%04d%02d00", - $month == 1 ? $year - 1 : $year, $month == 1 ? 12 : $month - 1, - $year, $month)?>" - ><</a></td> - <th colspan=5><a href="<?="$self?$s-$f"?>"><?=strftime("%b", $tlo)?></a> <a href="<?="$self?".sprintf("%04d0101-%04d0100", $year, $year+1)?>"><?=$year?></a></th> - <td><a href="<?="$self?".sprintf("%04d%02d01-%04d%02d00", - $year, $month+1, $year,$month+2)?>">></a></td> - </tr> - <tr><th>Su</th><th>Mo</th><th>Tu</th><th>We</th> - <th>Th</th><th>Fr</th><th>Sa</th></tr> -<? + /* Print the month navigation links */ + print "<td><table class=\"onemonth\"><tr class=\"nav\">"; + print "<th><a href=\"$prev_month_uri\"><</a></th>"; /* Prev month */ + print "<th colspan=5>" + ."<a href=\"$this_month_uri\">" /* This month */ + .$this_month_name + ."</a> " + ."<a href=\"$this_year_uri\">$year</a>" /* This year */ + ."</th>"; + print "<th><a href=\"$next_month_uri\">></a></th>"; /* Next month */ + + print "</tr>"; + + /* Print the day-of-the-week headings */ + print "<tr class=\"weekday\">"; + foreach(array("Su","Mo","Tu","We","Th","Fr","Sa") as $dayname) + print "<th>$dayname</th>"; + + /* Print the current-month calendar */ $wkday = 0; $ti = $ilo; if ($ti < $o["msgs"]) - $mi = getmsg($o, $ti); + $mi = getmsg($o, $ti); else - $mi = ""; + $mi = ""; for ($day = 1; $day < 32; $day++) { - $t = mktime(0,0,0,$month,$day+1,$year-1900)-1; - $ta = localtime($t, true); - if ($ta["tm_mon"] != $month - 1) - break; - $count = 0; - while ($ti < $o["msgs"] && $mi["date"] <= $t) { - if (!iskilled($mi)) - $count++; - $ti++; - if ($ti < $o["msgs"]) - $mi = getmsg($o, $ti); - } - if ($wkday == 7) { echo "</tr>"; $wkday = 0; } - if ($wkday == 0) echo "<tr>"; - while ($ta["tm_wday"] != $wkday) { - echo "<td></td>"; - $wkday++; - } - if ($start_t <= $t && $t <= $finish_t) - $dim = " class=\"dimmed\""; - else - $dim = ""; - if ($count) { - $s = $f = sprintf("%04d%02d%02d", $year, $month, $day); - echo "<td$dim><a href=\"$self?$s-$f\">$day</a></td>"; - } else - echo "<td$dim>$day</td>"; + $t = mktime(0,0,0,$month,$day+1,$year-1900)-1; + $ta = localtime($t, true); + + /* Break now if this is the wrong month */ + if ($ta["tm_mon"] != $month - 1) + break; + + /* Count the number of messages in the current day */ + $count = 0; + while ($ti < $o["msgs"] && $mi["date"] <= $t) { + if (!iskilled($mi)) + $count++; + $ti++; + if ($ti < $o["msgs"]) + $mi = getmsg($o, $ti); + } + + /* End/start a new row if necessary */ + if ($wkday == 7) $wkday = 0; + if ($wkday == 0) echo "</tr><tr>"; + while ($ta["tm_wday"] != $wkday) { + echo "<td></td>"; $wkday++; + } + + /* Dim the cell if it is outside the range */ + /* if ($start_t <= $t && $t <= $finish_t) + print "<td class=\"dimmed\">"; */ + + if ($count) + print "<td class=\"mark\">"; + else + print "<td>"; + + /* Print a link to show the day's mail, if there are any */ + if ($count) { + $s = $f = sprintf("%04d%02d%02d", $year, $month, $day); + echo "<a href=\"$self?$s-$f\">$day</a>"; + } else + echo "$day"; + + print "</td>"; + $wkday++; } + /* Finish off the month table */ while ($wkday < 7) { - echo "<td></td>"; - $wkday++; + echo "<td></td>"; + $wkday++; } - echo "</tr>\n"; -?> -</table> -</td> -<? - $month++; - if ($month == 13) { - $year++; - $month = 1; - } + echo "</tr></table></td>\n"; - $nmonths++; - if ($nmonths % $NCOLS == 0) - echo "</tr>"; + /* Try the next month */ + $month++; + if ($month == 13) { + $year++; + $month = 1; } - while ($nmonths > $NCOLS && $nmonths % $NCOLS != 0) { - echo "<td></td>"; - $nmonths++; - if ($nmonths % $NCOLS == 0) - echo "</tr>"; - } - if ($nmonths) - echo "</table>"; + $nmonths++; + if ($nmonths % $NCOLS == 0) + echo "</tr>"; + } -?> + /* Finish off the table-of-months table */ + while ($nmonths > $NCOLS && $nmonths % $NCOLS != 0) { + echo "<td></td>"; + $nmonths++; + if ($nmonths % $NCOLS == 0) + echo "</tr>"; + } + if ($nmonths) + echo "</table>"; +} -<ul> -<? - /* Show message threads, within the date range */ - $ilo = findmsgbydate($o, $start_t); - $ihi = findmsgbydate($o, $finish_t); - for ($i = $ilo; $i < $ihi; $i++) { - $m = getmsg($o, $i); - if (iskilled($m)) - continue; - $pi = $m["parent"]; - if ($pi) { - $mp = getmsg($o, $pi); - if ($mp["date"] < $start_t) - $pi = 0; - } - if ($pi == 0) - echomsgtree($o, $i, $ilo, $ihi, 0); - } +/* + * Figure out the range of dates the user wants displayed. + * The QUERY_STING should be of the form [YYYYMMDD]-[YYYYMMDD] + */ +if ($_SERVER[QUERY_STRING] == "") { + $start_t = mktime(0,0,0,date("m"), 1, date("Y")); + $finish_t= mktime(0,0,0,date("m")+1, 1, date("Y")) - 1; +} else { + list($start, $finish) = explode("-", $_SERVER[QUERY_STRING], 2); + + if ($start == "") $start_t = $first_m["date"]; + else $start_t = parsetime($start); + + if ($finish == "") { + if (substr($start, 0, 1) == ".") { + $start_t = mktime(0,0,0,date("m",$start_t), 1, date("Y",$start_t)); + $finish_t= mktime(0,0,0,date("m",$start_t)+1, 1, date("Y",$start_t)) - 1; + } else + $finish_t = $last_m["date"] + 1; + } else + $finish_t = parsetime($finish) + 24*60*60 - 1; +} + +/* ------------------------------------------------------------ */ ?> -</ul> +<html> +<head> + <title><?=htmlspecialchars($title)?></title> + <link rel="stylesheet" href="style.css" type="text/css"> +</head> +<body> + +<div class="calendar"> +<? show_bymonth_table(); ?> +<? show_byday_table($start_t, $finish_t); ?> +</div> + +<h1><?=strftime("%a %b %e %Y", $start_t)?> + — + <?=strftime("%a %b %e %Y", $finish_t - 1)?></h1> +<? show_message_tree($start_t, $finish_t); ?> <hr> <small>mailt by David Leonard</small> Index: util.c =================================================================== RCS file: /cvsroot/meshdb/src/mailt/util.c,v retrieving revision 1.1.1.1.2.2 retrieving revision 1.1.1.1.2.3 diff -u -d -r1.1.1.1.2.2 -r1.1.1.1.2.3 --- util.c 8 Nov 2004 13:31:20 -0000 1.1.1.1.2.2 +++ util.c 1 May 2005 12:28:27 -0000 1.1.1.1.2.3 @@ -150,7 +150,7 @@ } /* Find occurrence of a header, starting the seach at the given position */ -cstring_t +int findhdr(p, end, name, startp, endp) cstring_t p, end, name, *startp, *endp; { @@ -177,11 +177,11 @@ if (e < end && *n == '\0' && *e == ':') { *startp = e + 1; *endp = p; - return p; /* matched */ + return 1; /* matched */ } } *startp = *endp = NULL; - return p; + return 0; } /* Find first matching header */ @@ -191,8 +191,8 @@ cstring_t mbox; cstring_t name, *startp, *endp; { - findhdr(mbox + m->pos, mbox + m->pos + m->hdrlen, name, startp, endp); - return (*startp != NULL); + return findhdr(mbox + m->pos, mbox + m->pos + m->hdrlen, + name, startp, endp); } /* Extract a Message-ID, <blah>, from a header. Return next p or NULL */ Index: util.h =================================================================== RCS file: /cvsroot/meshdb/src/mailt/util.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.2.1 diff -u -d -r1.1.1.1 -r1.1.1.1.2.1 --- util.h 10 Aug 2002 03:45:14 -0000 1.1.1.1 +++ util.h 1 May 2005 12:28:27 -0000 1.1.1.1.2.1 @@ -1,7 +1,7 @@ /* $Id$ */ void fromname(cstring_t, cstring_t, cstring_t *, cstring_t *); int msgideq(cstring_t, cstring_t, cstring_t, cstring_t); -cstring_t findhdr(cstring_t, cstring_t, cstring_t, cstring_t *, cstring_t *); +int findhdr(cstring_t, cstring_t, cstring_t, cstring_t *, cstring_t *); int find1hdr(struct mail *, cstring_t, cstring_t, cstring_t *, cstring_t *); cstring_t msgid(cstring_t, cstring_t, cstring_t *, cstring_t *); int check_reply_tree(struct mail *, msgid_t, off_t max); Index: view.c =================================================================== RCS file: /cvsroot/meshdb/src/mailt/view.c,v retrieving revision 1.4.2.1 retrieving revision 1.4.2.2 diff -u -d -r1.4.2.1 -r1.4.2.2 --- view.c 8 Nov 2004 12:55:34 -0000 1.4.2.1 +++ view.c 1 May 2005 12:28:27 -0000 1.4.2.2 @@ -113,7 +113,7 @@ printf("</a>"); p = u - 1; } else if (c > '~') - printf("<i>\\x%02x</i>", c); + printf("<span class=\"hex\">\\x%02x</span>", c); else putchar(c); } @@ -333,43 +333,43 @@ if (id == 0) return; - printf("<LI>"); + printf("<li>"); /* printf("<SPAN CLASS=seqno>[%lu]</SPAN> ", id); */ if (id != displayed) - printf("<A HREF=\"%lu\">", id); + printf("<a href=\"%lu\" class=\"subject\">", id); else - printf("<SPAN CLASS=current>"); + printf("<span class=\"current subject\">"); printesc(o->m[id].subject, o->m[id].subject + strlen(o->m[id].subject)); if (id != displayed) - printf("</A>"); + printf("</a>"); else - printf("</SPAN>"); - printf(", <SPAN CLASS=email>"); + printf("</span>"); + printf(" <span class=\"author\">"); printesc(o->m[id].from, o->m[id].from + strlen(o->m[id].from)); - printf("</SPAN>"); + printf("</span>"); strftime(when, sizeof when, "%e%b%y", localtime(&o->m[id].date)); - printf(", <SPAN CLASS=shortdate>%s</SPAN> ", when); + printf(" <span class=\"shortdate\">%s</span> ", when); if (o->m[id].child) { if (nochld) { int replies = counttree(o, o->m[id].child); - printf("<SPAN CLASS=replies>["); + printf("<span class=\"replies\">"); if (replies == 1) printf("1 reply"); else printf("%u replies", replies); - printf("]</SPAN>"); + printf("</span>"); } else { - printf("<UL>\n"); + printf("<ul>\n"); print_threadlist(o, o->m[id].child, displayed, 0, 0); - printf("</UL>\n"); + printf("</ul>\n"); } } - printf("</LI>\n"); + printf("</li>\n"); if (!nosib && o->m[id].sibling) print_threadlist(o, o->m[id].sibling, displayed, 0, 0); @@ -425,9 +425,9 @@ isplain = 1; if (isplain) { - printf("<PRE WRAP=AUTO>"); + printf("<pre wrap=\"auto\">"); printescqp(bs, pe, isqp(ps, bs)); - printf("</PRE>\n"); + printf("</pre>\n"); } else if (bdry2) { showmixed(v2, ps, pe, &c, id); } else { @@ -474,31 +474,46 @@ isplain = 1; if (isplain) { - printf("<PRE WRAP=AUTO>"); + printf("<pre wrap=\"auto\">"); printescqp(bs, pe, isqp(ps, bs)); - printf("</PRE>\n"); + printf("</pre>\n"); shown = index; break; } } - printf("<P>Unshown multiparts:</P><UL>"); + printf("<div class=\"multiparts\"><p>Unshown multiparts:</p><ul>"); for (index = 1; getpart(b, e, bdry, index, &ps, &pe); index++) { cstring_t bs = find_bodystart(ps, pe); cstring_t hstart, hend; if (index == shown) continue; - printf("<LI>%u. <A HREF=\"%lu/%u\">", index, id, index); + printf("<li>%u. <a href=\"%lu/%u\">", index, id, index); if (findhdr(ps, bs, "content-type", &hstart, &hend)) printesc(hstart, hend); else printf("text/plain"); - printf("</A></LI>\n"); + printf("</a></li>\n"); } - printf("</UL>\n"); + printf("</ul></div>\n"); } +/* Prints a navigation bar */ +static void +navigation(o, id, prev, next) + struct open *o; + msgid_t id, prev, next; +{ + printf("<div class=\"navigation\">"); + if (prev) printf("<a class=\"prev\" href=\"%lu\">prev</a>", prev); + else printf("<span class=\"prev\">prev</span>"); + printf(" <a class=\"index\" href=\"%s%s?.%lu#m%lu\">index</a> ", + relpath, indexfile, id, id); + if (next) printf("<a class=\"next\" href=\"%lu\">next</a>", next); + else printf("<span class=\"next\">next</span>"); + printf("</div>\n"); +} /* Nice view of the document with HTML links */ static void nice_view(o, id) @@ -515,8 +530,8 @@ m = o->m + id; printf("Content-type: text/html\n\n"); - printf("<HTML><HEAD><REL LINK=STYLESHEET" - " TYPE=\"text/css\" HREF=\"../%s/style.css\">", relpath); + printf("<html><head><link rel=\"stylesheet\"" + " type=\"text/css\" href=\"%sstyle.css\">", relpath); if (!killed) { /* Start is the most distant ancestor */ @@ -529,63 +544,53 @@ prev = findprev(o, id); if (prev) - printf("<REL LINK=PREV HREF=\"%lu\">", prev); + printf("<link rel=\"prev\" href=\"%lu\">", prev); if (next) - printf("<REL LINK=NEXT HREF=\"%lu\">", next); + printf("<link rel=\"next\" href=\"%lu\">", next); if (start) - printf("<REL LINK=START HREF=\"%lu\">", start); + printf("<link rel=\"start\" href=\"%lu\">", start); } - printf("<TITLE>"); + printf("<title>"); /* printf("[%lu] ", id); */ printesc(m->subject, m->subject + strlen(m->subject)); - printf("</TITLE></HEAD>\n"); + printf("</title></head>\n"); - printf("<BODY>"); + printf("<body class=\"message\">"); if (killed) - printf("<P><STRONG>Message killed</STRONG></P>\n"); - else { - printf("<P>["); - if (prev) printf("<A HREF=\"%lu\">prev</A>", prev); - else printf("prev"); - printf(" | "); - printf("<A HREF=\"../%s/%s?.%lu#m%lu\">index</A>", - relpath, indexfile, id, id); - printf(" | "); - if (next) printf("<A HREF=\"%lu\">next</A>", next); - else printf("next"); - printf("]</P>\n"); - } + printf("<p class=\"killed\">Message killed</p>\n"); + else + navigation(o, id, prev, next); - printf("<TABLE CLASS=header>"); + printf("<table class=\"envelope\">"); ha = o->mbox + m->pos; hb = o->mbox + m->pos + m->hdrlen; if (findhdr(ha, hb, "from", &s, &e)) { - printf("<TR><TH>From:</TH><TD><SPAN CLASS=email>"); + printf("<tr class=\"envelope from\"><th>From:</th><td>"); printesc(s, e); - printf("</SPAN></TD></TR>\n"); + printf("</td></tr>\n"); } if (findhdr(ha, hb, "to", &s, &e)) { - printf("<TR><TH>To:</TH><TD><SPAN CLASS=email>"); + printf("<tr class=\"envelope to\"><th>To:</th><td>"); printesc(s, e); - printf("</SPAN></TD></TR>\n"); + printf("</td></tr>\n"); } if (findhdr(ha, hb, "reply-to", &s, &e)) { - printf("<TR><TH>Reply-To:</TH><TD><SPAN CLASS=email>"); + printf("<tr class=\"envelope reply\"><th>Reply-To:</th><td>"); printesc(s, e); - printf("</SPAN></TD></TR>\n"); + printf("</td></tr>\n"); } if (findhdr(ha, hb, "date", &s, &e)) { - printf("<TR><TH>Date:</TH><TD>"); + printf("<tr class=\"envelope date\"><th>Date:</th><td>"); printesc(s, e); - printf("</TD></TR>\n"); + printf("</td></tr>\n"); } if (findhdr(ha, hb, "subject", &s, &e)) { - printf("<TR><TH>Subject:</TH><TD>"); + printf("<tr class=\"envelope subject\"><th>Subject:</th><td>"); printesc(s, e); - printf("</TD></TR>\n"); + printf("</td></tr>\n"); } - printf("</TABLE><HR>\n"); + printf("</table>\n"); /* Choose text/plain from multipart/alternate */ /* @@ -608,7 +613,8 @@ else if (strcasecmp(v[0], "multipart/signed") == 0) choosemixed(v, s, e, id); else - printf("<a href=\"%lu/0\" type=\"%s\">" + printf("<a class=\"attachment\"" + " href=\"%lu/0\" type=\"%s\">" "Attachment of type %s</a>", id, v[0], v[0]); } else { textplain: @@ -616,7 +622,7 @@ bodystart = o->mbox + m->pos + m->hdrlen; bodyend = bodystart + m->bodylen; - printf("<PRE WRAP=AUTO>"); + printf("<pre wrap=\"auto\">"); #if 1 for (p = bodystart; p < bodyend; ) { @@ -631,9 +637,9 @@ gt++; while (q < bodyend && *q != '\n') q++; - if (gt) printf("<SPAN class=indent%d>", gt); + if (gt) printf("<span class=\"indent%d\">", gt); printescqp(p, q, qp); - if (gt) printf("</SPAN>"); + if (gt) printf("</span>"); p = q; if (p < bodyend && *p == '\n') { printf("\n"); @@ -643,47 +649,32 @@ #else printescqp(bodystart, bodyend, qp); #endif - printf("</PRE>"); + printf("</pre>"); } - printf("<HR>"); - if (!killed) { - printf("<P>["); - if (prev) printf("<A HREF=\"%lu\">prev</A>", prev); - else printf("prev"); - printf(" | "); - printf("<A HREF=\"../%s/%s#m%lu\">index</A>", relpath, - indexfile, start); - printf(" | "); - if (next) printf("<A HREF=\"%lu\">next</A>", next); - else printf("next"); - printf("]</P>\n"); - } - + navigation(o, id, prev, next); /* - printf("<P>["); - printf("<a href=\"%lu;mbox\">view raw</a>", id); - printf(" | "); - printf("<a href=\"%lu;raw\">download raw</a>", id); - printf("]</P>\n"); + printf("<div class=\"transform\">"); + printf("<a href=\"%lu;mbox\">view raw</a>", id); + printf("<a href=\"%lu;raw\">download raw</a>", id); + printf("</div>\n"); */ - if (!killed) { - printf("<UL CLASS=thread>"); + printf("<ul class=\"thread\">"); print_threadlist(o, findprevsib(o, start), id, 1, 1); print_threadlist(o, start, id, 1, 0); print_threadlist(o, o->m[start].sibling, id, 1, 1); - printf("</UL>\n"); + printf("</ul>\n"); } if (findhdr(ha, hb, "message-id", &s, &e)) { - printf("<P>[%ld] <SPAN CLASS=messageid>", id); + printf("<p class=\"messageid\">[%ld] ", id); printesc(s, e); - printf("</SPAN></P\n"); + printf("</p>\n"); } - printf("</BODY></HTML>\n"); + printf("</body></html>\n"); } /* Walk to a particular attachment and print the subtree literally */ @@ -758,15 +749,18 @@ int *path; int i, pathlen, raw; cstring_t mbox = "mbox"; + char relpath_buf[1024]; if (argc == 1) { - relpath = ""; + relpath = "../"; } else if (argc == 2) { - relpath = argv[1]; - if (chdir(relpath) == -1) { - perror(relpath); + if (chdir(argv[1]) == -1) { + perror(argv[1]); exit(1); } + snprintf(relpath_buf, sizeof relpath_buf, + "../%s/", argv[1]); + relpath = relpath_buf; } else { fprintf(stderr, "usage: %s [dir]\n", argv[0]); exit(1); |