diff -urp privatemsg/privatemsg.install privatemsg_tags/privatemsg.install
--- privatemsg/privatemsg.install	2008-09-26 23:53:16.193200000 +0100
+++ privatemsg_tags/privatemsg.install	2008-09-28 23:14:10.393600000 +0100
@@ -89,6 +89,51 @@ function privatemsg_schema() {
     ),
   );
   
+  $schema['pm_tags'] = array(
+    'description'       => t('{pm_tags} holds the names of tags and their id'),
+    'fields'        => array(
+      'tag_id'    => array(
+        'description'   => t('Tag ID'),
+        'type'          => 'serial',
+        'not null'      => TRUE,
+        'unsigned'      => TRUE,
+      ),
+      'tag'     => array(
+        'description'   => t('The name of the tag'),
+        'type'          => 'varchar',
+        'length'        => 255,
+        'not null'      => TRUE,
+      ),
+    ),
+    'indexes'         => array(
+      '`tag_id`'               => array('`tag_id`','`tag`'),
+
+    ),
+  );
+
+  $schema['pm_tags_index'] = array(
+    'description'       => t('{pm_tags} holds the names of tags and their id'),
+    'fields'        => array(
+      'tag_id'    => array(
+        'description'   => t('Tag ID'),
+        'type'          => 'int',
+        'not null'      => TRUE,
+        'unsigned'      => TRUE,
+      ),
+      'uid'    => array(
+        'description'   => t('ID of the user'),
+        'type'          => 'int',
+        'not null'      => TRUE,
+        'unsigned'      => TRUE,
+      ),
+      'thread_id'    => array(
+        'description'   => t('id of the thread'),
+        'type'          => 'int',
+        'not null'      => TRUE,
+        'unsigned'      => TRUE,
+      ),
+    ),
+  );
   
   return $schema;
 }
diff -urp privatemsg/privatemsg.module privatemsg_tags/privatemsg.module
--- privatemsg/privatemsg.module	2008-09-25 23:52:30.821400000 +0100
+++ privatemsg_tags/privatemsg.module	2008-09-28 23:43:13.439000000 +0100
@@ -236,14 +236,19 @@ function privatemsg_list($uid = NULL) {
   }
   // By this point we have figured out for which user we are listing messages and now it is safe to use $account->uid in the listing query.
 
-//  drupal_set_message('<pre>'. print_r($uid, 1) .'</pre>');
-  switch (arg(1)) {
+  $tags = arg(1);
+  
+  switch ($tags) {
     case 'sent':
       $query = _privatemsg_assemble_query('privatemsg_list_sent', $account);
       break;
     case 'inbox':
-    default:
+    case '':
       $query = _privatemsg_assemble_query('privatemsg_list', $account);
+      break;
+    default:
+      drupal_set_title('Messages tagged '. $tags);
+      $query = _privatemsg_assemble_query('privatemsg_list', $account, $tags);     
   }
   $result = db_query($query);
 
@@ -685,7 +690,7 @@ function privatemsg_privatemsg_list_sent
   $fragments['query_args'][]  = $account->uid;
 }
 
-function privatemsg_privatemsg_list_alter(&$fragments, $account) {
+function privatemsg_privatemsg_list_alter(&$fragments, $account, $tags = NULL) {
   $fragments['primary_table'] = '{pm_message} pm';
 
   $fragments['select'][]      = 'pmi.thread_id';
@@ -693,7 +698,14 @@ function privatemsg_privatemsg_list_alte
   $fragments['select'][]      = 'MAX(pm.timestamp) as timestamp';
   $fragments['select'][]      = 'MAX(pmi.new) as new';
   $fragments['inner_join'][]  = 'INNER JOIN {pm_index} pmi ON pm.mid = pmi.mid';
+  if (isset($tags) && $tags) {
+    $fragments['inner_join'][]  = 'INNER JOIN {pm_tags_index} pmti ON (pmti.thread_id = pmi.thread_id) AND (pmti.uid = pmi.uid)';
+    $fragments['inner_join'][]  = 'INNER JOIN {pm_tags} pmt ON pmt.tag_id = pmti.tag_id';
+    $fragments['where'][]       = 'pmt.tag = "%s"';
+    $fragments['query_args'][]  = $tags;
+  }
   $fragments['where'][]       = 'pmi.uid = %d';
+  $fragments['query_args'][]  = $account->uid;
   $fragments['where'][]       = 'pmi.deleted = 0';
   $fragments['group_by'][]    = 'pmi.thread_id';
   $order = 'pmi.new';
@@ -709,7 +721,6 @@ function privatemsg_privatemsg_list_alte
     $sort = isset($_GET['sort']) && ($_GET['sort'] == 'asc' || $_GET['sort'] == 'desc') ? $_GET['sort'] : 'desc';
   }
   $fragments['order_by'][]  = $order . ' ' . $sort . ', MAX(pmi.mid) DESC';
-  $fragments['query_args'][]  = $account->uid;
 
 }
 
