--- inactive_user.module	2007-05-07 03:26:33.000000000 +0200
+++ inactive_user.module.patched	2007-12-20 16:19:00.000000000 +0100
@@ -45,7 +45,9 @@ function inactive_user_custom_settings()
   if (user_access('change inactive user settings')) {
     $period = array(0 => 'disabled') + drupal_map_assoc(array(604800, 1209600, 1814400, 2419200, 2592000, 7776000, 15552000, 23328000, 31536000, 47088000, 63072000), '_format_interval');
     $warn_period = array(0 => 'disabled') + drupal_map_assoc(array(86400, 172800, 259200, 604800, 1209600, 1814400, 2592000), '_format_interval');
-    $mail_variables = ' %username, %useremail, %lastaccess, %period, %sitename, %siteurl';
+    $grace_period = $period;	//for never-returned users
+    unset ( $grace_period[0] );		// assures that users newer than 1 week will never be notified
+    $mail_variables = ' %username, %useremail, %lastaccess, %period, @sitename, %siteurl';
 
     // set administrator e-mail
     $form['inactive_user_admin_email_fieldset'] = array(
@@ -63,7 +65,43 @@ function inactive_user_custom_settings()
       '#required' => TRUE,
     );
 
-    // inactive user notification
+    // notification of never-returned user
+    $form['inactive_user_never_returned_notification'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Never-returned user notification'),
+      '#collapsible' => TRUE,
+      '#collapsed' => FALSE,
+    );
+    $form['inactive_user_never_returned_notification']['inactive_user_never_returned_notify_admin'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Notify administrator when a user has never logged in.'),
+      '#default_value' => variable_get('inactive_user_never_returned_notify_admin', 0),
+      '#description' => t('Generate an email to notify the site administrator that a user account has never been used after registration.  Requires crontab.'),
+    );
+    $form['inactive_user_never_returned_notification']['inactive_user_never_returned_user_notify'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Notify users when they have never logged in.'),
+      '#default_value' => variable_get('inactive_user_never_returned_user_notify', 0),
+      '#description' => t('Generate an email to notify users when they have never used their account after registration.  Requires crontab.'),
+    );
+    $form['inactive_user_never_returned_notification']['inactive_user_never_returned_grace_period'] = array(
+      '#type' => 'select',
+      '#title' => t('Don\'t notify about users newer than'),
+      '#default_value' => variable_get('inactive_user_never_returned_grace_period', 604800),
+      '#options' => $grace_period,
+      '#description' => t('Allows notification of users whose accounts have been created before the set time. Defaults to one week. Setting this period to zero is not allowed, to avoid notification of newly created users. Requires crontab.'),
+    );
+    $form['inactive_user_never_returned_notification']['inactive_user_never_returned_user_notify_text'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Body of user notification e-mail'),
+      '#default_value' => variable_get('inactive_user_never_returned_user_notify_text', _inactive_user_mail_text('never_returned_notify_text')),
+      '#cols' => 70,
+      '#rows' => 10,
+      '#description' => t('Customize the body of the notification e-mail sent to the user.') . ' ' . t('Available variables are:') . $mail_variables,
+      '#required' => TRUE,
+    );
+    
+	// inactive user notification
     $form['inactive_user_notification'] = array(
       '#type' => 'fieldset',
       '#title' => t('Inactive user notification'),
@@ -244,9 +282,43 @@ function inactive_user_cron() {
       }
     }
 
-    // notify administrator of inactive user accounts
+    // notify administrator of never-returned user accounts (doesn't send e-mails for a week after registration)
+    if ( variable_get('inactive_user_never_returned_notify_admin', 0) && $grace_time = variable_get('inactive_user_never_returned_grace_period', 604800) ) {
+      $result = db_query('SELECT uid, name, mail, access, login, created FROM {users} WHERE ( access = 0 or login = 0 ) && NOT (uid=1) and created < %d ORDER BY uid ASC', time() - $grace_time);
+      while ($user = db_fetch_object($result)) {
+        if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND notified_never_return_admin = 1 and never_returned = 1', $user->uid)) ) {
+          db_query('UPDATE {inactive_users} SET notified_never_return_admin = 1, never_returned = 1 WHERE uid = %d', $user->uid);
+          if (!db_affected_rows()) {
+            // must create a new row
+            @db_query('INSERT INTO {inactive_users} (uid, notified_never_return_admin, never_returned) VALUES(%d, 1, 1)', $user->uid);
+          }
+          $user_list .= "$user->uid $user->name ($user->mail)\n";
+        }
+      }
+      if ($user_list) {
+        _inactive_user_mail(t('[@sitename] Never-returned users', array('@sitename' => variable_get('site_name', 'drupal'))), _inactive_user_mail_text('never_returned_notify_admin_text'), $notify_time, NULL, $user_list);
+        unset($user_list);
+      }
+    }
+
+    // notify users that their account has never been used (doesn't send e-mails for a week after registration)
+    if ( variable_get('inactive_user_never_returned_user_notify', 0) && $grace_time = variable_get('inactive_user_never_returned_grace_period', 604800) ) {
+      $result = db_query('SELECT uid, name, mail, access, login, created FROM {users} WHERE ( access = 0 or login = 0 ) AND status != 0 AND NOT (uid=1)  and created < %d', time() - $grace_time);
+      while ($user = db_fetch_object($result)) {
+        if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE notified_never_return_user = 1 and never_returned = 1 AND uid = %d', $user->uid)) ) {
+          db_query('UPDATE {inactive_users} SET notified_never_return_user = 1, never_returned = 1 WHERE uid = %d', $user->uid);
+          if (!db_affected_rows()) {
+            @db_query('INSERT INTO {inactive_users} (uid, notified_never_return_user, never_returned) VALUES(%d, 1, 1)', $user->uid);
+          }
+          _inactive_user_mail(t('[@sitename] Never-used account', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_never_returned_user_notify_text', _inactive_user_mail_text('never_returned_notify_text')), $notify_time, $user, NULL);
+          watchdog('user', t('user %user notified of never-used account', array('%user' => $user->name)), WATCHDOG_NOTICE, l(t('edit user'), "admin/user/edit/$uid"));
+        }
+      }
+    }
+    
+        // notify administrator of inactive user accounts
     if ($notify_time = variable_get('inactive_user_notify_admin', 0)) {
-      $result = db_query('SELECT uid, name, mail, access, created FROM {users} WHERE access < (%d - %d) && NOT (uid=1)', time(), $notify_time);
+      $result = db_query('SELECT uid, name, mail, access, created FROM {users} WHERE access < (%d - %d) AND access != 0 and login != 0 AND status != 0 && NOT (uid=1)', time(), $notify_time);
       while ($user = db_fetch_object($result)) {
         if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND notified_admin = 1', $user->uid)) && ($user->created < (time() - $notify_time))) {
           db_query('UPDATE {inactive_users} SET notified_admin = 1 WHERE uid = %d', $user->uid);
@@ -258,21 +330,21 @@ function inactive_user_cron() {
         }
       }
       if ($user_list) {
-        _inactive_user_mail(t('[%sitename] Inactive users', array('%sitename' => variable_get('site_name', 'drupal'))), _inactive_user_mail_text('notify_admin_text'), $notify_time, NULL, $user_list);
+        _inactive_user_mail(t('[@sitename] Inactive users', array('@sitename' => variable_get('site_name', 'drupal'))), _inactive_user_mail_text('notify_admin_text'), $notify_time, NULL, $user_list);
         unset($user_list);
       }
     }
 
     // notify users that their account has been inactive
     if ($notify_time = variable_get('inactive_user_notify', 0)) {
-      $result = db_query('SELECT * FROM {users} WHERE access < (%d - %d) AND status != 0 AND NOT (uid=1)', time(), $notify_time);
+      $result = db_query('SELECT * FROM {users} WHERE access < (%d - %d) AND access != 0 and login != 0 AND status != 0 AND NOT (uid=1)', time(), $notify_time);
       while ($user = db_fetch_object($result)) {
         if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE notified_user = 1 AND uid = %d', $user->uid)) && ($user->created < (time() - $notify_time))) {
           db_query('UPDATE {inactive_users} SET notified_user = 1 WHERE uid = %d', $user->uid);
           if (!db_affected_rows()) {
             @db_query('INSERT INTO {inactive_users} (uid, notified_user) VALUES(%d, 1)', $user->uid);
           }
-          _inactive_user_mail(t('[%sitename] Account inactivity', array('%sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_notify_text', _inactive_user_mail_text('notify_text')), $notify_time, $user, NULL);
+          _inactive_user_mail(t('[@sitename] Account inactivity', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_notify_text', _inactive_user_mail_text('notify_text')), $notify_time, $user, NULL);
           watchdog('user', t('user %user notified of inactivity', array('%user' => $user->name)), WATCHDOG_NOTICE, l(t('edit user'), "admin/user/edit/$uid"));
         }
       }
@@ -288,7 +360,7 @@ function inactive_user_cron() {
           if (!db_affected_rows()) {
             @db_query('INSERT INTO {inactive_users} (uid, warned_user_block_timestamp) VALUES(%d, %d)', $user->uid, time() + $warn_time);
           }
-          _inactive_user_mail(t('[%sitename] Account inactivity', array('%sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_block_warn_text', _inactive_user_mail_text('block_warn_text')), $warn_time, $user, NULL);
+          _inactive_user_mail(t('[@sitename] Account inactivity', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_block_warn_text', _inactive_user_mail_text('block_warn_text')), $warn_time, $user, NULL);
           watchdog('user', t('user %user warned will be blocked due to inactivity', array('%user' => $user->name)), WATCHDOG_NOTICE, l(t('edit user'), "admin/user/edit/$uid"));
         }
       }
@@ -309,7 +381,7 @@ function inactive_user_cron() {
               if (!db_affected_rows()) {
                 @db_query('INSERT INTO {inactive_users} (uid, notified_user_block) VALUES(%d, 1)', $user->uid);
               }
-              _inactive_user_mail(t('[%sitename] Account blocked due to inactivity', array('%sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_block_notify_text', _inactive_user_mail_text('block_notify_text')), $block_time, $user, NULL);
+              _inactive_user_mail(t('[@sitename] Account blocked due to inactivity', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_block_notify_text', _inactive_user_mail_text('block_notify_text')), $block_time, $user, NULL);
               watchdog('user', t('user %user blocked due to inactivity', array('%user' => $user->name)), WATCHDOG_NOTICE, l(t('edit user'), "admin/user/edit/$uid"));
             }
           }
@@ -326,7 +398,7 @@ function inactive_user_cron() {
           }
         }
         if ($user_list) {
-          _inactive_user_mail(t('[%sitename] Blocked users', array('%sitename' => variable_get('site_name', 'drupal'))), _inactive_user_mail_text('block_notify_admin_text'), $block_time, NULL, $user_list);
+          _inactive_user_mail(t('[@sitename] Blocked users', array('@sitename' => variable_get('site_name', 'drupal'))), _inactive_user_mail_text('block_notify_admin_text'), $block_time, NULL, $user_list);
         unset($user_list);
         }
       }
@@ -349,7 +421,7 @@ function inactive_user_cron() {
             @db_query('INSERT INTO {inactive_users} (uid, warned_user_delete_timestamp, protected) VALUES(%d, %d, %d)', $user->uid, time() + $warn_time, $protected);
           }
           if (!$protected) {
-            _inactive_user_mail(t('[%sitename] Account inactivity', array('%sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_delete_warn_text', _inactive_user_mail_text('delete_warn_text')), $warn_time, $user, NULL);
+            _inactive_user_mail(t('[@sitename] Account inactivity', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_delete_warn_text', _inactive_user_mail_text('delete_warn_text')), $warn_time, $user, NULL);
             watchdog('user', t('user %user warned will be deleted due to inactivity', array('%user' => $user->mail)), WATCHDOG_NOTICE, l(t('edit user'), "admin/user/edit/$uid"));
           }
         }
@@ -375,7 +447,7 @@ function inactive_user_cron() {
             db_query("DELETE FROM {authmap} WHERE uid = %d", $user->uid);
             module_invoke_all('user', 'delete', $array, $user);
             if (variable_get('inactive_user_notify_delete', 0)) {
-              _inactive_user_mail(t('[%sitename] Account removed', array('%sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_delete_notify_text', _inactive_user_mail_text('delete_notify_text')), $delete_time, $user, NULL);
+              _inactive_user_mail(t('[@sitename] Account removed', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_delete_notify_text', _inactive_user_mail_text('delete_notify_text')), $delete_time, $user, NULL);
             }
             if (variable_get('inactive_user_notify_delete_admin', 0)) {
               $user_list .= "$user->name ($user->mail) last active on ". format_date($user->access, 'large'). ".\n";
@@ -385,7 +457,7 @@ function inactive_user_cron() {
         }
       }
       if ($user_list) {
-        _inactive_user_mail(t('[%sitename] Deleted accounts', array('%sitename' => variable_get('site_name', 'drupal'))), _inactive_user_mail_text('delete_notify_admin_text'), $delete_time, NULL, $user_list);
+        _inactive_user_mail(t('[@sitename] Deleted accounts', array('@sitename' => variable_get('site_name', 'drupal'))), _inactive_user_mail_text('delete_notify_admin_text'), $delete_time, NULL, $user_list);
         unset($user_list);
       }
     }
@@ -427,11 +499,11 @@ function _inactive_user_mail($subject, $
   global $base_url;
   if ($user_list) {
     $to = _inactive_user_admin_mail();
-    $variables = array('%period' => _format_interval($period), '%sitename' => variable_get('site_name', 'drupal'), '%siteurl' => "$base_url", "%userlist" => "$user_list");
+    $variables = array('%period' => _format_interval($period), '@sitename' => variable_get('site_name', 'drupal'), '%siteurl' => "$base_url", "%userlist" => "$user_list");
   }
   elseif (isset($user->uid)) {
     $to = $user->mail;
-    $variables = array('%username' => "$user->name", '%useremail' => "$user->mail", '%lastaccess' => format_date($user->access, 'custom', 'M d, Y'), '%period' => _format_interval($period), '%sitename' => variable_get('site_name', 'drupal'), '%siteurl' => "$base_url");
+    $variables = array('%username' => "$user->name", '%useremail' => "$user->mail", '%lastaccess' => format_date($user->access, 'custom', 'M d, Y'), '%period' => _format_interval($period), '@sitename' => variable_get('site_name', 'drupal'), '%siteurl' => "$base_url");
   }
   if ($to) {
     $from = variable_get('site_mail', ini_get('sendmail_from'));
@@ -452,29 +524,35 @@ function _inactive_user_mail($subject, $
  */
 function _inactive_user_mail_text($message) {
   switch ($message) {
+    case 'never_returned_notify_text':
+      return t("Hello %username,\n\n  We haven't seen you at @sitename since you first registered. Please come back and activate your account soon at %siteurl.\n\nSincerely,\n  @sitename team");
+      break;
+    case 'never_returned_notify_admin_text':
+      return t("Hello,\n\n  This automatic notification is to inform you that the following users have never been seen on @sitename since they first registered:\n\n%userlist");
+      break;
     case 'notify_text':
-      return t("Hello %username,\n\n  We haven't seen you at %sitename since %lastaccess, and we miss you!  Please come back and visit us soon at %siteurl.\n\nSincerely,\n  %sitename team");
+      return t("Hello %username,\n\n  We haven't seen you at @sitename since %lastaccess, and we miss you!  Please come back and visit us soon at %siteurl.\n\nSincerely,\n  @sitename team");
       break;
     case 'notify_admin_text':
-      return t("Hello,\n\n  This automatic notification is to inform you that the following users haven't been seen on %sitename for more than %period:\n\n%userlist");
+      return t("Hello,\n\n  This automatic notification is to inform you that the following users haven't been seen on @sitename for more than %period:\n\n%userlist");
       break;
     case 'block_warn_text':
-      return t("Hello %username,\n\n  We haven't seen you at %sitename since %lastaccess, and we miss you!  This automatic message is to warn you that your account will be disabled in %period unless you come back and visit us before that time.\n\n  Please visit us at %siteurl.\n\nSincerely,\n  %sitename team");
+      return t("Hello %username,\n\n  We haven't seen you at @sitename since %lastaccess, and we miss you!  This automatic message is to warn you that your account will be disabled in %period unless you come back and visit us before that time.\n\n  Please visit us at %siteurl.\n\nSincerely,\n  @sitename team");
       break;
     case 'block_notify_text':
-      return t("Hello %username,\n\n  This automatic message is to notify you that your account on %sitename has been automatically disabled due to no activity for more than %period.\n\n  Please visit us at %siteurl to have your account re-enabled.\n\nSincerely,\n  %sitename team");
+      return t("Hello %username,\n\n  This automatic message is to notify you that your account on @sitename has been automatically disabled due to no activity for more than %period.\n\n  Please visit us at %siteurl to have your account re-enabled.\n\nSincerely,\n  @sitename team");
       break;
     case 'block_notify_admin_text':
-      return t("Hello,\n\n  This automatic notification is to inform you that the following users have been automatically blocked due to inactivity on %sitename for more than %period:\n\n%userlist");
+      return t("Hello,\n\n  This automatic notification is to inform you that the following users have been automatically blocked due to inactivity on @sitename for more than %period:\n\n%userlist");
       break;
     case 'delete_warn_text':
-      return t("Hello %username,\n\n  We haven't seen you at %sitename since %lastaccess, and we miss you!  This automatic message is to warn you that your account will be completely removed in %period unless you come back and visit us before that time.\n\n  Please visit us at %siteurl.\n\nSincerely,\n  %sitename team");
+      return t("Hello %username,\n\n  We haven't seen you at @sitename since %lastaccess, and we miss you!  This automatic message is to warn you that your account will be completely removed in %period unless you come back and visit us before that time.\n\n  Please visit us at %siteurl.\n\nSincerely,\n  @sitename team");
       break;
     case 'delete_notify_text':
-      return t("Hello %username,\n\n  This automatic message is to notify you that your account on %sitename has been automatically removed due to no activity for more than %period.\n\n  Please visit us at %siteurl if you would like to create a new account.\n\nSincerely,\n  %sitename team");
+      return t("Hello %username,\n\n  This automatic message is to notify you that your account on @sitename has been automatically removed due to no activity for more than %period.\n\n  Please visit us at %siteurl if you would like to create a new account.\n\nSincerely,\n  @sitename team");
       break;
     case 'delete_notify_admin_text':
-      return t("Hello,\n\n  This automatic notification is to inform you that the following users have been automatically deleted due to inactivity on %sitename for more than %period:\n\n%userlist");
+      return t("Hello,\n\n  This automatic notification is to inform you that the following users have been automatically deleted due to inactivity on @sitename for more than %period:\n\n%userlist");
       break;
   }
 }

--- inactive_user.install	2006-05-10 01:19:42.000000000 +0200
+++ inactive_user.install.patched	2007-12-20 16:14:00.000000000 +0100
@@ -3,8 +3,11 @@ function inactive_user_install() {
   switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
-      db_query("CREATE TABLE {inactive_users} (
+      db_query("CREATE TABLE IF NOT EXISTS {inactive_users} (
         uid int(1) unsigned NOT NULL default '0',
+        never_returned INT( 1 ) unsigned NOT NULL DEFAULT '0',
+        notified_never_return_user INT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
+        notified_never_return_admin INT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
         notified_admin int(1) unsigned NOT NULL default '0',
         notified_user int(1) unsigned NOT NULL default '0',
         warned_user_block_timestamp int(11) unsigned NOT NULL default '0',
@@ -18,4 +21,50 @@ function inactive_user_install() {
   }
 }
 
+/**
+ * Implementation of hook_uninstall().
+ */
+function inactive_user_uninstall() {
+  db_query('DROP TABLE {inactive_users}');
+  variable_del('inactive_user_admin_email');
+  variable_del('inactive_user_auto_block');
+  variable_del('inactive_user_auto_block_warn');
+  variable_del('inactive_user_auto_delete');
+  variable_del('inactive_user_auto_delete_warn');
+  variable_del('inactive_user_block_notify_text');
+  variable_del('inactive_user_block_warn_text');
+  variable_del('inactive_user_delete_notify_text');
+  variable_del('inactive_user_delete_warn_text');
+  variable_del('inactive_user_never_returned_grace_period');
+  variable_del('inactive_user_never_returned_notify_admin');
+  variable_del('inactive_user_never_returned_user_notify');
+  variable_del('inactive_user_never_returned_user_notify_text');
+  variable_del('inactive_user_notify');
+  variable_del('inactive_user_notify_admin');
+  variable_del('inactive_user_notify_block');
+  variable_del('inactive_user_notify_block_admin');
+  variable_del('inactive_user_notify_delete');
+  variable_del('inactive_user_notify_delete_admin');
+  variable_del('inactive_user_notify_text');
+  variable_del('inactive_user_preserve_content');
+  variable_del('inactive_user_timestamp');
+}
+
+/**
+ * Add fields never_returned, notified_never_return_user, notified_never_return_admin to manage users who never used their accounts
+ */
+function inactive_user_update_1() {
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {inactive_users} 
+         ADD never_returned INT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER uid,
+         ADD notified_never_return_user INT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER never_returned,
+         ADD notified_never_return_admin INT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER notified_never_return_user;");
+         
+       return $ret;
+    break;
+  }
+}
+
 ?>
