public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Trace
data/conf/rspamd/dynmaps/bcc.php
Trace helps you understand code history line by line. See who changed each line, when it changed, and which commit introduced it.
Author
Date
Commit
Line
Code
1
<?php
2
// File size is limited by Nginx site to 10M
3
// To speed things up, we do not include prerequisites
4
header('Content-Type: text/plain');
5
require_once "vars.inc.php";
6
// Do not show errors, we log to using error_log
7
ini_set('error_reporting', 0);
8
// Init database
9
//$dsn = $database_type . ':host=' . $database_host . ';dbname=' . $database_name;
10
$dsn = $database_type . ":unix_socket=" . $database_sock . ";dbname=" . $database_name;
11
$opt = [
12
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
13
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
14
PDO::ATTR_EMULATE_PREPARES => false,
15
];
16
try {
17
$pdo = new PDO($dsn, $database_user, $database_pass, $opt);
18
}
19
catch (PDOException $e) {
20
error_log("BCC MAP SQL ERROR: " . $e . PHP_EOL);
21
http_response_code(501);
22
exit;
23
}
25
function parse_email($email) {
26
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) return false;
27
$a = strrpos($email, '@');
28
return array('local' => substr($email, 0, $a), 'domain' => substr(substr($email, $a), 1));
29
}
30
if (!function_exists('getallheaders')) {
31
function getallheaders() {
32
if (!is_array($_SERVER)) {
33
return array();
34
}
35
$headers = array();
36
foreach ($_SERVER as $name => $value) {
37
if (substr($name, 0, 5) == 'HTTP_') {
38
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
39
}
40
}
41
return $headers;
42
}
43
}
45
// Read headers
46
$headers = getallheaders();
47
// Get rcpt
48
$rcpt = $headers['Rcpt'];
49
// Get from
50
$from = $headers['From'];
51
// Remove tags
52
$rcpt = preg_replace('/^(.*?)\+.*(@.*)$/', '$1$2', $rcpt);
53
$from = preg_replace('/^(.*?)\+.*(@.*)$/', '$1$2', $from);
55
try {
56
if (!empty($rcpt)) {
57
$stmt = $pdo->prepare("SELECT `bcc_dest` FROM `bcc_maps` WHERE `type` = 'rcpt' AND `local_dest` = :local_dest AND `active` = '1'");
58
$stmt->execute(array(
59
':local_dest' => $rcpt
60
));
61
$bcc_dest = $stmt->fetch(PDO::FETCH_ASSOC)['bcc_dest'];
62
if (!empty($bcc_dest) && filter_var($bcc_dest, FILTER_VALIDATE_EMAIL)) {
63
error_log("BCC MAP: returning ". $bcc_dest . " for " . $rcpt . PHP_EOL);
64
http_response_code(201);
65
echo trim($bcc_dest);
66
exit;
67
}
68
}
69
if (!empty($from)) {
70
$stmt = $pdo->prepare("SELECT `bcc_dest` FROM `bcc_maps` WHERE `type` = 'sender' AND `local_dest` = :local_dest AND `active` = '1'");
71
$stmt->execute(array(
72
':local_dest' => $from
73
));
74
$bcc_dest = $stmt->fetch(PDO::FETCH_ASSOC)['bcc_dest'];
75
if (!empty($bcc_dest) && filter_var($bcc_dest, FILTER_VALIDATE_EMAIL)) {
76
error_log("BCC MAP: returning ". $bcc_dest . " for " . $from . PHP_EOL);
77
http_response_code(201);
78
echo trim($bcc_dest);
79
exit;
80
}
81
}
82
}
83
catch (PDOException $e) {
84
error_log("BCC MAP SQL ERROR: " . $e->getMessage() . PHP_EOL);
85
http_response_code(502);
86
exit;
87
}