<commit_before><?php
/**
 * SMTP_Server_Session
 *
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2008, <NAME>
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 1.0
 * @package php-smtp
 */

class SMTP_Server_Session {
	var $socket;
	var $buffer;
	var $date;
	var $to;
	var $from;
	var $domains;
	var $complete;
	
	function SMTP_Server_Session($socket) {
		$this->socket = $socket;
		$this->date = time();
		$this->to = array();
		$this->from = array();
		$this->complete = false;
		
		$this->domains = array(
			'localhost',
			'127.0.0.1',
		);
	}
	
	/**
	 * Enters a loop to read and process incoming commands, exits when $this->complete is true
	 */
	function run() {
		$this->socket->write(SMTP_220);
		
		while($this->buffer = $this->socket->read()) {
			$cmd = substr($this->buffer, 0, 4);
			$arg = trim(substr($this->buffer, 5));
			
			$this->dispatch($cmd, $arg);
			
			if($this->complete) {
				break;
			}
		}
		
		$this->socket->write(SMTP_221);
		$this->socket->close();
	}
	
	function dispatch($cmd, $arg) {			
		switch($cmd) {
			case 'HELO':
			case 'EHLO': $this->HELO($arg); break;
			case 'MAIL': $this->MAIL($arg); break;
			case 'RCPT': $this->RCPT($arg); break;
			case 'DATA': $this->DATA($arg); break;
			case 'HELP': $this->HELP($arg); break;
			case 'QUIT': $this->QUIT($arg); break;
			default: $this->NOT_IMPLEMENTED();
		}
	}
			
	function HELO($arg) {
		$this->socket->write(SMTP_250);
	} 
	
	function MAIL($arg) {
		$arg = trim($arg, 'FROM:<>');
		$arr = explode('@', $arg);
		
		$this->from['user'] = $arg[0];
		$this->from['domain'] = $arg[1];
		
		$this->socket->write(SMTP_250);
	}
	
	function RCPT($arg) {
		$arg = trim($arg, 'TO:<>');
		$arr = explode('@', $arg);
		
		$this->to['user'] = $arr[0];
		$this->to['domain'] = $arr[1];
		
		if(!in_array($this->to['domain'], $this->domains)) {
			$this->socket->write(SMTP_550);
			$this->socket->close();
			
			return;
		}
		
		$this->socket->write(SMTP_250);
	}
	
	function DATA($arg) {
		if(!$this->to) {
			$this->socket->write(SMTP_503);
			$this->socket->close();
			
			return;
		}
		
		$this->socket->write(SMTP_354);
		
		$file = SMTP_DEBUGSMTP_INBOUND.$this->date."-".$this->to['user']."-".$this->to['domain'];
		
		if($msg = fopen($file, 'w+')) {
			while($this->buffer = $this->socket->read()) {
				fwrite($msg, $this->buffer);
				
				if(substr($this->buffer, -5) == "\r\n.\r\n") {
					break;
				}
			}
			
			fclose($msg);
		}
		
		$this->socket->write(SMTP_250);
		
		$this->complete = true;
	}
	
	function HELP($arg) {
		$this->socket->write(SMTP_250);
	}
	
	function QUIT($arg) {
		$this->socket->write(SMTP_221);
		$this->socket->close();
	}
	
	function NOT_IMPLEMENTED() {
		$this->socket->write(SMTP_502);
	}
}
?><commit_msg>Fixed error<commit_after><?php
/**
 * SMTP_Server_Session
 *
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2008, <NAME>
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 1.0
 * @package php-smtp
 */

class SMTP_Server_Session {
	var $socket;
	var $buffer;
	var $date;
	var $to;
	var $from;
	var $domains;
	var $complete;
	
	function SMTP_Server_Session($socket) {
		$this->socket = $socket;
		$this->date = time();
		$this->to = array();
		$this->from = array();
		$this->complete = false;
		
		$this->domains = array(
			'localhost',
			'127.0.0.1',
		);
	}
	
	/**
	 * Enters a loop to read and process incoming commands, exits when $this->complete is true
	 */
	function run() {
		$this->socket->write(SMTP_220);
		
		while($this->buffer = $this->socket->read()) {
			$cmd = substr($this->buffer, 0, 4);
			$arg = trim(substr($this->buffer, 5));
			
			$this->dispatch($cmd, $arg);
			
			if($this->complete) {
				break;
			}
		}
		
		$this->socket->write(SMTP_221);
		$this->socket->close();
	}
	
	function dispatch($cmd, $arg) {			
		switch($cmd) {
			case 'HELO':
			case 'EHLO': $this->HELO($arg); break;
			case 'MAIL': $this->MAIL($arg); break;
			case 'RCPT': $this->RCPT($arg); break;
			case 'DATA': $this->DATA($arg); break;
			case 'HELP': $this->HELP($arg); break;
			case 'QUIT': $this->QUIT($arg); break;
			default: $this->NOT_IMPLEMENTED();
		}
	}
			
	function HELO($arg) {
		$this->socket->write(SMTP_250);
	} 
	
	function MAIL($arg) {
		$arg = trim($arg, 'FROM:<>');
		$arr = explode('@', $arg);
		
		$this->from['user'] = $arg[0];
		$this->from['domain'] = $arg[1];
		
		$this->socket->write(SMTP_250);
	}
	
	function RCPT($arg) {
		$arg = trim($arg, 'TO:<>');
		$arr = explode('@', $arg);
		
		$this->to['user'] = $arr[0];
		$this->to['domain'] = $arr[1];
		
		if(!in_array($this->to['domain'], $this->domains)) {
			$this->socket->write(SMTP_550);
			$this->socket->close();
			
			return;
		}
		
		$this->socket->write(SMTP_250);
	}
	
	function DATA($arg) {
		if(!$this->to) {
			$this->socket->write(SMTP_503);
			$this->socket->close();
			
			return;
		}
		
		$this->socket->write(SMTP_354);
		
		$file = SMTP_INBOUND.$this->date."-".$this->to['user']."-".$this->to['domain'];
		
		if($msg = fopen($file, 'w+')) {
			while($this->buffer = $this->socket->read()) {
				fwrite($msg, $this->buffer);
				
				if(substr($this->buffer, -5) == "\r\n.\r\n") {
					break;
				}
			}
			
			fclose($msg);
		}
		
		$this->socket->write(SMTP_250);
		
		$this->complete = true;
	}
	
	function HELP($arg) {
		$this->socket->write(SMTP_250);
	}
	
	function QUIT($arg) {
		$this->socket->write(SMTP_221);
		$this->socket->close();
	}
	
	function NOT_IMPLEMENTED() {
		$this->socket->write(SMTP_502);
	}
}
?>
{'fraction_non_alphanumeric': 0.23353724361281036, 'fraction_numerical': 0.020151133501259445, 'mean_word_length': 3.224164133738602, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 155, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1966582', 'n_tokens_mistral': 2610, 'n_tokens_neox': 2162, 'n_words': 367}