<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: inbox.php,v 1.9.2.4 2004/08/01 17:04:16 kirilt Exp $



/*************************************************************************/
 #  Mailbox 0.9.2a   by Sivaprasad R.L (http://netlogger.net)             #
 #                                                                        #
 #          --  A pop3 client addon for phpnuked websites --              #
 #                                                                        #
 # This program is distributed in the hope that it will be useful,        #
 # but WITHOUT ANY WARRANTY; without even the implied warranty of         #
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          #
 # GNU General Public License for more details.                           #
 #                                                                        #
 # You should have received a copy of the GNU General Public License      #
 # along with this program; if not, write to the Free Software            #
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              #
 #                                                                        #
 #             Copyright (C) by Sivaprasad R.L                            #
 #                                                                        #
/*************************************************************************/

   if( ! _MPN_USER )
   {
       $_SERVER['F_LIB'] -> redirectRequest( 'user.php' );
       exit;
   }

  global $mainfile, $op, $id;
  global $user, $server, $port, $username, $password;
  global $imgpath, $bgcolor1, $bgcolor2, $bgcolor3, $id;

  $index = 2;
//  if(!isset($mainfile)) include "mainfile.php";
//  parse_str(base64_decode($pop3_cookie));
  require("pop3.inc.php");
  //require("decodemessage.inc.php");
  include "header.php";
  include "mailheader.php";
  include "class.rc4crypt.php";

  getServer($id);
 @set_time_limit(0);
  $pop3=new POP3($server,$username,$password);
  $pop3->Open();

  if($op == "delete") {
      global $msgid;
      if(is_array($msgid)) {
          foreach($msgid as $mid) {
              $pop3->DeleteMessage($mid);
          }
      } else {
          $pop3->DeleteMessage($msgid);
      }
      $pop3->Close();
      $pop3->Open();
  }

  $s = $pop3->Stats() ;
  $mailsum = $s["message"];

  global $start,$numshow;
  if(!isset($start)) $upperlimit = $mailsum; else $upperlimit = $start;
  $lowerlimit = $upperlimit - $numshow;
  if($lowerlimit < 0) $lowerlimit = 0;
  $showstart =  $mailsum - $upperlimit + 1;
  $showend = $mailsum - $lowerlimit;

  echo "<form action=inbox.php method=post>
        <input type=hidden name=id value=$id>
        <input type=hidden name=op value='delete'>";

  navbuttons();

  echo "<table border=\"0\" width=100% bgcolor=\"$bgcolor3\" CELLPADDING=3 CELLSPACING=1>
        <tr>
        <td width=\"4%\" bgcolor=\"$bgcolor2\">&nbsp;</td>
        <td width=\"25%\" bgcolor=\"$bgcolor2\">" . translate("From") . "</td>
        <td width=\"51%\" bgcolor=\"$bgcolor2\">" . translate("Subject") . "</td>
        <td width=\"5%\" bgcolor=\"$bgcolor2\">" . translate("Size") . "</td>
        <td width=\"15%\" bgcolor=\"$bgcolor2\">" . translate("Date") . "</td>
        </tr>";

  for ($i=$upperlimit;$i>$lowerlimit;$i--) {
      $list = $pop3->ListMessage($i);
      echo "<tr> <td bgcolor=\"$bgcolor1\" height=\"24\"><input type=\"checkbox\" name=\"msgid[]\" value=\"$i\"></td>";
      echo "<td bgcolor=\"$bgcolor1\" height=\"24\"><a href=\"readmail.php?id=$id&msgid=$i\">";
      $sender = ($list["sender"]["name"]) ? $list["sender"]["name"] : $list["sender"]["email"];
      echo htmlspecialchars(substr($sender,0,16));
      echo "</a>";
      echo (strlen($sender) > 16) ? ".." : "";
      echo "</a></font></td>";
      echo "<td bgcolor=\"$bgcolor1\"><a href=\"readmail.php?id=$id&msgid=$i\">";
      echo chop($list["subject"]) ? htmlspecialchars($list["subject"]) : translate("(No Subject)");
      echo "</td><td bgcolor=\"$bgcolor1\">";
      echo round($list["size"]/1024)."k";
      echo $list["has_attachment"] ? "<img src='$imgpath/clip.gif'>" : "";
      echo "</td><td bgcolor=\"$bgcolor1\">";
      echo htmlspecialchars($list["date"]);
      echo "</font></td></tr>";
  }
  echo "</table>";
  navbuttons();
  echo "</form>";
  $pop3->Close();
  include "mailfooter.php";
?>

<?php
  function getServer($id) {
      global $user, $server, $port, $username, $password, $numshow, $mpnTables;

      if(!isset($id)) {
          echo translate("Error: Invalid Parameter") . "<br>";
          include "mailfooter.php";
          exit();
      }

      $query = "Select * from ".$mpnTables['popsettings']." where id = $id";
      if(($res = mysql_query($query)) && (mysql_num_rows($res) > 0)) {
              $row = mysql_fetch_array($res);
              $uid = $row["uid"];
              $auser = base64_decode($user);
              $userdata = explode(":", $auser);
              $userid = $userdata[0];

              if($uid != $userid) {
                 echo "<center><h2>" . translate("Error: Permission denied") . "</center>";
          include "mailfooter.php";
                 exit();
              }
              $server = $row["popserver"];
              $port = $row["port"];
              $username = $row["uname"];
              $rc4 = new rc4crypt();
              $password = $rc4->encrypt($username,$row["passwd"]);
              $numshow = $row["numshow"];
      } else {
              echo translate("Error: POP Server not set properly") . "<br>";
          include "mailfooter.php";
              exit();
      }
}

function navbuttons() {
  global $id, $showstart, $showend, $mailsum, $upperlimit, $lowerlimit, $numshow;
  echo "<br>
        <table border=0 width=100%>
        <tr><td width=15%><input class='button' type=submit name=delete value ='" . translate("Delete") . "'></td>
        <td width=70% align=center>" . sprintf(translate("Showing (%s - %s) of %s mails"), $showstart, $showend, $mailsum) . "</td>";

  if($upperlimit != $mailsum){
      $ul = $upperlimit + $numshow;
      if($ul > $mailsum ) $ul = $mailsum;
      echo "<td width=7%><a href=\"inbox.php?id=$id&start=$ul\">" . translate("Prev") . "</a></td>";
  }

  if($lowerlimit > 0) {
      echo "<td width=7%><a href=\"inbox.php?id=$id&start=$lowerlimit\">" . translate("Next") . "</a></td>";
  }
  echo "</tr></table>";
}

?>
