<commit_before><?php
namespace Zotlabs\Module;

require_once('include/acl_selectors.php');
require_once('include/message.php');
require_once('include/zot.php');
require_once("include/bbcode.php");




class Mail extends \Zotlabs\Web\Controller {

	function post() {
	
		if(! local_channel())
			return;
	
		$replyto   = ((x($_REQUEST,'replyto'))      ? notags(trim($_REQUEST['replyto']))      : '');
		$subject   = ((x($_REQUEST,'subject'))      ? notags(trim($_REQUEST['subject']))      : '');
		$body      = ((x($_REQUEST,'body'))         ? escape_tags(trim($_REQUEST['body']))    : '');
		$recipient = ((x($_REQUEST,'messageto'))    ? notags(trim($_REQUEST['messageto']))    : '');
		$rstr      = ((x($_REQUEST,'messagerecip')) ? notags(trim($_REQUEST['messagerecip'])) : '');
		$preview   = ((x($_REQUEST,'preview'))      ? intval($_REQUEST['preview'])            : 0);
		$expires   = ((x($_REQUEST,'expires'))      ? datetime_convert(date_default_timezone_get(),'UTC', $_REQUEST['expires']) : NULL_DATE);
		$raw       = ((x($_REQUEST,'raw'))          ? intval($_REQUEST['raw'])                : 0);
		$mimetype  = ((x($_REQUEST,'mimetype'))     ? notags(trim($_REQUEST['mimetype']))     : 'text/bbcode');

		if($preview) {

			if($raw) {
				$body = mail_prepare_binary(['id' => 'M0']);
				echo json_encode(['preview' => $body]);
			}
			else {
				$body = cleanup_bbcode($body);
				$results = linkify_tags($a, $body, local_channel());

				if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) {
					$attachments = array();
					foreach($match[2] as $mtch) {
						$hash = substr($mtch,0,strpos($mtch,','));
						$rev = intval(substr($mtch,strpos($mtch,',')));
						$r = attach_by_hash_nodata($hash,get_observer_hash(),$rev);
						if($r['success']) {
							$attachments[] = array(
								'href'     => z_root() . '/attach/' . $r['data']['hash'],
								'length'   =>  $r['data']['filesize'],
								'type'     => $r['data']['filetype'],
								'title'    => urlencode($r['data']['filename']),
								'revision' => $r['data']['revision']
							);
						}
						$body = trim(str_replace($match[1],'',$body));
					}
					echo json_encode(['preview' => zidify_links(smilies(bbcode($body)))]);
				}
			}
			killme();
		} 

		// If we have a raw string for a recipient which hasn't been auto-filled,<commit_msg>return preview also if we have no attachment<commit_after><?php
namespace Zotlabs\Module;

require_once('include/acl_selectors.php');
require_once('include/message.php');
require_once('include/zot.php');
require_once("include/bbcode.php");




class Mail extends \Zotlabs\Web\Controller {

	function post() {
	
		if(! local_channel())
			return;
	
		$replyto   = ((x($_REQUEST,'replyto'))      ? notags(trim($_REQUEST['replyto']))      : '');
		$subject   = ((x($_REQUEST,'subject'))      ? notags(trim($_REQUEST['subject']))      : '');
		$body      = ((x($_REQUEST,'body'))         ? escape_tags(trim($_REQUEST['body']))    : '');
		$recipient = ((x($_REQUEST,'messageto'))    ? notags(trim($_REQUEST['messageto']))    : '');
		$rstr      = ((x($_REQUEST,'messagerecip')) ? notags(trim($_REQUEST['messagerecip'])) : '');
		$preview   = ((x($_REQUEST,'preview'))      ? intval($_REQUEST['preview'])            : 0);
		$expires   = ((x($_REQUEST,'expires'))      ? datetime_convert(date_default_timezone_get(),'UTC', $_REQUEST['expires']) : NULL_DATE);
		$raw       = ((x($_REQUEST,'raw'))          ? intval($_REQUEST['raw'])                : 0);
		$mimetype  = ((x($_REQUEST,'mimetype'))     ? notags(trim($_REQUEST['mimetype']))     : 'text/bbcode');

		if($preview) {

			if($raw) {
				$body = mail_prepare_binary(['id' => 'M0']);
				echo json_encode(['preview' => $body]);
			}
			else {
				$body = cleanup_bbcode($body);
				$results = linkify_tags($a, $body, local_channel());

				if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) {
					$attachments = array();
					foreach($match[2] as $mtch) {
						$hash = substr($mtch,0,strpos($mtch,','));
						$rev = intval(substr($mtch,strpos($mtch,',')));
						$r = attach_by_hash_nodata($hash,get_observer_hash(),$rev);
						if($r['success']) {
							$attachments[] = array(
								'href'     => z_root() . '/attach/' . $r['data']['hash'],
								'length'   =>  $r['data']['filesize'],
								'type'     => $r['data']['filetype'],
								'title'    => urlencode($r['data']['filename']),
								'revision' => $r['data']['revision']
							);
						}
						$body = trim(str_replace($match[1],'',$body));
					}
				}
				echo json_encode(['preview' => zidify_links(smilies(bbcode($body)))]);
			}
			killme();
		} 

		// If we have a raw string for a recipient which hasn't been auto-filled,
{'fraction_non_alphanumeric': 0.23243014394580863, 'fraction_numerical': 0.002540220152413209, 'mean_word_length': 3.453345900094251, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '5488310', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1565, 'n_words': 224}