--- loncom/interface/lonmsgdisplay.pm 2017/03/15 20:58:12 1.184 +++ loncom/interface/lonmsgdisplay.pm 2017/08/07 20:22:13 1.185 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.184 2017/03/15 20:58:12 raeburn Exp $ +# $Id: lonmsgdisplay.pm,v 1.185 2017/08/07 20:22:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2756,7 +2756,7 @@ sub sendoffmail { $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; } if ($env{'form.send'}) { - if (!$env{'form.multiforward'}) { + if (!$env{'form.multiforward'}) { if ($group eq '') { &printheader($r,'','Messages being sent.'); } else { @@ -2786,6 +2786,8 @@ sub sendoffmail { my $mode = $env{'form.sendmode'}; my (%toaddr,$tos,$cc,$bcc,$broadcast); + my (%willtrust,%trustchecked,%disallowed); + my $serverdefdom = &Apache::lonnet::default_login_domain(); if ($mode eq 'group') { if (defined($env{'form.courserecips'})) { @@ -2795,9 +2797,17 @@ sub sendoffmail { foreach my $dest (@to) { my ($user,$domain) = split(/:/, $dest); if (($user ne '') && ($domain ne '')) { - my $rec = $user.":".$domain; - $toaddr{$rec} = ''; - $broadcast->{$rec} = ''; + unless ($trustchecked{$domain}) { + $willtrust{$domain} = &Apache::lonnet::will_trust('msg',$serverdefdom,$domain); + $trustchecked{$domain} = 1; + } + if ($willtrust{$domain}) { + my $rec = $user.":".$domain; + $toaddr{$rec} = ''; + $broadcast->{$rec} = ''; + } else { + $disallowed{'to'}{$user.":".$domain} = 1; + } } } } @@ -2808,22 +2818,47 @@ sub sendoffmail { if ($txt) { $rec =~ s/^\s+//; $rec =~ s/\s+$//; - $toaddr{$rec}.=$txt."\n"; - $broadcast->{$rec} = ''; + my ($recuname,$recudom) = split(/:/,$rec); + unless ($trustchecked{$recudom}) { + $willtrust{$recudom} = &Apache::lonnet::will_trust('msg',$serverdefdom,$recudom); + $trustchecked{$recudom} = 1; + } + if ($willtrust{$recudom}) { + $toaddr{$rec}.=$txt."\n"; + $broadcast->{$rec} = ''; + } else { + $disallowed{'to'}{$rec} = 1; + } } } } else { if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) { - $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}=''; - $tos->{$env{'form.recuname'}.':'.$env{'form.recdomain'}}=''; + unless ($trustchecked{$env{'form.recdomain'}}) { + $willtrust{$env{'form.recdomain'}} = &Apache::lonnet::will_trust('msg',$serverdefdom,$env{'form.recdomain'}); + $trustchecked{$env{'form.recdomain'}} = 1; + } + if ($willtrust{$env{'form.recdomain'}}) { + $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}=''; + $tos->{$env{'form.recuname'}.':'.$env{'form.recdomain'}}=''; + } else { + $disallowed{'to'}{$env{'form.recuname'}.':'.$env{'form.recdomain'}}; + } } } if ($env{'form.additionalrec_to'}) { foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_to'})) { my ($auname,$audom)=split(/:/,$rec); if (($auname ne "") && ($audom ne "")) { - $toaddr{$auname.':'.$audom}=''; - $tos->{$auname.':'.$audom}=''; + unless ($trustchecked{$audom}) { + $willtrust{$audom} = &Apache::lonnet::will_trust('msg',$serverdefdom,$audom); + $trustchecked{$audom} = 1; + } + if ($willtrust{$audom}) { + $toaddr{$auname.':'.$audom}=''; + $tos->{$auname.':'.$audom}=''; + } else { + $disallowed{'to'}{$auname.':'.$audom}; + } } } } @@ -2833,8 +2868,16 @@ sub sendoffmail { foreach my $rec (@toreplies) { my ($auname,$audom)=split(/:/,$rec); if (($auname ne "") && ($audom ne "")) { - $toaddr{$auname.':'.$audom}=''; - $tos->{$auname.':'.$audom}=''; + unless ($trustchecked{$audom}) { + $willtrust{$audom} = &Apache::lonnet::will_trust('msg',$serverdefdom,$audom); + $trustchecked{$audom} = 1; + } + if ($willtrust{$audom}) { + $toaddr{$auname.':'.$audom}=''; + $tos->{$auname.':'.$audom}=''; + } else { + $disallowed{'to'}{$auname.':'.$audom}; + } } } } @@ -2842,9 +2885,17 @@ sub sendoffmail { foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_cc'})) { my ($auname,$audom)=split(/:/,$rec); if (($auname ne "") && ($audom ne "")) { - $toaddr{$auname.':'.$audom}=''; if (!defined($tos->{$auname.':'.$audom})) { - $cc->{$auname.':'.$audom}=''; + unless ($trustchecked{$audom}) { + $willtrust{$audom} = &Apache::lonnet::will_trust('msg',$serverdefdom,$audom); + $trustchecked{$audom} = 1; + } + if ($willtrust{$audom}) { + $toaddr{$auname.':'.$audom}=''; + $cc->{$auname.':'.$audom}=''; + } else { + $disallowed{'cc'}{$auname.':'.$audom}; + } } } } @@ -2855,9 +2906,17 @@ sub sendoffmail { foreach my $rec (@ccreplies) { my ($auname,$audom)=split(/:/,$rec); if (($auname ne "") && ($audom ne "")) { - $toaddr{$auname.':'.$audom}=''; if (!defined($tos->{$auname.':'.$audom})) { - $cc->{$auname.':'.$audom}=''; + unless ($trustchecked{$audom}) { + $willtrust{$audom} = &Apache::lonnet::will_trust('msg',$serverdefdom,$audom); + $trustchecked{$audom} = 1; + } + if ($willtrust{$audom}) { + $toaddr{$auname.':'.$audom}=''; + $cc->{$auname.':'.$audom}=''; + } else { + $disallowed{'cc'}{$auname.':'.$audom} = 1; + } } } } @@ -2868,9 +2927,17 @@ sub sendoffmail { foreach my $rec (@groupreplies) { my ($auname,$audom)=split(/:/,$rec); if (($auname ne "") && ($audom ne "")) { - $toaddr{$auname.':'.$audom}=''; if (!defined($tos->{$auname.':'.$audom})) { - $broadcast->{$auname.':'.$audom}=''; + unless ($trustchecked{$audom}) { + $willtrust{$audom} = &Apache::lonnet::will_trust('msg',$serverdefdom,$audom); + $trustchecked{$audom} = 1; + } + if ($willtrust{$audom}) { + $toaddr{$auname.':'.$audom}=''; + $broadcast->{$auname.':'.$audom}=''; + } else { + $disallowed{'to'}{$auname.':'.$audom} = 1; + } } } } @@ -2879,10 +2946,18 @@ sub sendoffmail { foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_bcc'})) { my ($auname,$audom)=split(/:/,$rec); if (($auname ne "") && ($audom ne "")) { - $toaddr{$auname.':'.$audom}=''; - if ((!defined($tos->{$auname.':'.$audom})) && + if ((!defined($tos->{$auname.':'.$audom})) && (!defined($cc->{$auname.':'.$audom}))) { - $bcc->{$auname.':'.$audom}=''; + unless ($trustchecked{$audom}) { + $willtrust{$audom} = &Apache::lonnet::will_trust('msg',$serverdefdom,$audom); + $trustchecked{$audom} = 1; + } + if ($willtrust{$audom}) { + $toaddr{$auname.':'.$audom}=''; + $bcc->{$auname.':'.$audom}=''; + } else { + $disallowed{'bcc'}{$auname.':'.$audom} = 1; + } } } } @@ -2902,42 +2977,42 @@ sub sendoffmail { } else { $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'}); } - my %reciphash = ( - to => $tos, - cc => $cc, - bcc => $bcc, - ); - if ($mode eq 'group') { - if ($group eq '') { - $reciphash{'course_broadcast'} = $broadcast; - } else { - if ($env{'form.groupmail'} eq 'cc') { - $reciphash{'group_cc_broadcast'} = $broadcast; + my ($recipid, @recusers, @recudoms, %permresults); + if (keys(%toaddr) > 0) { + my %reciphash = ( + to => $tos, + cc => $cc, + bcc => $bcc, + ); + if ($mode eq 'group') { + if ($group eq '') { + $reciphash{'course_broadcast'} = $broadcast; } else { - $reciphash{'group_bcc_broadcast'} = $broadcast; + if ($env{'form.groupmail'} eq 'cc') { + $reciphash{'group_cc_broadcast'} = $broadcast; + } else { + $reciphash{'group_bcc_broadcast'} = $broadcast; + } } } - } - my ($recipid,$recipstatus) = - &Apache::lonmsg::store_recipients($msgsubj,$env{'user.name'}, - $env{'user.domain'},\%reciphash); - if ($recipstatus ne 'ok') { - &Apache::lonnet::logthis('Failed to store To, Bcc and Cc recipients for '.$env{'user.name'}.':'.$env{'user.domain'}); - } - if ($env{'form.attachment'}) { - if (length($env{'form.attachment'})<131072) { - $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback/'.$now); - } else { - $r->print('

'.&mt('Attachment not included - exceeded permitted length').'

'); - } - } elsif ($env{'form.multiforward'}) { - if ($env{'form.attachmenturl'} ne '') { - $attachmenturl = $env{'form.attachmenturl'}; + ($recipid,my $recipstatus) = + &Apache::lonmsg::store_recipients($msgsubj,$env{'user.name'}, + $env{'user.domain'},\%reciphash); + if ($recipstatus ne 'ok') { + &Apache::lonnet::logthis('Failed to store To, Bcc and Cc recipients for '.$env{'user.name'}.':'.$env{'user.domain'}); + } + if ($env{'form.attachment'}) { + if (length($env{'form.attachment'})<131072) { + $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback/'.$now); + } else { + $r->print('

'.&mt('Attachment not included - exceeded permitted length').'

'); + } + } elsif ($env{'form.multiforward'}) { + if ($env{'form.attachmenturl'} ne '') { + $attachmenturl = $env{'form.attachmenturl'}; + } } } - my @recusers; - my @recudoms; - my %permresults; foreach my $address (sort(keys(%toaddr))) { my ($recuname,$recdomain)=split(/\:/,$address); my $msgtxt = $savemsg; @@ -3075,6 +3150,23 @@ sub sendoffmail { $r->print($message); } } + if (keys(%disallowed)) { + if ((ref($disallowed{'to'}) eq 'HASH') && (keys(%{$disallowed{'to'}}) > 0)) { + $r->print(&mt("The following recipients were excluded because the user's domain does not accept messages from server's domain:").'