version 1.180, 2006/04/08 06:53:37
|
version 1.186, 2006/11/01 22:22:31
|
Line 33 use Apache::lonnet;
|
Line 33 use Apache::lonnet;
|
use HTML::TokeParser(); |
use HTML::TokeParser(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
use Mail::Send; |
use Mail::Send; |
|
use lib '/home/httpd/lib/perl/'; |
|
use LONCAPA; |
|
|
{ |
{ |
my $uniq; |
my $uniq; |
Line 59 sub packagemsg {
|
Line 61 sub packagemsg {
|
my $course_context; |
my $course_context; |
if (defined($env{'form.replyid'})) { |
if (defined($env{'form.replyid'})) { |
my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)= |
my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)= |
split(/\:/,&Apache::lonnet::unescape($env{'form.replyid'})); |
split(/\:/,&unescape($env{'form.replyid'})); |
$course_context = $origcid; |
$course_context = $origcid; |
} |
} |
foreach my $key (keys(%env)) { |
foreach my $key (keys(%env)) { |
if ($key=~/^form\.(rep)?rec\_(.*)$/) { |
if ($key=~/^form\.(rep)?rec\_(.*)$/) { |
my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) = |
my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) = |
split(/\:/,&Apache::lonnet::unescape($2)); |
split(/\:/,&unescape($2)); |
$course_context = $origcid; |
$course_context = $origcid; |
last; |
last; |
} |
} |
Line 108 sub packagemsg {
|
Line 110 sub packagemsg {
|
for (my $i=0; $i<@{$recuser}; $i++) { |
for (my $i=0; $i<@{$recuser}; $i++) { |
if ($type eq 'dcmail') { |
if ($type eq 'dcmail') { |
my ($username,$email) = split(/:/,$$recuser[$i]); |
my ($username,$email) = split(/:/,$$recuser[$i]); |
$username = &Apache::lonnet::unescape($username); |
$username = &unescape($username); |
$email = &Apache::lonnet::unescape($email); |
$email = &unescape($email); |
$username = &HTML::Entities::encode($username,'<>&"'); |
$username = &HTML::Entities::encode($username,'<>&"'); |
$email = &HTML::Entities::encode($email,'<>&"'); |
$email = &HTML::Entities::encode($email,'<>&"'); |
$result .= '<recipient username="'.$username.'">'. |
$result .= '<recipient username="'.$username.'">'. |
Line 178 sub unpackagemsg {
|
Line 180 sub unpackagemsg {
|
|
|
sub buildmsgid { |
sub buildmsgid { |
my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_; |
my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_; |
$subject=&Apache::lonnet::escape($subject); |
$subject=&escape($subject); |
return(&Apache::lonnet::escape($now.':'.$subject.':'.$uname.':'. |
return(&escape($now.':'.$subject.':'.$uname.':'. |
$udom.':'.$msgcount.':'.$course_context.':'.$pid)); |
$udom.':'.$msgcount.':'.$course_context.':'.$pid)); |
} |
} |
|
|
sub unpackmsgid { |
sub unpackmsgid { |
my ($msgid,$folder,$skipstatus,$status_cache)=@_; |
my ($msgid,$folder,$skipstatus,$status_cache)=@_; |
$msgid=&Apache::lonnet::unescape($msgid); |
$msgid=&unescape($msgid); |
my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid, |
my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid, |
$processid)=split(/\:/,&Apache::lonnet::unescape($msgid)); |
$processid)=split(/\:/,&unescape($msgid)); |
|
$shortsubj = &unescape($shortsubj); |
|
$shortsubj = &HTML::Entities::decode($shortsubj); |
if (!defined($processid)) { $fromcid = ''; } |
if (!defined($processid)) { $fromcid = ''; } |
my %status=(); |
my %status=(); |
unless ($skipstatus) { |
unless ($skipstatus) { |
Line 206 sub unpackmsgid {
|
Line 210 sub unpackmsgid {
|
|
|
sub sendemail { |
sub sendemail { |
my ($to,$subject,$body)=@_; |
my ($to,$subject,$body)=@_; |
|
my %senderemails=&Apache::loncommon::getemails(); |
|
my $senderaddress=''; |
|
foreach my $type ('notification','permanentemail','critnotification') { |
|
if ($senderemails{$type}) { |
|
$senderaddress=$senderemails{$type}; |
|
} |
|
} |
$body= |
$body= |
"*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n". |
"*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n". |
"*** ".&mt('Please do not reply to this address.')."\n\n".$body; |
"*** ".($senderaddress?&mt('You can reply to this message'):&mt('Please do not reply to this address.')."\n*** ". |
|
&mt('A reply will not be received by the recipient!'))."\n\n".$body; |
my $msg = new Mail::Send; |
my $msg = new Mail::Send; |
$msg->to($to); |
$msg->to($to); |
$msg->subject('[LON-CAPA] '.$subject); |
$msg->subject('[LON-CAPA] '.$subject); |
|
if ($senderaddress) { $msg->add('Reply-to',$senderaddress); } |
if (my $fh = $msg->open()) { |
if (my $fh = $msg->open()) { |
print $fh $body; |
print $fh $body; |
$fh->close; |
$fh->close; |
Line 278 sub author_res_msg {
|
Line 291 sub author_res_msg {
|
my $homeserver=&Apache::lonnet::homeserver($author,$domain); |
my $homeserver=&Apache::lonnet::homeserver($author,$domain); |
if ($homeserver ne 'no_host') { |
if ($homeserver ne 'no_host') { |
my $id=unpack("%32C*",$message); |
my $id=unpack("%32C*",$message); |
|
$message .= " <p>This error occurred on machine ". |
|
$Apache::lonnet::perlvar{'lonHostID'}."</p>"; |
my $msgid; |
my $msgid; |
($msgid,$message)=&packagemsg($filename,$message); |
($msgid,$message)=&packagemsg($filename,$message); |
return &Apache::lonnet::reply('put:'.$domain.':'.$author. |
return &Apache::lonnet::reply('put:'.$domain.':'.$author. |
':nohist_res_msgs:'. |
':nohist_res_msgs:'. |
&Apache::lonnet::escape($filename.'_'.$id).'='. |
&escape($filename.'_'.$id).'='. |
&Apache::lonnet::escape($message),$homeserver); |
&escape($message),$homeserver); |
} |
} |
return 'no_host'; |
return 'no_host'; |
} |
} |
Line 348 sub all_url_author_res_msg {
|
Line 363 sub all_url_author_res_msg {
|
return %returnhash; |
return %returnhash; |
} |
} |
|
|
|
# ====================================== Add a comment to the User Notes screen |
|
|
|
sub store_instructor_comment { |
|
my ($msg,$uname,$udom) = @_; |
|
my $cid = $env{'request.course.id'}; |
|
my $cnum = $env{'course.'.$cid.'.num'}; |
|
my $cdom = $env{'course.'.$cid.'.domain'}; |
|
my $subject= &mt('Record').' ['.$uname.':'.$udom.']'; |
|
my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg); |
|
return $result; |
|
} |
|
|
# ================================================== Critical message to a user |
# ================================================== Critical message to a user |
|
|
sub user_crit_msg_raw { |
sub user_crit_msg_raw { |
Line 363 sub user_crit_msg_raw {
|
Line 390 sub user_crit_msg_raw {
|
if ($sendback) { $message.='<sendback>true</sendback>'; } |
if ($sendback) { $message.='<sendback>true</sendback>'; } |
$status=&Apache::lonnet::critical( |
$status=&Apache::lonnet::critical( |
'put:'.$domain.':'.$user.':critical:'. |
'put:'.$domain.':'.$user.':critical:'. |
&Apache::lonnet::escape($msgid).'='. |
&escape($msgid).'='. |
&Apache::lonnet::escape($message),$homeserver); |
&escape($message),$homeserver); |
if (defined($sentmessage)) { |
if (defined($sentmessage)) { |
$$sentmessage = $message; |
$$sentmessage = $message; |
} |
} |
Line 372 sub user_crit_msg_raw {
|
Line 399 sub user_crit_msg_raw {
|
$status='no_host'; |
$status='no_host'; |
} |
} |
# Notifications |
# Notifications |
my %userenv = &Apache::lonnet::get('environment',['critnotification', |
my %userenv = &Apache::loncommon::getemails($user,$domain); |
'permanentemail'], |
|
$domain,$user); |
|
if ($userenv{'critnotification'}) { |
if ($userenv{'critnotification'}) { |
&sendnotification($userenv{'critnotification'},$user,$domain,$subject,1, |
&sendnotification($userenv{'critnotification'},$user,$domain,$subject,1, |
$text); |
$text); |
Line 402 sub user_crit_msg_raw {
|
Line 427 sub user_crit_msg_raw {
|
a critical message $message to the $user at $domain. If $sendback is true, |
a critical message $message to the $user at $domain. If $sendback is true, |
a reciept will be sent to the current user when $user recieves the message. |
a reciept will be sent to the current user when $user recieves the message. |
|
|
|
Additionally it will check if the user has a Forwarding address |
|
set, and send the message to that address instead |
|
|
|
returns |
|
- in array context a list of results for each message that was sent |
|
- in scalar context a space seperated list of results for each |
|
message sent |
|
|
=cut |
=cut |
|
|
sub user_crit_msg { |
sub user_crit_msg { |
my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_; |
my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_; |
my $status=''; |
my @status; |
my %userenv = &Apache::lonnet::get('environment',['msgforward'], |
my %userenv = &Apache::lonnet::get('environment',['msgforward'], |
$domain,$user); |
$domain,$user); |
my $msgforward=$userenv{'msgforward'}; |
my $msgforward=$userenv{'msgforward'}; |
if ($msgforward) { |
if ($msgforward) { |
foreach (split(/\,/,$msgforward)) { |
foreach my $addr (split(/\,/,$msgforward)) { |
my ($forwuser,$forwdomain)=split(/\:/,$_); |
my ($forwuser,$forwdomain)=split(/\:/,$addr); |
$status.= |
push(@status, |
&user_crit_msg_raw($forwuser,$forwdomain,$subject,$message, |
&user_crit_msg_raw($forwuser,$forwdomain,$subject,$message, |
$sendback,$toperm,$sentmessage).' '; |
$sendback,$toperm,$sentmessage)); |
} |
} |
} else { |
} else { |
$status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage); |
push(@status, |
|
&user_crit_msg_raw($user,$domain,$subject,$message,$sendback, |
|
$toperm,$sentmessage)); |
} |
} |
return $status; |
if (wantarray) { |
|
return @status; |
|
} |
|
return join(' ',@status); |
} |
} |
|
|
# =================================================== Critical message received |
# =================================================== Critical message received |
Line 469 sub user_normal_msg_raw {
|
Line 507 sub user_normal_msg_raw {
|
# Store in user folder |
# Store in user folder |
$status=&Apache::lonnet::critical( |
$status=&Apache::lonnet::critical( |
'put:'.$domain.':'.$user.':nohist_email:'. |
'put:'.$domain.':'.$user.':nohist_email:'. |
&Apache::lonnet::escape($msgid).'='. |
&escape($msgid).'='. |
&Apache::lonnet::escape($packed_message),$homeserver); |
&escape($packed_message),$homeserver); |
# Save new message received time |
# Save new message received time |
&Apache::lonnet::put |
&Apache::lonnet::put |
('email_status',{'recnewemail'=>time},$domain,$user); |
('email_status',{'recnewemail'=>time},$domain,$user); |
Line 554 sub store_sent_mail {
|
Line 592 sub store_sent_mail {
|
my $status =' '.&Apache::lonnet::critical( |
my $status =' '.&Apache::lonnet::critical( |
'put:'.$env{'user.domain'}.':'.$env{'user.name'}. |
'put:'.$env{'user.domain'}.':'.$env{'user.name'}. |
':nohist_email_sent:'. |
':nohist_email_sent:'. |
&Apache::lonnet::escape($msgid).'='. |
&escape($msgid).'='. |
&Apache::lonnet::escape($message),$env{'user.home'}); |
&escape($message),$env{'user.home'}); |
return $status; |
return $status; |
} |
} |
|
|
Line 564 sub store_sent_mail {
|
Line 602 sub store_sent_mail {
|
sub foldersuffix { |
sub foldersuffix { |
my $folder=shift; |
my $folder=shift; |
unless ($folder) { return ''; } |
unless ($folder) { return ''; } |
return '_'.&Apache::lonnet::escape($folder); |
return '_'.&escape($folder); |
} |
} |
|
|
1; |
1; |