diff -urp mailarchive/mailarchive.install mailarchive.bart/mailarchive.install
--- mailarchive/mailarchive.install	2007-10-04 02:56:14.000000000 +0200
+++ mailarchive.bart/mailarchive.install	2007-10-15 21:13:54.000000000 +0200
@@ -117,6 +117,9 @@ function mailarchive_uninstall() {
   }
 
   db_query('DELETE FROM {variable} WHERE name LIKE "mailarchive_%"');
+
+  // search
+  db_query('DELETE FROM {search_index} WHERE type = "mailarchive"');
   // Flush cache so if we re-install we're not using stale variables.
   db_query('DELETE FROM {cache}');
 }
diff -urp mailarchive/mailarchive.module mailarchive.bart/mailarchive.module
--- mailarchive/mailarchive.module	2007-09-25 19:52:56.000000000 +0200
+++ mailarchive.bart/mailarchive.module	2007-10-15 22:43:29.000000000 +0200
@@ -110,7 +110,24 @@ function mailarchive_admin_settings() {
     '#default_value' => variable_get('mailarchive_attachments_path', 'mailarchive'),
     '#description' => t('If you enable the mailarchive module to save attachments, you need to specify the subdirectory where these attachments should be saved.  The attachment subdirectory requires that your Drupal file system settings are properly configured.  Based on your currently configured file system path, the attachment subdirectory will be created within the <em>%path</em> directory.', array('%path' => file_directory_path()))
   );
+  
+  
+  $form['search'] = array('#type' => 'fieldset',
+    '#title' => t('Indexing'),
+    '#collapsible' => TRUE,
+  );
+
+
+  $number_idx = drupal_map_assoc(array(0, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 20000, 10000, 50000));
+  $form['search']['mailarchive_search_cron_limit'] = array(
+                          '#type' => 'select',
+                          '#title' => t('Messages to index at a time'),
+                          '#default_value' => variable_get('mailarchive_search_cron_limit', 100),
+                          '#options' => $number_idx,
+                          '#description' => t('Specify how many messages should be indexed at a time. 0 disables indexing altogether')
+  );
 
+ 
   $form['save'] = array(
     '#type' => 'submit',
     '#value' => t('Save'),
@@ -144,6 +161,7 @@ function mailarchive_admin_settings_subm
   variable_set('mailarchive_save_attachments', $form['mailarchive_save_attachments']);
   variable_set('mailarchive_attachments_path', $form['mailarchive_attachments_path']);
   variable_set('mailarchive_filter_format', $form['format']);
+  variable_set('mailarchive_search_cron_limit', $form['mailarchive_search_cron_limit']);
   drupal_set_message('Mailing list archive settings saved.');
 }
 
@@ -1396,4 +1414,72 @@ function _mailarchive_fetch($sid) {
   return $messages_downloaded;
 }
 
+
+/**
+ * Drupal _search hook. Adds a search tab to www.yoursite.org/search. 
+ */
+function mailarchive_search($op = 'search', $keys = null) {
+  switch ($op) {
+    case 'name':
+      return t('Mailarchive');
+
+    case 'reset':
+      variable_del('mailarchive_search_cron_last');
+      return;
+
+    case 'search':
+      $find = do_search($keys, 'mailarchive', 'INNER JOIN {mailarchive_messages} m ON m.mid = i.sid', 'i.type = "mailarchive"');
+      $results = array();
+
+      foreach ($find as $item) {
+        $msg = db_fetch_object(db_query('SELECT m.mid, s.urlname, m.mailfrom, m.subject, m.body, m.created, m.year, m.month, m.day FROM {mailarchive_messages} m INNER JOIN {mailarchive_subscriptions} s ON s.sid = m.sid WHERE mid = %d', $item->sid));
+        $link = 'mailarchive/'.$msg->urlname.'/'.$msg->year.'/'.$msg->month.'/'.$msg->day.'/'.$msg->mid;
+        $format = variable_get('mailarchive_filter_format', FILTER_FORMAT_DEFAULT);
+
+        $results[] = array('link' => url($link),
+                           'type' => 'mailarchive' ,
+                           'title' => $msg->subject,
+                           'date' => $msg->created,
+                           'extra' => array('from' => $msg->mailfrom,
+                                            'list' => $msg->urlname),
+                           'snippet' => search_excerpt($keys, check_markup($msg->body, $format))
+        );
+      }
+      return $results;
+
+    case 'status':
+      // TODO: this can be slow 
+      $max = db_result(db_query('SELECT MAX(sid) FROM {search_index} WHERE type = \'mailarchive\' '));
+      $last = variable_get('mailarchive_search_cron_last', 0);
+      return is_null($max) ? 0 : $max - $last; 
+      
+    default:
+      break;
+  }
+}
+
+
+/**
+ * Drupal _update_index hook. 
+ */
+function mailarchive_update_index() {
+  // limit the number of messages being indexed per cron run
+
+  $limit = (int)variable_get('mailarchive_search_cron_limit', 0);
+
+  if ($limit > 0) {
+    $last = (int)variable_get('mailarchive_search_cron_last', 0);
+ 
+    $result = db_query_range('SELECT mid, subject, body FROM {mailarchive_messages} WHERE mid > %d ORDER BY mid ASC', $last, $limit);
+
+    while ($msg = db_fetch_object($result)) {
+      $text = '<h1>'. $msg->subject. '</h1>';
+      $text .= '<h2>'.  $msg->body. '</h2>';
+      search_index($msg->mid, 'mailarchive', $text);
+
+      // update this inside the loop, in case of a time-out
+      variable_set('mailarchive_search_cron_last', $msg->mid);
+    }
+  }
+}
 ?>
