[LON-CAPA-cvs] cvs: loncom /interface lonmsg.pm lonmsgdisplay.pm

raeburn raeburn at source.lon-capa.org
Thu Feb 12 16:22:08 EST 2015


raeburn		Thu Feb 12 21:22:08 2015 EDT

  Modified files:              
    /loncom/interface	lonmsg.pm lonmsgdisplay.pm 
  Log:
  - Report if e-mail was created, in case where privileged user checked:
    "Send copy to permanent e-mail address (if known)". Also log this.   
  
  
-------------- next part --------------
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.237 loncom/interface/lonmsg.pm:1.238
--- loncom/interface/lonmsg.pm:1.237	Thu Dec 11 01:53:22 2014
+++ loncom/interface/lonmsg.pm	Thu Feb 12 21:22:07 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.237 2014/12/11 01:53:22 raeburn Exp $
+# $Id: lonmsg.pm,v 1.238 2015/02/12 21:22:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -120,7 +120,7 @@
 
 New routine that respects "forward" and calls old routine
 
-=item * B<user_crit_msg($user, $domain, $subject, $message, $sendback, $nosentstore,$recipid,$attachmenturl)>: 
+=item * B<user_crit_msg($user, $domain, $subject, $message, $sendback, $nosentstore, $recipid, $attachmenturl, $permresults)>: 
     Sends a critical message $message to the $user at $domain.  If $sendback
     is true,  a receipt will be sent to the current user when $user receives 
     the message.
@@ -148,7 +148,7 @@
 
 =item * B<user_normal_msg($user, $domain, $subject, $message, $citation,
        $baseurl, $attachmenturl, $toperm, $sentmessage, $symb, $restitle,
-       $error,$nosentstore,$recipid)>:
+       $error,$nosentstore,$recipid,$permresults)>:
  Sends a message to the  $user at $domain, with subject $subject and message $message.
 
     Additionally it will check if the user has a Forwarding address
@@ -424,6 +424,7 @@
     my ($to,$subject,$body,$to_uname,$to_udom,$user_lh)=@_;
     my $senderaddress='';
     my $replytoaddress='';
+    my $msgsent;
     if ($env{'form.can_reply'} eq 'N') {
         my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
         my $hostname = &Apache::lonnet::hostname($lonhost);
@@ -469,7 +470,9 @@
     if (my $fh = $msg->open()) {
 	print $fh $body;
 	$fh->close;
+        $msgsent = 1;
     }
+    return $msgsent;
 }
 
 # ==================================================== Send notification emails
@@ -481,6 +484,7 @@
 	$sender=$env{'user.name'}.':'.$env{'user.domain'};
     }
     my $critical=($crit?' critical':'');
+    my $numsent = 0;
 
     $text=~s/\&lt\;/\</gs;
     $text=~s/\&gt\;/\>/gs;
@@ -558,7 +562,9 @@
                 }
                 $body = $bodybegin.$bodysubj.$sendtext.$bodyend;
             }
-            &sendemail($addr,$subject,$body,$touname,$toudom,$user_lh);
+            if (&sendemail($addr,$subject,$body,$touname,$toudom,$user_lh)) {
+                $numsent ++;
+            }
         }
     } else {
         if ($blocked) {
@@ -567,8 +573,11 @@
             my $htmlfree = &make_htmlfree($text);
             $body = $bodybegin.$bodysubj.$htmlfree.$bodyend;
         }
-        &sendemail($to,$subject,$body,$touname,$toudom,$user_lh);
+        if (&sendemail($to,$subject,$body,$touname,$toudom,$user_lh)) {
+            $numsent ++;
+        }
     }
+    return $numsent;
 }
 
 sub make_htmlfree {
@@ -696,7 +705,7 @@
 
 sub user_crit_msg_raw {
     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
-        $nosentstore,$recipid,$attachmenturl)=@_;
+        $nosentstore,$recipid,$attachmenturl,$permresults)=@_;
 # Check if allowed missing
     my ($status,$packed_message);
     my $msgid='undefined';
@@ -727,22 +736,40 @@
 
 # Notifications
     my %userenv = &Apache::loncommon::getemails($user,$domain);
-    if ($userenv{'critnotification'}) {
-      &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1,
-			$text,$msgid);
-    }
-    if ($toperm && $userenv{'permanentemail'}) {
-      &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,1,
-			$text,$msgid);
+    my $critnotify = $userenv{'critnotification'};
+    my $permemail = $userenv{'permanentemail'};
+    my $numcrit = 0;
+    my $numperm = 0;
+    my $permlogmsgstatus;
+    if ($critnotify) {
+        $numcrit = &sendnotification($critnotify,$user,$domain,$subject,1,$text,$msgid);
+    }
+    if ($toperm && $permemail) {
+        if ($critnotify && $numcrit) {
+            if (grep(/^\Q$permemail\E/,split(/,/,$critnotify))) {
+                $numperm = 1;
+            }
+        }
+        unless ($numperm) {
+            $numperm = &sendnotification($permemail,$user,$domain,$subject,1,$text,$msgid);
+        }
+    }
+    if ($toperm) {
+        $permlogmsgstatus = '. Perm. email log status '.
+                            &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},$env{'user.home'},
+                                                 "Perm. e-mail count $numperm for $user at $domain");
+        if (ref($permresults) eq 'HASH') {
+            $permresults->{"$user:$domain"} = $numperm;
+        }
     }
 # Log this
     &Apache::lonnet::logthis(
-      'Sending critical email '.$msgid.
+      'Sending critical '.$msgid.
       ', log status: '.
       &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
                          $env{'user.home'},
-      'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
-      .$status));
+      'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status '
+      .$status).$permlogmsgstatus);
     return $status;
 }
 
@@ -750,7 +777,7 @@
 
 sub user_crit_msg {
     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
-        $nosentstore,$recipid,$attachmenturl)=@_;
+        $nosentstore,$recipid,$attachmenturl,$permresults)=@_;
     my @status;
     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                                        $domain,$user);
@@ -761,13 +788,13 @@
          push(@status,
 	      &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
 				 $sendback,$toperm,$sentmessage,$nosentstore,
-                                 $recipid,$attachmenturl));
+                                 $recipid,$attachmenturl,$permresults));
        }
     } else { 
 	push(@status,
 	     &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
 				$toperm,$sentmessage,$nosentstore,$recipid,
-                                $attachmenturl));
+                                $attachmenturl,$permresults));
     }
     if (wantarray) {
 	return @status;
@@ -816,7 +843,7 @@
 sub user_normal_msg_raw {
     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
         $toperm,$currid,$newid,$sentmessage,$crsmsgid,$symb,$restitle,
-        $error,$nosentstore,$recipid)=@_;
+        $error,$nosentstore,$recipid,$permresults)=@_;
 # Check if allowed missing
     my ($status,$packed_message);
     my $msgid='undefined';
@@ -853,19 +880,37 @@
        }
 # Notifications
        my %userenv = &Apache::loncommon::getemails($user,$domain);
-       if ($userenv{'notification'}) {
-	   &sendnotification($userenv{'notification'},$user,$domain,$subject,0,
-			     $text,$msgid);
+       my $notify = $userenv{'notification'};
+       my $permemail = $userenv{'permanentemail'};
+       my $numnotify = 0;
+       my $numperm = 0;
+       my $permlogmsgstatus;
+       if ($notify) {
+           $numnotify = &sendnotification($notify,$user,$domain,$subject,0,$text,$msgid);
+       }
+       if ($toperm && $permemail) {
+           if ($notify && $numnotify) {
+               if (grep(/^\Q$permemail\E/,split(/,/,$notify))) {
+                   $numperm = 1;
+               }
+           }
+           unless ($numperm) {
+               $numperm = &sendnotification($permemail,$user,$domain,$subject,0,
+                                            $text,$msgid);
+           }
        }
-       if ($toperm && $userenv{'permanentemail'}) {
-           if ((!$userenv{'notification'}) || ($userenv{'notification'} ne $userenv{'permanentemail'})) {
-	       &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0,
-	  		         $text,$msgid);
+       if ($toperm) {
+           $permlogmsgstatus = '. Perm. email log status '.
+                         &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},$env{'user.home'},
+                                              "Perm. e-mail count $numperm for $user at $domain");
+           if (ref($permresults) eq 'HASH') {
+               $permresults->{"$user:$domain"} = $numperm;
            }
        }
        &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
 			    $env{'user.home'},
-			    'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
+			    'Sending '.$msgid.' to '.$user.' at '.$domain.' with status '.$status.
+                            $permlogmsgstatus);
    } else {
        $status='no_host';
    }
@@ -874,7 +919,8 @@
 
 sub user_normal_msg {
     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
-	$toperm,$sentmessage,$symb,$restitle,$error,$nosentstore,$recipid)=@_;
+	$toperm,$sentmessage,$symb,$restitle,$error,$nosentstore,$recipid,
+        $permresults)=@_;
     my @status;
     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                                        $domain,$user);
@@ -886,13 +932,13 @@
 	        &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
 				     $citation,$baseurl,$attachmenturl,$toperm,
 				     undef,undef,$sentmessage,undef,$symb,
-                                     $restitle,$error,$nosentstore,$recipid));
+                                     $restitle,$error,$nosentstore,$recipid,$permresults));
         }
     } else {
 	push(@status,&user_normal_msg_raw($user,$domain,$subject,$message,
 				     $citation,$baseurl,$attachmenturl,$toperm,
 				     undef,undef,$sentmessage,undef,$symb,
-                                     $restitle,$error,$nosentstore,$recipid));
+                                     $restitle,$error,$nosentstore,$recipid,$permresults));
     }
     if (wantarray) {
         return @status;
Index: loncom/interface/lonmsgdisplay.pm
diff -u loncom/interface/lonmsgdisplay.pm:1.179 loncom/interface/lonmsgdisplay.pm:1.180
--- loncom/interface/lonmsgdisplay.pm:1.179	Thu Feb 12 21:09:24 2015
+++ loncom/interface/lonmsgdisplay.pm	Thu Feb 12 21:22:07 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging display
 #
-# $Id: lonmsgdisplay.pm,v 1.179 2015/02/12 21:09:24 raeburn Exp $
+# $Id: lonmsgdisplay.pm,v 1.180 2015/02/12 21:22:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2913,6 +2913,7 @@
         }
         my @recusers;
         my @recudoms;
+        my %permresults;
 	foreach my $address (sort(keys(%toaddr))) {
 	    my ($recuname,$recdomain)=split(/\:/,$address);
             my $msgtxt = $savemsg;
@@ -2930,7 +2931,7 @@
 						   $env{'form.permanent'},
 						   \$sentmessage{$address},
                                                    $nosentstore,$recipid,
-                                                   $attachmenturl);
+                                                   $attachmenturl,\%permresults);
 	    } else {
 		$r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
 		@thismsg=
@@ -2941,13 +2942,20 @@
 						     $env{'form.permanent'},
 						     \$sentmessage{$address},
                                                      undef,undef,undef,
-                                                     $nosentstore,$recipid);
+                                                     $nosentstore,$recipid,
+                                                     \%permresults);
             }
 	    $msg_status{$recuname.':'.$recdomain}=join(' ', at thismsg);
 	    if ($msg_status{$recuname.':'.$recdomain} =~ /(ok|con_delayed)/) {  
 	        $numsent++;
                 push(@recusers,$recuname);
                 push(@recudoms,$recdomain);
+                if ($1 eq 'ok') {
+                    $r->print('ok ');
+                }
+                if ($permresults{$recuname.':'.$recdomain}) {
+                    $r->print(' (email) ');
+                }
 	    }
 	    $sendstatus.=' '.join(' ', at thismsg);
 	}


More information about the LON-CAPA-cvs mailing list