Missing a repository? Have a look at https://code.cacert.org/.

summaryrefslogtreecommitdiff
blob: 10185fcd18d84b31909cb40c3c1016b7d9794373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<? /*
    LibreSSL - CAcert web application
    Copyright (C) 2004-2008  CAcert Inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; version 2 of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

	$_SESSION['mconn'] = mysql_connect("127.0.0.1", "username", "password");
	if ($_SESSION['mconn'] != FALSE)
	{
		mysql_select_db("database");
		$_SESSION['mconn'] = TRUE;
	}
	$_SESSION['_config']['normalhostname'] = "www.cacert.org";
	$_SESSION['_config']['securehostname'] = "secure.cacert.org";
	$_SESSION['_config']['tverify'] = "tverify.cacert.org";

	function sendmail($to, $subject, $message, $from, $replyto = "", $toname = "", $fromname = "", $errorsto = "returns@cacert.org", $extra="")
	{
		$lines = explode("\n", $message);
		$message = "";
		foreach($lines as $line)
		{
			$line = trim($line);
			if($line == ".")
				$message .= " .\n";
			else
				$message .= $line."\n";
		}

		if($fromname == "")
			$fromname = $from;

		$bits = explode(",", $from);
		$from = addslashes($bits['0']);
		$fromname = addslashes($fromname);

		$smtp = fsockopen("localhost", 25);
		if(!$smtp)
		{
                  echo("Could not connect to mailserver at localhost:25\n");
		  return;
		}
		$InputBuffer = fgets($smtp, 1024);
		fputs($smtp, "HELO www.cacert.org\r\n");
		$InputBuffer = fgets($smtp, 1024);
		fputs($smtp, "MAIL FROM:<returns@cacert.org>\r\n");
		$InputBuffer = fgets($smtp, 1024);
		$bits = explode(",", $to);
		foreach($bits as $user)
			fputs($smtp, "RCPT TO:<".trim($user).">\r\n");
		$InputBuffer = fgets($smtp, 1024);
		fputs($smtp, "DATA\r\n");
		$InputBuffer = fgets($smtp, 1024);
		fputs($smtp, "X-Mailer: CAcert.org Website\r\n");
		if (array_key_exists("REMOTE_ADDR", $_SERVER))
			fputs($smtp, "X-OriginatingIP: ".$_SERVER["REMOTE_ADDR"]."\r\n");
		fputs($smtp, "Sender: $errorsto\r\n");
		fputs($smtp, "Errors-To: $errorsto\r\n");
		if($replyto != "")
			fputs($smtp, "Reply-To: $replyto\r\n");
		else
			fputs($smtp, "Reply-To: $from\r\n");
		fputs($smtp, "From: $from\r\n");
		fputs($smtp, "To: $to\r\n");
		if(preg_match("/[^a-zA-Z0-9 .-\[\]!_@]/",$subject))
		{
			fputs($smtp, "Subject: =?utf-8?B?".base64_encode(recode("html..utf-8", $subject))."?=\r\n");
		}
		else
		{
			fputs($smtp, "Subject: $subject\r\n");
		}
		fputs($smtp, "Mime-Version: 1.0\r\n");
		if($extra == "")
		{
			fputs($smtp, "Content-Type: text/plain; charset=\"utf-8\"\r\n");
			fputs($smtp, "Content-Transfer-Encoding: 8bit\r\n");
		} else {
			fputs($smtp, "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n");
			fputs($smtp, "Content-Transfer-Encoding: quoted-printable\r\n");
			fputs($smtp, "Content-Disposition: inline\r\n");
		}
//		fputs($smtp, "Content-Transfer-Encoding: BASE64\r\n");
		fputs($smtp, "\r\n");
//		fputs($smtp, chunk_split(base64_encode(recode("html..utf-8", $message)))."\r\n.\r\n");
		fputs($smtp, recode("html..utf-8", $message)."\r\n.\r\n");
		fputs($smtp, "QUIT\n");
		$InputBuffer = fgets($smtp, 1024);
		fclose($smtp);
	}

?>