4 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
6 $shortoptions = 'e::ay';
7 $longoptions = array('email=', 'all', 'yes');
9 $self = basename($_SERVER['PHP_SELF']);
11 $helptext = <<<END_OF_HELP
13 resends confirmation email either for a specific email (if found) or for
14 all lingering confirmations.
16 NOTE: You probably want to do something like this to your database first so
17 only relatively fresh accounts get resent this:
19 DELETE FROM confirm_address WHERE modified < DATE_SUB(NOW(), INTERVAL 1 month);
23 -e --email e-mail address to send for
24 -a --all send for all emails in confirm_address table
25 -y --yes skip interactive verification
29 require_once INSTALLDIR.'/scripts/commandline.inc';
34 if (have_option('e', 'email')) {
35 $email = get_option_value('e', 'email');
36 $ca = Confirm_address::getAddress($email, 'email');
37 if (!$ca instanceof Confirm_address) {
38 print "Can't find email $email in confirm_address table.\n";
41 } elseif (have_option('a', 'all')) {
43 $ca = new Confirm_address();
44 $ca->address_type = 'email';
46 print "confirm_address table contains no lingering email addresses\n";
50 print "You must provide an email (or --all).\n";
54 if (!have_option('y', 'yes')) {
55 print "About to resend confirm_address email to {$ca->N} recipients. Are you sure? [y/N] ";
56 $response = fgets(STDIN);
57 if (strtolower(trim($response)) != 'y') {
63 function mailConfirmAddress(Confirm_address $ca)
66 $user = User::getByID($ca->user_id);
67 $profile = $user->getProfile();
68 if ($profile->isSilenced()) {
72 if ($user->email === $ca->address) {
73 throw new AlreadyFulfilledException('User already has identical confirmed email address.');
75 } catch (AlreadyFulfilledException $e) {
76 print "\n User already had verified email: "._ve($ca->address);
78 } catch (Exception $e) {
79 print "\n Failed to get user with ID "._ve($user_id).', deleting confirm_address entry: '._ve($e->getMessage());
83 mail_confirm_address($user, $ca->code, $user->getNickname(), $ca->address);
86 require_once(INSTALLDIR . '/lib/mail.php');
89 mailConfirmAddress($ca);
91 while ($ca->fetch()) {
92 mailConfirmAddress($ca);