";
my $remote_id = $remote->{'userid'};
return " $LJ::SITENAMESHORT, siteroot => $LJ::SITEROOT }) . " p?>"
unless $remote->is_validated;
# $_[1] is a pre-request scratch area
# put variables here so that we can access them later
# outside of this _code block
my $head = \$_[1]->{'head'};
my $body = '';
my $reply_to; # User replying to
my $reply_u; # User replying to
my $disabled_to = 0; # disable To field if sending a reply message
my $msg_subject = ''; # reply subject
my $msg_body = ''; # reply body
my $msg_parent = ''; # Hidden msg field containing id of parent message
my $msg_limit = $remote->count_usermessage_length;
my $subject_limit = 255;
my $force = 0; # flag for if user wants to force an empty PM
my @errors;
push @errors, $ML{'.suspended.cannot.send'} if $remote->is_suspended;
# Submitted message
if (LJ::did_post()) {
my $mode = $POST{'mode'};
push @errors, $ML{'error.invalidform'}
unless LJ::check_form_auth();
if ($mode eq 'send') {
# test encoding
my $msg_subject_text = $POST{'msg_subject'};
push @errors, $ML{'.error.text.encoding.subject'}
unless LJ::text_in($msg_subject_text);
my ( $subject_length_b, $subject_length_c ) = LJ::text_length( $msg_subject_text );
push @errors, BML::ml( ".error.subject.length",
{
subject_length => LJ::commafy( $subject_length_c ),
subject_limit => LJ::commafy( $subject_limit ),
} )
unless $subject_length_c <= $subject_limit;
# test encoding and length
my $msg_body_text = $POST{'msg_body'};
push @errors, $ML{'.error.text.encoding.text'}
unless LJ::text_in($msg_body_text);
my ($msg_len_b, $msg_len_c) = LJ::text_length($msg_body_text);
push @errors, BML::ml( ".error.message.length",
{ msg_length => LJ::commafy( $msg_len_c ),
msg_limit => LJ::commafy( $msg_limit ) } )
unless ($msg_len_c <= $msg_limit);
# checks if the PM is empty (no text)
$force = $POST{'force'};
unless ( $msg_len_c > 0 || $force ) {
push @errors, $ML{'.warning.empty.message'};
$force = 1;
}
# Get list of recipients
my $to_field = $POST{'msg_to'};
$to_field =~ s/\s//g;
# Get recipient list without duplicates
my %to_hash = map { lc($_), 1 } split(",", $to_field);
my @to_list = keys %to_hash;
push @to_list, $remote->username if $POST{'cc_msg'};
my @msg_list;
# persist the default value of the cc_msg option
$remote->cc_msg( $POST{'cc_msg'} ? 1 : 0 );
# must be at least one username
push @errors, $ML{'.error.no.username'} unless ( scalar( @to_list ) > 0 );
# Check each user being sent a message
foreach my $to (@to_list) {
# Check the To field
my $tou = LJ::load_user_or_identity( $to );
unless ($tou) {
push @errors, BML::ml( '.error.invalid.username',
{ to => $to } );
next;
}
# Can only send to other individual users
unless ($tou->is_person || $tou->is_identity || $tou->is_renamed) {
push @errors, BML::ml( 'error.message.individual', { ljuser => $tou->ljuser_display } );
next;
}
# Can't send to unvalidated users
unless ( $tou->is_validated || $remote->has_priv( "siteadmin", "*" ) ) {
push @errors, BML::ml( 'error.message.unvalidated',
{ ljuser => $tou->ljuser_display } );
next;
}
# Will target user accept messages from sender
unless ($tou->can_receive_message($remote)) {
push @errors, BML::ml( 'error.message.canreceive', { ljuser => $tou->ljuser_display } );
next;
}
my $msguserpic;
$msguserpic = $POST{'prop_picture_keyword'} if ( defined $POST{'prop_picture_keyword'} );
push @msg_list, LJ::Message->new({journalid => $remote_id,
otherid => $tou->{userid},
subject => $msg_subject_text,
body => $msg_body_text,
parent_msgid => $POST{'msg_parent'} || undef,
userpic => $msguserpic,
});
}
# Check that the rate limit will not be exceeded
# This is only necessary if there are multiple recipients
if (scalar(@msg_list) > 1) {
my $up;
$up = LJ::Hooks::run_hook('upgrade_message', $remote, 'message');
$up = "
$up" if ($up);
push @errors, BML::ml( ".error.rate.limit", { up => $up } )
unless LJ::Message::ratecheck_multi(userid => $remote_id, msg_list => \@msg_list)
}
# check if any of the messages will throw an error
unless (@errors) {
foreach my $msg (@msg_list) {
$msg->can_send(\@errors);
}
}
# send all the messages and display confirmation
unless (@errors) {
foreach my $msg (@msg_list) {
$msg->send(\@errors);
}
unless (@errors) {
$body .= $ML{'.message.sent'};
$body .= "";
$body .= "
| }; $body .= LJ::Widget::InboxFolderNav->render(); $body .= qq{ | ![]() |
}; $body .= ' |