--- loncom/interface/lonmsg.pm 2002/04/11 20:46:21 1.30 +++ loncom/interface/lonmsg.pm 2002/10/11 20:09:36 1.41 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.30 2002/04/11 20:46:21 matthew Exp $ +# $Id: lonmsg.pm,v 1.41 2002/10/11 20:09:36 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -49,6 +49,8 @@ use Apache::lonnet(); use vars qw($msgcount); use HTML::TokeParser; use Apache::Constants qw(:common); +use Apache::loncommon; +use Apache::lontexconvert; # ===================================================================== Package @@ -117,6 +119,17 @@ sub unpackmsgid { return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid}); } +# ============================================================= Check for email + +sub newmail { + if ((time-$ENV{'user.mailcheck.time'})>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 +152,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=''; @@ -166,6 +179,27 @@ 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 { @@ -193,7 +227,7 @@ sub user_crit_received { # ======================================================== Normal communication -sub user_normal_msg { +sub user_normal_msg_raw { my ($user,$domain,$subject,$message,$citation)=@_; # Check if allowed missing my $status=''; @@ -206,6 +240,8 @@ sub user_normal_msg { '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'; } @@ -215,6 +251,29 @@ sub user_normal_msg { return $status; } +# New routine that respects "forward" and calls old routine + +sub user_normal_msg { + my ($user,$domain,$subject,$message,$citation)=@_; + 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).' '; + } + } else { + $status= + &user_normal_msg_raw($user,$domain,$subject,$message,$citation); + } + return $status; +} + + # =============================================================== Status Change sub statuschange { @@ -312,9 +371,15 @@ sub discrit { my %content=&unpackagemsg($what{$_}); next if ($content{'senderdomain'} eq ''); $content{'message'}=~s/\n/\/g; - $result.='
From: '.$content{'sendername'}.'@'. - $content{'senderdomain'}.' ('.$content{'time'}. - ')
'.$content{'message'}.'
'. + $result.='
From: '. +&Apache::loncommon::aboutmewrapper( + &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('. +$content{'sendername'}.'@'. + $content{'senderdomain'}.') '.$content{'time'}. + '
Subject: '.$content{'subject'}. + '
'. + &Apache::lontexconvert::msgtexconverted($content{'message'}). + '
'. ''. ''; @@ -342,16 +407,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

'; + ' Send as critical message ' . $crithelp . + '
'. + ' Send as critical message ' . + ' and return receipt' . $crithelp . '

'; } $r->print(<<"ENDREPLY");

Subject:

-

$dispcrit @@ -396,24 +463,24 @@ ENDDISHEADER $ENV{'user.home'}))) { my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)= &Apache::lonmsg::unpackmsgid($_); - unless ($status eq 'deleted') { - if ($status eq 'new') { - $r->print(''); - } elsif ($status eq 'read') { - $r->print(''); - } elsif ($status eq 'replied') { - $r->print(''); - } else { - $r->print(''); - } - $r->print('OpenDelete'. - ''.localtime($sendtime).''. - $fromname.''.$fromdomain.''. + if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) { + if ($status eq 'new') { + $r->print(''); + } elsif ($status eq 'read') { + $r->print(''); + } elsif ($status eq 'replied') { + $r->print(''); + } else { + $r->print(''); + } + $r->print('OpenDelete'. + ''.localtime($sendtime).''. + $fromname.''.$fromdomain.''. &Apache::lonnet::unescape($shortsubj).''. $status.''); - } + } } $r->print('

'. 'Check All '. @@ -431,10 +498,12 @@ sub compout { my $dismsg=''; my $func='Send New'; 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

'; + ' Send as critical message ' . $crithelp . + '
'. + ' Send as critical message ' . + ' and return receipt' . $crithelp . '

'; } if ($forwarding) { $dispcrit.=''. - ''); + ''."\n". + ''."\n". + '
'); unless (($broadcast eq 'group') || ($broadcast eq 'upload')) { + my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain'); + $r->print(<<"ENDREC");
- + - + ENDREC } - unless ($broadcast eq 'upload') { + if ($broadcast ne 'upload') { $r->print(<<"ENDCOMP");
Username:
Username:
Domain:
$domform
Additional Recipients
username\@domain,username\@domain, ...
Subject:
-

$dispcrit ENDCOMP - } - if ($broadcast eq 'upload') { + } else { # $broadcast is 'upload' $r->print(<

Generate messages from a file

+

Subject: +

+

General message text
+

+

+The file format for the uploaded portion of the message is:

 username1\@domain1: text
 username2\@domain2: text
-username1\@domain1: text
+username3\@domain1: text
 
+

+

The messages will be assembled from all lines with the respective -username\@domain, and appended to the general message text.

+username\@domain, and appended to the general message text.

+

-General message text:

-

$dispcrit ENDUPLOAD @@ -512,36 +591,28 @@ sub handler { return OK if $r->header_only; # --------------------------- Get query string for limited number of parameters + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['display','replyto','forward','markread','markdel','markunread', + 'sendreply','compose','sendmail','critical','recname','recdom']); - foreach (split(/&/,$ENV{'QUERY_STRING'})) { - my ($name, $value) = split(/=/,$_); - $value =~ tr/+/ /; - $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; - if (($name eq 'display') || ($name eq 'replyto') || - ($name eq 'forward') || ($name eq 'markread') || - ($name eq 'markdel') || ($name eq 'markunread') || - ($name eq 'sendreply') || ($name eq 'compose') || - ($name eq 'sendmail') || ($name eq 'critical')) { - unless ($ENV{'form.'.$name}) { - $ENV{'form.'.$name}=$value; - } - } - } - +# ------------------------------------------------------ They checked for email + &Apache::lonnet::put('email_status',{'recnewemail'=>0}); # --------------------------------------------------------------- Render Output - $r->print('EMail and Messaging'); - $r->print( - ''); - $r->print('

EMail

'); + $r->print('EMail and Messaging'. + &Apache::loncommon::bodytag('EMail and Messages')); if ($ENV{'form.display'}) { my $msgid=$ENV{'form.display'}; &statuschange($msgid,'read'); my %message=&Apache::lonnet::get('nohist_email',[$msgid]); my %content=&unpackagemsg($message{$msgid}); $r->print('Subject: '.$content{'subject'}. - '
From: '.$content{'sendername'}.' at '. - $content{'senderdomain'}. + '
From: '. +&Apache::loncommon::aboutmewrapper( +&Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}), +$content{'sendername'},$content{'senderdomain'}).' ('. + $content{'sendername'}.' at '. + $content{'senderdomain'}.') '. '
Time: '.$content{'time'}.'

'. ''. ''. ''. '
Functions:Mark UnreadDisplay all Messages

'.
-             $content{'message'}.'

'.$content{'citation'}); + &Apache::lontexconvert::msgtexconverted($content{'message'}). + '
'.$content{'citation'}); } elsif ($ENV{'form.replyto'}) { &comprep($r,$ENV{'form.replyto'}); } elsif ($ENV{'form.sendreply'}) {