diff -u -r -P -x *.orig -x *~ -x *.in pan-0.111/pan/gui/pan.cc pannew/pan/gui/pan.cc
--- pan-0.111/pan/gui/pan.cc	Tue Aug 29 17:20:44 2006
+++ pannew/pan/gui/pan.cc	Sun Sep  3 16:48:05 2006
@@ -32,6 +32,7 @@
 #include <pan/tasks/nzb.h>
 #include <pan/data-impl/data-impl.h>
 #include <pan/icons/pan-pixbufs.h>
+#include <pan/tasks/headers.h>
 #include "gui.h"
 #include "group-prefs.h"
 #include "prefs-file.h"
@@ -141,6 +142,9 @@
 _("General Options\n"
 "  -h, --help               Show this usage page.\n"
 "\n"
+"  --headers                Retrieve NEW headers for subscribed groups.\n"
+"  --headers-all            Retrieve ALL headers for subscribed groups.\n"
+"\n"
 "URL Options\n"
 "  news:message-id          Show the specified article.\n"
 "  news:group.name          Show the specified newsgroup.\n"
@@ -151,6 +155,21 @@
 "  -o path, --output=path   Path to save attachments listed in the nzb files.\n"
 "  --nogui                  Only show console output, not the download queue.\n") << std::endl;
   }
+  
+  gboolean kill_timeout(gpointer data)
+  {
+	  Queue *q=static_cast<Queue*>(data);
+	  int r,t;
+	  
+	  q->get_task_counts(r,t);
+	  if(t==0 && r==0)
+	  {
+		  gtk_main_quit();
+		  return FALSE;
+	  }
+	  
+	  return TRUE;
+  }
 }
 
 int
@@ -163,7 +182,7 @@
   gtk_init (&argc, &argv);
   g_mime_init (GMIME_INIT_FLAG_UTF8);
 
-  bool gui(true), nzb(false);
+  bool gui(true), nzb(false), headers(false), headers_all(false);
   std::string url;
   typedef std::vector<std::string> strings_t;
   strings_t nzb_files;
@@ -183,6 +202,10 @@
       _debug_flag = true;
     else if (!strcmp (tok, "--nzb"))
       nzb = true;
+	else if (!strcmp (tok, "--headers-all"))
+		headers=headers_all=true;
+	else if (!strcmp (tok, "--headers"))
+		headers=true;
     else if (!strcmp (tok, "-o") && i<argc-1) 
       nzb_output_path = argv[++i];
     else if (!memcmp (tok, "--output=", 9))
@@ -199,8 +222,8 @@
     return 0;
   }
 #endif
-  if (!gui && nzb_files.empty() && url.empty()) {
-    std::cerr << _("Error: --nogui used without nzb files or news:message-id.") << std::endl;
+  if (!gui && !headers && nzb_files.empty() && url.empty()) {
+    std::cerr << _("Error: --nogui used without nzb files, headers or news:message-id.") << std::endl;
     return 0;
   }
 
@@ -228,14 +251,25 @@
     GIOChannelSocket::Creator socket_creator;
     Queue queue (data, data, &socket_creator, prefs.get_flag("work-online",true));
     g_timeout_add (5000, queue_upkeep_timer_cb, &queue);
+	
+	headers_set_data(static_cast<Data*>(&data),&queue,&cache);
 
-    if (nzb)
+    if (nzb || headers)
     {
-      // load the nzb files...
-      std::vector<Task*> tasks;
-      foreach_const (strings_t, nzb_files, it)
-        NZB :: tasks_from_nzb_file (*it, nzb_output_path, cache, data, data, data, tasks);
-      queue.add_tasks (tasks, Queue::BOTTOM);
+		if(headers)
+			headers_queue_subscribed(headers_all);
+		if(nzb)
+		{
+			  // load the nzb files...
+			  std::vector<Task*> tasks;
+			  foreach_const (strings_t, nzb_files, it)
+				NZB :: tasks_from_nzb_file (*it, nzb_output_path, cache, data, data, data, tasks);
+			  queue.add_tasks (tasks);
+		}
+		
+		// this will kill pan when the queue is empty
+		// called every 2 sec
+		g_timeout_add(2*1000,kill_timeout,&queue);
 
       // don't open the full-blown Pan, just act as a nzb client,
       // with a gui or without.
diff -u -r -P -x *.orig -x *~ -x *.in pan-0.111/pan/tasks/Makefile.am pannew/pan/tasks/Makefile.am
--- pan-0.111/pan/tasks/Makefile.am	Thu Aug 17 13:42:41 2006
+++ pannew/pan/tasks/Makefile.am	Sun Sep  3 16:43:21 2006
@@ -14,7 +14,8 @@
   socket.cc \
   socket-impl-gio.cc \
   socket-impl-scripted.cc \
-  nntp-pool.cc
+  nntp-pool.cc \
+  headers.cc
 
 noinst_HEADERS = \
   adaptable-set.cc \
@@ -33,7 +34,8 @@
   socket.h \
   socket-impl-gio.h \
   socket-impl-scripted.h \
-  nntp-pool.h
+  nntp-pool.h \
+  headers.h
 
 noinst_PROGRAMS = \
   adaptable-set-test \
diff -u -r -P -x *.orig -x *~ -x *.in pan-0.111/pan/tasks/headers.cc pannew/pan/tasks/headers.cc
--- pan-0.111/pan/tasks/headers.cc	Wed Dec 31 17:00:00 1969
+++ pannew/pan/tasks/headers.cc	Sun Sep  3 16:43:21 2006
@@ -0,0 +1,76 @@
+#include <config.h>
+#include <glib.h>
+#include "headers.h"
+#include "task-article.h"
+#include "task-xover.h"
+#include "queue.h"
+
+using namespace pan;
+
+static Data *data=NULL;
+static ArticleCache *cache=NULL;
+static Queue *queue=NULL;
+
+void pan::headers_set_data(Data *d, Queue *q, ArticleCache *c)
+{
+	data=d;
+	queue=q;
+	cache=c;
+	g_assert(data!=NULL);
+	g_assert(queue!=NULL);
+	g_assert(cache!=NULL);
+}
+
+void pan::headers_queue_subscribed(bool get_all)
+{
+	std::vector<Task*> tasks;
+	std::vector<Quark> groups;
+	
+	data->get_subscribed_groups(groups);
+	tasks.reserve(groups.size());
+	foreach(std::vector<Quark>,groups,g)
+	  tasks.push_back(new TaskXOver(*data,*g,(get_all?TaskXOver::ALL:TaskXOver::NEW)));
+	
+	queue->add_tasks(tasks);
+}
+
+void pan::headers_queue_articles(const Quark &group)
+{
+	g_assert(data!=NULL);
+	g_assert(queue!=NULL);
+	g_assert(cache!=NULL);
+	
+  // FIXME: need to protect with pref
+  FilterInfo filter,ftemp;
+  filter.set_type_aggregate_and();
+  ftemp.set_type_is_unread();
+  filter._aggregates.push_back(ftemp);
+  // FIXME: should be a pref
+  ftemp.set_type_score_ge(9999);
+  filter._aggregates.push_back(ftemp);
+  //ftemp.set_type_cached();
+  //ftemp.set_negate(true);
+  //filter._aggregates.push_back(ftemp);
+  std::auto_ptr<Data::ArticleTree> tree(data->group_get_articles(group,Data::SHOW_ARTICLES,&filter));
+  unsigned long size=tree->size();
+  Data::ArticleTree::articles_t arts;
+  if(size>0)
+  {
+    arts.reserve(size);
+    tree->get_children(Quark(),arts);
+    foreach(Data::ArticleTree::articles_t, arts, it)
+    {
+      const Article *a(*it);
+      tree->get_children(a->message_id,arts);
+    }
+    
+    const StringView sv;
+    if(arts.size()>0)
+      foreach(Data::ArticleTree::articles_t, arts, it)
+      {
+        const Article *a(*it);
+        queue->add_task(new TaskArticle(*data, *data, *a, *cache, *data, NULL, sv),Queue::BOTTOM);
+      }
+  }
+}
+
diff -u -r -P -x *.orig -x *~ -x *.in pan-0.111/pan/tasks/headers.h pannew/pan/tasks/headers.h
--- pan-0.111/pan/tasks/headers.h	Wed Dec 31 17:00:00 1969
+++ pannew/pan/tasks/headers.h	Sun Sep  3 16:43:21 2006
@@ -0,0 +1,15 @@
+#ifndef _HEADERS_H_
+#define _HEADERS_H_
+
+#include <pan/data-impl/data-impl.h>
+#include <pan/tasks/queue.h>
+
+namespace pan
+{
+void headers_set_data(Data*, Queue*, ArticleCache*);
+void headers_queue_subscribed(bool get_all=false);
+void headers_queue_articles(const Quark &group);
+
+}
+#endif
+
diff -u -r -P -x *.orig -x *~ -x *.in pan-0.111/pan/tasks/task-xover.cc pannew/pan/tasks/task-xover.cc
--- pan-0.111/pan/tasks/task-xover.cc	Tue Aug 29 11:05:44 2006
+++ pannew/pan/tasks/task-xover.cc	Sun Sep  3 16:43:21 2006
@@ -31,6 +31,7 @@
 #include <pan/data/data.h>
 #include "nntp.h"
 #include "task-xover.h"
+#include "headers.h"
 
 using namespace pan;
 
@@ -357,6 +358,8 @@
   else {
     _state.set_completed ();
     set_finished (OK);
+	
+	headers_queue_articles(_group);
   }
 }
 
