diff -Nur listhandler.old/listhandler.info listhandler/listhandler.info --- listhandler.old/listhandler.info 1969-12-31 19:00:00.000000000 -0500 +++ listhandler/listhandler.info 2007-04-09 09:29:54.000000000 -0400 @@ -0,0 +1,5 @@ +; $Id $ +name = Listhandler +description = "Integrate with mailing lists." +version = "5.1-1.0" + diff -Nur listhandler.old/listhandler.module listhandler/listhandler.module --- listhandler.old/listhandler.module 2007-04-09 10:37:27.000000000 -0400 +++ listhandler/listhandler.module 2007-04-09 10:35:32.000000000 -0400 @@ -3,23 +3,24 @@ function listhandler_help($section) { $output = ''; - switch($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': $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/mailhandler'))); break; } return $output; @@ -37,8 +38,8 @@ $items = array(); if ($may_cache) { - $items[] = array('path' => 'admin/listhandler', - 'title' => t('listhandler'), + $items[] = array('path' => 'admin/content/listhandler', + 'title' => t('Listhandler'), 'callback' => 'listhandler_admin', 'access' => user_access('administer listhandler')); } @@ -49,7 +50,7 @@ /** * Configuration options for this module */ -function listhandler_admin_form() { +function listhandler_admin_form($form) { $form['listhandler_from'] = array( '#type' => 'textfield', '#title' => t('Admin address'), @@ -90,8 +91,9 @@ '#type' => 'submit', '#value' => t('Submit'), ); + return $form; - return drupal_get_form('listhandler_settings', $form); +//OLD return drupal_get_form('listhandler_settings', $form); } /** @@ -99,15 +101,15 @@ */ 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) { + 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,14 +117,14 @@ $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/mailhandler')) .'
    '; } - $output .= form_render($form); + $output .= drupal_render($form); return $output; } function listhandler_admin() { - $op = $_POST['op']; + $op = $form_values['op']; $edit = $_POST['edit']; if ($op == t('Submit')) { variable_set('listhandler_from', $edit['listhandler_from']); @@ -135,8 +137,8 @@ } drupal_set_message('The configuration options have been saved.'); } - - print theme('page', listhandler_admin_form()); + $output = drupal_get_form('listhandler_admin_form', $form); + return $output; } /** @@ -149,7 +151,7 @@ break; case 'insert': // mail new forum topics to mailing list. if ($node->type == 'forum') { - if($node->sentbylisthandler) { // avoid running an infinite loop. + if ($node->sentbylisthandler) { // avoid running an infinite loop. // save ids in listhandler table. db_query("INSERT INTO {listhandler} (msgid, nid, cid, pid, uid, mid, tid) VALUES ('%s','%s','%s','%s','%s','%s','%s')", $node->message_id, $node->nid, 0, 0, $node->uid, $node->mid, $node->tid); // call watchdog @@ -183,15 +185,15 @@ * $edit["tid"]: taxo id of the forum */ function listhandler_comment($edit = array(), $type) { - if($type == "insert") { // only accept calls by the comment insert hook. - if($edit["sentbylisthandler"]) { // avoid running an infinite loop. + if ($type == "insert") { // only accept calls by the comment insert hook. + if ($edit["sentbylisthandler"]) { // avoid running an infinite loop. // save comment ids in listhandler table. db_query("INSERT INTO {listhandler} (msgid, nid, cid, pid, uid, mid, tid) VALUES ('%s','%s','%s','%s','%s','%s','%s')", $edit["message_id"], $edit["nid"], $edit["cid"], $edit["pid"], $edit["uid"], $edit["mid"], $edit["tid"]); // call watchdog watchdog('listhandler', 'Comment '. $edit["subject"] ." inserted."); } else { - if(filter_access($edit['format']) && $edit['subject'] == truncate_utf8(decode_entities(strip_tags(check_markup($edit['comment'], $edit['format']))), 29, TRUE)) { + if (filter_access($edit['format']) && $edit['subject'] == truncate_utf8(decode_entities(strip_tags(check_markup($edit['comment'], $edit['format']))), 29, TRUE)) { // subject was autogenerated, get it from parent instead if ($edit['pid']) { $parent = db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $edit['pid'])); @@ -214,7 +216,7 @@ function listhandler_send_mail($edit) { global $user, $base_url; - if(!$user->uid) { + if (!$user->uid) { $edit["name"] = variable_get("anonymous", "Anonymous"); $edit["mail"] = variable_get("listhandler_from", ""); } @@ -260,7 +262,7 @@ } } // Find parent's MsgID if received by listhandler. - if ($edit["pid"]){ + if ($edit["pid"]) { // We should get only one or no result. $result = db_fetch_object(db_query("SELECT * FROM {listhandler} WHERE cid = %d", $edit['pid'])); } @@ -268,7 +270,7 @@ $result = db_fetch_object(db_query("SELECT * FROM {listhandler} WHERE nid = %d", $edit['nid'])); $edit['pid']=0; } - if($result) {// Parent was sent or received by listhandler + if ($result) {// Parent was sent or received by listhandler $mid = "References: ". $result->msgid ."\n"; $mid .= "In-Reply-To: ". $result->msgid ."\n"; } @@ -295,12 +297,15 @@ $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))); } } @@ -315,10 +320,10 @@ * $mailbox: Array containing info about the mailbox the message is from. * $header: Some, but not all headers (From, To, message_id, ...) of the current message. */ -function listhandler_mailhandler($node, $result, $msg_number, $header, $mailbox){ +function listhandler_mailhandler($node, $result, $msg_number, $header, $mailbox) { global $base_url; - if($node->tid) { // If no tid is assigned, then the mail is not comming through a mailhandler enabled list. Do nothing. + if ($node->tid) { // If no tid is assigned, then the mail is not comming through a mailhandler enabled list. Do nothing. $node->cid = 0; // Might have a cid from the msg id. This will confuse comment_post. Updating comments via mail does not make sense anyway. GK // Override value from msgid. Might be crossposted. $node->mid = $mailbox['mid']; @@ -326,9 +331,9 @@ // get processed. We would get an infinite loop on a mailing list. $dir = str_replace("/", ".", substr(strchr(str_replace("http://", "", $base_url), "/"), 1)); $regex = ""; - if(ereg($regex, $header->message_id)){ + 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; } @@ -372,13 +377,13 @@ * if no account can be created (email or name already taken) the name and address * are prepended to the node body and posted as anonymous. */ -function listhandler_create_author($node, $header){ +function listhandler_create_author($node, $header) { $from = $header->from; $from_address = strtolower(sprintf("%s@%s", $from[0]->mailbox, $from[0]->host)); // decode encoded author name $from_name = ''; $from_arr = imap_mime_header_decode($header->from[0]->personal); - for($i = 0; $i < count($from_arr); $i++) { + for ($i = 0; $i < count($from_arr); $i++) { if ($from_arr[$i]->charset != 'default') { $from_name .= drupal_convert_to_utf8($from_arr[$i]->text, $from_arr[$i]->charset); } @@ -392,19 +397,19 @@ } // 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(); + $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; @@ -419,13 +424,13 @@ * Then try to find a parent based on Subject line. * If all else fails, start a new forum topic. */ -function listhandler_find_parent($node, $header){ +function listhandler_find_parent($node, $header) { - if($node->threading) { + if ($node->threading) { $parent = db_fetch_object(db_query("SELECT * FROM {listhandler} WHERE msgid = '<%s>'", $node->threading)); // Debug // watchdog('listhandler', "Parent seek
    '". $node->threading ."\np.nid:".$parent->nid."\n p.cid".$parent->cid."\nSubject: ".$header->subject."'
    "); - if($parent) { // parent (!) seen by listhandler on this site. + if ($parent) { // parent (!) seen by listhandler on this site. return listhandler_parent_thread($node, $parent); } } @@ -445,7 +450,7 @@ // Debug // watchdog('listhandler', "Parent found
    '". $node->threading ."\np.nid:".$parent->nid."\np.cid".$parent->cid."\nSubject:".$node->title."'
    "); $node->pid = $parent->cid; - if($node->cid) unset($node->cid); + if ($node->cid) unset($node->cid); $node->nid = $parent->nid; $node->type = 'comment';