We've recently had two 419 spammers/scammers register and start sending pms to tonnes of users. We usually delete rather than block spammers, but because some of their pms hadn't been read, a few users got "you have a new private message", but then nothing when they clicked on it, which confused us for a bit.

Obviously we could block them instead, but we don't like them taking up space in the user table, so would it be easy enough to unset that message if a sender is deleted?

Comments

mindless’s picture

function privatemsg_user doesn't seem to have a case 'delete'. if you're able to provide a patch, please do. otherwise, would you be able to test changes if made available?

catch’s picture

I could have a look at doing a patch, might take a little while to get to it.

And yeah we should be able to test.

abramo’s picture

subscribing - delete should be made available, as essential.

mindless’s picture

Assigned: Unassigned » mindless
Status: Active » Fixed

code added. please test next 5.x dev snapshot.

catch’s picture

Status: Fixed » Needs work

Hi, I just tried this, but still get the alert.

Here's steps to reproduce:

1. create new user
2. send private message to your own account from that user
3. delete the new user before you read the message

I still get a "you have one new private message" alert with the latest dev version - i.e. there's the notification, but then when I go to my inbox there's no message.

catch’s picture

Alright, looking at the code now, must be here:

$new = _privatemsg_get_new_messages();
    $items[] = array('path' => 'privatemsg/inbox',
                     'title' => t(variable_get('privatemsg_menu_link', 'My inbox')) . ($new ? ' ('. $new .')' : ''),
                     'callback' => 'privatemsg_list',
                     'type' => $user->uid && (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1) ? MENU_DYNAMIC_ITEM : MENU_CALLBACK);

    if ($new && strncmp($_GET['q'], 'privatemsg', 10) && (isset($user->privatemsg_setmessage_notify) ? $user->privatemsg_setmessage_notify : 1) && user_access('access private messages')) {
      $m = drupal_set_message();
      if (empty($m)) {
        drupal_set_message(strtr(format_plural($new, 'You have one new <a href="!url">private message</a>.', 'You have @count new <a href="!url">private messages</a>.'), array('!url' => url('privatemsg'))));
      }
    }
  }
  return $items;
}

or here:

function _privatemsg_get_new_messages($uid = 0) {
  global $user;
  static $cache = array();
  if ($uid == 0) {
    $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));
  }
  return $cache[$uid];
}
mindless’s picture

With the new code (verify you have 1.70.2.29 at the top of your privatemsg.module file) you should still see that you have a new message, but you should be able to see it. The message should be from "anonymous". This is consistent with how other modules handle deleting a user... content that can be viewed by other users remains, but is now owned by the anonymous user. I did make it actually delete any private messages that were sent TO to the deleted user.
So, the question is why you couldn't see the new message.. is the guest user marked as "blocked" in your drupal?

catch’s picture

Status: Needs work » Fixed

ahhh it's .28! Maybe the tarbal didn't update yet. Will try again later on tonight or some time tomorrow.

Marking back to fixed assuming that's the only problem. Thanks!

catch’s picture

Just a note to say with latest development snapshot (verified), I now get the message sent from anonymous after the user's been deleted, which is great!

I'm still getting an alert for the deleted message prior to that upgrade, but will try find where it is in the database and reset it manually, that's not a problem.

Thanks very, very much for sorting that out. We've not had another 419er register since I originally posted but this issue was going to be painful.

Anonymous’s picture

Status: Fixed » Closed (fixed)