Location: PHPKode > projects > Akasha > message_process.php
<?

require( "includes/global.inc" );        // Global Variables
require( "includes/functions.inc" );     // Global Functions

if ($akashaID == $ID) {

	if ($mbox_id == 'inbox') {
		$user_id = findUserByHash($ID);
  	   	$mailbox_id = $slcmbox;
  	   	$auth_user = getUserIDMbox($mailbox_id);
  	   	if ($auth_user != $user_id && $auth_user != 0 ) {
  	 		Header("Location: main.php?error_code=1");
        exit;
  	   	}

    	$username =  getUsername($ID);
   		$password = getPassword($ID);

   		$count=count($chk);
  	   	$top = $top - $count;

   		$mailboxtip = getMboxTip($mailbox_id);
	   	if ($mailboxtip == 2) {
	      	$maxmessage = $trash_quota;
	   	}
	   
		if ($mailboxtip == 1) {
	      	$maxmessage = $out_quota;
	   	}
	   
		if ($mailboxtip == 3) {
	      	$maxmessage = $mailbox_quota;
	   	}

      	$messagecount = findMboxMessageCount($mailbox_id);
      	$messagecount = $messagecount + $count;
      	$artikmesaj = $messagecount - $maxmessage;


      	if ($artikmesaj > 0) {
        	for ($m=1;$m<$artikmesaj;$m++) {
            	$query = "select min(message_id) from tblMessages where mbox_id = $mailbox_id";
               	$result = mysql_db_query("$dbname",$query);
                if($result) {
                	while ($r = mysql_fetch_array($result)) {
                    	$minmessage = $r["min(message_id)"];
                        $query1 = "delete from tblMessages where user_id = $user_id and mbox_id = $mailbox_id and message_id = $minmessage";
                        $result1 = mysql_db_query("$dbname",$query1);
                	}
               	}
          	}
        }

   		$mbox = imap_open("{".$domain."/pop3:110}INBOX", "$username", "$password");
      	for ($i=0; $i<$count; $i++) {
       		$messageno = $chk[$i];
			$header=imap_header($mbox,$messageno);
			$from	=decode_mime_string($header->fromaddress);
        	$subject =decode_mime_string($header->subject);
         	$to	=decode_mime_string($header->toaddress);
         	$replyto =decode_mime_string($header->reply_toaddress);
         	$cc	=decode_mime_string($header->ccaddress);
  		   	$date=ereg_replace(" ","&nbsp;", date("Y M d - H:i",$header->udate));
    	   	$body = imap_body($mbox,$messageno);
			$message_id = $messageno;
         	$start=0;
         	$structure=imap_fetchstructure($mbox,$message_id);				
      		if (eregi("MIXED",$structure->subtype) )  {
      			$body   =imap_fetchbody($mbox,$message_id,1);
      			$fullheader	=imap_fetchheader($mbox,$message_id);
      			if (eregi("Content-Type: text/html",$fullheader) ) {
      				$showhtml=1;
      			} else {
      				$showhtml=0;
      			}
      			$start=1;
      		}
      		if (eregi("RELATED",$structure->subtype) )  {
      			$body   =imap_fetchbody($mbox,$message_id,1);
      			$showhtml=1;
      			$start=1;
      		}
      		if ( $start== 0) {
      			$fullheader	=imap_fetchheader($mbox,$message_id);
      			if ( eregi("Content-Type: text/html",$fullheader) ) {
      				$showhtml=1;
      			} else {
      				$showhtml=0;
      			}
      			$body	=imap_fetchbody($mbox,$message_id,1);
      			$start=0;
      		}
      		$messageencoding = 4;
      		$messagepart=$structure->parts[0];
      		$messageencoding=$messagepart->encoding;
      		if ($messageencoding==3) {
      			$body = imap_base64($body);
      		}

      		if ($showhtml == 1) {
      			$htmlbody = htmlisle($body);
      		} else {
      			$htmlbody=bodyIsle($body);
      		}

  			$body = addSlashes($htmlbody);
      		$query = "select max(message_id) as maxi from tblMessages";
      		$result = mysql_db_query("$dbname",$query);
      		if($result) {
         		$maxmessage = @mysql_result( $result, 0, "maxi" );
      		}

   			$message_no = $maxmessage +1;
      		$query = "insert into tblMessages values($message_no,$mailbox_id,$user_id,'$from','$to','$cc','$replyto','$date','$subject','$body')";
      		$result = mysql_db_query("$dbname",$query);
     		if($result) {
    		}

      		$query = "select max(message_id) as maxi from tblMessages where user_id=$user_id and mbox_id=$mailbox_id";
      		$result = mysql_db_query("$dbname",$query);
     		if($result) {
        		 $maxmessage = @mysql_result( $result, 0, "maxi" );
    		}

      		$structure=imap_fetchstructure($mbox,$message_id);
      		$c=count($structure->parts);
      		if ($c<=1 ) {
      			$attachyok = 1;
      		}

    		if ($attachyok == 0) {
      			for ($j=$start; $j<$c; $j++) {
      				$part0=$structure->parts[$j];
      				$part=$j+1;
      				$parameters=$part0->parameters;
      				$attach_type=$part0->subtype;
      				$mytype=$part0->type;
      				$encoding=$part0->encoding;
      				$text_encoding=$mime_encoding[$encoding];
      			
      				if (empty($text_encoding)) {
      					$text_encoding="unknown";
      				}

      				if (eregi("RFC822",$attach_type)) {
      					$att="RFC822 Message";
      					$val="message.txt";
      				} else {
      					$att=$parameters[0]->attribute;
      					$val=$parameters[0]->value;
      				}
      			
      				$val=eregi_replace(" ","_",$val);
      				$size=sprintf("%0.2f",$part0->bytes / 1024);
					$att_msg = $maxmessage;
          			$att_body=imap_fetchbody($mbox,$message_id,$part);
          			if ($encoding==3){
          		//$att_body   =imap_base64($att_body);
          			}
  					$att_body = addslashes($att_body);
          			$tersname = strrev($val);
          			$dosya_isim = stristr($tersname,".");
          			$lenisim = strlen($dosya_isim);
          			$extension=trim(strtolower(substr($val,$lenisim)));
          			$dosyatipi="application/octet-stream";
          			$mime=fopen("mime.types","r");
          			while ( !feof($mime) ) {
          				$mytype=fgets($mime,1000);
          				$mimeparts=explode("	",$mytype);	
          				$mimeuzanti = trim(strtolower($mimeparts[1]));
          		
          				if ($mimeuzanti == $extension) {
          					$dosyatipi=$mimeparts[0];
          				}	
          			}
          			fclose($mime);

            		$query = "insert into tblAttachments values(NULL,$att_msg,'$att_body',$user_id,'$dosyatipi','$val')";
            		$result = mysql_db_query("$dbname",$query);
           			if($result) {
          			}
      			}
  			}
  			@imap_delete($mbox, $messageno);
    	} 

  		@imap_close($mbox,CL_EXPUNGE);
		Header ("Location: mailbox.php?ID=$ID&mbox_id=$mbox_id&top=$top");

		echo "<html>";
		echo "<head>";
		echo "<meta http-equiv='refresh' content='0; url=mailbox.php?ID=$ID&mbox_id=$mbox_id&top=$top'>\n";
		echo "</head>";
		echo "<body bgcolor='#FFFFFF'></body></html>\n";

	}

	if ($mbox_id !='inbox') {
		if ($slcmbox) {
	   		$user_id = findUserByHash($ID);
  			$auth_user = getUserIDMbox($slcmbox);
	  		if ($auth_user != $user_id) {
  				Header("Location: main.php?error_code=1");
         		exit;
  			}
	
	   		$count=count($chk);
	  		$top = $top - $count;
	   		for ($i=0; $i<$count; $i++) {
  	  	   		$messageno = $chk[$i];
    	  		$query = "update tblMessages set mbox_id=$slcmbox where message_id = $messageno";
   	  			$result = mysql_db_query("$dbname",$query);
      			if($result) {
    	   		}
      		}
		}
	}

	if ($top < 0) {
		$top = 0;
	} 

	Header("Location: mailbox.php?ID=$ID&mbox_id=$mbox_id&top=$top");
} else {
	Header("Location: main.php?error_code=1");
}
?>
Return current item: Akasha