msg.php3
上传用户:xuanqunsh
上传日期:2007-01-04
资源大小:58k
文件大小:5k
源码类别:

WEB邮件程序

开发平台:

PHP

  1. <?php
  2. # ---------------------------------------------------------------
  3. # phpop
  4. # A WWW based POP3 basic mail user agent (MUA)
  5. # Copyright (C) 1999  Padraic Renaghan
  6. # Licensed under terms of GNU General Public License
  7. # (see http://www.renaghan.com/phpop/source/LICENSE)
  8. # ---------------------------------------------------------------
  9. # $Id: msg.php3,v 1.5 2000/03/17 22:53:25 prenagha Exp $
  10. # ---------------------------------------------------------------
  11. include("poprepend.inc");
  12. page_open(array( "sess" => "pop_sess",
  13.                  "auth" => "pop_auth"));
  14. # connect to the pop server
  15.  # connect to the pop server
  16.  if ( ! $pop3->connect($auth->auth["server"], $auth->auth["port"]) ) {
  17.   $error_msg .= sprintf("Failed to connect to POP server %s on port %s.<br><small>%s</small>", $auth->auth["server"], $auth->auth["port"], $pop3->ERROR);
  18.  }
  19.  # login to the POP server
  20.  $count = $pop3->apop($auth->auth["uname"], $auth->auth["passwd"]);
  21. #if ( (!$count) or ($count == -1) ) {
  22.  if ( $count < 0 ) {
  23.   $error_msg .= "Failed to login to POP server<br><small>$pop3->ERROR</small>";
  24.  }
  25. $tpl->define(array(
  26.  standard   => "common.standard.tpl",
  27.  body       => "msg.body.tpl",
  28.  msg_display => "msg.msgdisplay.tpl",
  29.  msg        => "common.message.tpl",
  30.  error_msg  => "common.error_message.tpl"
  31. ));
  32. set_standard("message", &$tpl);
  33. switch ($action) {
  34.   ## delete message
  35.   case "D":
  36. # delete the message
  37.     if ( $pop3->delete($id) ) {
  38.       $msg .= "Message $id deleted successfully.";
  39. #     reset the id var so that the message is NOT displayed below
  40.       $id = 0;
  41.     } else {
  42.       $error_msg .= "Failed to delete message number $id. <br><small>$pop3->ERROR</small>";
  43.     }
  44. # reset the id var so that the message is NOT displayed below
  45.   $id = 0;
  46.   break;
  47.   
  48.   default:
  49.   break;
  50. }
  51. # if we have an msg ID set, then display that
  52. # message. Delete resets the msg ID after it has
  53. # deleted the msg.
  54. if ( $id > 0 ) {
  55. # get the entire message
  56.   $msg_array = $pop3->get($id);
  57.   
  58. # loop through the headers and look for the stuff
  59. # we are interested in...
  60.   $in_body = false;
  61.   while ( list ($linenbr, $line) = each ($msg_array) ) {
  62.     if ( (!$from) and (eregi ("^From:(.*)", $line, $match)) ) {
  63.       $from = htmlentities(trim ( $match[1] ));
  64.     } elseif ( (!$subject) and (eregi ("^Subject:(.*)", $line, $match)) ) {
  65.       $subject = htmlentities(trim ( $match[1] ));
  66.     
  67.     } elseif ( (!$date) and (eregi ("^Date:(.*)", $line, $match)) ) {
  68.       $date = htmlentities(trim ( $match[1] ));
  69.     } elseif ( (!$cc) and (eregi ("^cc:(.*)", $line, $match)) ) {
  70.       $cc = htmlentities(trim ( $match[1] ));
  71.     } elseif ( (!$to) and (eregi ("^To:(.*)", $line, $match)) ) {
  72.       $to = htmlentities(trim ( $match[1] ));
  73.     } elseif ( eregi ("^r", $line) ) {
  74.       $in_body = true;
  75.     } elseif ( $in_body ) {
  76.       $body .= "<br>" . htmlentities($line);
  77.     }
  78.   } # for each line in the message header
  79.   $space = "&nbsp;";
  80.   if (empty($from)) $from = $space;
  81.   if (empty($subject)) $subject = $space;
  82.   if (empty($date)) $date = $space;
  83.   if (empty($cc)) $cc = $space;
  84.   if (empty($to)) $to = $space;
  85. # replace URLs in the message body with HTML anchor tags
  86. # Note that this regular expression allows for URL's to extend over more
  87. # than one line (n).  In some cases you might like to remove this
  88. # capability since if the URL finishes exactly at the end of a line and 
  89. # there are no spaces before the next word that word will be enabled.
  90.   $body = eregi_replace(
  91.     "(http|https|ftp)://([[:alnum:]/n+-=%&:_.~?]+[#[:alnum:]+]*)",
  92.     "<a href="\1://\2" target="_blank">\1://\2</a>",
  93.     $body);
  94. # replace email addresses in message body with anchor tags to 
  95. # send.php3 page with the clicked address as the TO:
  96.   $body = eregi_replace(
  97.     "([._a-z0-9-]+)@([._a-z0-9-]+)",
  98.     "<a href="send.php3?newto=\1@\2" target="_blank">\1@\2</a>",
  99.     $body);
  100.   $tpl->assign(array(
  101.     DEL_URL     => $sess->url("msg.php3?id=$id&action=D"),
  102.     REPLY_URL   => $sess->url("send.php3?id=$id&action=R"),
  103.     FWD_URL     => $sess->url("send.php3?id=$id&action=F"),
  104.     FROM        => $from,
  105.     TO          => $to,
  106.     CC          => $cc,
  107.     SUBJECT     => $subject,
  108.     DATE        => $date,
  109.     MSGNBR      => $id,
  110.     MSGBODY     => $body
  111.   ));
  112.   $tpl->parse(MSG_DISPLAY, "msg_display");
  113.   
  114. } # if ID > 0
  115. # close the POP session
  116. $pop3->quit();
  117. # assign messages if any found
  118. if (isset ($error_msg)) {
  119.   $tpl->assign(ERROR_MSG_TEXT, $error_msg);
  120.   $tpl->parse(ERROR_MSG, "error_msg");
  121. }
  122. if (isset ($msg)) {
  123.   $tpl->assign(MSG_TEXT, $msg);
  124.   $tpl->parse(MSG, "msg");
  125. }
  126. $tpl->parse(BODY, "body");
  127. $tpl->parse(MAIN, "standard");
  128.   
  129. $tpl->FastPrint();
  130. page_close();
  131. ?>