Download | Plain Text | No Line Numbers


  1. --- html/functions.inc.php.orig 2010-05-24 18:34:26.000000000 +0200
  2. +++ html/functions.inc.php 2010-05-24 18:40:33.000000000 +0200
  3. @@ -1293,4 +1293,6 @@
  4. return false;
  5. }
  6.  
  7. +require_once($confixx_homeDir . '/udmedia.inc.php');
  8. +
  9. ?>
  10. --- /dev/null 2012-02-21 15:24:06.016184274 +0100
  11. +++ udmedia.inc.php 2012-09-24 14:02:03.000000000 +0200
  12. @@ -0,0 +1,275 @@
  13. +<?php
  14. +
  15. +/*
  16. + * get all destination from email: $user@$domain of $customer on $serverid
  17. + */
  18. +function email_get_destination($user, $domain, $customer, $serverid)
  19. +{
  20. + if ($user instanceof SQLString)
  21. + $user = $user->GetValue();
  22. + if ($domain instanceof SQLString)
  23. + $domain = $domain->GetValue();
  24. + if ($customer instanceof SQLString)
  25. + $customer = $customer->GetValue();
  26. +
  27. + $dbres = safe_query2("
  28. + SELECT fwd.pop3
  29. + FROM email e
  30. + JOIN email_forward fwd
  31. + ON (e.ident = fwd.email_ident AND e.kunde = fwd.kunde AND e.server_id = fwd.server_id)
  32. + WHERE e.prefix = ? AND e.domain = ? AND e.kunde = ? AND e.server_id = '".$serverid."'",
  33. + new SQLString($user),
  34. + new SQLString($domain),
  35. + new SQLString($customer)
  36. + );
  37. +
  38. + $result = array();
  39. + while($row = db_fetch_array($dbres))
  40. + $result[] = $row['pop3'];
  41. + return $result;
  42. +}
  43. +
  44. +/*
  45. + * reverse of email_get_destination
  46. + * returns all mail addresses that forwards to $user
  47. + */
  48. +function email_get_source($user, $domain, $customer, $serverid)
  49. +{
  50. + if ($user instanceof SQLString)
  51. + $user = $user->GetValue();
  52. + if ($domain instanceof SQLString)
  53. + $domain = $domain->GetValue();
  54. + if ($customer instanceof SQLString)
  55. + $customer = $customer->GetValue();
  56. + $email = (empty($domain)) ? $user : $user . '@' . $domain;
  57. +
  58. + $dbres = safe_query2("
  59. + SELECT e.prefix, e.domain
  60. + FROM email e
  61. + JOIN email_forward fwd
  62. + ON (e.ident = fwd.email_ident AND e.kunde = fwd.kunde AND e.server_id = fwd.server_id)
  63. + WHERE fwd.pop3 = ? AND e.kunde = ? AND e.server_id = '".$serverid."'",
  64. + new SQLString($email),
  65. + new SQLString($customer)
  66. + );
  67. +
  68. + $result = array();
  69. + while($row = db_fetch_array($dbres))
  70. + {
  71. + $result[] = array(
  72. + 'prefix' => $row['prefix'],
  73. + 'domain' => $row['domain']
  74. + );
  75. + }
  76. + return $result;
  77. +}
  78. +
  79. +/*
  80. + * walks back the email address to its origin (may be muliple)
  81. + * format:
  82. + * array(
  83. + * array('u1@dom', 'u1fwd1@dom', 'u1fwd2@dom', 'dest@dom'),
  84. + * array('u2@dom', 'u2fwd1@dom', ...),
  85. + * ...
  86. + * )
  87. + */
  88. +function email_walkback($user, $domain, $customer, $serverid, $routes = array())
  89. +{
  90. + if ($user instanceof SQLString)
  91. + $user = $user->GetValue();
  92. + if ($domain instanceof SQLString)
  93. + $domain = $domain->GetValue();
  94. + if ($customer instanceof SQLString)
  95. + $customer = $customer->GetValue();
  96. + $email = (empty($domain)) ? $user : $user . '@' . $domain;
  97. +
  98. + /* add the looked up address to the route too */
  99. + if (empty($routes))
  100. + $routes[] = $email;
  101. +
  102. + $sources = email_get_source($user, $domain, $customer, $serverid);
  103. + /* if address has no more sources (= forwards to this address) return the route */
  104. + if (empty($sources))
  105. + return array($routes);
  106. +
  107. + $result = array();
  108. + foreach($sources as $source)
  109. + {
  110. + $routescpy = $routes;
  111. + array_unshift($routescpy, $source['prefix'] . '@' . $source['domain']);
  112. + $tmpres = email_walkback($source['prefix'], $source['domain'], $customer, $serverid, $routescpy);
  113. + if (is_array($tmpres[0]))
  114. + $result = array_merge($result, $tmpres);
  115. + else
  116. + $result[] = $tmpres;
  117. + }
  118. + return $result;
  119. +}
  120. +
  121. +/*
  122. + * walks the email address to its destination (may be multiple)
  123. + * format:
  124. + * array(
  125. + * array('f1@dom', 'f2@dom', 'dest1@dom'),
  126. + * array('f1@dom', 'f3@dom', 'dest2@dom'),
  127. + * ...
  128. + * )
  129. + */
  130. +function email_walkforward($user, $domain, $customer, $serverid, $routes = array())
  131. +{
  132. + if ($user instanceof SQLString)
  133. + $user = $user->GetValue();
  134. + if ($domain instanceof SQLString)
  135. + $domain = $domain->GetValue();
  136. + if ($customer instanceof SQLString)
  137. + $customer = $customer->GetValue();
  138. + $email = (empty($domain)) ? $user : $user . '@' . $domain;
  139. +
  140. + /* add the looked up address to the route too */
  141. + if (empty($routes))
  142. + $routes[] = $email;
  143. +
  144. + $dests = email_get_destination($user, $domain, $customer, $serverid);
  145. + if (empty($dests))
  146. + return array($routes);
  147. +
  148. + $result = array();
  149. + foreach($dests as $dest)
  150. + {
  151. + $routescpy = $routes;
  152. + array_push($routescpy, $dest);
  153. +
  154. + list($dest_user, $dest_domain) = explode('@', $dest . '@', 2);
  155. + $tmpres = email_walkforward($dest_user, $dest_domain, $customer, $serverid, $routescpy);
  156. + if (is_array($tmpres[0]))
  157. + $result = array_merge($result, $tmpres);
  158. + else
  159. + $result[] = $tmpres;
  160. + }
  161. + return $result;
  162. +}
  163. +
  164. +/*
  165. + * simple loop detection algorithm:
  166. + * - walk back the source address to its origins
  167. + * - walk forward the destination address to its final destinations
  168. + * - if an email address appears in both arrays we have a loop
  169. + *
  170. + * returns the found mail loops as array
  171. + */
  172. +function email_checkloop($source_user, $source_domain,
  173. + $dest_user, $dest_domain, $customer, $serverid)
  174. +{
  175. + $origins = email_walkback($source_user, $source_domain, $customer, $serverid);
  176. + $dests = email_walkforward($dest_user, $dest_domain, $customer, $serverid);
  177. +
  178. + $result = array();
  179. + foreach($origins as $origin)
  180. + {
  181. + $loop = array();
  182. + foreach($dests as $dest)
  183. + {
  184. + $intersect = array_intersect($origin, $dest);
  185. + if (empty($intersect))
  186. + continue;
  187. +
  188. + $loop[] = $source_user . '@' . $source_domain;
  189. + for($i = 0; $i < count($dest); ++$i)
  190. + {
  191. + $loop[] = $dest[$i];
  192. + if ($dest[$i] == current($intersect))
  193. + break;
  194. + }
  195. +
  196. + /* start at index of intersection of origin */
  197. + for($i = key($intersect) + 1; $i < count($origin); ++$i)
  198. + {
  199. + $loop[] = $origin[$i];
  200. + if ($origin[$i] == $s[0] . '@' . $s[1])
  201. + break;
  202. + }
  203. + break;
  204. + }
  205. +
  206. + if (!empty($loop))
  207. + $result[] = $loop;
  208. + }
  209. + return $result;
  210. +}
  211. +
  212. +#-------------------------------------------------------------------------------
  213. +
  214. +$lang_udmedia['en']['mailloop'] = "You will create at least one e-mail loop with this forward <i>%s</i>:";
  215. +$lang_udmedia['de']['mailloop'] = "Sie erzeugen mindestens eine E-Mail-Schleife mit dieser Weiterleitung <i>%s</i>:";
  216. +
  217. +function ltextud($identifier)
  218. +{
  219. + global $lang_udmedia;
  220. + global $shortlang;
  221. +
  222. + $text = "";
  223. + if (isset($shortlang) && isset($lang_udmedia[$shortlang][$identifier]))
  224. + $text = $lang_udmedia[$shortlang][$identifier];
  225. + else if (isset($lang_udmedia['en'][$identifier]))
  226. + $text = $lang_udmedia['en'][$identifier];
  227. +
  228. + $args = func_get_args();
  229. + array_shift($args);
  230. + if (!empty($text) && count($args))
  231. + $text = vsprintf($text, $args);
  232. +
  233. + return $text;
  234. +}
  235. +
  236. +#-------------------------------------------------------------------------------
  237. +
  238. +function call_user_func_array_reffix($name, &$args)
  239. +{
  240. + $refl = null;
  241. + if (is_array($name) && count($name) == 2 && is_object($name[0]) && is_string($name[1]))
  242. + $refl = new ReflectionMethod(get_class($name[0]), $name[1]);
  243. + else if (is_string($name))
  244. + $refl = new ReflectionFunction($name);
  245. + if ($refl == null)
  246. + return array();
  247. +
  248. + $ret = array();
  249. + $params = $refl->getParameters();
  250. + for($i = 0; $i < count($args); ++$i)
  251. + {
  252. + if (isset($params[$i]) && $params[$i]->isPassedByReference())
  253. + $ret[$i] = &$args[$i];
  254. + else
  255. + $ret[$i] = $args[$i];
  256. + }
  257. + return $ret;
  258. +}
  259. +
  260. +function call_user_func_array2($name, $args)
  261. +{
  262. + return call_user_func_array($name, call_user_func_array_reffix($name, $args));
  263. +}
  264. +
  265. +#-------------------------------------------------------------------------------
  266. +
  267. +if (!function_exists('session_register'))
  268. +{
  269. + function session_register()
  270. + {
  271. + $args = func_get_args();
  272. + foreach($args as $key)
  273. + $_SESSION[$key] = $GLOBALS[$key];
  274. + }
  275. +
  276. + function session_is_registered($key)
  277. + {
  278. + return isset($_SESSION[$key]);
  279. + }
  280. +
  281. + function session_unregister($key)
  282. + {
  283. + unset($_SESSION[$key]);
  284. + }
  285. +}
  286. +
  287. +?>
  288.