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

raeburn raeburn@source.lon-capa.org
Sun, 04 Jan 2009 16:21:10 -0000


raeburn		Sun Jan  4 16:21:10 2009 EDT

  Modified files:              (Branch: version_2_8_X)
    /loncom/interface	lonmsg.pm 
  Log:
  - Backport 1.220.
  
  
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.214.2.3 loncom/interface/lonmsg.pm:1.214.2.4
--- loncom/interface/lonmsg.pm:1.214.2.3	Tue Dec 23 19:27:33 2008
+++ loncom/interface/lonmsg.pm	Sun Jan  4 16:21:10 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.214.2.3 2008/12/23 19:27:33 raeburn Exp $
+# $Id: lonmsg.pm,v 1.214.2.4 2009/01/04 16:21:10 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -86,7 +86,7 @@
     $baseurl =~ s|^https?\://[^/]+/|/|;
     $baseurl =&HTML::Entities::encode($baseurl,'<>&"');
     #remove machine specification
-    $attachmenturl =~ s|^https\://[^/]+/|/|;
+    $attachmenturl =~ s|^https?\://[^/]+/|/|;
     $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
     my $course_context = &get_course_context();
     my $now=time;
@@ -283,21 +283,48 @@
 
 sub sendemail {
     my ($to,$subject,$body,$to_uname,$to_udom,$user_lh)=@_;
-    my %senderemails=&Apache::loncommon::getemails();
     my $senderaddress='';
-    foreach my $type ('notification','permanentemail','critnotification') {
-	if ($senderemails{$type}) {
-	    $senderaddress=$senderemails{$type};
-	}
+    my $replytoaddress='';
+    if ($env{'form.can_reply'} eq 'N') {
+        my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
+        my $hostname = &Apache::lonnet::hostname($lonhost);
+        $replytoaddress = 'do-not-reply@'.$hostname;
+    } else {
+        my %senderemails;
+        my $have_sender;
+        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') {
+                    %senderemails = 
+                        &Apache::loncommon::getemails($replytoname,$replytodom);
+                    $have_sender = 1;
+                }
+            }
+        }
+        if (!$have_sender) {
+            %senderemails=&Apache::loncommon::getemails();
+        }
+        foreach my $type ('permanentemail','critnotification','notification') {
+	    if ($senderemails{$type}) {
+                ($senderaddress) = split(/,/,$senderemails{$type});
+                last if ($senderaddress);
+	    }
+        }
     }
     $body=
     "*** ".&mt_user($user_lh,'This is an automatic message generated by the LON-CAPA system.')."\n".
     "*** ".($senderaddress?&mt_user($user_lh,'You can reply to this message'):&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;
+    &mt_user($user_lh,'A reply will not be received by the recipient!'))."\n\n".$body;
     my $msg = new Mail::Send;
     $msg->to($to);
     $msg->subject('[LON-CAPA] '.$subject);
-    if ($senderaddress) { $msg->add('Reply-to',$senderaddress); $msg->add('From',$senderaddress); }
+    if ($replytoaddress) { 
+        $msg->add('Reply-to',$replytoaddress);
+    }
+    if ($senderaddress) {
+        $msg->add('From',$senderaddress); 
+    }
     if (my $fh = $msg->open()) {
 	print $fh $body;
 	$fh->close;