--- html/functions.inc.php.orig 2010-05-24 18:34:26.000000000 +0200 +++ html/functions.inc.php 2010-05-24 18:40:33.000000000 +0200 @@ -1293,4 +1293,6 @@ return false; } +require_once($confixx_homeDir . '/udmedia.inc.php'); + ?> --- /dev/null 2012-02-21 15:24:06.016184274 +0100 +++ udmedia.inc.php 2012-09-24 14:02:03.000000000 +0200 @@ -0,0 +1,275 @@ +GetValue(); + if ($domain instanceof SQLString) + $domain = $domain->GetValue(); + if ($customer instanceof SQLString) + $customer = $customer->GetValue(); + + $dbres = safe_query2(" + SELECT fwd.pop3 + FROM email e + JOIN email_forward fwd + ON (e.ident = fwd.email_ident AND e.kunde = fwd.kunde AND e.server_id = fwd.server_id) + WHERE e.prefix = ? AND e.domain = ? AND e.kunde = ? AND e.server_id = '".$serverid."'", + new SQLString($user), + new SQLString($domain), + new SQLString($customer) + ); + + $result = array(); + while($row = db_fetch_array($dbres)) + $result[] = $row['pop3']; + return $result; +} + +/* + * reverse of email_get_destination + * returns all mail addresses that forwards to $user + */ +function email_get_source($user, $domain, $customer, $serverid) +{ + if ($user instanceof SQLString) + $user = $user->GetValue(); + if ($domain instanceof SQLString) + $domain = $domain->GetValue(); + if ($customer instanceof SQLString) + $customer = $customer->GetValue(); + $email = (empty($domain)) ? $user : $user . '@' . $domain; + + $dbres = safe_query2(" + SELECT e.prefix, e.domain + FROM email e + JOIN email_forward fwd + ON (e.ident = fwd.email_ident AND e.kunde = fwd.kunde AND e.server_id = fwd.server_id) + WHERE fwd.pop3 = ? AND e.kunde = ? AND e.server_id = '".$serverid."'", + new SQLString($email), + new SQLString($customer) + ); + + $result = array(); + while($row = db_fetch_array($dbres)) + { + $result[] = array( + 'prefix' => $row['prefix'], + 'domain' => $row['domain'] + ); + } + return $result; +} + +/* + * walks back the email address to its origin (may be muliple) + * format: + * array( + * array('u1@dom', 'u1fwd1@dom', 'u1fwd2@dom', 'dest@dom'), + * array('u2@dom', 'u2fwd1@dom', ...), + * ... + * ) + */ +function email_walkback($user, $domain, $customer, $serverid, $routes = array()) +{ + if ($user instanceof SQLString) + $user = $user->GetValue(); + if ($domain instanceof SQLString) + $domain = $domain->GetValue(); + if ($customer instanceof SQLString) + $customer = $customer->GetValue(); + $email = (empty($domain)) ? $user : $user . '@' . $domain; + + /* add the looked up address to the route too */ + if (empty($routes)) + $routes[] = $email; + + $sources = email_get_source($user, $domain, $customer, $serverid); + /* if address has no more sources (= forwards to this address) return the route */ + if (empty($sources)) + return array($routes); + + $result = array(); + foreach($sources as $source) + { + $routescpy = $routes; + array_unshift($routescpy, $source['prefix'] . '@' . $source['domain']); + $tmpres = email_walkback($source['prefix'], $source['domain'], $customer, $serverid, $routescpy); + if (is_array($tmpres[0])) + $result = array_merge($result, $tmpres); + else + $result[] = $tmpres; + } + return $result; +} + +/* + * walks the email address to its destination (may be multiple) + * format: + * array( + * array('f1@dom', 'f2@dom', 'dest1@dom'), + * array('f1@dom', 'f3@dom', 'dest2@dom'), + * ... + * ) + */ +function email_walkforward($user, $domain, $customer, $serverid, $routes = array()) +{ + if ($user instanceof SQLString) + $user = $user->GetValue(); + if ($domain instanceof SQLString) + $domain = $domain->GetValue(); + if ($customer instanceof SQLString) + $customer = $customer->GetValue(); + $email = (empty($domain)) ? $user : $user . '@' . $domain; + + /* add the looked up address to the route too */ + if (empty($routes)) + $routes[] = $email; + + $dests = email_get_destination($user, $domain, $customer, $serverid); + if (empty($dests)) + return array($routes); + + $result = array(); + foreach($dests as $dest) + { + $routescpy = $routes; + array_push($routescpy, $dest); + + list($dest_user, $dest_domain) = explode('@', $dest . '@', 2); + $tmpres = email_walkforward($dest_user, $dest_domain, $customer, $serverid, $routescpy); + if (is_array($tmpres[0])) + $result = array_merge($result, $tmpres); + else + $result[] = $tmpres; + } + return $result; +} + +/* + * simple loop detection algorithm: + * - walk back the source address to its origins + * - walk forward the destination address to its final destinations + * - if an email address appears in both arrays we have a loop + * + * returns the found mail loops as array + */ +function email_checkloop($source_user, $source_domain, + $dest_user, $dest_domain, $customer, $serverid) +{ + $origins = email_walkback($source_user, $source_domain, $customer, $serverid); + $dests = email_walkforward($dest_user, $dest_domain, $customer, $serverid); + + $result = array(); + foreach($origins as $origin) + { + $loop = array(); + foreach($dests as $dest) + { + $intersect = array_intersect($origin, $dest); + if (empty($intersect)) + continue; + + $loop[] = $source_user . '@' . $source_domain; + for($i = 0; $i < count($dest); ++$i) + { + $loop[] = $dest[$i]; + if ($dest[$i] == current($intersect)) + break; + } + + /* start at index of intersection of origin */ + for($i = key($intersect) + 1; $i < count($origin); ++$i) + { + $loop[] = $origin[$i]; + if ($origin[$i] == $s[0] . '@' . $s[1]) + break; + } + break; + } + + if (!empty($loop)) + $result[] = $loop; + } + return $result; +} + +#------------------------------------------------------------------------------- + +$lang_udmedia['en']['mailloop'] = "You will create at least one e-mail loop with this forward %s:"; +$lang_udmedia['de']['mailloop'] = "Sie erzeugen mindestens eine E-Mail-Schleife mit dieser Weiterleitung %s:"; + +function ltextud($identifier) +{ + global $lang_udmedia; + global $shortlang; + + $text = ""; + if (isset($shortlang) && isset($lang_udmedia[$shortlang][$identifier])) + $text = $lang_udmedia[$shortlang][$identifier]; + else if (isset($lang_udmedia['en'][$identifier])) + $text = $lang_udmedia['en'][$identifier]; + + $args = func_get_args(); + array_shift($args); + if (!empty($text) && count($args)) + $text = vsprintf($text, $args); + + return $text; +} + +#------------------------------------------------------------------------------- + +function call_user_func_array_reffix($name, &$args) +{ + $refl = null; + if (is_array($name) && count($name) == 2 && is_object($name[0]) && is_string($name[1])) + $refl = new ReflectionMethod(get_class($name[0]), $name[1]); + else if (is_string($name)) + $refl = new ReflectionFunction($name); + if ($refl == null) + return array(); + + $ret = array(); + $params = $refl->getParameters(); + for($i = 0; $i < count($args); ++$i) + { + if (isset($params[$i]) && $params[$i]->isPassedByReference()) + $ret[$i] = &$args[$i]; + else + $ret[$i] = $args[$i]; + } + return $ret; +} + +function call_user_func_array2($name, $args) +{ + return call_user_func_array($name, call_user_func_array_reffix($name, $args)); +} + +#------------------------------------------------------------------------------- + +if (!function_exists('session_register')) +{ + function session_register() + { + $args = func_get_args(); + foreach($args as $key) + $_SESSION[$key] = $GLOBALS[$key]; + } + + function session_is_registered($key) + { + return isset($_SESSION[$key]); + } + + function session_unregister($key) + { + unset($_SESSION[$key]); + } +} + +?>