--- loncom/interface/lonmsgdisplay.pm 2015/06/18 20:19:06 1.182
+++ loncom/interface/lonmsgdisplay.pm 2019/08/12 15:15:56 1.190
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging display
#
-# $Id: lonmsgdisplay.pm,v 1.182 2015/06/18 20:19:06 musolffc Exp $
+# $Id: lonmsgdisplay.pm,v 1.190 2019/08/12 15:15:56 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -102,6 +102,8 @@ use HTML::TokeParser();
use Apache::Constants qw(:common);
use Apache::loncommon();
use Apache::lonhtmlcommon();
+use Apache::longroup;
+use Apache::lonnavmaps;
use Apache::lontexconvert();
use HTML::Entities();
use Apache::lonlocal;
@@ -773,14 +775,24 @@ sub groupmail_header {
text=>"Groups",
title=>$brtitle});
}
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
- text=>"Group: $description",
- title=>"Go to group's home page"},
- {href=>"/adm/email?compose=group&group=".
- "$env{'form.group'}&$refarg",
- text=>"Send a Message in a Group",
- title=>"Compose Group Message"},);
+ my $view_permission =
+ &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
+ my $navmap=Apache::lonnavmaps::navmap->new();
+ my $grouppagelink = &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap,$view_permission,$refarg);
+ if ($grouppagelink) {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>$grouppagelink,
+ text=>"Group: $description",
+ title=>"Go to group's home page"},);
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({text=>"Group: $description",});
+ }
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"/adm/email?compose=group&group=".
+ "$env{'form.group'}&$refarg",
+ text=>"Send a Message in a Group",
+ title=>"Compose Group Message"},);
if ($action eq 'sending') {
&Apache::lonhtmlcommon::add_breadcrumb
({text=>"Messages being sent.",
@@ -1405,9 +1417,9 @@ sub compout {
);
if (!$forwarding && !$multiforward) {
$attachrow = '
'.$lt{'atta'}.' '.$attachmax{'text'}
- .': '
- .'
'
- .'';
+ .': '
+ .''
+ .'';
}
if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
|| &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
@@ -2177,7 +2189,8 @@ sub displaymessage {
my @actionlist;
if ($env{'user.adv'}) {
- if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
+ if (($env{'request.course.id'}) && ($from_student) &&
+ (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
push(@actionlist,&Apache::loncommon::track_student_link(
'View recent activity'
,$content{'sendername'}
@@ -2640,6 +2653,13 @@ sub displayresource {
}
# Could not get a symb, give up
unless ($symb) { return $content{'citation'}; }
+ if ($symb =~ /ext\.tool$/) {
+ return '
'.&mt('Current transactions for student (if applicable)').'
'.
+ &Apache::loncommon::get_previous_attempt($symb,
+ $content{'sendername'},
+ $content{'senderdomain'},
+ $content{'courseid'});
+ }
# Have a symb, can render
return '
'.&mt('Current attempts of student (if applicable)').'
'.
&Apache::loncommon::get_previous_attempt($symb,
@@ -2743,7 +2763,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 {
@@ -2773,6 +2793,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'})) {
@@ -2782,9 +2804,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;
+ }
}
}
}
@@ -2795,22 +2825,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};
+ }
}
}
}
@@ -2820,8 +2875,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};
+ }
}
}
}
@@ -2829,9 +2892,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};
+ }
}
}
}
@@ -2842,9 +2913,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;
+ }
}
}
}
@@ -2855,9 +2934,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;
+ }
}
}
}
@@ -2866,10 +2953,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;
+ }
}
}
}
@@ -2889,42 +2984,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'}) <= 1048576) {
+ $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;
@@ -3062,6 +3157,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:").'
'.
+ join("
\n",sort(keys(%{$disallowed{'to'}}))).
+ '
');
+ }
+ if (ref($disallowed{'cc'}) eq 'HASH') {
+ $r->print(&mt("The following CCs were excluded because the user's domain does not accept messages from server's domain:").'
'.
+ join("
\n",sort(keys(%{$disallowed{'cc'}}))).
+ '
');
+ }
+ if (ref($disallowed{'bcc'}) eq 'HASH') {
+ $r->print(&mt("The following BCCs were excluded because the user's domain does not accept messages from server's domain:").'