xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / inc / mail.inc.php (797f5a78b35d27b831400c49046a0b1cf27fc8d6) (2,480B) (mode 100644) [raw]
<?php
require_once($INC . "/prof.inc.php");
require_once($INC . "/log.inc.php");
require_once($INC . "/util.inc.php");


$rg_mail_error = "";

function rg_mail_set_error($str)
{
	global $rg_mail_error;
	$rg_mail_error = $str;
}

function rg_mail_error()
{
	global $rg_mail_error;
	return $rg_mail_error;
}

/*
 * Function to send e-mails
 * TODO: Replace mail() with rg_mail everywhere.
 */
function rg_mail_template($template, $more)
{
	global $rg_admin_name, $rg_admin_email;

	rg_prof_start("mail_template");
	rg_log("mail_template: $template, more=" . rg_array2string($more));

	$ret = FALSE;
	while (1) {
		if (!isset($more['ignore_debug']))
			$more['ignore_debug'] = 0;

		if (!isset($more['ui']['ignore_confirmed']))
			$more['ui']['ignore_confirmed'] = 0;

		if (($more['ui']['ignore_confirmed'] == 0)
			&& ($more['ui']['confirmed'] == 0)) {
				rg_log('Confirmed is 0 and ignore_confirmed is 0!');
				$ret = TRUE;
				break;
		}

		if (empty($more['ui']['email'])) {
			$ret = TRUE;
			break;
		}

		$more['HTML:rg_admin_email'] = $rg_admin_email;
		$more['HTML:utf8_rg_admin_name'] = "=?UTF-8?B?"
			. base64_encode($rg_admin_name) . "?=";

		$subject = rg_template($template . ".subj.txt", $more, FALSE /*xss*/);
		$subject = trim($subject);
		$subject = str_replace("\r", '', $subject);
		$subject = str_replace("\n", '', $subject);
		// TODO: do not encode it as UTF-8 if not needed
		$subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";

		$header = rg_template("mail/common.head.txt", $more, FALSE /*xss*/);
		$header .= rg_template($template . ".head.txt", $more, FALSE /*xss*/);
		$header = trim($header);

		$body = rg_template($template . ".body.txt", $more, FALSE /*xss*/);

		rg_log("CHECK: mail_template(" . $more['ui']['email']
			. ", $subject, $body, $header, -f $rg_admin_email");
		if (($more['debug'] == 1) && ($more['ignore_debug'] == 0)) {
			if (!isset($more['ui']['uid']))
				$k = $more['ui']['email'];
			else
				$k = $more['ui']['uid'];

			rg_cache_set('DEBUG::' . $k . '::mail::' . $template,
				array(
					'header' => $header,
					'subject' => $subject,
					'to' => $more['ui']['email'],
					'body' => $body
				), RG_SOCKET_NO_WAIT);
			$ret = TRUE;
			break;
		}

		$ret = mail($more['ui']['email'], $subject, $body, $header,
			"-f $rg_admin_email");
		if ($ret === FALSE)
			rg_log("Sending mail failed to=" . $more['ui']['email']
				. " subject=$subject!");
		break;
	}

	rg_prof_end("mail_template");
	return $ret;
}

?>
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master