Skip to content

Commit

Permalink
Simplify email conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
dlglin committed Jul 23, 2024
1 parent f388182 commit ea523cc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
14 changes: 5 additions & 9 deletions lib/Mojolicious/WeBWorK/Tasks/SendInstructorEmail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 4 additions & 7 deletions lib/WeBWorK/ContentGenerator/Feedback.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions lib/WeBWorK/Utils/ProblemProcessing.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ea523cc

Please sign in to comment.