<?
/*
   File name         : deleteattachment.php
   Version           : 1.1.0
   Last Modified By  : Umut Gokbayrak
   e-mail            : umut@trlinux.com
   Last modified     : 10 Sep 2000
*/

include ("includes/global.inc");
session_start();

// basename("/tmp/../etc/passwd") returns "passwd"
// so we avoid the possibility of a bad user trying to delete
// another file out of the temporary directory
$slcsil=basename($_POST["slcsil"]);
$ID=addslashes($_SESSION["ID"]);

// ID comparison between logged hash and session. If they are both the same, let the user to go on...
$dbq = $db->execute("select user_id,username,password from tblUsers where hash = '$ID'");
$user_id = $dbq->fields['user_id'];
$username = $dbq->fields['username'];
$password = $dbq->fields['password'];
$dbq->close();

if (($user_id == "") || (strlen($ID)==0)){
  Header("Location: index.php?error_id=1");
} else {

  // Saving the message body to a temporary file.
  $dosyaadi = "msgbody.txt";
  $fp = fopen($attach_directory . $ID . "#####" . "msgbody.txt", "w+");
  if ($fp) {
    $sonuc = fputs($fp, $msgbody);
    fclose($fp);
  } //end if

  // Deleting the actual file.
  unlink($attach_directory . $slcsil);

  Header("Location: attachments.php?to=$to&cc=$cc&bcc=$bcc&subject=$subject&attached=1&mbox_id=$mbox_id&post_act=1");

}

?>
