diff -ruP --exclude=.svn --exclude=CVS --exclude=privatemsgapi privatemsg.old/views/privatemsg.views.inc privatemsg/views/privatemsg.views.inc
--- privatemsg.old/views/privatemsg.views.inc	2009-11-09 16:44:09.000000000 +0000
+++ privatemsg/views/privatemsg.views.inc	2010-03-03 20:30:02.000000000 +0000
@@ -5,7 +5,263 @@
  * Provide views data and handlers for privatemsg.module
  */
 
+/**
+ * Implementation of hook_views_data().
+ */
 function privatemsg_views_data() {
+  // ----------------------------------------------------------------
+  // privatemsg table -- basic table information.
+
+  // Define the base group of this table. Fields that don't
+  // have a group defined will go into this field by default.
+  $data['pm_message']['table']['group']  = t('Private message');
+
+  // Advertise this table as a possible base table
+  $data['pm_message']['table']['base'] = array(
+    'field' => 'mid',
+    'title' => t('Private message'),
+    'help' => t("Private messages sent between users."),
+    'weight' => 10,
+  );
+
+  // For other base tables, explain how we join
+  // Join with the user table
+  $data['pm_message']['table']['join'] = array(
+    'user' => array(
+      'left_field' => 'uid',
+      'field' => 'author',
+    ),
+  );
+  
+  // ----------------------------------------------------------------
+  // pm_message table -- fields
+
+  // mid
+  $data['pm_message']['mid'] = array(
+    'title' => t('Message ID'),
+    'help' => t('The ID of the private message.'),
+    // Information for displaying the nid
+    'field' => array(
+      'handler' => 'views_handler_field_privatemsg',
+      'click sortable' => TRUE,
+    ),
+    // Information for accepting a mid as an argument
+    'argument' => array(
+      'handler' => 'views_handler_argument_numeric',
+      'name field' => 'subject', // the field to display in the summary.
+      'numeric' => TRUE,
+      'validate type' => 'numeric',
+    ),
+    // Information for accepting a mid as a filter
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    // Information for sorting on a mid.
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+      'click sortable' => TRUE,
+    ),
+  );
+
+  // title
+  // This definition has more items in it than it needs to as an example.
+  $data['pm_message']['subject'] = array(
+    'title' => t('Subject'), // The item it appears as on the UI,
+    'help' => t('The subject of the message.'), // The help that appears on the UI,
+     // Information for displaying a title as a field
+    'field' => array(
+      'handler' => 'views_handler_field_privatemsg_subject',
+      'click sortable' => TRUE,
+     ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+      'click sortable' => TRUE,
+    ),
+    // Information for accepting a title as a filter
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  // Body field
+  $data['pm_message']['body'] = array(
+    'title' => t('Body'), // The item it appears as on the UI,
+    'help' => t('The body of the message.'), // The help that appears on the UI,
+     // Information for displaying a title as a field
+    'field' => array(
+      'handler' => 'views_handler_field_markup',
+      'format' => variable_get('filter_default_format', 1), // The name of the format field or an integer
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+  );
+
+  // author field
+  $data['pm_message']['author'] = array(
+    'title' => t('Author'),
+    'help' => t('Author of the message.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'base' => 'users',
+      'field' => 'uid', // join pm_message.author = user.uid 
+      'label' => t('Author'),
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_user_name',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+      'click sortable' => TRUE,
+    ),
+  );
+
+  // created field
+  $data['pm_message']['timestamp'] = array(
+    'title' => t('Sent date'),
+    'help' => t('The date and time when the message was sent.'),
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+      'click sortable' => TRUE,
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_date',
+    ),
+  );
+
+  // ----------------------------------------------------------------------
+  // privatemsg message instance table
+
+  // Define the base group of this table. Fields that don't
+  // have a group defined will go into this field by default.
+  $data['pm_index']['table']['group']  = t('Private message');
+
+  // For other base tables, explain how we join
+  $data['pm_index']['table']['join'] = array(
+    // Directly links to privatemsg table.
+    'pm_message' => array(
+      'left_field' => 'mid',
+      'field' => 'mid',
+      'type' => 'INNER',
+    ),
+    // Join with the user table
+    'user' => array(
+      'left_field' => 'uid',
+      'field' => 'uid',
+    ),
+  );
+
+  // thread_id
+  $data['pm_index']['thread_id'] = array(
+    'title' => t('Thread ID'),
+    'help' => t('ID of the thread the message belongs to.'),
+    // Information for displaying the thread_id
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+      'click sortable' => TRUE,
+    ),
+    // Information for accepting a thread_id as an argument
+    'argument' => array(
+      'handler' => 'views_handler_argument_numeric',
+      'name field' => 'subject', // the field to display in the summary.
+      'numeric' => TRUE,
+      'validate type' => 'numeric',
+    ),
+    // Information for accepting a thread_id as a filter
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    // Information for sorting on a thread_id
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+      'click sortable' => TRUE,
+    ),
+  );
+
+  // uid
+  $data['pm_index']['uid'] = array(
+    'title' => t('Recipient'),
+    'help' => t('Relate a message to the user who received it.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'base' => 'users',
+      'field' => 'uid',
+      'label' => t('Recipient'),
+    ),
+    'field' => array(
+      'title' => t('Participants'),
+      'help' => t('Display user participants.'),
+      'handler' => 'views_handler_field_privatemsg_participants',
+      'skip base' => 'pm_index',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_user_name',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+      'click sortable' => TRUE,
+    ),
+  );
+
+  $data['pm_index']['is_new'] = array(
+    'title' => t('New?'),
+    'help' => t('Whether the user has read this message.'),
+    'field' => array(
+      'handler' => 'views_handler_field_boolean',
+      'click sortable' => TRUE,
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_boolean_operator',
+      'type' => 'yes-no',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+      'click sortable' => TRUE,
+    ),
+  );
+
+  $data['pm_index']['deleted'] = array(
+    'title' => t('Deleted?'),
+    'help' => t('Whether the user has deleted this message.'),
+    'field' => array(
+      'handler' => 'views_handler_field_boolean',
+      'click sortable' => TRUE,
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_boolean_operator',
+      'type' => 'yes-no',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+  );
+
+  $data['pm_index']['is_head'] = array(
+    'title' => t('Head?'),
+    'help' => t('Whether this message is the first in its thread.'),
+    'filter' => array(
+      'handler' => 'views_handler_filter_privatemsg_head',
+      'type' => 'yes-no',
+    ),
+  );
+
+  $data['pm_index']['count'] = array(
+    'title' => t('Count'),
+    'help' => t('Count of messages in this thread.'),
+    'field' => array(
+      'field' => 'thread_id',
+      'handler' => 'views_handler_field_privatemsg_count',
+      'click sortable' => TRUE,
+    ),
+  );
+
   $data['users']['privatemsg_link'] = array(
     'group' => t('Privatemsg'),
     'title' => t('Send message'),
@@ -18,7 +274,6 @@
   return $data;
 }
 
-
 /**
  * Implementation of hook_views_handlers().
  */
@@ -29,12 +284,22 @@
     ),
     'handlers' => array(
       // field handlers
-      'views_handler_field_privatemsg_link' => array(
+ 	    'views_handler_field_privatemsg_link' => array(
+        'parent' => 'views_handler_field',
+      ),
+      'views_handler_field_privatemsg_subject' => array(
+        'parent' => 'views_handler_field',
+      ),
+      'views_handler_field_privatemsg_participants' => array(
+        'parent' => 'views_handler_field_prerender_list',
+      ),
+      'views_handler_filter_privatemsg_head' => array(
+        'parent' => 'views_handler_filter_boolean_operator',
+      ),
+      'views_handler_field_privatemsg_count' => array(
         'parent' => 'views_handler_field',
       ),
     ),
   );
 }
 
-
-
diff -ruP --exclude=.svn --exclude=CVS --exclude=privatemsgapi privatemsg.old/views/views_handler_field_privatemsg_count.inc privatemsg/views/views_handler_field_privatemsg_count.inc
--- privatemsg.old/views/views_handler_field_privatemsg_count.inc	1970-01-01 00:00:00.000000000 +0000
+++ privatemsg/views/views_handler_field_privatemsg_count.inc	2010-03-03 20:26:32.000000000 +0000
@@ -0,0 +1,9 @@
+<?php
+// $Id$
+
+class views_handler_field_privatemsg_count extends views_handler_field {
+  function render($values) {
+    return db_result(db_query("SELECT COUNT(DISTINCT mid) FROM {pm_index} WHERE thread_id = " . $values->{$this->field_alias}));
+  }
+}
+
diff -ruP --exclude=.svn --exclude=CVS --exclude=privatemsgapi privatemsg.old/views/views_handler_field_privatemsg_participants.inc privatemsg/views/views_handler_field_privatemsg_participants.inc
--- privatemsg.old/views/views_handler_field_privatemsg_participants.inc	1970-01-01 00:00:00.000000000 +0000
+++ privatemsg/views/views_handler_field_privatemsg_participants.inc	2010-03-03 00:05:46.000000000 +0000
@@ -0,0 +1,5 @@
+<?php
+
+class views_handler_field_privatemsg_participants extends views_handler_field_prerender_list {
+  // @TODO: We have to implement something similar to taxonomy:all terms
+}
diff -ruP --exclude=.svn --exclude=CVS --exclude=privatemsgapi privatemsg.old/views/views_handler_field_privatemsg_subject.inc privatemsg/views/views_handler_field_privatemsg_subject.inc
--- privatemsg.old/views/views_handler_field_privatemsg_subject.inc	1970-01-01 00:00:00.000000000 +0000
+++ privatemsg/views/views_handler_field_privatemsg_subject.inc	2010-03-03 00:05:46.000000000 +0000
@@ -0,0 +1,56 @@
+<?php
+// $Id$
+/**
+ * @file
+ * Contains the basic 'Private message: Subject' field handler.
+ */
+
+/**
+ * Field handler to provide simple renderer that allows linking to a private message.
+ */
+class views_handler_field_privatemsg_subject extends views_handler_field {
+  /**
+   * Constructor to provide additional field to add.
+   */
+  function construct() {
+    parent::construct();
+    $this->additional_fields['mid'] = 'mid';
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['link_to_msg'] = array('default' => FALSE);
+    return $options;
+  }
+
+  /**
+   * Provide link to node option
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['link_to_msg'] = array(
+      '#title' => t('Link this field to its message'),
+      '#description' => t('This will override any other link you have set.'),
+      '#type' => 'checkbox',
+      '#default_value' => !empty($this->options['link_to_msg']),
+    );
+    // @TODO: Add an option like Node:Title upadted mark 
+  }
+
+  /**
+   * Render whatever the data is as a link to the node.
+   *
+   * Data should be made XSS safe prior to calling this function.
+   */
+  function render_link($data, $values) {
+    if (!empty($this->options['link_to_msg']) && $data !== NULL && $data !== '') {
+      $this->options['alter']['make_link'] = TRUE;
+      $this->options['alter']['path'] = "messages/view/" . $values->{$this->aliases['mid']};
+    }
+    return $data;
+  }
+
+  function render($values) {
+    return $this->render_link(check_plain($values->{$this->field_alias}), $values);
+  }
+}
diff -ruP --exclude=.svn --exclude=CVS --exclude=privatemsgapi privatemsg.old/views/views_handler_filter_privatemsg_head.inc privatemsg/views/views_handler_filter_privatemsg_head.inc
--- privatemsg.old/views/views_handler_filter_privatemsg_head.inc	1970-01-01 00:00:00.000000000 +0000
+++ privatemsg/views/views_handler_filter_privatemsg_head.inc	2010-03-03 19:50:38.000000000 +0000
@@ -0,0 +1,14 @@
+<?php
+// $Id$
+
+class views_handler_filter_privatemsg_head extends views_handler_filter_boolean_operator {
+  function construct() {
+    parent::construct();
+  }
+
+  function query() {
+    $this->ensure_my_table();
+    $this->query->add_where($this->options['group'], "$this->table_alias.thread_id " . (empty($this->value) ? '<>' : '=') . " $this->table_alias.mid");
+  }
+}
+
