<commit_before><?php
// $Id: notificationemaillib.php,v 1.36.2.2 2008-01-29 19:01:17 sylvieg Exp $
/** \brief send the email notifications dealing with the forum changes to
  * \brief outbound address + admin notification addresses / forum admin email + watching users addresses
  * \param $event = 'forum_post_topic' or 'forum_post_thread'
  * \param $object = forumId watch if forum_post_topic or topicId watch if forum_post_thread
  * \param $threadId = topicId if forum_post_thread
  * \param $title of the message
  * \param $topicName name of the parent topic
  */

include_once('lib/reportslib.php');
  
function sendForumEmailNotification($event, $object, $forum_info, $title, $data, $author, $topicName, $messageId='', $inReplyTo='', $threadId, $parentId, $contributions='', $postId='') {
	global $tikilib, $prefs, $smarty, $userlib;

	// Per-forum From address overrides global default.
	if( $forum_info['outbound_from'] )
	{
	    $my_sender = '"' . "$author" . '" <' . $forum_info['outbound_from'] . '>';
	} else {
	    $my_sender = $prefs['sender_email'];
	}

	//outbound email ->  will be sent in utf8 - from sender_email
	if ($forum_info['outbound_address']) {
		include_once('lib/webmail/tikimaillib.php');
		$mail = new TikiMail();
		$mail->setSubject($title);
		if (!empty($forum_info['outbound_mails_reply_link']) && $forum_info['outbound_mails_reply_link'] == 'y') {
			$foo = parse_url($_SERVER["REQUEST_URI"]);
			$machine = $tikilib->httpPrefix() . dirname( $foo["path"] );
			if ($event == 'forum_post_topic') {
				$reply_link="$machine/tiki-view_forum_thread.php?forumId=" .
				$forum_info['forumId'] .
				"&comments_parentId=$threadId#form";
			} else {
		  		$reply_link="$machine/tiki-view_forum_thread.php?forumId=" .
				$forum_info['forumId'] .
				"&comments_reply_threadId=$object&comments_parentId=$threadId&post_reply=1#form";
			}
		} else {
			$reply_link = '';
		}
		$smarty->assign('title', $title);
		$smarty->assign('data', $data);
		$smarty->assign('reply_link', $reply_link);
		$smarty->assign('author', $author);
		$mail_data = $smarty->fetch("mail/forum_outbound.tpl");
		$mail->setText($mail_data);
		$mail->setHeader("Reply-To", $my_sender);
		$mail->setHeader("From", $my_sender);
		$mail->setSubject($topicName);

		if ($inReplyTo)	{
		    $mail->setHeader("In-Reply-To", "<".$inReplyTo.">");
		}

		global $commentslib;
		$attachments = $commentslib->get_thread_attachments( $event == 'forum_post_topic'? $threadId: $object, 0 );

		if( count( $attachments ) > 0 )
		{
		    foreach ( $attachments as $att )
		    {
				$att_data = $commentslib->get_thread_attachment( $att['attId'] );
				if($att_data['dir'].$att_data['path'] == ""){ // no path to file on disk
					$file = $att_data['data']; // read file from database
				} else {
					$file = $mail->getFile( $att_data['dir'].$att_data['path'] ); // read file from disk
				}
				$mail->addAttachment( $file, $att_data['filename'], $att_data['filetype'] );
		    }
		}


		$mail->buildMessage();

		// Message-ID is set below buildMessage because otherwise lib/webmail/htmlMimeMail.php will over-write it.
		$mail->setHeader("Message-ID", "<".$messageId.">");

		$mail->send(array($forum_info['outbound_address']));
	}

	$nots = array();
	$defaultLanguage = $prefs['site_language'];

	// Users watching this forum or this post
	if ($prefs['feature_user_watches'] == 'y' || $prefs['feature_group_watches'] == 'y') {
		$nots = $tikilib->get_event_watches($event, $event == 'forum_post_topic'? $forum_info['forumId']: $threadId, $forum_info);
		for ($i = count($nots) - 1; $i >=0; --$i) {
			$nots[$i]['language'] = $tikilib->get_user_preference($nots[$i]['user'], "language", $defaultLanguage);
		}
	}

	// Special forward address
	//TODO: merge or use the admin notification feature
	if ($forum_info["useMail"] == 'y') {
		$not['email'] =  $forum_info['mail'];
		if ($not['user'] = $userlib->get_user_by_email($forum_info['mail']) )
			$not['language'] = $tikilib->get_user_preference($not['user'], "language", $defaultLanguage);
		else
			$not['language'] = $defaultLanguage;
		$nots[] = $not;
	}

	global $reportslib;

	if ($prefs['feature_user_watches'] == 'y' && $prefs['feature_daily_report_watches'] == 'y') {
		$reportslib->makeReportCache($nots, array("event"=>$event, "forumId"=>$forum_info['forumId'], "forumName"=>$forum_info['name'], "topicId"=>$threadId, "threadId"=>$postId, "threadName"=>$topicName, "user"=>$author));
	}

	if (count($nots)) {
		include_once('lib/webmail/tikimaillib.php');
		$mail = new TikiMail();
		$smarty->assign('mail_forum', $forum_info["name"]);
		$smarty->assign('mail_title', $title);
		$smarty->assign('mail_date', $tikilib->now);
		$smarty->assign('mail_message', $data);<commit_msg>[ENH] Mozilla upstream 409683. Do not send watch email to post author in forums<commit_after><?php
// $Id: notificationemaillib.php,v 1.36.2.2 2008-01-29 19:01:17 sylvieg Exp $
/** \brief send the email notifications dealing with the forum changes to
  * \brief outbound address + admin notification addresses / forum admin email + watching users addresses
  * \param $event = 'forum_post_topic' or 'forum_post_thread'
  * \param $object = forumId watch if forum_post_topic or topicId watch if forum_post_thread
  * \param $threadId = topicId if forum_post_thread
  * \param $title of the message
  * \param $topicName name of the parent topic
  */

include_once('lib/reportslib.php');
  
function sendForumEmailNotification($event, $object, $forum_info, $title, $data, $author, $topicName, $messageId='', $inReplyTo='', $threadId, $parentId, $contributions='', $postId='') {
	global $tikilib, $prefs, $smarty, $userlib;

	// Per-forum From address overrides global default.
	if( $forum_info['outbound_from'] )
	{
	    $my_sender = '"' . "$author" . '" <' . $forum_info['outbound_from'] . '>';
	} else {
	    $my_sender = $prefs['sender_email'];
	}

	//outbound email ->  will be sent in utf8 - from sender_email
	if ($forum_info['outbound_address']) {
		include_once('lib/webmail/tikimaillib.php');
		$mail = new TikiMail();
		$mail->setSubject($title);
		if (!empty($forum_info['outbound_mails_reply_link']) && $forum_info['outbound_mails_reply_link'] == 'y') {
			$foo = parse_url($_SERVER["REQUEST_URI"]);
			$machine = $tikilib->httpPrefix() . dirname( $foo["path"] );
			if ($event == 'forum_post_topic') {
				$reply_link="$machine/tiki-view_forum_thread.php?forumId=" .
				$forum_info['forumId'] .
				"&comments_parentId=$threadId#form";
			} else {
		  		$reply_link="$machine/tiki-view_forum_thread.php?forumId=" .
				$forum_info['forumId'] .
				"&comments_reply_threadId=$object&comments_parentId=$threadId&post_reply=1#form";
			}
		} else {
			$reply_link = '';
		}
		$smarty->assign('title', $title);
		$smarty->assign('data', $data);
		$smarty->assign('reply_link', $reply_link);
		$smarty->assign('author', $author);
		$mail_data = $smarty->fetch("mail/forum_outbound.tpl");
		$mail->setText($mail_data);
		$mail->setHeader("Reply-To", $my_sender);
		$mail->setHeader("From", $my_sender);
		$mail->setSubject($topicName);

		if ($inReplyTo)	{
		    $mail->setHeader("In-Reply-To", "<".$inReplyTo.">");
		}

		global $commentslib;
		$attachments = $commentslib->get_thread_attachments( $event == 'forum_post_topic'? $threadId: $object, 0 );

		if( count( $attachments ) > 0 )
		{
		    foreach ( $attachments as $att )
		    {
				$att_data = $commentslib->get_thread_attachment( $att['attId'] );
				if($att_data['dir'].$att_data['path'] == ""){ // no path to file on disk
					$file = $att_data['data']; // read file from database
				} else {
					$file = $mail->getFile( $att_data['dir'].$att_data['path'] ); // read file from disk
				}
				$mail->addAttachment( $file, $att_data['filename'], $att_data['filetype'] );
		    }
		}


		$mail->buildMessage();

		// Message-ID is set below buildMessage because otherwise lib/webmail/htmlMimeMail.php will over-write it.
		$mail->setHeader("Message-ID", "<".$messageId.">");

		$mail->send(array($forum_info['outbound_address']));
	}

	$nots = array();
	$defaultLanguage = $prefs['site_language'];

	// Users watching this forum or this post
	if ($prefs['feature_user_watches'] == 'y' || $prefs['feature_group_watches'] == 'y') {
		$nots_raw = $tikilib->get_event_watches($event, $event == 'forum_post_topic'? $forum_info['forumId']: $threadId, $forum_info);
		$nots = array();
		foreach( $nots_raw as $n ) {
			if( $n['user'] != $author ) {
				$n['language'] = $tikilib->get_user_preference($n['user'], "language", $defaultLanguage);
				$nots[] = $n;
			}
		}
	}

	// Special forward address
	//TODO: merge or use the admin notification feature
	if ($forum_info["useMail"] == 'y') {
		$not['email'] =  $forum_info['mail'];
		if ($not['user'] = $userlib->get_user_by_email($forum_info['mail']) )
			$not['language'] = $tikilib->get_user_preference($not['user'], "language", $defaultLanguage);
		else
			$not['language'] = $defaultLanguage;
		$nots[] = $not;
	}

	global $reportslib;

	if ($prefs['feature_user_watches'] == 'y' && $prefs['feature_daily_report_watches'] == 'y') {
		$reportslib->makeReportCache($nots, array("event"=>$event, "forumId"=>$forum_info['forumId'], "forumName"=>$forum_info['name'], "topicId"=>$threadId, "threadId"=>$postId, "threadName"=>$topicName, "user"=>$author));
	}

	if (count($nots)) {
		include_once('lib/webmail/tikimaillib.php');
		$mail = new TikiMail();
		$smarty->assign('mail_forum', $forum_info["name"]);
		$smarty->assign('mail_title', $title);
		$smarty->assign('mail_date', $tikilib->now);
		$smarty->assign('mail_message', $data);
{'fraction_non_alphanumeric': 0.1951372221642492, 'fraction_numerical': 0.005634978607951581, 'mean_word_length': 4.908754623921085, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 86, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5514937', 'n_tokens_mistral': 3758, 'n_tokens_neox': 3378, 'n_words': 630}