FIX: Do not send system emails to suspended users (#10192)

FIX: Do not send system emails to suspended users (#10192)

diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rb
index 1197499..20edc25 100644
--- a/app/jobs/regular/user_email.rb
+++ b/app/jobs/regular/user_email.rb
@@ -220,7 +220,7 @@ module Jobs
           return SkippedEmailLog.reason_types[:user_email_post_deleted]
         end
 
-        if user.suspended? && !post.user&.staff?
+        if user.suspended? && (!post.user&.staff? || !post.user&.human?)
           return SkippedEmailLog.reason_types[:user_email_user_suspended]
         end
 
diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rb
index e6def35..0c22877 100644
--- a/spec/jobs/user_email_spec.rb
+++ b/spec/jobs/user_email_spec.rb
@@ -326,6 +326,26 @@ describe Jobs::UserEmail do
             suspended.email
           )
         end
+
+        it "doesn't send PM from system user" do
+          pm_from_system = SystemMessage.create(suspended, :unsilenced)
+
+          system_pm_notification = Fabricate(:notification,
+            user: suspended,
+            topic: pm_from_system.topic,
+            post_number: pm_from_system.post_number,
+            data: { original_post_id: pm_from_system.id }.to_json
+          )
+
+          Jobs::UserEmail.new.execute(
+            type: :user_private_message,
+            user_id: suspended.id,
+            post_id: pm_from_system.id,
+            notification_id: system_pm_notification.id
+          )
+
+          expect(ActionMailer::Base.deliveries).to eq([])
+        end
       end
 
       context 'user is anonymous' do

GitHub sha: 67582e7d

This commit appears in #10192 which was approved by eviltrout. It was merged by pmusaraj.