--- ezmlm.module.org	2008-05-31 20:33:59.000000000 +0100
+++ ezmlm.module	2008-12-10 10:48:01.000000000 +0000
@@ -11,6 +11,64 @@
  */
 
 /**
+ * Implementation of hook_user().
+ * by mjs2020
+ * this adds the ability to subscribe to mailing lists
+ * during the registration process.
+ */
+function ezmlm_user($op, &$edit, &$account, $category = NULL) {
+  switch($op) {
+    case 'register':
+      if ( variable_get('ezmlm_register', 0) && variable_get('ezmlm_register_list', 0) ) {
+        $listsform = _ezmlm_subscribe_form('REG');
+        unset($listsform['ezmlm_email'], $listsform['submit'], $listsform['subscribe'] );
+
+        $form['ezmlm'] = array(
+          "#type" => "fieldset",
+          "#title" => t("Mailing lists"),
+          "#description" => t("Please select the mailing lists you would like to subscribe to."),
+          '#collapsible' => FALSE,
+          "#tree" => FALSE,
+          "#parents" => array("ezmlm"),
+        );
+        $form['ezmlm']['ezmlm_subscribe'] = array();
+        foreach($listsform['ezmlm_subscribe'] as $key=>$ezmlm_list) {
+          $ezmlm_list['#parents'][0] = $key;
+          $ezmlm_list['#name'] = $key;
+          $form['ezmlm']['ezmlm_subscribe'][$key] = $ezmlm_list;
+        }
+        return $form;
+      }
+      break;
+    case 'insert':
+      if ( variable_get('ezmlm_register', 0) && variable_get('ezmlm_register_list', 0) ) {
+        $lists = _ezmlm_get_lists('REG');
+        $listct = _ezmlm_get_count('REG');
+        $arr = array();
+        // get the selected mailing list addresses
+        for($ct=1; $ct <= $listct; $ct++) {
+          if (isset($edit["ezmlm_list_$ct"])) {
+            $address = $edit["ezmlm_list_$ct"];
+            if ($address && in_array($address, $lists)) {
+              $arr[] = $address;
+            }
+          }
+        }
+        $email = trim($edit['mail']);
+        $ret = _ezmlm_subscribe_process($arr, $email);
+        if (is_array($ret)) {
+          $output = (t('Please check your mail at %mail to confirm registration of:', array('%mail' => $email)));
+          drupal_set_message($output ."<br>". implode('<br>', $ret));
+        }
+        else {
+          drupal_set_message($ret, 'error');
+        }
+      }
+      break;
+  }
+}
+
+/**
  * Implementation of hook_help().
  */
 function ezmlm_help($section) {
@@ -46,14 +104,14 @@
   if ($may_cache) {
     $items[] = array(
       'path' => 'ezmlm/add',
-      'title' => ('mailing lists'),
+      'title' => t('mailing lists'),
       'callback' => 'ezmlm_block',
       'access' => user_access('access content'),
       'type' => MENU_CALLBACK,
     );
     $items[] = array(
       'path' => 'ezmlm',
-      'title' => ('Mailing lists'),
+      'title' => t('Mailing lists'),
       'callback' => 'ezmlm_page',
       'access' => user_access('access content'),
       'type' => MENU_NORMAL_ITEM,
@@ -154,7 +212,31 @@
         );
       }
     }
+
+    // registration
+    $form['ezmlm_reg'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Registration settings'),
+      '#description' => t('Allow new users to select mailing lists on registration'),
+      '#collapsible' => TRUE,
+    );
+    $form['ezmlm_reg']['ezmlm_register'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Display lists in registration form'),
+      '#default_value' => variable_get('ezmlm_register', 1),
+    );
+    if (is_array($lists)) {
+      $reglist = variable_get('ezmlm_register_list', '');
+      foreach ($lists as $list_text => $list_email) {
+        $form['ezmlm_reg']["reg_$list_text"] = array(
+          '#type' => 'checkbox',
+          '#title' => "$list_text ($list_email)" ,
+          '#default_value' => ((is_array($reglist) && in_array($list_email, $reglist)) ? 1 : 0),
+        );
+      }
   }
+  }
+
   $form['ezmlm_misc'] = array(
       '#type' => 'fieldset',
       '#title' => t('Various settings'),
@@ -241,6 +323,31 @@
     variable_set('ezmlmmailinglists', $lists);
     drupal_set_message( t('The mailing lists have been saved.'));
   }
+
+  // registration
+  if ($form_values['ezmlm_register']) {
+    variable_set('ezmlm_register', 1);
+  }
+  else {
+    variable_set('ezmlm_register', 0);
+  }
+
+  if ( variable_get('ezmlm_register', 0) ) {
+    // reg list
+    if (is_array($lists) && $count > 0) {
+      variable_del('ezmlm_register_list');
+      $arr = array();
+      foreach ($lists as $list_text => $list_email) {
+        if ( isset($form_values["reg_$list_text"]) && $form_values["reg_$list_text"] == 1 ) {
+          $arr[$list_text] = $list_email;
+        }
+      }
+      if ( count($arr) ) {
+        variable_set('ezmlm_register_list', $arr);
+      }
+    }
+
+  }
 }
 
 // internal functions
@@ -250,14 +357,14 @@
  * @return
  *  HTML form.
  */
-function _ezmlm_subscribe_form() {
+function _ezmlm_subscribe_form($type='DEFAULT') {
   global $user;
 
-  $listct = _ezmlm_get_count();
+  $listct = _ezmlm_get_count($type);
   if ($listct == 0) {
     return t('There are no lists available for subscription.'); // formatting?
   }
-  $lists = _ezmlm_get_lists();
+  $lists = _ezmlm_get_lists($type);
 
   $form['subscribe'] = array(
     '#type' => 'markup',
@@ -358,8 +465,8 @@
  * Return current number of lists.
  * Use this instead of count(_ezmlm_get_lists()) because non-array counts as 1.
  */
-function _ezmlm_get_count() {
-  $lists = _ezmlm_get_lists();
+function _ezmlm_get_count($type='DEFAULT') {
+  $lists = _ezmlm_get_lists($type);
   if (!is_array($lists)) {
     return 0;
   }
@@ -371,6 +478,11 @@
 /**
  * Return array of current mailing lists.
  */
-function _ezmlm_get_lists() {
+function _ezmlm_get_lists($type='DEFAULT') {
+  if ($type=='DEFAULT') {
   return variable_get('ezmlmmailinglists', '');
 }
+  elseif ($type=='REG') {
+    return variable_get('ezmlm_register_list', '');
+  }
+}
