From ea523cca16e22aeb4163b56e1fa5124119eb95ff Mon Sep 17 00:00:00 2001 From: Danny Glin Date: Tue, 23 Jul 2024 22:16:53 +0000 Subject: [PATCH] Simplify email conditional --- .../WeBWorK/Tasks/SendInstructorEmail.pm | 14 +++++--------- lib/WeBWorK/ContentGenerator/Feedback.pm | 11 ++++------- lib/WeBWorK/Utils/ProblemProcessing.pm | 7 +++---- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/Mojolicious/WeBWorK/Tasks/SendInstructorEmail.pm b/lib/Mojolicious/WeBWorK/Tasks/SendInstructorEmail.pm index d545dda3de..3f9c177e19 100644 --- a/lib/Mojolicious/WeBWorK/Tasks/SendInstructorEmail.pm +++ b/lib/Mojolicious/WeBWorK/Tasks/SendInstructorEmail.pm @@ -79,17 +79,13 @@ sub mail_message_to_recipients ($job, $ce, $db, $mail_data) { $mail_data->{merge_data} ); - my $email; + my $email = Email::Stuffer->to($user_record->email_address)->subject($mail_data->{subject})->text_body($msg) + ->header('X-Remote-Host' => $mail_data->{remote_host}); if ($ce->{instructor_sender_email}) { - $email = - Email::Stuffer->to($user_record->email_address) - ->from($mail_data->{from_name} . ' <' . $ce->{instructor_sender_email} . '>') - ->reply_to($mail_data->{from})->subject($mail_data->{subject})->text_body($msg) - ->header('X-Remote-Host' => $mail_data->{remote_host}); + $email->from($mail_data->{from_name} . ' <' . $ce->{instructor_sender_email} . '>') + ->reply_to($mail_data->{from}); } else { - $email = - Email::Stuffer->to($user_record->email_address)->from($mail_data->{from}) - ->subject($mail_data->{subject})->text_body($msg)->header('X-Remote-Host' => $mail_data->{remote_host}); + $email->from($mail_data->{from}); } eval { diff --git a/lib/WeBWorK/ContentGenerator/Feedback.pm b/lib/WeBWorK/ContentGenerator/Feedback.pm index 7206e37adb..b4d66e5945 100644 --- a/lib/WeBWorK/ContentGenerator/Feedback.pm +++ b/lib/WeBWorK/ContentGenerator/Feedback.pm @@ -186,15 +186,12 @@ $emailableURL } my $from_name = $user ? $user->full_name : $ce->{generic_sender_name}; - my $email; + my $email = Email::Stuffer->to(join(',', @recipients))->subject($subject)->text_body($msg) + ->header('X-Remote-Host' => $remote_host); if ($ce->{feedback_sender_email}) { - $email = - Email::Stuffer->to(join(',', @recipients))->from("$from_name <$ce->{feedback_sender_email}>") - ->reply_to($sender)->subject($subject)->text_body($msg)->header('X-Remote-Host' => $remote_host); + $email->from("$from_name <$ce->{feedback_sender_email}>")->reply_to($sender); } else { - $email = - Email::Stuffer->to(join(',', @recipients))->from($sender)->subject($subject)->text_body($msg) - ->header('X-Remote-Host' => $remote_host); + $email->from($sender); } # Extra headers $email->header('X-WeBWorK-Route', $route) if defined $route; diff --git a/lib/WeBWorK/Utils/ProblemProcessing.pm b/lib/WeBWorK/Utils/ProblemProcessing.pm index 5dc19f4180..9002533b95 100644 --- a/lib/WeBWorK/Utils/ProblemProcessing.pm +++ b/lib/WeBWorK/Utils/ProblemProcessing.pm @@ -464,12 +464,11 @@ Recitation: $recitation Comment: $comment /; - my $email; + my $email = Email::Stuffer->to(join(',', @recipients))->subject($subject)->text_body($msg); if ($ce->{jitar_sender_email}) { - $email = Email::Stuffer->to(join(',', @recipients))->from("$full_name <$ce->{jitar_sender_email}>") - ->reply_to($sender)->subject($subject)->text_body($msg); + $email->from("$full_name <$ce->{jitar_sender_email}>")->reply_to($sender); } else { - $email = Email::Stuffer->to(join(',', @recipients))->from($sender)->subject($subject)->text_body($msg); + $email->from($sender); } # Extra headers