[LON-CAPA-cvs] cvs: loncom /interface lonmsg.pm
raeburn
raeburn@source.lon-capa.org
Sat, 29 May 2010 22:39:52 -0000
raeburn Sat May 29 22:39:52 2010 EDT
Modified files:
/loncom/interface lonmsg.pm
Log:
- Improved more general fix for bug6233.
Unless recipient user preference set to retain HTML tags in notification e-mail:
- Remove HTML tags and decode HTML Entities in message excerpt, then encode in utf8 before sending e-mail.
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.225 loncom/interface/lonmsg.pm:1.226
--- loncom/interface/lonmsg.pm:1.225 Tue Mar 2 15:10:47 2010
+++ loncom/interface/lonmsg.pm Sat May 29 22:39:52 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.225 2010/03/02 15:10:47 jms Exp $
+# $Id: lonmsg.pm,v 1.226 2010/05/29 22:39:52 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -203,6 +203,8 @@
use HTML::TokeParser();
use Apache::lonlocal;
use Mail::Send;
+use HTML::Entities;
+use Encode;
use LONCAPA qw(:DEFAULT :match);
{
@@ -454,8 +456,6 @@
"*** ".($senderaddress?&mt_user($user_lh,'You can reply to this e-mail'):&mt_user($user_lh,'Please do not reply to this address.')."\n*** ".
&mt_user($user_lh,'A reply will not be received by the recipient!'))."\n\n".$body;
- $body =~ s/ / /g;
-
my $msg = new Mail::Send;
$msg->to($to);
$msg->subject('[LON-CAPA] '.$subject);
@@ -487,7 +487,8 @@
my $protocol = $Apache::lonnet::protocol{$homeserver};
$protocol = 'http' if ($protocol ne 'https');
my $url = $protocol.'://'.&Apache::lonnet::hostname($homeserver).
- '/adm/email?username='.$touname.'&domain='.$toudom;
+ '/adm/email?username='.$touname.'&domain='.$toudom.
+ '&display='.&escape($msgid);
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,
$symb,$error) = &Apache::lonmsg::unpackmsgid($msgid);
my ($coursetext,$body,$bodybegin,$bodysubj,$bodyend);
@@ -540,13 +541,16 @@
}
if ($userenv{'notifywithhtml'} ne '') {
my @htmlexcerpt = split(/,/,$userenv{'notifywithhtml'});
+ my $htmlfree = &make_htmlfree($text);
foreach my $addr (@recipients) {
if ($blocked) {
$body = $bodybegin."\n".$blocktext."\n".$bodyend;
} else {
- my $sendtext = $text;
+ my $sendtext;
if (!grep/^\Q$addr\E/,@htmlexcerpt) {
- $sendtext =~ s/\<\/*[^\>]+\>//gs;
+ $sendtext = &htmlfree;
+ } else {
+ $sendtext = $text;
}
$body = $bodybegin.$bodysubj.$sendtext.$bodyend;
}
@@ -556,13 +560,21 @@
if ($blocked) {
$body = $bodybegin."\n".$blocktext."\n".$bodyend;
} else {
- $text =~ s/\<\/*[^\>]+\>//gs;
- $body = $bodybegin.$bodysubj.$text.$bodyend;
+ my $htmlfree = &make_htmlfree($text);
+ $body = $bodybegin.$bodysubj.$htmlfree.$bodyend;
}
&sendemail($to,$subject,$body,$touname,$toudom,$user_lh);
}
}
+sub make_htmlfree {
+ my ($text) = @_;
+ $text =~ s/\<\/*[^\>]+\>//gs;
+ $text = &HTML::Entities::decode($text);
+ $text = &Encode::encode('utf8',$text);
+ return $text;
+}
+
sub mynewmail{
&newmail();
return $env{'user.mailcheck.lastnewmassagetime'} > $env{'user.mailcheck.lastvisit'};