version 1.190, 2006/12/13 01:45:15
|
version 1.195, 2006/12/28 19:43:24
|
Line 47 use LONCAPA qw(:DEFAULT :match);
|
Line 47 use LONCAPA qw(:DEFAULT :match);
|
|
|
sub packagemsg { |
sub packagemsg { |
my ($subject,$message,$citation,$baseurl,$attachmenturl, |
my ($subject,$message,$citation,$baseurl,$attachmenturl, |
$recuser,$recdomain,$msgid,$type,$crsmsgid)=@_; |
$recuser,$recdomain,$msgid,$type,$crsmsgid,$symb,$error)=@_; |
$message =&HTML::Entities::encode($message,'<>&"'); |
$message =&HTML::Entities::encode($message,'<>&"'); |
$citation=&HTML::Entities::encode($citation,'<>&"'); |
$citation=&HTML::Entities::encode($citation,'<>&"'); |
$subject =&HTML::Entities::encode($subject,'<>&"'); |
$subject =&HTML::Entities::encode($subject,'<>&"'); |
Line 78 sub packagemsg {
|
Line 78 sub packagemsg {
|
my $msgcount = &get_uniq(); |
my $msgcount = &get_uniq(); |
unless(defined($msgid)) { |
unless(defined($msgid)) { |
$msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'}, |
$msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'}, |
$msgcount,$course_context,$$); |
$msgcount,$course_context,$symb,$error,$$); |
} |
} |
my $result = '<sendername>'.$env{'user.name'}.'</sendername>'. |
my $result = '<sendername>'.$env{'user.name'}.'</sendername>'. |
'<senderdomain>'.$env{'user.domain'}.'</senderdomain>'. |
'<senderdomain>'.$env{'user.domain'}.'</senderdomain>'. |
Line 134 sub packagemsg {
|
Line 134 sub packagemsg {
|
if (defined($attachmenturl)) { |
if (defined($attachmenturl)) { |
$result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>'; |
$result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>'; |
} |
} |
return $msgid,$result; |
if (defined($symb)) { |
|
$result.= '<symb>'.$symb.'</symb>'; |
|
if (defined($course_context)) { |
|
if ($course_context eq $env{'request.course.id'}) { |
|
my $resource_title = &Apache::lonnet::gettitle($symb); |
|
if (defined($resource_title)) { |
|
$result .= '<resource_title>'.$resource_title.'</resource_title>'; |
|
} |
|
} |
|
} |
|
} |
|
return ($msgid,$result); |
} |
} |
|
|
# ================================================== Unpack message into a hash |
# ================================================== Unpack message into a hash |
Line 178 sub unpackagemsg {
|
Line 189 sub unpackagemsg {
|
# ======================================================= Get info out of msgid |
# ======================================================= Get info out of msgid |
|
|
sub buildmsgid { |
sub buildmsgid { |
my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_; |
my ($now,$subject,$uname,$udom,$msgcount,$course_context,$symb,$error,$pid) = @_; |
$subject=&escape($subject); |
$subject=&escape($subject); |
|
$symb = &escape($symb); |
return(&escape($now.':'.$subject.':'.$uname.':'. |
return(&escape($now.':'.$subject.':'.$uname.':'. |
$udom.':'.$msgcount.':'.$course_context.':'.$pid)); |
$udom.':'.$msgcount.':'.$course_context.':'.$pid.':'.$symb.':'.$error)); |
} |
} |
|
|
sub unpackmsgid { |
sub unpackmsgid { |
my ($msgid,$folder,$skipstatus,$status_cache)=@_; |
my ($msgid,$folder,$skipstatus,$status_cache)=@_; |
$msgid=&unescape($msgid); |
$msgid=&unescape($msgid); |
my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid, |
my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid, |
$processid)=split(/\:/,&unescape($msgid)); |
$processid,$symb,$error) = split(/\:/,&unescape($msgid)); |
$shortsubj = &unescape($shortsubj); |
$shortsubj = &unescape($shortsubj); |
$shortsubj = &HTML::Entities::decode($shortsubj); |
$shortsubj = &HTML::Entities::decode($shortsubj); |
|
$symb = &unescape($symb); |
if (!defined($processid)) { $fromcid = ''; } |
if (!defined($processid)) { $fromcid = ''; } |
my %status=(); |
my %status=(); |
unless ($skipstatus) { |
unless ($skipstatus) { |
Line 203 sub unpackmsgid {
|
Line 216 sub unpackmsgid {
|
if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; } |
if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; } |
unless ($status{$msgid}) { $status{$msgid}='new'; } |
unless ($status{$msgid}) { $status{$msgid}='new'; } |
} |
} |
return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid); |
return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid,$symb,$error); |
} |
} |
|
|
|
|
Line 233 sub sendemail {
|
Line 246 sub sendemail {
|
# ==================================================== Send notification emails |
# ==================================================== Send notification emails |
|
|
sub sendnotification { |
sub sendnotification { |
my ($to,$touname,$toudom,$subj,$crit,$text)=@_; |
my ($to,$touname,$toudom,$subj,$crit,$text,$msgid)=@_; |
my $sender=$env{'environment.firstname'}.' '.$env{'environment.lastname'}; |
my $sender=$env{'environment.firstname'}.' '.$env{'environment.lastname'}; |
unless ($sender=~/\w/) { |
unless ($sender=~/\w/) { |
$sender=$env{'user.name'}.'@'.$env{'user.domain'}; |
$sender=$env{'user.name'}.'@'.$env{'user.domain'}; |
Line 245 sub sendnotification {
|
Line 258 sub sendnotification {
|
my $url='http://'. |
my $url='http://'. |
$Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}. |
$Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}. |
'/adm/email?username='.$touname.'&domain='.$toudom; |
'/adm/email?username='.$touname.'&domain='.$toudom; |
my $body=(<<ENDMSG); |
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid, |
You received a$critical message from $sender in LON-CAPA. The subject is |
$symb,$error) = &Apache::lonmsg::unpackmsgid($msgid); |
|
my $coursetext; |
|
if ($fromcid ne '') { |
|
$coursetext = "\n".&mt('Course').': '; |
|
if ($env{'course.'.$fromcid.'.description'} ne '') { |
|
$coursetext .= $env{'course.'.$fromcid.'.description'}; |
|
} else { |
|
my %coursehash = &Apache::lonnet::coursedescription($fromcid,); |
|
if ($coursehash{'description'} ne '') { |
|
$coursetext .= $coursehash{'description'}; |
|
} |
|
} |
|
$coursetext .= "\n\n"; |
|
} |
|
my $body = $coursetext. |
|
&mt('You received a'.$critical.' message from [_1] in LON-CAPA.',$sender).' '.&mt('The subject is |
|
|
$subj |
[_1] |
|
|
=== Excerpt ============================================================ |
',$subj)."\n". |
|
'=== '.&mt('Excerpt')." ============================================================ |
$text |
$text |
======================================================================== |
======================================================================== |
|
|
Use |
".&mt('Use |
|
|
$url |
[_1] |
|
|
to access the full message. |
to access the full message.',$url); |
ENDMSG |
|
&sendemail($to,'New'.$critical.' message from '.$sender,$body); |
&sendemail($to,'New'.$critical.' message from '.$sender,$body); |
} |
} |
# ============================================================= Check for email |
# ============================================================= Check for email |
Line 394 sub user_crit_msg_raw {
|
Line 422 sub user_crit_msg_raw {
|
if (defined($sentmessage)) { |
if (defined($sentmessage)) { |
$$sentmessage = $packed_message; |
$$sentmessage = $packed_message; |
} |
} |
(undef,my $packed_message_no_citation) = |
if ($env{'request.course.id'} eq '') { |
|
(undef,my $packed_message_no_citation) = |
&packagemsg($subject,$message,undef,undef,undef,$user,$domain, |
&packagemsg($subject,$message,undef,undef,undef,$user,$domain, |
$msgid); |
$msgid); |
$status .= &store_sent_mail($msgid,$packed_message_no_citation); |
if ($status eq 'ok' || $status eq 'con_delayed') { |
|
&store_sent_mail($msgid,$packed_message_no_citation); |
|
} |
|
} |
} else { |
} else { |
$status='no_host'; |
$status='no_host'; |
} |
} |
Line 406 sub user_crit_msg_raw {
|
Line 438 sub user_crit_msg_raw {
|
my %userenv = &Apache::loncommon::getemails($user,$domain); |
my %userenv = &Apache::loncommon::getemails($user,$domain); |
if ($userenv{'critnotification'}) { |
if ($userenv{'critnotification'}) { |
&sendnotification($userenv{'critnotification'},$user,$domain,$subject,1, |
&sendnotification($userenv{'critnotification'},$user,$domain,$subject,1, |
$text); |
$text,$msgid); |
} |
} |
if ($toperm && $userenv{'permanentemail'}) { |
if ($toperm && $userenv{'permanentemail'}) { |
&sendnotification($userenv{'permanentemail'},$user,$domain,$subject,1, |
&sendnotification($userenv{'permanentemail'},$user,$domain,$subject,1, |
$text); |
$text,$msgid); |
} |
} |
# Log this |
# Log this |
&Apache::lonnet::logthis( |
&Apache::lonnet::logthis( |
Line 495 sub user_crit_received {
|
Line 527 sub user_crit_received {
|
|
|
sub user_normal_msg_raw { |
sub user_normal_msg_raw { |
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl, |
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl, |
$toperm,$currid,$newid,$sentmessage,$crsmsgid)=@_; |
$toperm,$currid,$newid,$sentmessage,$crsmsgid,$symb,$restitle, |
|
$error)=@_; |
# Check if allowed missing |
# Check if allowed missing |
my ($status,$packed_message); |
my ($status,$packed_message); |
my $msgid='undefined'; |
my $msgid='undefined'; |
Line 506 sub user_normal_msg_raw {
|
Line 539 sub user_normal_msg_raw {
|
($msgid,$packed_message)= |
($msgid,$packed_message)= |
&packagemsg($subject,$message,$citation,$baseurl, |
&packagemsg($subject,$message,$citation,$baseurl, |
$attachmenturl,$user,$domain,$currid, |
$attachmenturl,$user,$domain,$currid, |
undef,$crsmsgid); |
undef,$crsmsgid,$symb,$error); |
|
|
# Store in user folder |
# Store in user folder |
$status=&Apache::lonnet::critical( |
$status=&Apache::lonnet::critical( |
Line 525 sub user_normal_msg_raw {
|
Line 558 sub user_normal_msg_raw {
|
'/'.$env{'request.course.sec'})))) { |
'/'.$env{'request.course.sec'})))) { |
(undef,my $packed_message_no_citation) = |
(undef,my $packed_message_no_citation) = |
&packagemsg($subject,$message,undef,$baseurl,$attachmenturl, |
&packagemsg($subject,$message,undef,$baseurl,$attachmenturl, |
$user,$domain,$currid,undef,$crsmsgid); |
$user,$domain,$currid,undef,$crsmsgid,$symb,$error); |
$status .= &store_sent_mail($msgid,$packed_message_no_citation); |
if ($status eq 'ok' || $status eq 'con_delayed') { |
|
&store_sent_mail($msgid,$packed_message_no_citation); |
|
} |
} |
} |
} else { |
} else { |
$status='no_host'; |
$status='no_host'; |
Line 544 sub user_normal_msg_raw {
|
Line 579 sub user_normal_msg_raw {
|
$domain,$user); |
$domain,$user); |
if ($userenv{'notification'}) { |
if ($userenv{'notification'}) { |
&sendnotification($userenv{'notification'},$user,$domain,$subject,0, |
&sendnotification($userenv{'notification'},$user,$domain,$subject,0, |
$text); |
$text,$msgid); |
} |
} |
if ($toperm && $userenv{'permanentemail'}) { |
if ($toperm && $userenv{'permanentemail'}) { |
&sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0, |
&sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0, |
$text); |
$text,$msgid); |
} |
} |
&Apache::lonnet::log($env{'user.domain'},$env{'user.name'}, |
&Apache::lonnet::log($env{'user.domain'},$env{'user.name'}, |
$env{'user.home'}, |
$env{'user.home'}, |
Line 560 sub user_normal_msg_raw {
|
Line 595 sub user_normal_msg_raw {
|
|
|
=pod |
=pod |
|
|
=item * B<user_normal_msg($user, $domain, $subject, $message, |
=item * B<user_normal_msg($user, $domain, $subject, $message, $citation, |
$citation, $baseurl, $attachmenturl)>: Sends a message to the |
$baseurl, $attachmenturl, $toperm, $sentmessage, $symb, $restitle, $error)>: |
$user at $domain, with subject $subject and message $message. |
Sends a message to the $user at $domain, with subject $subject and message $message. |
|
|
=cut |
=cut |
|
|
sub user_normal_msg { |
sub user_normal_msg { |
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl, |
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl, |
$toperm,$sentmessage)=@_; |
$toperm,$sentmessage,$symb,$restitle,$error)=@_; |
my $status=''; |
my $status=''; |
my %userenv = &Apache::lonnet::get('environment',['msgforward'], |
my %userenv = &Apache::lonnet::get('environment',['msgforward'], |
$domain,$user); |
$domain,$user); |
Line 579 sub user_normal_msg {
|
Line 614 sub user_normal_msg {
|
$status.= |
$status.= |
&user_normal_msg_raw($forwuser,$forwdomain,$subject,$message, |
&user_normal_msg_raw($forwuser,$forwdomain,$subject,$message, |
$citation,$baseurl,$attachmenturl,$toperm, |
$citation,$baseurl,$attachmenturl,$toperm, |
undef,undef,$sentmessage).' '; |
undef,undef,$sentmessage,undef,$symb,$restitle,$error).' '; |
} |
} |
} else { |
} else { |
$status=&user_normal_msg_raw($user,$domain,$subject,$message, |
$status=&user_normal_msg_raw($user,$domain,$subject,$message, |
$citation,$baseurl,$attachmenturl,$toperm, |
$citation,$baseurl,$attachmenturl,$toperm, |
undef,undef,$sentmessage); |
undef,undef,$sentmessage,undef,$symb,$restitle,$error); |
} |
} |
return $status; |
return $status; |
} |
} |