<?
/*
   File name         : attachments.php
   Version           : 1.1.3
   Last Modified By  : Umut Gokbayrak
   e-mail            : umut@trlinux.com
   Purpose           : Adding and deleting attachments to the e-mail to be send.
   Last modified     : 7 Nov 2000
*/

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

$attached=$_REQUEST["attached"];
$mbox_id=$_REQUEST["mbox_id"];
$post_act=$_REQUEST["post_act"];
$to=$_REQUEST["to"];
$cc=$_REQUEST["cc"];
$bcc=$_REQUEST["bcc"];
$subject=$_REQUEST["subject"];
$msgbody=$_REQUEST["msgbody"];
$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 {

  function mychop($thistring,$length) {
    $result="";
    $mystring=trim($thistring);
    if (strlen($mystring)>$length) {
      $result=substr($mystring,0,$length);
      $result = "$result...";
    }else {
      $result=$mystring;
    }

    return($result);
  }

  $mbox_id = rawurldecode($mbox_id);

  include ("$postaci_directory" . "classes/imap_pop3.inc");

  $email=new imap_pop3($default_port,$default_protocol,$default_host,$username,$password,$mbox_id);

  //$email->mbox_exists($mbox_id);
  include ("$postaci_directory" . "includes/commonhead.inc");
  include ("$postaci_directory" . "includes/stylesheets.inc");
  include ("$postaci_directory" . "includes/javascripts.inc");
  include ("$postaci_directory" . "includes/functions.inc");

  $to=rawurlencode($to);
  $cc=rawurlencode($cc);
  $bcc=rawurlencode($bcc);
  $subject=rawurlencode($subject);
  if ($attached ==1) {												// Attachment eklendi
    $dosyaadi = "$attach_directory$ID#####msgbody.txt";
    $msgbody = fread(fopen($dosyaadi, "r"), filesize($dosyaadi));
    fclose($fp);
    unlink("$dosyaadi");
  } else {
    $msgbody=stripslashes($msgbody);
    $msgbody=rawurlencode($msgbody);
  }
?>
  </head>

  <body bgcolor='#FFCC88' leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" background="images/background.gif" text="#000000" link="#1F4687" vlink="#1F4687" alink="#1F4687">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="1%" bgcolor="#4F0000"><img src="images/empty.gif" width="15" height="1"></td>
      <td width="1%" bgcolor="#4F0000"><img src="images/empty.gif" width="152" height="1"></td>
      <td width="98%" bgcolor="#4F0000" align="right"><img src="images/minilogo.jpg"></td>
    </tr>
  </table>
  <table width="100%" border="0" cellspacing="0" cellpadding="0" height="400">
    <tr>
      <td width="1%"><img src="images/empty.gif" width="15" height="1"></td>
      <td width="1%" valign="top" align="left"><img src="images/company_logo2.jpg" width="152" height="152"><br>
        <table width="120" border="0" cellspacing="0" cellpadding="0" align="center">
          <tr>
            <td>
              <img src="images/dot.gif" width="10" height="10"> <a href="sendmail.php?mbox_id=<? echo $mbox_id; ?>"><? echo "$text25"; ?></a>
            </td>
          </tr>
          <tr>
            <td>
              <img src="images/dot.gif" width="10" height="10"> <a href="mailbox.php?mbox_id=INBOX"><? echo "$text26"; ?></a>
            </td>
          </tr>
          <tr>
            <td>
              <img src="images/dot.gif" width="10" height="10"> <a href="folders.php"><? echo "$text27"; ?></a>
            </td>
          </tr>
          <tr>
            <td>
              <table border="0" cellpadding="0" cellspacing="0" width="111">
                <tr>
                  <td width="8">
                    <img src="images/empty.gif" height="1" width="15">
                  </td>
                  <td width="112">
                    <?
                      if ($default_protocol == "pop3") {
                        echo "- <a href=\"mailbox.php?mbox_id=INBOX\">INBOX</a><br>";
                      }
                      $folders = $email->getMailboxes();
                      $folder_names = array();
                      $folder_counter=-1;
                      while (list($key,$val) = each($folders["name"])) {
                        $folder_counter++;
                        $folder_names[$folder_counter] = $val;
                      }
                      $ids = array();
                      $folder_counter=-1;
                      while (list($key,$val) = each($folders["id"])) {
                        $folder_counter++;
                        $ids[$folder_counter] = $val;
                      }

                      for($i=0;$i<count($ids);$i++) {
                        echo "- <a href=\"mailbox.php?mbox_id=$ids[$i]\">$folder_names[$i]</a><br>";
                      }
                    ?>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>
            <td>
              <img src="images/dot.gif" width="10" height="10"> <a href="preferences.php"><? echo "$text28"; ?></a>
            </td>
          </tr>
          <tr>
            <td>
              <img src="images/dot.gif" width="10" height="10"> <a href="index.php"><? echo "$text29"; ?></a>
            </td>
          </tr>
        <tr valign="bottom" align="center">
          <?
            if($show_sponsor) {
              echo "<td height=\"70\" class=\"style=\"8\">$text78</td>\n";
            } else {
              echo "<td height=\"70\" class=\"style=\"8\">&nbsp;</td>\n";
            }
          ?>
        </tr>
        <tr>
          <td>
            <div align="center">
              <table width="111" border="0" cellspacing="0" cellpadding="1" bgcolor="#333333">
                <tr>
                  <?
                    if ($show_sponsor) {
                      echo "<td><a href=\"http://www.yimpas.net.tr\"><img src=\"images/sponsor.gif\" width=\"109\" height=\"30\" border=\"0\"></a></td>\n";
                    }
                  ?>
                </tr>
              </table>
            </div>
          </td>
        </tr>
        </table>
      </td>
      <td width="98%" valign="top">

      <table width="100%" border="0" cellspacing="0" cellpadding="0" height="150">
       <? include ($postaci_directory . "includes/headinside.inc"); ?>
        <tr>
          <td width="10" height="180" valign="top">
            <p><img src="images/empty.gif" width="1" height="180"></p>
          </td>
          <td valign="top" align="left">
            <hr size="1">&nbsp;<br>

            <div align="center">



       <table width='500' border='0' cellspacing='0' cellpadding='1' align='center'>
         <tr bgcolor='#999999'>
          <td>
            <table width='100%' border='0' cellspacing='0' cellpadding='0' height='200'>
              <tr bgcolor='#FFDDAA'>
                <td height='20' width='4%'>&nbsp;</td>
                <td height='20' width='92%'>&nbsp;</td>
                <td height='20' width='4%'>&nbsp;</td>
              </tr>
              <tr bgcolor='#FFDDAA'>
                <td height='25' width='4%'>&nbsp;</td>
                <td height='25' width='92%'>
                  <form enctype="multipart/form-data" action="upload.php" method="post" onSubmit="submitonce(this)">
                    <input type="hidden" name="to" value="<? echo $to; ?>">
                    <input type="hidden" name="cc" value="<? echo $cc; ?>">
                    <input type="hidden" name="bcc" value="<? echo $bcc; ?>">
                    <input type="hidden" name="subject" value="<? echo $subject; ?>">
                    <input type='hidden' name='msgbody' value='<? echo $msgbody; ?>'>
                    <input type='hidden' name='mbox_id' value='<? echo $mbox_id; ?>'>
                    <input type='hidden' name='post_act' value='<? echo $post_act; ?>'>
                    <input name='userfile' type='file' size='30'>
                    <input type='submit' value='<? echo $text44; ?>' name='submit'>
                  </form>
                </td>
                <td height='25' width='4%'>&nbsp;</td>
              </tr>
              <tr bgcolor='#FFDDAA'>
                <td width='4%'>&nbsp;</td>
                <td width='92%' valign='top'>
                  <hr size='1'>
                  <form method="post" action="deleteattachment.php" onSubmit="submitonce(this)">
                    <select name='slcsil' size='5'>
                      <option value='0'>-- <? echo $text45; ?> --</option>
                        <?
                        // lists the attached files in a listbox.

                          $handle=opendir($attach_directory);
                          while ($file = readdir($handle)) {
                            $attach_id = substr($file,1,46);
                            $idvar = strstr($file,$ID);
                            if ($idvar) {
                              $attachedfile = strstr($file,"######");
                              $attach_name = substr($attachedfile,6);
                              $ebat = filesize($attach_directory . $file);
                              $ebat = ceil($ebat / 1024);
                              echo "<option value='$file'>$attach_name ($ebat K)</option>\n";
                            } // end if
                          } // end while
                          closedir($handle);
                        ?>
                    </select>
                    <input type="hidden" name="to" value="<? echo $to; ?>">
                    <input type="hidden" name="cc" value="<? echo $cc; ?>">
                    <input type="hidden" name="bcc" value="<? echo $bcc; ?>">
                    <input type="hidden" name="subject" value="<? echo $subject; ?>">
                    <input type='hidden' name='msgbody' value='<? echo $msgbody; ?>'>
                    <input type='hidden' name='mbox_id' value='<? echo $mbox_id; ?>'>
                    <input type='hidden' name='post_act' value='<? echo $post_act; ?>'>
                    <input type='submit' name='eklentisil' value='<? echo $text46; ?>'>
                  </form>
                  <form method="post" action="sendmail.php" onSubmit="submitonce(this)">
                    <input type='hidden' name="attached" value="1">
                    <input type="hidden" name="to" value="<? echo $to; ?>">
                    <input type="hidden" name="cc" value="<? echo $cc; ?>">
                    <input type="hidden" name="bcc" value="<? echo $bcc; ?>">
                    <input type="hidden" name="subject" value="<? echo $subject; ?>">
                    <input type='hidden' name='msgbody' value='<? echo $msgbody; ?>'>
                    <input type='hidden' name='mbox_id' value='<? echo $mbox_id; ?>'>

                    <input type='submit' name='geridon' value='<- <? echo $text47; ?>'>
                  </form>
                </td>
                <td width='4%'>&nbsp;</td>
              </tr>

            </table>
            </td>
          </tr>
        </table>
            </div>









            <p>&nbsp; </p>
          </td>
          <td valign="top" width="10">&nbsp;</td>
        </tr>
        <tr>
          <td width="10" height="80" valign="top">&nbsp;</td>
          <td valign="bottom" align="right">
            <hr size="1">
            <div align="right"><span class="style8"><? echo $text84; ?></span></div>
            <p>
          </td>
          <td>&nbsp;</td>
        </tr>
      </table>
      </td>
    </tr>
  </table>
  </body>
  </html>

<?
}
?>
