Attachment: '.$fname.'.'.$ft.'';
+ }
+ }
return %content;
}
@@ -117,6 +143,53 @@ sub unpackmsgid {
return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
}
+
+sub sendemail {
+ my ($to,$subject,$body)=@_;
+ $body=
+ "*** This is an automatic message generated by the LON-CAPA system.\n".
+ "*** Please do not reply to this address.\n\n".$body;
+ my $msg = new Mail::Send;
+ $msg->to($to);
+ $msg->subject('[LON-CAPA] '.$subject);
+ my $fh = $msg->open('smtp',Server => 'localhost');
+ print $fh $body;
+ $fh->close;
+}
+
+# ==================================================== Send notification emails
+
+sub sendnotification {
+ my ($to,$touname,$toudom,$subj,$crit)=@_;
+ my $sender=$ENV{'environment.firstname'}.' '.$ENV{'environment.lastname'};
+ my $critical=($crit?' critical':'');
+ my $url='http://'.
+ $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
+ '/adm/login&username='.$touname.'&domain='.$toudom;
+ my $body=(<300) {
+ my %what=&Apache::lonnet::get('email_status',['recnewemail']);
+ &Apache::lonnet::appenv('user.mailcheck.time'=>time);
+ if ($what{'recnewemail'}>0) { return 1; }
+ }
+ return 0;
+}
+
# =============================== Automated message to the author of a resource
sub author_res_msg {
@@ -139,7 +212,7 @@ sub author_res_msg {
# ================================================== Critical message to a user
-sub user_crit_msg {
+sub user_crit_msg_raw {
my ($user,$domain,$subject,$message,$sendback)=@_;
# Check if allowed missing
my $status='';
@@ -153,9 +226,23 @@ sub user_crit_msg {
'put:'.$domain.':'.$user.':critical:'.
&Apache::lonnet::escape($msgid).'='.
&Apache::lonnet::escape($message),$homeserver);
+ if ($ENV{'request.course.id'}) {
+ &user_normal_msg_raw(
+ $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+ 'Critical ['.$user.':'.$domain.']',
+ $message);
+ }
} else {
$status='no_host';
}
+# Notifications
+ my %userenv = &Apache::lonnet::get('environment',['critnotification'],
+ $domain,$user);
+ if ($userenv{'critnotification'}) {
+ &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1);
+ }
+# Log this
&Apache::lonnet::logthis(
'Sending critical email '.$msgid.
', log status: '.
@@ -166,19 +253,41 @@ sub user_crit_msg {
return $status;
}
+# New routine that respects "forward" and calls old routine
+
+sub user_crit_msg {
+ my ($user,$domain,$subject,$message,$sendback)=@_;
+ my $status='';
+ my %userenv = &Apache::lonnet::get('environment',['msgforward'],
+ $domain,$user);
+ my $msgforward=$userenv{'msgforward'};
+ if ($msgforward) {
+ foreach (split(/\,/,$msgforward)) {
+ my ($forwuser,$forwdomain)=split(/\:/,$_);
+ $status.=
+ &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
+ $sendback).' ';
+ }
+ } else {
+ $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback);
+ }
+ return $status;
+}
+
# =================================================== Critical message received
sub user_crit_received {
my $msgid=shift;
my %message=&Apache::lonnet::get('critical',[$msgid]);
- my %contents=&unpackagemsg($message{$msgid});
+ my %contents=&unpackagemsg($message{$msgid},1);
my $status='rec: '.($contents{'sendback'}?
&user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},
'User '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}.
- ' acknowledged receipt of message "'.
- $contents{'subject'}.'" dated '.$contents{'time'}.".\n\n"
- .'Message ID: '.$contents{'msgid'}):'no msg req');
+ ' acknowledged receipt of message'."\n".' "'.
+ $contents{'subject'}.'"'."\n".'dated '.
+ $contents{'time'}.".\n"
+ ):'no msg req');
$status.=' trans: '.
&Apache::lonnet::put(
'nohist_email',{$contents{'msgid'} => $message{$msgid}});
@@ -193,28 +302,60 @@ sub user_crit_received {
# ======================================================== Normal communication
-sub user_normal_msg {
- my ($user,$domain,$subject,$message,$citation)=@_;
+sub user_normal_msg_raw {
+ my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_;
# Check if allowed missing
my $status='';
my $msgid='undefined';
unless (($message)&&($user)&&($domain)) { $status='empty'; };
my $homeserver=&Apache::lonnet::homeserver($user,$domain);
if ($homeserver ne 'no_host') {
- ($msgid,$message)=&packagemsg($subject,$message,$citation);
+ ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl,
+ $attachmenturl);
$status=&Apache::lonnet::critical(
'put:'.$domain.':'.$user.':nohist_email:'.
&Apache::lonnet::escape($msgid).'='.
&Apache::lonnet::escape($message),$homeserver);
+ &Apache::lonnet::put
+ ('email_status',{'recnewemail'=>time},$domain,$user);
} else {
$status='no_host';
}
+# Notifications
+ my %userenv = &Apache::lonnet::get('environment',['notification'],
+ $domain,$user);
+ if ($userenv{'notification'}) {
+ &sendnotification($userenv{'notification'},$user,$domain,$subject,0);
+ }
&Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
$ENV{'user.home'},
'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
return $status;
}
+# New routine that respects "forward" and calls old routine
+
+sub user_normal_msg {
+ my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_;
+ my $status='';
+ my %userenv = &Apache::lonnet::get('environment',['msgforward'],
+ $domain,$user);
+ my $msgforward=$userenv{'msgforward'};
+ if ($msgforward) {
+ foreach (split(/\,/,$msgforward)) {
+ my ($forwuser,$forwdomain)=split(/\:/,$_);
+ $status.=
+ &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
+ $citation,$baseurl,$attachmenturl).' ';
+ }
+ } else {
+ $status=&user_normal_msg_raw($user,$domain,$subject,$message,
+ $citation,$baseurl,$attachmenturl);
+ }
+ return $status;
+}
+
+
# =============================================================== Status Change
sub statuschange {
@@ -303,21 +444,36 @@ ENDDISHEADER
sub discrit {
my $r=shift;
- $r->print('
Critical Messages
'.
- '');
+ my $header = '
Critical Messages
'.
+ '');
}
# =============================================================== Compose reply
@@ -325,7 +481,7 @@ sub discrit {
sub comprep {
my ($r,$msgid)=@_;
my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
- my %content=&unpackagemsg($message{$msgid});
+ my %content=&unpackagemsg($message{$msgid},1);
my $quotemsg='> '.$content{'message'};
$quotemsg=~s/\r/\n/g;
$quotemsg=~s/\f/\n/g;
@@ -333,16 +489,18 @@ sub comprep {
my $subject='Re: '.$content{'subject'};
my $dispcrit='';
if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
+ my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
$dispcrit=
- ' Send as critical message '.
- ' Send as critical message'.
- ' and return receipt