Index: privatemsg.module
===================================================================
--- privatemsg.module	(revision 129)
+++ privatemsg.module	(working copy)
@@ -180,6 +180,9 @@
       'arguments'        => array('recipients' => NULL),
       'template'         => 'privatemsg-between',
     ),
+    'privatemsg_list'    => array(
+      'arguments'        => array('threads' => NULL),
+    ),
     'privatemsg_message_row'  => array(
       'arguments'             => array('row'),
     ),
@@ -273,8 +276,20 @@
   }
   $result = pager_query($query['query'], variable_get('privatemsg_per_page', 25), 0, $query['count']);
 
+  $threads = array();
+  while ($thread = db_fetch_array($result)) {
+    $threads[$thread['thread_id']] = $thread;
+  }
+
+  return theme('privatemsg_list', $threads);
+}
+
+/**
+ * Theme a list of threads.
+ */
+function theme_privatemsg_list($threads) {
   $rows = array();
-  while ($thread = db_fetch_array($result)) {
+  foreach ($threads as $thread_id => $thread) {
     $rows[] = theme('privatemsg_message_row', $thread);
   }
 
