[LON-CAPA-cvs] cvs: loncom(version_2_9_X) /interface lonmsg.pm

raeburn raeburn@source.lon-capa.org
Fri, 20 Aug 2010 18:45:21 -0000


raeburn		Fri Aug 20 18:45:21 2010 EDT

  Modified files:              (Branch: version_2_9_X)
    /loncom/interface	lonmsg.pm 
  Log:
  - Backport 1.226.
  
  
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.222 loncom/interface/lonmsg.pm:1.222.2.1
--- loncom/interface/lonmsg.pm:1.222	Thu Feb  5 00:45:29 2009
+++ loncom/interface/lonmsg.pm	Fri Aug 20 18:45:20 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.222 2009/02/05 00:45:29 raeburn Exp $
+# $Id: lonmsg.pm,v 1.222.2.1 2010/08/20 18:45:20 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);
 
 {
@@ -484,7 +486,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);
@@ -537,13 +540,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;
             }
@@ -553,13 +559,20 @@
         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 newmail {
     if ((time-$env{'user.mailcheck.time'})>300) {