Просмотр файла pofhq-wapmail/mailview.php

Размер файла: 4.91Kb
<?
/*
$Header: /home/cvsroot/pofhq-wapmail/mailview.php,v 1.3 2002/12/12 20:49:57 pau Exp $
Copyright (c) 2002 Pau Oliva Fora <[email protected]>               
Licensed under the GNU GPL. For full terms see the file COPYING.
*/

require("config.php");
wmlheader();

$mbox = imap_open ("\{$IMAPSERVER:$IMAPPORT}$F", "$U", "$P") or wmldie ("can't connect: " . imap_last_error());
$header = imap_header ($mbox, $msgid, 50, 50, 50);
$from = $header->from;
$msgfrom = sprintf("%s@%s", $from[0]->mailbox,$from[0]->host);
$msgsubject = getsubject($header->fetchsubject);
$msgdate = date("d/m/y H:i:s", $header->udate);
$msgbody = getmsgbody($mbox, $msgid);
$bodysize = strlen($msgbody);
$parts = ceil($bodysize / $MESSAGESIZE);

imap_close($mbox);

if ($parts > 1) { /* better measure of parts */
	$counter = 1;
	$pos = 0;
	while ( ($pos + $MESSAGESIZE) < $bodysize ) {
		$pos = $pos + $MESSAGESIZE;
		while ($msgbody[$pos] != " ") $pos++;
		if ( $pos != $bodysize - 1 ) $counter++;
	}
	$parts = $counter;
}


print "<card id=\"mailbody\">\n";

if ( !isset($part) or $part == 1 ){
	
	/* print from and link to reply */
	echo "<p mode=\"nowrap\">\n";
	echo "<small>$S_FROM";
	waplink($S_REPLY,$msgfrom,"compose.php",array("subject"=>"RE:$msgsubject","msgto"=>$msgfrom,"F"=>$F,"U"=>$U,"P"=>$P));	
	echo "</small>\n";
	echo "</p>\n";
	
	/* print subject */
	echo "<p mode=\"nowrap\">\n";
	echo "<small>$S_SUBJECT $msgsubject</small>";
	echo "</p>\n";

	/* print date */
	echo "<p mode=\"nowrap\">\n";
	echo "<small>$S_DATE $msgdate</small>";
	echo "<br/></p>\n";

}

if ( $parts == 1 ) {

	/* print body */
	echo "<p mode=\"wrap\">\n";
	echo $msgbody;
	echo "\n</p>\n";

} else { /* message is longer than MESSAGESIZE */

	if ( isset($part) and $part == $parts ) { /* last part */

		/* find position for previous message */
		$pos=0;
		for($n=1; $n < $part - 1; $n++) {
			$pos = $pos + $MESSAGESIZE;
			while ($msgbody[$pos] != " ") $pos++;
		}

		/* print previous */
		echo "<p>\n";
		$prev_part = $part - 1;
		waplink($S_SUBMIT,$S_PREVIOUS,"mailview.php",array("position"=>$pos,"page"=>$page,"part"=>$prev_part,"msgid"=>$msgid,"F"=>$F,"U"=>$U,"P"=>$P));
		echo "</p>\n";

		/* print body from where we stopped */
		if (!isset($position)) $position = ($MESSAGESIZE * ($part - 1));
		echo "<p mode=\"wrap\">\n";
		echo "<small><b>Part:</b> $part/". $parts ."- <b>Size:</b> $bodysize</small><br/>\n";
		while ($msgbody[$position] != " ") $position++;
		for ($i = $position; $i < $bodysize; $i++) print("$msgbody[$i]");
		echo "\n</p>\n";

		/* link to reply */
		echo "<p>\n";
		waplink($S_REPLY,$S_REPLY,"compose.php",array("subject"=>"RE:$msgsubject","msgto"=>$msgfrom,"F"=>$F,"U"=>$U,"P"=>$P));	
		echo "</p>\n";

	} else { /* print this part */

		if (!isset($part) or $part == 1) { 
		/* we are on the 1st part, we have to set part here and link to part 2 */

			echo "<p mode=\"wrap\">\n";
			echo "<small><b>Part:</b> 1/". $parts ."- <b>Size:</b> $bodysize</small><br/>\n";
			for ($i = 0; $i < $MESSAGESIZE; $i++) print("$msgbody[$i]");
			while ($msgbody[$i] != " ") {
			/* don't cut the message until we find a suitable place */
				print("$msgbody[$i]");
				$i++;
			}
			echo "\n</p>\n";
			
			/* print next */
			echo "<p>\n";
			waplink($S_SUBMIT,$S_NEXT,"mailview.php",array("page"=>$page,"part"=>"2","msgid"=>$msgid,"F"=>$F,"U"=>$U,"P"=>$P));	
			echo "</p>\n";

		} else {
		/* we are on a part that is not 1st, we have to link to next and previous part */

			/* find position for previous message */
			$pos=0;
			for($n=1; $n < $part - 1; $n++) {
				$pos = $pos + $MESSAGESIZE;
				while ($msgbody[$pos] != " ") $pos++;
			}
			
			/* print previous */
			echo "<p>\n";
			$prev_part = $part - 1;
			waplink($S_SUBMIT,$S_PREVIOUS,"mailview.php",array("position"=>$pos,"page"=>$page,"part"=>$prev_part,"msgid"=>$msgid,"F"=>$F,"U"=>$U,"P"=>$P));
			echo "</p>\n";

			if (!isset($position)) $position = ($MESSAGESIZE * ($part - 1));

			echo "<p mode=\"wrap\">\n";
			echo "<small><b>Part:</b> $part/". $parts ."- <b>Size:</b> $bodysize</small><br/>";
			while ($msgbody[$position] != " ") $position++;
			for ($i = $position; $i < $position + $MESSAGESIZE; $i++) print("$msgbody[$i]");
			$position = $i;
			while ($msgbody[$position] != " ") {
			/* don't cut the message until we find a suitable place */
				print("$msgbody[$position]");
				$position++;
			}
			echo "\n</p>\n";

			/* print next */
			echo "<p>\n";
			$next_part = $part + 1;
			waplink($S_SUBMIT,$S_NEXT,"mailview.php",array("position"=>$position,"page"=>$page,"part"=>$next_part,"msgid"=>$msgid,"F"=>$F,"U"=>$U,"P"=>$P));
			echo "</p>\n";
		}
	}
}

/* always print delete return and back */
echo "<p>\n";
waplink($S_SUBMIT,$S_DELETE,"maildel.php",array("msgid"=>$msgid,"F"=>$F,"U"=>$U,"P"=>$P));
echo "</p>\n";
echo "<p>\n";
wapbutton(0,$S_INDEX,"index.php",array("F"=>$F,"U"=>$U,"P"=>$P));
echo "</p>\n";
echo "<p>\n";
wapbutton(0,$S_BACK,"maillist.php",array("page"=>$page,"F"=>$F,"U"=>$U,"P"=>$P));
echo "</p>\n";


wmlfooter();
?>