diff -aburN --exclude='CVS*' --exclude=.project --exclude=phpgw.log phpgw_cvs/nntp/admin.php phpgw_patch/nntp/admin.php
--- phpgw_cvs/nntp/admin.php	2006-10-01 14:22:11.000000000 +0100
+++ phpgw_patch/nntp/admin.php	2006-10-09 18:40:49.000000000 +0100
@@ -10,6 +10,12 @@
 	*  option) any later version.                                              *
 	\**************************************************************************/
 
+  /**************************************************************************\
+  * Modified by Steve Price <steep@sdprice.plus.com>                         *
+  * Modified to make the search function work properly, and work with the    *
+  * nextmatchs class                                                         *
+  \**************************************************************************/
+
 	/* $Id: admin.php,v 1.25.2.1.2.1 2005/12/15 14:06:41 skwashd Exp $ */
 
 	if ( (isset($_POST['submit']) && $_POST['submit']) 
@@ -35,16 +41,16 @@
 	$GLOBALS['phpgw_info']['flags'] = $phpgw_flags;
 	include('../header.inc.php');
 
-	function get_tg()
+	function get_tg($where='')
 	{
-		$GLOBALS['phpgw']->db->query('SELECT count(con) FROM newsgroups');
+		$GLOBALS['phpgw']->db->query("SELECT count(con) FROM newsgroups $where");
 		$GLOBALS['phpgw']->db->next_record();
 		$tg = $GLOBALS['phpgw']->db->f(0);
 		if($tg == 0)
 		{
 			@set_time_limit(0);
 			$GLOBALS['nntp']->load_table();
-			return get_tg();
+			return get_tg($where);
 		}
 		else
 		{
@@ -63,9 +69,6 @@
 			$tg = intval($_REQUEST['tg']);
 		}
 
-		//$phpgw->common->phpgw_header();
-		//echo parse_navbar();
-
 		$max = intval($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']);
 
 		$urlname = '/nntp/admin.php';
@@ -87,15 +90,6 @@
 			$start = (int) $_REQUEST['start'];
 		}
 
-		if (!isset($_REQUEST['query_result']) || !$_REQUEST['query_result'] )
-		{
-			$query_result = 0;
-		}
-		else
-		{
-			$query_result = (int) $_REQUEST['query_result'];
-		}
-
 		if ( !isset($_REQUEST['order']) || !$_REQUEST['order'] )
 		{
 			$order = 1;
@@ -126,22 +120,17 @@
 			}
 		}
 
-		$query_result = get_var('query_result', array('POST'), 0);
-		if ( (isset($_REQUEST['search']) && $_REQUEST['search']) || (isset($_REQUEST['next']) && $_REQUEST['next']) )
-		{
-			if (isset($_REQUEST['next']) && $_REQUEST['next'])
+		$where_str = '' ;
+		if (isset($_REQUEST['search']) && $_REQUEST['search'])
 			{
-				$query_result++;
-			}
+			$where_str = "WHERE name LIKE '%" . $GLOBALS['phpgw']->db->db_addslashes($_REQUEST['query']) ."%'" ;
+			$tg = intval(get_tg($where_str));
 
-			$GLOBALS['phpgw']->db->limit_query("SELECT con FROM newsgroups WHERE name LIKE '%" 
-					. $GLOBALS['phpgw']->db->db_addslashes($_REQUEST['query']) . "%'$orderby ",
-				$query_result, __LINE__, __FILE__);
-			$GLOBALS['phpgw']->db->next_record();
-			$start = (int)$GLOBALS['phpgw']->db->f('con') - 1;
-			if($start < 0)
+			// if 'stop' is set then this is a search
+			if (isset($_REQUEST['stop']))
 			{
-				$start = 0;
+				// Always reset counter for a new search
+				$start=0;
 			}
 		}
 
@@ -149,12 +138,6 @@
 					. '<input type="hidden" name="stop" value="' . ($start + $max) . "\">\n"
 					. "<input type=\"hidden\" name=\"tg\" value=\"{$tg}\">";
 
-		if (isset($query_result) && $query_result)
-		{
-			$common_hidden_vars .= "<input type=\"hidden\" name=\"query_result\" value=\"{$query_result}\" />\n";
-		}
-
-
 		$extra_parms = array();
 		$extra_parms['tg'] = $tg;
 
@@ -167,9 +150,20 @@
 			$extra_parms['order'] = $order;
 		}
 
+		$query_val = get_var('query', array('POST', 'GET'), '');
+		if( $query_val )
+		{
+			$extra_parms['query'] = $query_val;
+			$extra_parms['search'] = 'Search' ;
+			$common_hidden_vars .= 
+					"<input type=\"hidden\" name=\"query\" value=\"{$query_val}\" />\n" .
+					"<input type=\"hidden\" name=\"search\" value=\"Search\">";
+			
+		}
+
 		$var = array
 			(
-				'search_value'		=>	get_var('query', array('POST'), ''),
+				'search_value'		=>	$query_val,
 				'search'		=>	lang('search'),
 				'next'			=>	lang('next'),
 				'nml'			=>	$GLOBALS['phpgw']->nextmatchs->left($urlname,intval($start),intval($tg),$extra_parms),
@@ -195,7 +189,7 @@
 			$totaltodisplay = ($tg - $start) - 1;
 		}
 
-		$GLOBALS['phpgw']->db->limit_query('SELECT con, name, active FROM newsgroups'.$orderby,$start);
+		$GLOBALS['phpgw']->db->limit_query("SELECT con, name, active FROM newsgroups $where_str $orderby", $start);
 
 		for ( $i = 0; $i < $totaltodisplay; $i++)
 		{
@@ -233,8 +227,9 @@
 		}
 		$var = array
 			(
+				'common_hidden_vars'	=>	$common_hidden_vars,
 				'lang_update'	=>	lang('update'),
-				'checkmark'	=>	$GLOBALS['phpgw']->common->get_image_path('email').'/check'
+				'checkmark'	=>	$GLOBALS['phpgw']->common->get_image_path('email').'/check.gif'
 			);
 
 		$p->set_var($var);
@@ -255,6 +250,15 @@
 		}
 		$GLOBALS['phpgw']->db->unlock();
 
-		$GLOBALS['phpgw']->redirect_link('/nntp/admin.php', array('start' => $_REQUEST['start'], 'tg' => $_REQUEST['tg']) );
+		$params = array() ;
+		foreach (array('start', 'tg', 'search', 'query') as $field)
+		{
+			if (isset($_REQUEST[$field]))
+			{
+				$params[$field] = $_REQUEST[$field] ;
+			}
+		}
+	
+		$GLOBALS['phpgw']->redirect_link('/nntp/admin.php', $params) ;
 	}
 ?>
diff -aburN --exclude='CVS*' --exclude=.project --exclude=phpgw.log phpgw_cvs/nntp/inc/class.decode.inc.php phpgw_patch/nntp/inc/class.decode.inc.php
--- phpgw_cvs/nntp/inc/class.decode.inc.php	2006-10-01 14:22:11.000000000 +0100
+++ phpgw_patch/nntp/inc/class.decode.inc.php	2006-10-09 18:33:07.000000000 +0100
@@ -192,6 +192,8 @@
 			$mime_encoding = $this->get_mime_encoding($de_part);
 
 			$tag = "pre";
+			$str="";
+			
 			//  $jnk = isset($de_part->disposition) ? $de_part->disposition : "unknown";
 
 			//  echo "<!-- MIME disp: $jnk -->\n";
@@ -223,7 +225,7 @@
 			}
 			elseif (isset($de_part->subtype) && strtoupper($de_part->subtype) == 'HTML')
 			{
-				$str = $this->output_bound($mime_section.':',$mime_type.'/'.$de_part->subtype);
+//				$str = $this->output_bound($mime_section.':',$mime_type.'/'.$de_part->subtype);
 				return $str.$dsp;
 			}
 			elseif (isset($de_part->subtype) && 
@@ -234,12 +236,12 @@
 				strtoupper($de_part->subtype) == 'PNG'))
 			{
 				$att_name = $this->get_att_name($de_part);
-				$str = $this->output_bound($mime_section.':',$mime_type.'/'.$de_part->subtype);
+//				$str = $this->output_bound($mime_section.':',$mime_type.'/'.$de_part->subtype);
 				return $str.$this->image_display($dsp,$att_name);
 			}
 			else
 			{
-				$str = $this->output_bound($mime_section.':',$mime_type.'/'.$de_part->subtype);
+//				$str = $this->output_bound($mime_section.':',$mime_type.'/'.$de_part->subtype);
 				return "$str<$tag>$dsp</$tag>\n";
 			}
 		}
diff -aburN --exclude='CVS*' --exclude=.project --exclude=phpgw.log phpgw_cvs/nntp/preferences.php phpgw_patch/nntp/preferences.php
--- phpgw_cvs/nntp/preferences.php	2006-10-01 14:22:11.000000000 +0100
+++ phpgw_patch/nntp/preferences.php	2006-10-09 18:21:14.000000000 +0100
@@ -10,6 +10,12 @@
   *  option) any later version.                                              *
   \**************************************************************************/
 
+  /**************************************************************************\
+  * Modified by Steve Price <steep@sdprice.plus.com>                         *
+  * Modified to make the search function work properly, and work with the    *
+  * nextmatchs class                                                         *
+  \**************************************************************************/
+
 	/* $Id: preferences.php,v 1.36.4.1 2005/12/15 14:06:41 skwashd Exp $ */
 
 	$GLOBALS['phpgw_info']['flags'] = array
@@ -22,16 +28,18 @@
 
 	include('../header.inc.php');
 
-	function get_tg()
+	function get_tg($where='')
 	{
 		$db = $GLOBALS['phpgw']->db;
-		$db->query("SELECT count(con) FROM newsgroups WHERE active='Y'");
+		$db->query("SELECT count(con) FROM newsgroups WHERE active='Y' $where");
 		$db->next_record();
 		$con = $db->f(0);
 		unset($db);
 		return $con;
 	}
 	
+	//===========================================================================================
+	// Update
 	if( isset($_REQUEST['submit']) && $_REQUEST['submit'] )
 	{
 		$GLOBALS['phpgw']->preferences->read_repository();
@@ -57,10 +65,21 @@
 		}
 		$GLOBALS['phpgw']->preferences->save_repository(True);
 
-		$GLOBALS['phpgw']->redirect_link('/nntp/preferences.php', array('start' => $_REQUEST['start'], 'tg' => $_REQUEST['tg']) );
+		$params = array() ;
+		foreach (array('start', 'tg', 'search', 'query') as $field)
+		{
+			if (isset($_REQUEST[$field]))
+			{
+				$params[$field] = $_REQUEST[$field] ;
+			}
+		}
+	
+		$GLOBALS['phpgw']->redirect_link('/nntp/preferences.php', $params );
 		$GLOBALS['phpgw']->common->phpgw_exit();
 	}
 
+	//===========================================================================================
+	// View
 	if ( !isset($_REQUEST['start']) || !$_REQUEST['start'] )
 	{
 		$start = 0;
@@ -70,15 +89,6 @@
 		$start = (int) $_REQUEST['start'];
 	}
 
-	if (!isset($_REQUEST['query_result']) || !$_REQUEST['query_result'] )
-	{
-		$query_result = 0;
-	}
-	else
-	{
-		$query_result = (int) $_REQUEST['query_result'];
-	}
-
 	if ( !isset($_REQUEST['order']) || !$_REQUEST['order'] )
 	{
 		$order = 1;
@@ -111,36 +121,25 @@
 
 	$db2 = $GLOBALS['phpgw']->db;
 	
-	//FIXME this is ugly shit!
-	$query_result = get_var('query_result', array('POST'), 0);
-	if ( (isset($_REQUEST['search']) && $_REQUEST['search']) || (isset($_REQUEST['next']) && $_REQUEST['next']) )
-	{
-		if (isset($_REQUEST['next']) && $_REQUEST['next'])
-		{
-			$query_result++;
-		}
-		$db2->query("SELECT name FROM newsgroups WHERE active='Y'$orderby");
-		$j = 0;
-		$i = 0;
-		while($db2->next_record())
-		{
-			if (stristr($db2->f('name'),$query))
-			{
-				if($i==$query_result)
+		$query_val = get_var('query', array('POST', 'GET'), '');
+
+		$where_str = '' ;
+		if (isset($_REQUEST['search']) && $_REQUEST['search'])
 				{
-					$start = $j;
-					break;
-				}
-				else
+			$where_str = "AND name LIKE '%" . $GLOBALS['phpgw']->db->db_addslashes($query_val) ."%'" ;
+			$tg = intval(get_tg($where_str));
+
+			// if 'stop' is set then this is a search
+			if (isset($_REQUEST['stop']))
 				{
-					$i++;
-				}
-			}
-			$j++;
+				// Always reset counter for a new search
+				$start=0;
 		}
 	}
 
-	$querystr = "SELECT con, name FROM newsgroups WHERE active='Y'$orderby";
+
+
+	$querystr = "SELECT con, name FROM newsgroups WHERE active='Y' $where_str $orderby";
 	$db2->limit_query($querystr,$start,__LINE__,__FILE__);
 
 	if(!$db2->num_rows())
@@ -150,8 +149,6 @@
 	}
 	else
 	{
-		$GLOBALS['phpgw']->common->phpgw_header();
-		echo parse_navbar();
 		$minarray = Array();
 		$nntpavail = Array();
 		while($db2->next_record())
@@ -164,6 +161,10 @@
 			$minarray[] = $db2->f('con');
 		}
 		unset($db2);
+
+		$GLOBALS['phpgw']->common->phpgw_header();
+		echo parse_navbar();
+
 	}
 
 	$p = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('nntp'));
@@ -178,7 +179,7 @@
 
 	if (!isset($tg) || !$tg)
 	{
-		$tg = get_tg();
+		$tg = get_tg($where_str);
 	}
 	$first = count($minarray) ? min($minarray) : 0;
 
@@ -187,6 +188,7 @@
 	$common_hidden_vars = '<input type="hidden" name="start" value="'.$start.'">'."\n"
 		. '<input type="hidden" name="first" value="'.$first.'">'."\n"
 		. '<input type="hidden" name="nntparray" value="'.urlencode(serialize($minarray)).'">'."\n"
+					. '<input type="hidden" name="stop" value="' . 1 . "\">\n"
 		. '<input type="hidden" name="tg" value="'.$tg.'">'."\n";
 	if(isset($order) && $order)
 	{
@@ -196,10 +198,6 @@
 	{
 		$common_hidden_vars .= '<input type="hidden" name="sort" value="'.$sort.'">'."\n";
 	}
-	if(isset($query_result) && $query_result)
-	{
-		$common_hidden_vars .= '<input type="hidden" name="query_result" value="'.$query_result.'">'."\n";
-	}
 
 	$extra_parms = '&tg='.$tg;
 	if(isset($sort) && $sort)
@@ -211,11 +209,21 @@
 		$extra_parms .= '&order='.$order;
 	}
 
+		if( $query_val )
+		{
+			$extra_parms .= '&query='.$query_val;
+			$extra_parms .='&search=Search' ;
+			$common_hidden_vars .= 
+					"<input type=\"hidden\" name=\"query\" value=\"{$query_val}\" />\n" .
+					"<input type=\"hidden\" name=\"search\" value=\"Search\">";
+			
+		}
+
 	$urlname = '/nntp/preferences.php';
 
 	$p->set_var(array
 		(
-			'search_value'		=> (isset($query) && $query?$query:''),
+			'search_value'		=> $query_val,
 			'search'		=> lang('search'),
 			'next'			=> lang('next'),
 			'nml'			=> $GLOBALS['phpgw']->nextmatchs->left($urlname,$start,$tg,$extra_parms),
@@ -259,6 +267,7 @@
 
 	$p->set_var(array
 		(	
+				'common_hidden_vars'	=>	$common_hidden_vars,
 			'lang_update'	=> lang('update'),
 			'checkmark'	=> $GLOBALS['phpgw']->common->get_image_path('email').'/check.gif'
 		));
diff -aburN --exclude='CVS*' --exclude=.project --exclude=phpgw.log phpgw_cvs/nntp/templates/default/nntp.tpl phpgw_patch/nntp/templates/default/nntp.tpl
--- phpgw_cvs/nntp/templates/default/nntp.tpl	2006-10-01 14:22:11.000000000 +0100
+++ phpgw_patch/nntp/templates/default/nntp.tpl	2006-10-09 18:38:59.000000000 +0100
@@ -3,11 +3,19 @@
 <script>
 function check_all()
 {
-  for (i=0; i<document.allow.elements.length; i++) {
-      if (document.allow.elements[i].type == "checkbox") {
-	 if (document.allow.elements[i].checked) {
+  check=-1;
+  for (i=0; i<document.allow.elements.length; i++) 
+  {
+  	if (document.allow.elements[i].type == "checkbox") 
+  	{
+		if (check<0) {check = document.allow.elements[i].checked; } 
+		
+		if (check)
+		{
 	    document.allow.elements[i].checked = false;
-	 } else {
+	 	} 
+	 	else 
+	 	{
 	    document.allow.elements[i].checked = true;
 	 }
       }	
@@ -24,7 +32,7 @@
           {common_hidden_vars}
           <input type="text" name="query" value="{search_value}">
           <input type="submit" name="search" value="{search}">
-          <input type="submit" name="next" value="{next}">
+<!--          <input type="submit" name="next" value="{next}"> -->
         </form>
 	</div>
       </td>
