Skip to content

Commit

Permalink
Addvalidifcation to the from email in Feedback.pm
Browse files Browse the repository at this point in the history
  Verify the from email address is at least in the form [email protected]
  before sending any email to avoid perl errors if trying to send an
  email from an invalid address.
  • Loading branch information
somiaj authored and drgrice1 committed Feb 14, 2024
1 parent c4ffa56 commit 58b3e05
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/WeBWorK/ContentGenerator/Feedback.pm
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,30 @@ sub initialize ($c) {

# Determine the sender of the email.
my $sender;
if ($user) {
if ($user->email_address) {
$sender = $user->rfc822_mailbox;
} else {
if ($user->full_name) {
$sender = $user->full_name . " <$from>";
} else {
$sender = $from;
}
}
} else {
$sender = $from;
if ($user && $user->email_address) {
$from = $user->email_address;
$sender = $user->rfc822_mailbox;
}

unless ($sender) {
unless ($from) {
$c->stash->{send_error} = $c->maketext('No Sender specified.');
return;
}
unless ($from =~ /^[a-zA-Z0-9.!#$%&\'*+\/=?^_`~\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9.\-]+$/) {
$c->stash->{send_error} = $c->maketext('Sender is not a valid email address.');
return;
}
unless ($feedback) {
$c->stash->{send_error} = $c->maketext('Message was blank.');
return;
}
unless ($sender) {
if ($user && $user->full_name) {
$sender = $user->full_name . " <$from>";
} else {
$sender = $from;
}
}

my %subject_map = (
'c' => $courseID,
Expand Down

0 comments on commit 58b3e05

Please sign in to comment.