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

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: index.php3,v 1.5 2000/03/17 22:48:52 prenagha Exp $
  10. # ---------------------------------------------------------------
  11. function pop_login () {
  12.  global $pop3, $auth, $error_msg, $count;
  13.  # connect to the pop server
  14.  if ( ! $pop3->connect($auth->auth["server"], $auth->auth["port"]) ) {
  15.   $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);
  16.  }
  17.  # login to the POP server
  18.  $count = $pop3->apop($auth->auth["uname"], $auth->auth["passwd"]);
  19.  if ( $count < 0 ) {
  20.   $error_msg .= "Failed to login to POP server<br><small>$pop3->ERROR</small>";
  21.  }
  22. }
  23. include("poprepend.inc");
  24. page_open(array( "sess" => "pop_sess",
  25.                  "auth" => "pop_auth"));
  26. pop_login();
  27. $tpl->define(array(
  28.  standard   => "common.standard.tpl",
  29.  body       => "index.body.tpl",
  30.  msg_list   => "index.msglist.tpl",
  31.  msg         => "common.message.tpl",
  32.  error_msg   => "common.error_message.tpl"
  33. ));
  34. set_standard("list", &$tpl);
  35. ## Check if there was a submission
  36. $relogin = false;
  37. while ( is_array($HTTP_POST_VARS) 
  38.      && list($key, $val) = each($HTTP_POST_VARS)) {
  39.   if (eregi('delete_msg_([0-9]+)' ,$key, $match)) {
  40.     $id = $match[1];
  41.   ## delete selected msgs
  42.   
  43. # delete the message
  44.     if ( $pop3->delete($id) ) {
  45.       $msg .= sprintf("<br>Message %s deleted successfully.", $id);
  46.       $relogin = true;
  47.     } else {
  48.       $error_msg .= "<br>Failed to delete message number $id. <br><small>$pop3->ERROR</small>";
  49.     }
  50.  }
  51. }
  52. if ($relogin) {
  53. # need to close and re-open to refresh msg list?
  54.   $pop3->quit();
  55.   pop_login();
  56. }
  57. for ( $i = 1; $i <= $count; $i++ ){
  58. # get the size of this message
  59.   $size = $pop3->pop_list($i);
  60.   
  61. # get the headers and zero lines of body
  62.   $body_lines = 0;
  63.   $header_array = $pop3->top($i, $body_lines);
  64.   $show_msg = TRUE;
  65. # reset header variables
  66.   $from = $subject = $date = "&nbsp;";
  67. # loop through the headers and look for the stuff
  68. # we are interested in...
  69.   while ( list ($linenbr, $line) = each ($header_array) ) {
  70.     if ( eregi ("^From:(.*)", $line, $match) ) {
  71.       $from = trim ( $match[1] );
  72.     } elseif ( eregi ("^Subject:(.*)", $line, $match) ) {
  73.       $subject = trim ( $match[1] );
  74.       
  75. # skip pine generated internal messages      
  76.       if ( ereg ("DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA", $subject) ) {
  77.         $show_msg = FALSE;
  78.       }
  79.     
  80.     } elseif ( eregi ("^Date:(.*)", $line, $match) ) {
  81.       $date = trim ( $match[1] );
  82.     }
  83.   } # for each line in the message header
  84.   if ( $show_msg ) {
  85.     $tpl->assign(array(
  86.       FORM_ACTION => $sess->self_url(),
  87.       FROM        => $from,
  88.       SUBJECT     => $subject,
  89.       DATE        => $date,
  90.       MSGNBR      => $i,
  91.       MSGURL      => $sess->url("msg.php3?id=$i")
  92.     ));
  93.     $tpl->parse(MSG_LIST, ".msg_list");
  94.   }
  95. } # for each message
  96. # assign messages if any found
  97. if (isset ($error_msg)) {
  98.   $tpl->assign(ERROR_MSG_TEXT, $error_msg);
  99.   $tpl->parse(ERROR_MSG, "error_msg");
  100. }
  101. if (isset ($msg)) {
  102.   $tpl->assign(MSG_TEXT, $msg);
  103.   $tpl->parse(MSG, "msg");
  104. }
  105. $tpl->parse(BODY, "body");
  106. $tpl->parse(MAIN, "standard");
  107.   
  108. $tpl->FastPrint();
  109. $pop3->quit();
  110. page_close();
  111. ?>