uid && (strstr($u->mail, '@') == ZALTERNC_SITE_DOMAIN) ) { $has_email_address = true; } return $has_email_address; } function zalternc_auth_update_display_block_mail() { global $user; if ( zalternc_auth_update_has_email_address() ) { $current_dir = getcwd(); $dir = str_replace('@', '_', $user->mail); $path = '/var/alternc/mail/'. escapeshellcmd($user->mail[0]). '/'. escapeshellcmd($dir). '/Maildir/cur'; $output = ""; if (is_dir($path)) { chdir($path); $nbr_unread_files = count(glob('*,')); chdir($current_dir); if ( $nbr_unread_files > 1 ) { $out = t('You have %d unread messages.', array('%d' => $nbr_unread_files)); } else if ( $nbr_unread_files == 1 ) { $out = t('You have %d unread message.', array('%d' => $nbr_unread_files)); } else { $out = t("You don't have any unread messages."); } $out .= '
' . t('Click here to go to webmail'). ''; } return $out; } } /** * implementation of hook_user() */ function zalternc_auth_update_user($op, &$edit, &$user, $category = NULL) { if ($edit['name']) { $name = $edit['name']; } else { $name = $user->name; } switch ($op) { case 'validate': // taken from valid_email_address() because it's being used to invent the email if (!preg_match('/^[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+$/', $name)) { form_set_error('name', t('The username is invalid.')); return $edit; } break; case 'insert': if (!$edit['mail'] || $edit['mail'] == '' || strstr($edit['mail'], '@') == ZALTERNC_SITE_DOMAIN) { $edit['mail'] = strtolower($name . ZALTERNC_SITE_DOMAIN); db_query("UPDATE {users} SET mail = '%s' WHERE uid = %d", $edit['mail'], $user->uid); drupal_set_message('reset ' . $user->uid . ' email to '. $edit['mail']); } break; case 'update': if (!$edit['mail'] || $edit['mail'] == '' || strstr($edit['mail'], '@') == ZALTERNC_SITE_DOMAIN) { $edit['mail'] = strtolower($name . ZALTERNC_SITE_DOMAIN); } break; } $mail = strtolower($name . ZALTERNC_SITE_DOMAIN); $pass = $edit['pass']; switch ($op) { case 'insert': /* recall: * 0 only site admins * 1 everyone * 2 approval necessary */ if (variable_get('user_register', 1) == 1 && zalternc_auth_update_has_email_address(array2object(array_merge($edit, array('uid' => $user->uid))))) { _zalternc_auth_create_email($mail, $pass); drupal_set_message(t('created your homelessnation email')); } break; case 'update': if (!empty($pass) && zalternc_auth_update_has_email_address(array2object(array_merge($edit, array('uid' => $user->uid))))) { $salt = ''; if (variable_get('sql_auth_pass_salt', 0)) { $salt = ', '. variable_get('sql_auth_pass_col', 'pass'); } $res = _sql_auth_query("UPDATE %s SET %s=%s('%s'%s) WHERE %s='%s'", array(variable_get('sql_auth_table', 'users'), variable_get('sql_auth_pass_col', 'pass'), _sql_auth_current_scheme(), $pass, $salt, variable_get('sql_auth_user_col', 'name'), $mail)); drupal_set_message(t("changed webmail password")); } break; } return true; } function _zalternc_auth_create_email($name, $pass) { $salt = ''; if (variable_get('mysql_auth_pass_salt', 0)) { $salt = ", '". user_password() . "'"; // use a random string as an initial salt } /* since Drupal usernames cannot contain periods ("."), it is safe to use the username in a path*/ $alias = str_replace('@', '_', $name); $first = substr($alias, 0, 1); $path = '/var/alternc/mail/'.$first.'/'.$alias; $res = _sql_auth_query("INSERT IGNORE INTO %s (%s, %s) VALUES ('%s', %s('%s'".$salt."))", array(variable_get('sql_auth_table', 'users'), variable_get('sql_auth_user_col', 'name'), variable_get('sql_auth_pass_col', 'pass'), $name, _sql_auth_current_scheme(), $pass)); $res = _sql_auth_query("INSERT IGNORE INTO %s (uid, %s, path, %s) VALUES (%d, '%s', '%s', %s('%s'".$salt.")) ON DUPLICATE KEY UPDATE uid=2001,path='%s'", array(variable_get('sql_auth_table', 'users'), variable_get('sql_auth_user_col', 'name'), variable_get('sql_auth_pass_col', 'pass'), 2001, $name, $path, _sql_auth_current_scheme(), $pass, $path)); $res = _sql_auth_query("INSERT IGNORE INTO %s (uid, %s, path, %s) VALUES (%d, '%s', '%s', %s('%s'".$salt."))", array(variable_get('sql_auth_table', 'users'), variable_get('sql_auth_user_col', 'name'), variable_get('sql_auth_pass_col', 'pass'), 2001, $alias, $path, _sql_auth_current_scheme(), $pass)); $res = _sql_auth_query("INSERT IGNORE INTO mail_domain (mail, alias, uid, pop, type) VALUES ('%s', '%s', '%s', '%s', '%s')", array($name, $alias, 2001, 1, 0)); $res = _sql_auth_query("INSERT IGNORE INTO mail_alias (mail, alias) VALUES ('%s', '%s')", array($alias, $path.'/Maildir/')); $f=fopen("/var/lib/squirrelmail/data/".$alias.".pref","wb"); fputs($f,"email_address=$name\nchosen_theme=default_theme.php\n"); fclose($f); $f=fopen("/var/lib/squirrelmail/data/".$name.".pref","wb"); fputs($f,"email_address=$name\nchosen_theme=default_theme.php\n"); fclose($f); mkdir($path); mkdir($path.'/Maildir'); // okay, we cheat and should use maildirmake, but forgive us. mkdir($path.'/Maildir/cur'); mkdir($path.'/Maildir/new'); mkdir($path.'/Maildir/tmp'); }