Allow bare email addresses as message recipients.
BREAKING CHANGE: requires modification of messages_recipients table: ALTER TABLE `messages_recipients` CHANGE `recipient_id` `recipient_id` INT(10) UNSIGNED NULL DEFAULT NULL COMMENT 'ID of the user sho should get the email'; ALTER TABLE `messages_recipients` ADD `email` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL AFTER `recipient_id`;
This commit is contained in:
parent
f2e5f6884c
commit
917f78d024
@ -588,24 +588,35 @@ sub _queue_message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## @method private $ _add_recipient($messageid, $recipientid)
|
## @method private $ _add_recipient($messageid, $recipient)
|
||||||
# Add a message recipient. This creates a new recipient row, associating the
|
# Add a message recipient. This creates a new recipient row, associating the
|
||||||
# specified recipient userid with a message.
|
# specified recipient with a message.
|
||||||
#
|
#
|
||||||
# @param messageid The ID of the message to add a recipient to.
|
# @param messageid The ID of the message to add a recipient to.
|
||||||
# @param recipientid The ID of the user who should recieve the message.
|
# @param recipient The ID of the user who should recieve the message, or an email
|
||||||
|
# address to use as the recipient.
|
||||||
# @return true on success, undef on error.
|
# @return true on success, undef on error.
|
||||||
sub _add_recipient {
|
sub _add_recipient {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $messageid = shift;
|
my $messageid = shift;
|
||||||
my $recipientid = shift;
|
my $recipient = shift;
|
||||||
|
my ($recipid, $email);
|
||||||
|
|
||||||
$self -> clear_error();
|
$self -> clear_error();
|
||||||
|
|
||||||
|
# int value indicate the recipient is a userid, otherwise check for email
|
||||||
|
if($recipient =~ /^\d+$/) {
|
||||||
|
$recipid = $recipient;
|
||||||
|
} elsif($recipient =~ /^[\w.+-]+\@([\w-]+\.)+\w+$/) {
|
||||||
|
$email = $recipient;
|
||||||
|
} else {
|
||||||
|
return $self -> self_error("Invalid recipient '$recipient' specified for message $messageid");
|
||||||
|
}
|
||||||
|
|
||||||
my $newh = $self -> {"dbh"} -> prepare("INSERT INTO `".$self -> {"settings"} -> {"database"} -> {"message_recipients"}."`
|
my $newh = $self -> {"dbh"} -> prepare("INSERT INTO `".$self -> {"settings"} -> {"database"} -> {"message_recipients"}."`
|
||||||
(message_id, recipient_id)
|
(message_id, recipient_id, email)
|
||||||
VALUES(?, ?)");
|
VALUES(?, ?, ?)");
|
||||||
my $result = $newh -> execute($messageid, $recipientid);
|
my $result = $newh -> execute($messageid, $recipid, $email);
|
||||||
return $self -> self_error("Unable to perform recipient addition: ". $self -> {"dbh"} -> errstr) if(!$result);
|
return $self -> self_error("Unable to perform recipient addition: ". $self -> {"dbh"} -> errstr) if(!$result);
|
||||||
return $self -> self_error("Recipient addition failed, no rows inserted") if($result eq "0E0");
|
return $self -> self_error("Recipient addition failed, no rows inserted") if($result eq "0E0");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user