<commit_before><?php

/**
 * @file src/Model/Mail.php
 */
namespace Friendica\Model;

use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Model\Item;
use Friendica\Database\DBA;
use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat;
use Friendica\Worker\Delivery;

/**
 * Class to handle private messages
 */
class Mail
{
	/**
	 * Insert received private message
	 *
	 * @param array $msg
	 * @return int|boolean Message ID or false on error
	 */
	public static function insert($msg)
	{
		$user = User::getById($msg['uid']);

		if (!isset($msg['reply'])) {
			$msg['reply'] = DBA::exists('mail', ['parent-uri' => $msg['parent-uri']]);
		}

		if (empty($msg['convid'])) {
			$mail = DBA::selectFirst('mail', ['convid'], ["`convid` != 0 AND `parent-uri` = ?", $msg['parent-uri']]);
			if (DBA::isResult($mail)) {
				$msg['convid'] = $mail['convid'];
			}
		}

		if (empty($msg['guid'])) {
			$host = parse_url($msg['from-url'], PHP_URL_HOST);
			$msg['guid'] = Item::guidFromUri($msg['uri'], $host);
		}

		DBA::lock('mail');

		if (DBA::exists('mail', ['uri' => $msg['uri'], 'uid' => $msg['uid']])) {
			DBA::unlock();
			Logger::info('duplicate message already delivered.');
			return false;
		}

		DBA::insert('mail', $msg);

		$msg['id'] = DBA::lastInsertId();

		DBA::unlock();

		if (!empty($msg['convid'])) {
			DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $msg['convid']]);
		}

		// send notifications.
		$notif_params = [
			'type' => NOTIFY_MAIL,
			'notify_flags' => $user['notify-flags'],
			'language' => $user['language'],
			'to_name' => $user['username'],
			'to_email' => $user['email'],
			'uid' => $user['uid'],
			'item' => $msg,
			'parent' => 0,
			'source_name' => $msg['from-name'],
			'source_link' => $msg['from-url'],<commit_msg>Sanitize the date for mails<commit_after><?php

/**
 * @file src/Model/Mail.php
 */
namespace Friendica\Model;

use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Model\Item;
use Friendica\Database\DBA;
use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat;
use Friendica\Worker\Delivery;

/**
 * Class to handle private messages
 */
class Mail
{
	/**
	 * Insert received private message
	 *
	 * @param array $msg
	 * @return int|boolean Message ID or false on error
	 */
	public static function insert($msg)
	{
		$user = User::getById($msg['uid']);

		if (!isset($msg['reply'])) {
			$msg['reply'] = DBA::exists('mail', ['parent-uri' => $msg['parent-uri']]);
		}

		if (empty($msg['convid'])) {
			$mail = DBA::selectFirst('mail', ['convid'], ["`convid` != 0 AND `parent-uri` = ?", $msg['parent-uri']]);
			if (DBA::isResult($mail)) {
				$msg['convid'] = $mail['convid'];
			}
		}

		if (empty($msg['guid'])) {
			$host = parse_url($msg['from-url'], PHP_URL_HOST);
			$msg['guid'] = Item::guidFromUri($msg['uri'], $host);
		}

		$msg['created'] = (isset($msg['created']) ? DateTimeFormat::utc($msg['created']) : DateTimeFormat::utcNow());

		DBA::lock('mail');

		if (DBA::exists('mail', ['uri' => $msg['uri'], 'uid' => $msg['uid']])) {
			DBA::unlock();
			Logger::info('duplicate message already delivered.');
			return false;
		}

		DBA::insert('mail', $msg);

		$msg['id'] = DBA::lastInsertId();

		DBA::unlock();

		if (!empty($msg['convid'])) {
			DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $msg['convid']]);
		}

		// send notifications.
		$notif_params = [
			'type' => NOTIFY_MAIL,
			'notify_flags' => $user['notify-flags'],
			'language' => $user['language'],
			'to_name' => $user['username'],
			'to_email' => $user['email'],
			'uid' => $user['uid'],
			'item' => $msg,
			'parent' => 0,
			'source_name' => $msg['from-name'],
			'source_link' => $msg['from-url'],
{'fraction_non_alphanumeric': 0.23809523809523808, 'fraction_numerical': 0.0020817069997397866, 'mean_word_length': 4.391304347826087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '1412651', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1379, 'n_words': 263}