diff --git a/privatemsg.module b/privatemsg.module index 995b97b..c5455a3 100644 --- a/privatemsg.module +++ b/privatemsg.module @@ -1421,6 +1421,13 @@ function privatemsg_privatemsg_block_message($author, $recipients, $context = ar 'message' => t('%recipient has disabled private message receiving.', array('%recipient' => privatemsg_recipient_format($recipient, array('plain' => TRUE)))), ); } + // Do not send private messages to blocked users. + else if (($recipient->type == 'user') && (!$recipient->status)) { + $blocked[] = array( + 'recipient' => 'user_' . $recipient->uid, + 'message' => t('%recipient has disabled his or her account.', array('%recipient' => privatemsg_recipient_format($recipient, array('plain' => TRUE)))), + ); + } } return $blocked; diff --git a/privatemsg.test b/privatemsg.test index 8e15c98..b14e38f 100644 --- a/privatemsg.test +++ b/privatemsg.test @@ -242,6 +242,10 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { $author = $this->drupalCreateUser(array('write privatemsg', 'select text format for privatemsg', filter_permission_name(filter_format_load('full_html')))); $recipient = $this->drupalCreateUser(array('read privatemsg')); $recipient2 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg')); + $blocked_recipient = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg')); // set up user with read/write privatemsg permissions + // Block one of the recipients to make sure that no messages are delivered + // to invalid recipients. + user_save($blocked_recipient, array('status' => 0)); // Login author and go to new message form. $this->drupalLogin($author); @@ -271,6 +275,12 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { 'subject' => $this->randomName(20), 'body[value]' => $this->randomName(100), ); + // Blocked recipient + $editblocked = array( + 'recipient' => $blocked_recipient, + 'subject' => $this->randomName(20), + 'body[value]' => $this->randomName(100), + ); // Empty body. $editnobody = array( 'recipient' => $recipient->name, @@ -324,6 +334,9 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { $this->assertText(t('You must include at least one valid recipient.'), 'Message was not sent.'); $this->assertText(t('The following recipients will not receive this private message: @recipients.', array('@recipients' => $editinvalid['recipient'])), 'Message about non-existing user displayed.'); + $this->drupalPost('messages/new', $editblocked, t('Send message')); + $this->assertText(t('%recipient has disabled his or her account.', array('%recipient' => $editblocked['recipient'])), 'Message was not sent.'); + $this->drupalPost('messages/new', $editnobody, t('Send message')); $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), 'Message sent confirmation displayed.');