--- loncom/interface/lonmsg.pm 2007/05/02 20:26:08 1.203 +++ loncom/interface/lonmsg.pm 2007/05/09 21:04:51 1.207 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.203 2007/05/02 20:26:08 albertel Exp $ +# $Id: lonmsg.pm,v 1.207 2007/05/09 21:04:51 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -163,6 +163,17 @@ sub packagemsg { if (defined($recipid)) { $result.= ''.$recipid.''; } + if ($env{'form.can_reply'} eq 'N') { + $result .= '1'; + } + if ($env{'form.reply_to_addr'}) { + my ($replytoname,$replytodom) = split(/:/,$env{'form.reply_to_addr'}); + if (!($replytoname eq $env{'user.name'} && $replytodom eq $env{'user.domain'})) { + if (&Apache::lonnet::homeserver($replytoname,$replytodom) ne 'no_host') { + $result .= ''.$env{'form.reply_to_addr'}.''; + } + } + } return ($msgid,$result); } @@ -293,13 +304,12 @@ sub sendnotification { my $critical=($crit?' critical':''); $text=~s/\<\;/\/gs; - $text=~s/\<\/*[^\>]+\>//gs; my $url='http://'. &Apache::lonnet::hostname(&Apache::lonnet::homeserver($touname,$toudom)). '/adm/email?username='.$touname.'&domain='.$toudom; my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid, $symb,$error) = &Apache::lonmsg::unpackmsgid($msgid); - my $coursetext; + my ($coursetext,$body,$bodystart,$bodyend); if ($fromcid ne '') { $coursetext = "\n".&mt('Course').': '; if ($env{'course.'.$fromcid.'.description'} ne '') { @@ -312,14 +322,16 @@ sub sendnotification { } $coursetext .= "\n\n"; } - my $body = $coursetext. + my @recipients = split(/,/,$to); + $bodystart = $coursetext. &mt('You received a'.$critical.' message from [_1] in LON-CAPA.',$sender).' '.&mt('The subject is [_1] ',$subj)."\n". '=== '.&mt('Excerpt')." ============================================================ -$text +"; + $bodyend = " ======================================================================== ".&mt('Use @@ -327,7 +339,23 @@ $text [_1] to access the full message.',$url); - &sendemail($to,'New'.$critical.' message from '.$sender,$body); + my %userenv = &Apache::lonnet::get('environment',['notifywithhtml'],$toudom,$touname); + my $subject = &mt("'New' $critical message from ").$sender; + if ($userenv{'notifywithhtml'} ne '') { + my @htmlexcerpt = split(/,/,$userenv{'notifywithhtml'}); + foreach my $addr (@recipients) { + my $sendtext = $text; + if (!grep/^\Q$addr\E/,@htmlexcerpt) { + $sendtext =~ s/\<\/*[^\>]+\>//gs; + } + $body = $bodystart.$sendtext.$bodyend; + &sendemail($addr,$subject,$body); + } + } else { + $text =~ s/\<\/*[^\>]+\>//gs; + $body = $bodystart.$text.$bodyend; + &sendemail($to,$subject,$body); + } } # ============================================================= Check for email @@ -551,14 +579,24 @@ sub user_crit_received { my $msgid=shift; my %message=&Apache::lonnet::get('critical',[$msgid]); my %contents=&unpackagemsg($message{$msgid},1); + my $destname = $contents{'sendername'}; + my $destdom = $contents{'senderdomain'}; + if ($contents{'replytoaddr'}) { + my ($repname,$repdom) = split(/:/,$contents{'replytoaddr'}); + if (&Apache::lonnet::homeserver($repname,$repdom) ne 'no_host') { + $destname = $repname; + $destdom = $repdom; + } + } my $status='rec: '.($contents{'sendback'}? - &user_normal_msg($contents{'sendername'},$contents{'senderdomain'}, - &mt('Receipt').': '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.', '.$contents{'subject'}, - &mt('User').' '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}. - ' acknowledged receipt of message'."\n".' "'. - $contents{'subject'}.'"'."\n".&mt('dated').' '. - $contents{'time'}.".\n" - ):'no msg req'); + &user_normal_msg($destname,$destdom,&mt('Receipt').': '.$env{'user.name'}. + ' '.&mt('at').' '.$env{'user.domain'}.', '. + $contents{'subject'},&mt('User').' '.$env{'user.name'}. + ' '.&mt('at').' '.$env{'user.domain'}. + ' acknowledged receipt of message'."\n".' "'. + $contents{'subject'}.'"'."\n".&mt('dated').' '. + $contents{'time'}.".\n" + ):'no msg req'); $status.=' trans: '. &Apache::lonnet::put( 'nohist_email',{$contents{'msgid'} => $message{$msgid}}); @@ -613,9 +651,7 @@ sub user_normal_msg_raw { $$sentmessage = $packed_message; } # Notifications - my %userenv = &Apache::lonnet::get('environment',['notification', - 'permanentemail'], - $domain,$user); + my %userenv = &Apache::loncommon::getemails($user,$domain); if ($userenv{'notification'}) { &sendnotification($userenv{'notification'},$user,$domain,$subject,0, $text,$msgid); @@ -685,6 +721,11 @@ sub process_sent_mail { my $sentsubj; if ($numsent > 1) { $sentsubj = $subj_prefix.' ('.$numsent.' sent) '.$msgsubj; + } else { + if ($subj_prefix) { + $sentsubj = $subj_prefix.' '; + } + $sentsubj .= $msgsubj; } $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"'); my $sentmsgid =