I'm having an issue whereby emails sent to users of a role are getting sent to users regardless of if they're blocked or not.

This issue is being addressed in rules at #1111436: Emails being sent to blocked user accounts but I thought I would make a patch specifically for mimemail because I need it working :)

Thoughts?

Comments

sgabe’s picture

Status: Needs review » Needs work

There is too much overlap in the code. We should rewrite this using the Database API. Something like this would be much more efficient and transparent.

$query = db_select('users', 'u');

$query->addField('u', 'mail');

if (!$blocked) {
  $query->condition('u.status', 1, '=');
}

if (in_array(DRUPAL_AUTHENTICATED_RID, $roles)) {
  $query->condition('u.uid', 0, '>');
}
else {
  $query->join('users_roles', 'r', 'u.uid = r.uid');
  $query->condition('r.rid', $roles, 'IN');
  $query->distinct();
}

$result = $query->execute();
sgabe’s picture

Status: Needs work » Needs review
StatusFileSize
new2.26 KB

See the attached patch.

sgabe’s picture

Title: When sending an html email to all users of a role, have an option to exclude blocked users. » Option to exclude blocked users from a role
Status: Needs review » Fixed

Committed!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.