### Eclipse Workspace Patch 1.0
#P standard.int
Index: sites/all/modules/privatemsg/privatemsg.module
===================================================================
--- sites/all/modules/privatemsg/privatemsg.module	(revision 8220)
+++ sites/all/modules/privatemsg/privatemsg.module	(working copy)
@@ -973,7 +973,7 @@
         }
       }
       $extra_folders['new'] = t('New folder...');
-  
+
       // Control to move messages to a new folder. Display only for inbox and
       // custom folders.
       if ((arg(1) == NULL || arg(1) == 'list') && count($extra_folders) > 0 && $current_folder != PRIVATEMSG_FOLDER_RECYCLE_BIN && $current_folder != PRIVATEMSG_FOLDER_SENT) {
@@ -1637,7 +1637,7 @@
       return FALSE;
     }
   }
-  
+
   $message_id = db_next_id('{privatemsg}_id');
   if (!$thread) {
     $thread = db_next_id('{privatemsg}_thread');
@@ -2096,7 +2096,7 @@
     $uid = $user->uid;
   }
   if (!isset($cache[$uid])) {
-    $cache[$uid] = (int)db_result(db_query('SELECT COUNT(*) FROM {privatemsg} WHERE recipient = %d AND newmsg = 1 AND recipient_del = 0', $uid));
+    $cache[$uid] = (int)db_result(db_query('SELECT COUNT(*) FROM {privatemsg} p INNER JOIN {users} u ON p.author = u.uid WHERE p.recipient = %d AND p.newmsg = 1 AND p.recipient_del = 0', $uid));
   }
   return $cache[$uid];
 }
@@ -2166,7 +2166,7 @@
     $pm_from = $user->name;
   }
   else {
-          
+
 
     $pm_from = '<div class="pm-username">'. theme('privatemsg_username', $message) .'</div>';
     $pm_from .= '<div class="pm-inbox-avatar">'. theme('privatemsg_user_picture', user_load(array('uid' => $message->uid))).'</div>';
@@ -2484,22 +2484,22 @@
   if (variable_get('user_pictures', 0)) {
     if ($account->picture && file_exists($account->picture)) {
 
-      if (arg(0) == 'user' && is_numeric(arg(1))) { // If on user profile page       
+      if (arg(0) == 'user' && is_numeric(arg(1))) { // If on user profile page
         $picture = file_create_url($account->picture);
       }
       else { // somewhere else on the site - use small pic
         $info = image_get_info($account->picture);
         $newpicture = dirname($account->picture) . '/picture-' . $account->uid . "-avatar." . $info['extension'];
-        
+
         if (!file_exists($newpicture) || (filectime($newpicture) < filectime($account->picture))) {
-          image_scale($account->picture, $newpicture, 64, 64); 
+          image_scale($account->picture, $newpicture, 64, 64);
           if (!file_exists($newpicture)) {
             $newpicture = $account->picture;
           }
         }
-        
+
         $picture = file_create_url($newpicture);
-      } 
+      }
     }
     else if (variable_get('user_picture_default', '')) {
       $picture = variable_get('user_picture_default', '');
@@ -2517,16 +2517,16 @@
         $uid = $account->uid; // get the current userid for the avatar.
         $users = db_query("SELECT uid, name, access FROM {users} WHERE access >= %d AND uid = %s", time() - $time_period, $uid);
         $total_users = db_num_rows($users);
-  
+
         if ($total_users == 1) {
           $output = '<span style="color: #00DD45; font-weight: bold; display:block;">' . t('Online') . '</span>';
           }
         else {
-          $output = '<span style="color: #AA4444; display:block;">' . t('Offline') . '</span>';     
+          $output = '<span style="color: #AA4444; display:block;">' . t('Offline') . '</span>';
         }
       }
       return '<div class="picture">' . $output . $picture . '</div>';
-        
+
     }
   }
 }
\ No newline at end of file
