[LON-CAPA-cvs] cvs: loncom /interface lonnotify.pm /lonnet/perl lonnet.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Fri, 09 Dec 2005 00:08:54 -0000


raeburn		Thu Dec  8 19:08:54 2005 EDT

  Modified files:              
    /loncom/interface	lonnotify.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Unify storage of DCmail on domain's primary domain server
  
  
Index: loncom/interface/lonnotify.pm
diff -u loncom/interface/lonnotify.pm:1.8 loncom/interface/lonnotify.pm:1.9
--- loncom/interface/lonnotify.pm:1.8	Tue Nov 15 16:08:47 2005
+++ loncom/interface/lonnotify.pm	Thu Dec  8 19:08:35 2005
@@ -273,25 +273,17 @@
 <form method="post" name="$formname">
 ENDONE
 
-    foreach my $server (keys(%sentmail)) {
-        foreach my $msgid (keys(%{$sentmail{$server}})) {
-            my %content = &unpackagemail($sentmail{$server}{$msgid});
-            if (defined($dcmail{$msgid})) {
-                foreach my $user (keys(%{$content{'recipients'}})) {
+    foreach my $msgid (keys(%sentmail)) {
+        my %content = &unpackagemail($sentmail{$msgid});
+        $msgcount ++;
+        %{$dcmail{$msgid}} = ();
+        foreach my $item (keys(%content)) {
+            if ($item eq 'recipients') {
+                foreach my $user (keys(%{$content{recipients}})) {
                     $dcmail{$msgid}{recipients}{$user} = $content{recipients}{$user};
                 }
             } else {
-                $msgcount ++;
-                %{$dcmail{$msgid}} = ();
-                foreach my $item (keys(%content)) {
-                    if ($item eq 'recipients') {
-                        foreach my $user (keys(%{$content{recipients}})) {
-                            $dcmail{$msgid}{recipients}{$user} = $content{recipients}{$user};
-                        }
-                    } else {
-                        $dcmail{$msgid}{$item} = $content{$item};
-                    }
-                }
+                $dcmail{$msgid}{$item} = $content{$item};
             }
         }
     }
@@ -849,20 +841,25 @@
 
 sub store_mail {
     my ($subject,$message,$domain,$recipients,$attachmenturl,$ltext) = @_;
-    my %servers = ();
-    my $msgid=&packagemail($subject,$message,$domain,
-                           $recipients,\%servers,$attachmenturl);
-# Store in dc email db files on appropriate servers.
-    foreach my $server (keys(%servers)) {
-        unless (&Apache::lonnet::dcmailput($domain,$msgid,\%servers,$server) eq 'ok') {
-            &Apache::lonnet::logthis('Storage of dc mail failed for domain'.$domain.' for server: '.
-                      $server.'.  Message ID was '.$msgid);
+    my $msgid;
+    ($msgid,$message) = &packagemail($subject,$message,$domain,$recipients,
+                                                               $attachmenturl);
+# Store in dc email db files on primary library server for domain.
+    my $server = $Apache::lonnet::domain_primary{$domain};
+    if (defined($server)) {
+        unless (&Apache::lonnet::dcmailput($domain,$msgid,$message,$server) 
+                                                            eq 'ok') {
+            &Apache::lonnet::logthis('Storage of dc mail failed for domain'.
+                 $domain.' for server: '. $server.'.  Message ID was '.$msgid);
         }
+    } else {
+        &Apache::lonnet::logthis('Storage of dc mail failed for domain'.
+           $domain.' as no primary server identified. Message ID was '.$msgid);
     }
 }
 
 sub packagemail {
-    my ($subject,$message,$dom,$recipients,$servers,$attachmenturl,$ltext) = @_;
+    my ($subject,$message,$dom,$recipients,$attachmenturl) = @_;
     my %record = ();
     my $partsubj=$subject;
     $partsubj=&Apache::lonnet::escape($partsubj);
@@ -893,19 +890,12 @@
         my ($username,$email) = split(/:/,$recip);
         $username = &Apache::lonnet::unescape($username);
         $email = &Apache::lonnet::unescape($email);
-        my ($uname,$udom) = split(/:/,$username);
-        my $uhom=&Apache::lonnet::homeserver($uname,$udom);
-        if ($uhom ne 'no_host') {
-            $username = &HTML::Entities::encode($username,'<>&"');
-            $email = &HTML::Entities::encode($email,'<>&"');
-            $record{$uhom} .= '<recipient username="'.$username.'">'.
+        $username = &HTML::Entities::encode($username,'<>&"');
+        $email = &HTML::Entities::encode($email,'<>&"');
+        $result .= '<recipient username="'.$username.'">'.
                               $email.'</recipient>';
-        }
-    }
-    foreach my $server (keys(%record)) {
-        $$servers{$server} = $result.$record{$server};
     }
-    return $msgid;
+    return ($msgid,$result);
 }
 
 sub unpackagemail {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.684 loncom/lonnet/perl/lonnet.pm:1.685
--- loncom/lonnet/perl/lonnet.pm:1.684	Mon Nov 21 21:24:55 2005
+++ loncom/lonnet/perl/lonnet.pm	Thu Dec  8 19:08:51 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.684 2005/11/22 02:24:55 raeburn Exp $
+# $Id: lonnet.pm,v 1.685 2005/12/09 00:08:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -40,8 +40,8 @@
    %courselogs %accesshash %userrolehash %domainrolehash $processmarker $dumpcount 
    %coursedombuf %coursenumbuf %coursehombuf %coursedescrbuf %courseinstcodebuf %courseownerbuf
    %domaindescription %domain_auth_def %domain_auth_arg_def 
-   %domain_lang_def %domain_city %domain_longi %domain_lati $tmpdir $_64bit
-   %env);
+   %domain_lang_def %domain_city %domain_longi %domain_lati %domain_primary
+   $tmpdir $_64bit %env);
 
 use IO::Socket;
 use GDBM_File;
@@ -1853,28 +1853,25 @@
 # ---------------------------------------------------------- DC e-mail
 
 sub dcmailput {
-    my ($domain,$msgid,$contents,$server)=@_;
+    my ($domain,$msgid,$message,$server)=@_;
     my $status = &Apache::lonnet::critical(
        'dcmailput:'.$domain.':'.&Apache::lonnet::escape($msgid).'='.
-       &Apache::lonnet::escape($$contents{$server}),$server);
+       &Apache::lonnet::escape($message),$server);
     return $status;
 }
 
 sub dcmaildump {
     my ($dom,$startdate,$enddate,$senders) = @_;
-    my %returnhash=(); 
-    foreach my $tryserver (keys(%libserv)) {
-        if ($hostdom{$tryserver} eq $dom) {
-            %{$returnhash{$tryserver}}=();
-	    my $cmd='dcmaildump:'.$dom.':'.
-		&escape($startdate).':'.&escape($enddate).':';
-	    my @esc_senders=map { &escape($_)} @$senders;
-	    $cmd.=&escape(join('&',@esc_senders));
-	    foreach (split(/\&/,&reply($cmd,$tryserver))) {
-                my ($key,$value) = split(/\=/,$_);
-                if (($key) && ($value)) {
-                    $returnhash{$tryserver}{&unescape($key)} = &unescape($value);
-                }
+    my %returnhash=();
+    if (exists($domain_primary{$dom})) {
+        my $cmd='dcmaildump:'.$dom.':'.&escape($startdate).':'.
+                                                         &escape($enddate).':';
+	my @esc_senders=map { &escape($_)} @$senders;
+	$cmd.=&escape(join('&',@esc_senders));
+	foreach (split(/\&/,&reply($cmd,$domain_primary{$dom}))) {
+            my ($key,$value) = split(/\=/,$_);
+            if (($key) && ($value)) {
+                $returnhash{&unescape($key)} = &unescape($value);
             }
         }
     }
@@ -6214,7 +6211,7 @@
 #           next if /^\#/;
            chomp;
            my ($domain, $domain_description, $def_auth, $def_auth_arg,
-	       $def_lang, $city, $longi, $lati) = split(/:/,$_);
+	       $def_lang, $city, $longi, $lati, $primary) = split(/:/,$_);
 	   $domain_auth_def{$domain}=$def_auth;
            $domain_auth_arg_def{$domain}=$def_auth_arg;
 	   $domaindescription{$domain}=$domain_description;
@@ -6222,6 +6219,7 @@
 	   $domain_city{$domain}=$city;
 	   $domain_longi{$domain}=$longi;
 	   $domain_lati{$domain}=$lati;
+           $domain_primary{$domain}=$primary;
 
  #         &logthis("Domain.tab: $domain, $domain_auth_def{$domain}, $domain_auth_arg_def{$domain},$domaindescription{$domain}");
 #          &logthis("Domain.tab: $domain ".$domaindescription{$domain} );