--- listhandler.info 1969-12-31 19:00:00.000000000 -0500 +++ listhandler.info 2007-05-23 16:08:02.000000000 -0400 @@ -0,0 +1,5 @@ +; $Id $ +name = Listhandler +description = "Integrate with mailing lists." +version = "5.1-1.0" +dependencies = mailhandler --- listhandler.install 2006-09-26 19:35:23.000000000 -0400 +++ listhandler.install 2007-07-04 20:22:06.000000000 -0400 @@ -7,7 +7,7 @@ function listhandler_install() { switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': - db_query("CREATE TABLE listhandler ( + db_query("CREATE TABLE {listhandler} ( lid int(10) unsigned not null auto_increment primary key, msgid varchar(255) not null, nid int(10) NOT NULL default '0', @@ -16,13 +16,35 @@ function listhandler_install() { uid int(10) NOT NULL default '0', mid int(10) NOT NULL default '0', tid int(10) NOT NULL default '0', + prefix varchar(255) NOT NULL DEFAULT'', key (lid) ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); - db_query("ALTER TABLE mailhandler ADD prefix varchar(255) not null DEFAULT ''"); break; + case 'pgsql': + db_query("CREATE TABLE {listhandler} ( + lid serial, + msgid text not null, + nid integer NOT NULL default 0, + cid integer NOT NULL default 0, + pid integer NOT NULL default 0, + uid integer NOT NULL default 0, + mid integer NOT NULL default 0, + tid integer NOT NULL default 0, + prefix text NOT NULL DEFAULT '', + PRIMARY KEY (lid) + );"); + break; + } } +function listhandler_uninstall() { + db_query('DROP TABLE {listhandler}'); + variable_del('listhandler_from'); + variable_del('listhandler_strip_title'); + variable_del('listhandler_accountstatus'); +} + /** * Update database hooks */ --- listhandler.module 2007-02-14 06:25:57.000000000 -0500 +++ listhandler.module 2007-07-04 20:37:10.000000000 -0400 @@ -6,20 +6,21 @@ function listhandler_help($section) { switch($section) { case 'admin/help#listhandler': $output = '

'. t('The listhandler module allows you to connect mailing lists to forums and vice versa. It works in conjunction with the mailhandler module. Mailhandler receives an email and then asks listhandler if the received email is part of a list. If the email is from a mailing list associated with a forum on your site, then listhandler adds the recieved email to the forum.') .'

'; - $output .= '

' .t('Listhandler administration allows you to set the email address of the list administrator. The email address is used as the From: field to check the address of messages sent by anonymous users. You can also enable and disable the listhandler for a list.') .'

'; + $output .= '

'. t('Listhandler administration allows you to set the email address of the list administrator. The email address is used as the From: field to check the address of messages sent by anonymous users. You can also enable and disable the listhandler for a list.') .'

'; $output .= t('

You can:

'; - $output .= '

'. t('For more information please read the configuration and customization handbook Listhandler page.', array('%listhandler' => 'http://www.drupal.org/handbook/modules/listhandler/')) .'

'; +
  • administer listhandler administer >> listhandler.
  • +
  • administer mailhandler administer >> mailhandler to create a mailbox which list handler can work with.
  • +
  • administer forum administer >> forum.
  • +', array('!admin-listhandler' => url('admin/content/listhandler'), '!admin-mailhandler' => +url('admin/content/mailhandler'), '!admin-forum' => url('admin/content/forum'))) .''; + $output .= '

    '. t('For more information please read the configuration and customization handbook Listhandler page.', array('!listhandler' => 'http://www.drupal.org/handbook/modules/listhandler/')) .'

    '; return $output; - case 'admin/modules#description': + case 'admin/build/modules#description': $output = t('Connect your mailing lists to your drupal site and your drupal site to your mailing lists.'); break; - case 'admin/listhandler': - $output = t("First go to the mailhandler configuration screen and add some mailboxes. A mailbox becomes recognised as a mailing list if the 'Second E-mail address' is set. This is not optional for mailing lists.", array('%url' => url('admin/mailhandler'))); + case 'admin/content/listhandler': + $output = t("First go to the mailhandler configuration screen and add some mailboxes. A mailbox becomes recognised as a mailing list if the 'Second E-mail address' is set. This is not optional for mailing lists.", array('!url' => url('admin/content/mailhandler'))); break; } return $output; @@ -37,9 +38,11 @@ function listhandler_menu($may_cache) { $items = array(); if ($may_cache) { - $items[] = array('path' => 'admin/listhandler', - 'title' => t('listhandler'), - 'callback' => 'listhandler_admin', + $items[] = array('path' => 'admin/content/listhandler', + 'title' => t('Listhandler'), + 'description' => t('Manage mailing-lists subscriptions.'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('listhandler_admin_settings'), 'access' => user_access('administer listhandler')); } @@ -49,27 +52,28 @@ function listhandler_menu($may_cache) { /** * Configuration options for this module */ -function listhandler_admin_form() { +function listhandler_admin_settings() { + $form['#submit'] = array('listhandler_admin_settings_submit' => array()); $form['listhandler_from'] = array( - '#type' => 'textfield', - '#title' => t('Admin address'), - '#default_value' => variable_get('listhandler_from', ''), - '#size' => 50, - '#maxlength' => 100, - '#description' => t('The email address of the list administrator. Used as From: address of messages sent by anonymous users.')); + '#type' => 'textfield', + '#title' => t('Admin address'), + '#default_value' => variable_get('listhandler_from', ''), + '#size' => 50, + '#maxlength' => 100, + '#description' => t('The email address of the list administrator. Used as From: address of messages sent by anonymous users.')); $form['listhandler_strip_title'] = array( - '#type' => 'textfield', - '#title' => t('Strip title'), - '#default_value' => variable_get('listhandler_strip_title', 'Re: , AW:,[my list]'), - '#size' => 50, - '#maxlength' => 100, - '#description' => t("A comma delimited sequence of strings that should be stripped from the titles of topics and comments posted to the forums. You can use it to remove certain tags like 'Re: ' or '[My Mailinglist]'.")); + '#type' => 'textfield', + '#title' => t('Strip title'), + '#default_value' => variable_get('listhandler_strip_title', 'Re: , AW:,[my list]'), + '#size' => 50, + '#maxlength' => 100, + '#description' => t("A comma delimited sequence of strings that should be stripped from the titles of topics and comments posted to the forums. You can use it to remove certain tags like 'Re: ' or '[My Mailinglist]'.")); $form['listhandler_accountstatus'] = array( - '#type' => 'select', - '#title' => t('Account status'), - '#default_value' => variable_get('listhandler_accountstatus', 0), - '#options' => array(0 => t('blocked'), 1 => t('active')), - '#description' => t('The status of accounts created by listhandler.')); + '#type' => 'select', + '#title' => t('Account status'), + '#default_value' => variable_get('listhandler_accountstatus', 0), + '#options' => array(0 => t('blocked'), 1 => t('active')), + '#description' => t('The status of accounts created by listhandler.')); $form['listhandler_list']['#tree'] = TRUE; $form['listhandler_prefix']['#tree'] = TRUE; @@ -77,21 +81,16 @@ function listhandler_admin_form() { while ($mailbox = db_fetch_object($result)) { $form['listhandler_list'][$mailbox->mid] = array( - '#value' => "
    mailto\">$mailbox->mailto
    "); + '#value' => "
    mailto\">$mailbox->mailto
    "); $form['listhandler_prefix'][$mailbox->mid] = array( - '#type' => 'textfield', - '#title' => '', - '#default_value' => $mailbox->prefix, - '#size' => 50, - '#maxlength' => 100); + '#type' => 'textfield', + '#title' => $mailbox->mid, + '#default_value' => $mailbox->prefix, + '#size' => 50, + '#maxlength' => 100); } - $form[] = array( - '#type' => 'submit', - '#value' => t('Submit'), - ); - - return drupal_get_form('listhandler_settings', $form); + return system_settings_form($form); } /** @@ -99,15 +98,15 @@ function listhandler_admin_form() { */ function theme_listhandler_settings($form) { - $output = form_render($form['listhandler_from']); - $output .= form_render($form['listhandler_strip_title']); - $output .= form_render($form['listhandler_accountstatus']); + $output = drupal_render($form['listhandler_from']); + $output .= drupal_render($form['listhandler_strip_title']); + $output .= drupal_render($form['listhandler_accountstatus']); if (count($form['listhandler_list'])) { $rows = array(); foreach(element_children($form['listhandler_list']) as $mid) { $row = array(); - $row[] = form_render($form['listhandler_list'][$mid]); - $row[] = form_render($form['listhandler_prefix'][$mid]); + $row[] = drupal_render($form['listhandler_list'][$mid]); + $row[] = drupal_render($form['listhandler_prefix'][$mid]); $rows[] = $row; } $header = array(t('mailing list'), t('prefix')); @@ -115,28 +114,25 @@ function theme_listhandler_settings($for $output .= '
    '. t("The prefix well be prepended to all outgoing mail subjects for the specified list. It is a good idea to put the prefix in the 'strip title' field.") .'
    '; } else { - $output .= '
    '. t("No mailing lists have been defined. Please go to the mailhandler configuration screen and add some mailboxes. A mailbox becomes recognised as a mailing list if the 'Second E-mail address' is set.", array('%url' => 'admin/mailhandler')) .'
    '; + $output .= '
    '. t("No mailing lists have been defined. Please go to the mailhandler configuration screen and add some mailboxes. A mailbox becomes recognised as a mailing list if the 'Second E-mail address' is set.", array('!url' => 'admin/content/mailhandler')) .'
    '; } - $output .= form_render($form); + $output .= drupal_render($form); return $output; } -function listhandler_admin() { - $op = $_POST['op']; - $edit = $_POST['edit']; - if ($op == t('Submit')) { - variable_set('listhandler_from', $edit['listhandler_from']); - variable_set('listhandler_strip_title', $edit['listhandler_strip_title']); - variable_set('listhandler_accountstatus', $edit['listhandler_accountstatus']); - if (isset($edit['listhandler_prefix'])) { - foreach ($edit['listhandler_prefix'] as $key => $value) { - db_query("UPDATE {mailhandler} SET prefix = '%s' WHERE mid = %d", $value, $key); - } +function listhandler_admin_settings_submit($form_id, &$form_values) { + $edit = $form_values['edit']; + variable_set('listhandler_from', $edit['listhandler_from']); + variable_set('listhandler_strip_title', $edit['listhandler_strip_title']); + variable_set('listhandler_accountstatus', $edit['listhandler_accountstatus']); + if (isset($edit['listhandler_prefix'])) { + foreach ($edit['listhandler_prefix'] as $key => $value) { + db_query("UPDATE {mailhandler} SET prefix = '%s' WHERE mid = %d", $value, $key); } - drupal_set_message('The configuration options have been saved.'); } + drupal_set_message('The configuration options have been saved.'); - print theme('page', listhandler_admin_form()); + return system_settings_form_submit($form_id, $form_values); } /** @@ -146,7 +142,7 @@ function listhandler_admin() { function listhandler_nodeapi(&$node, $op, $arg = 0) { switch ($op) { case 'update': // what to do with updates? - break; + break; case 'insert': // mail new forum topics to mailing list. if ($node->type == 'forum') { if($node->sentbylisthandler) { // avoid running an infinite loop. @@ -215,8 +211,8 @@ function listhandler_send_mail($edit) { global $user, $base_url; if(!$user->uid) { - $edit["name"] = variable_get("anonymous", "Anonymous"); - $edit["mail"] = variable_get("listhandler_from", ""); + $edit['name'] = variable_get('anonymous', 'Anonymous'); + $edit['mail'] = variable_get('listhandler_from', ''); } else { $edit["name"] = $user->name; @@ -295,12 +291,15 @@ function listhandler_send_mail($edit) { $body = strip_tags($edit['comment']); } - $err = user_mail($address, $subject, $body, "From: ". $edit["name"] ." <". $edit["mail"] .">\n". $mid); + // OLD $err = user_mail($address, $subject, $body, "From: ". $edit["name"] ." <". $edit["mail"] .">\n". $mid); + + $err = drupal_mail($mid, $address, $subject, $body, $edit["mail"]); + // save comment ids in listhandler table. // Not strictly needed, the same info is stored in the msgid. db_query("INSERT INTO {listhandler} (msgid, nid, cid, pid, uid, mid, tid) VALUES ('%s','%s','%s','%s','%s','%s','%s')", $msgid, $edit["nid"], $edit["cid"], $edit["pid"], $user->uid, $edit["mid"], $edit["tid"]); // call watchdog - watchdog('listhandler', t("'%s' sent to '%a'.", array("%s" => $edit["subject"], "%a" => $address))); + watchdog('listhandler', t("'!s' sent to '!a'.", array("!s" => $edit["subject"], "!a" => $address))); } } @@ -328,7 +327,7 @@ function listhandler_mailhandler($node, $regex = ""; if(ereg($regex, $header->message_id)){ // Sent by listhandler on this site. Destroy the node. - watchdog('listhandler', t("Discarded message '%s' to avoid loop.", array("%s" => $node->title))); + watchdog('listhandler', t("Discarded message '!s' to avoid loop.", array("!s" => $node->title))); unset($node); return; } @@ -392,19 +391,19 @@ function listhandler_create_author($node } // check if name is available if (db_num_rows(db_query("SELECT name FROM {users} WHERE LOWER(name) = LOWER('%s')", $from_name)) > 0) { - $node->body = t('Message from %n %a', array('%n' => $from_name, '%a' => $from_address)) ."\n\n". $node->body; - watchdog('listhandler', t("Cannot create account: The name '%s' is already taken.", array("%s" => $from_name))); + $node->body = t('Message from !n !a', array('!n' => $from_name, '!a' => $from_address)) ."\n\n". $node->body; + watchdog('listhandler', t("Cannot create account: The name '!s' is already taken.", array("!s" => $from_name))); } // check if address is valid elseif (!valid_email_address($from_address)) { - $node->body = t('Message from %n %a', array('%n' => $from_name, '%a' => $from_address)) ."\n\n". $node->body; - watchdog('listhandler', t("Listhandler: Cannot create account: The email address '%s' is not valid.", array("%s" => $from_address))); + $node->body = t('Message from !n !a', array('!n' => $from_name, '!a' => $from_address)) ."\n\n". $node->body; + watchdog('listhandler', t("Listhandler: Cannot create account: The email address '!s' is not valid.", array("!s" => $from_address))); } // create account else { $empty_account = new StdClass(); $from_user = user_save($empty_account, array('name' => $from_name, 'pass' => user_password(), 'init' => $from_address, 'mail' => $from_address, 'roles' => array(DRUPAL_AUTHENTICATED_RID), 'status' => variable_get('listhandler_accountstatus', 0)), 'account'); - watchdog('listhandler', t('Created account for %fa, with roles %rid', array ('%fa' => $from_address, '%rid' => implode(', ', $from_user->roles)))); + watchdog('listhandler', t('Created account for !fa, with roles !rid', array ('!fa' => $from_address, '!rid' => implode(', ', $from_user->roles)))); mailhandler_switch_user($from_user->uid); } $node->uid = $from_user->uid;