<?php

function update_postfix_aliases() {
  $postfix_alias_file = "/etc/postfix/aliases.users";
  $query = "SELECT user_mail,user_alias FROM users_db WHERE user_mail IS NOT NULL AND user_alias IS NOT NULL AND user_enable = 1";
  $result = mysql_query($query) or die("unable to query db");
  $str = "";
  while ($user = mysql_fetch_array($result)) {
    $str .= $user["user_alias"].":\t".$user["user_mail"]."\n";
  }

  if (strlen(trim($str)) > 0) {
    $f = fopen($postfix_alias_file, "w");
    fwrite($f, $str);
    fclose($f);
    system("/usr/bin/newaliases");
  }
 }
?>