--- mailman_manager.module Thu Feb 21 16:20:12 2008 +++ mailman_manager - modified.module Fri Mar 7 20:38:31 2008 @@ -660,4 +660,91 @@ function _mailman_manager_rand_str($size $rand_str .= substr($feed, rand(0, strlen($feed) - 1), 1); } return $rand_str; -} \ No newline at end of file +} + +/** + * Incorporated changes to allow anonymous users to subscribe to mailman lists. + * See http://drupal.org/node/123650 for original information/code. +*/ +function mailman_manager_archive_link($list_address, $text = "Mailing List Archive") { + $query = "SELECT * FROM mailman_lists WHERE name = '%s'"; + $result = db_query($query, $list_address); + if (db_num_rows($result)) { + $list = db_fetch_array($result); + print l($text, $list['webarch']); + } + else { + drupal_set_message(t("Mailing list link error. Please verify list name")); + } +} + +function mailman_manager_subscribe_form($list_address, $text = "Email address") { + print "Subscribe to the ". $list_address . " mailing list."; + $query = "SELECT * FROM mailman_lists WHERE name = '%s'"; + $result = db_query($query, $list_address); + if (db_num_rows($result)) { + $list = db_fetch_array($result); + $form['details']['email'] = array( + '#type' => 'textfield', + '#title' => t("$text"), + '#default_value' => '', + '#size' => 20, + '#maxlength' => 128, + '#required' => FALSE + ); + $form['details']['lid'] = array( + '#type' => 'hidden', + '#value' => $list['lid'] + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Subscribe') + ); + } + else { + drupal_set_message(t("Mailing list subscription error. Please verify list name")); + } + return $form; +} + +function mailman_manager_subscribe_form_validate($form_id, $form_values) { + if ($form_values['email'] == '') { + form_set_error('email', t('Please complete with an email address')); + } + else if (!valid_email_address($form_values['email'])) { + form_set_error('email', t('Please enter a valid email address')); + } + + if ($form_values['lid'] == 0) { + form_set_error('', t('Invalid list id')); + } +} + +function mailman_manager_subscribe_form_submit($form_id, $form_values) { + $query = "SELECT * FROM {mailman_lists} WHERE lid = %d"; + $result = db_query($query, $form_values['lid']); + $list = db_fetch_array($result); + + $commandaddress = $list['command']; + $command = "subscribe nodigest address=". trim($form_values['email']); + //$headers = array(variable_get('site_mail', ini_get('sendmail_from')), 'Precedence' => ''); + //error_log("\nHere $body \n".print_r($headers, TRUE), 3, "/tmp/debug.txt"); + //Send the command to the request list + $mailsuccess = drupal_mail('mailman-manager', $commandaddress, '', $command, variable_get('site_mail', ini_get('sendmail_from')), array('Precedence' => '')); + //drupal_set_message("|$commandaddress| |$command| |".variable_get('site_mail', ini_get('sendmail_from'))."|"); + // print "command would be ".$command." to ".$commandaddress; + + //Put into watchdog + if ($mailsuccess) { + $watchdog = t('New subscription to list %lid for email %email completed successfully.', array('%lid' => $list['name'], '%email' => $form_values['email'])); + drupal_set_message(t('%email has been subscribed to email list %list. Please check your email to confirm your subscription.', array('%email' => $form_values['email'], '%list' => $list['name']))); + //drupal_set_message(t('%email has been subscribed to email list %list. Please check your email to confirm your subscription.', array('%email' => $form_values['email'], '%list' => $list['name'])). $commandaddress." ". $command); + watchdog('mailman man', $watchdog, 'WATCHDOG_NOTICE', NULL); + } + else { + $watchdog = t('New subscription to list %lid for email %email completed failed.', array('%lid' => $list['name'], '%uid' => $form_values['email'])); + drupal_set_message(t('You have not been subscribed. Email error')); + watchdog('mailman man', $watchdog, 'WATCHDOG_ERROR', NULL); + } +} +?> \ No newline at end of file