[LON-CAPA-cvs] cvs: loncom / lond /interface lonmsg.pm lonnotify.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Fri, 09 Dec 2005 20:54:26 -0000
This is a MIME encoded message
--raeburn1134161666
Content-Type: text/plain
raeburn Fri Dec 9 15:54:26 2005 EDT
Modified files:
/loncom lond
/loncom/interface lonnotify.pm lonmsg.pm
Log:
Use packagemsg() and unpackagemsg() routines in lonmsg.pm to store and retrieve DC mail, and eliminate packagmail() and unpackagemail() routines (no longer needed) from lonnotify.pm.
--raeburn1134161666
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20051209155426.txt"
Index: loncom/lond
diff -u loncom/lond:1.301 loncom/lond:1.302
--- loncom/lond:1.301 Mon Oct 17 16:09:01 2005
+++ loncom/lond Fri Dec 9 15:54:23 2005
@@ -2,7 +2,7 @@
# The LearningOnline Network
# lond "LON Daemon" Server (port "LOND" 5663)
#
-# $Id: lond,v 1.301 2005/10/17 20:09:01 www Exp $
+# $Id: lond,v 1.302 2005/12/09 20:54:23 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -59,7 +59,7 @@
my $status='';
my $lastlog='';
-my $VERSION='$Revision: 1.301 $'; #' stupid emacs
+my $VERSION='$Revision: 1.302 $'; #' stupid emacs
my $remoteVERSION;
my $currenthostid="default";
my $currentdomainid;
@@ -3594,6 +3594,7 @@
if ($hashref) {
while (my ($key,$value) = each(%$hashref)) {
my $match = 1;
+ $key = &unescape($key);
my ($timestamp,$subj,$uname,$udom) = split(/:/,&unescape($key),5);
$timestamp = &unescape($timestamp);
$subj = &unescape($subj);
Index: loncom/interface/lonnotify.pm
diff -u loncom/interface/lonnotify.pm:1.9 loncom/interface/lonnotify.pm:1.10
--- loncom/interface/lonnotify.pm:1.9 Thu Dec 8 19:08:35 2005
+++ loncom/interface/lonnotify.pm Fri Dec 9 15:54:26 2005
@@ -274,13 +274,13 @@
ENDONE
foreach my $msgid (keys(%sentmail)) {
- my %content = &unpackagemail($sentmail{$msgid});
+ my %content = &Apache::lonmsg::unpackagemsg($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};
+ if ($item eq 'recipient') {
+ foreach my $user (keys(%{$content{recipient}})) {
+ $dcmail{$msgid}{recipient}{$user} = $content{recipient}{$user};
}
} else {
$dcmail{$msgid}{$item} = $content{$item};
@@ -308,8 +308,8 @@
my $recipients = '';
my ($date,$subj,$sname,$sdom,$cdom) = split(/:/,$msgid,5);
$date = &Apache::lonlocal::locallocaltime($date);
- foreach my $user (sort(keys(%{$dcmail{$msgid}{recipients}}))) {
- $recipients .= $dcmail{$msgid}{recipients}{$user}.', ';
+ foreach my $user (sort(keys(%{$dcmail{$msgid}{recipient}}))) {
+ $recipients .= $dcmail{$msgid}{recipient}{$user}.', ';
}
$recipients =~ s/,\s$//;
$output .= '<tr bgcolor="'.$rowColor.'"><td><small>'.$date.'</small></td><td><small>'.&cr_to_br($dcmail{$msgid}{subject}).'</small></td><td><small>'.$sname.':'.$sdom.'</small></td><td><small>'.&cr_to_br($dcmail{$msgid}{message}).'</small></td><td><small>'.$recipients.'</small></td></tr>'."\n";
@@ -324,8 +324,8 @@
push @{$Sortby{$dcmail{$msgid}{message}}},$msgid;
} elsif ($env{'form.sortby'} eq 'recipients') {
my $recipients ='';
- foreach my $user (sort(keys(%{$dcmail{$msgid}{recipients}}))) {
- $recipients .= $dcmail{$msgid}{recipients}{$user}.', ';
+ foreach my $user (sort(keys(%{$dcmail{$msgid}{recipient}}))) {
+ $recipients .= $dcmail{$msgid}{recipient}{$user}.', ';
}
$recipients =~ s/,\s$//;
push @{$Sortby{$recipients}},$msgid;
@@ -346,8 +346,8 @@
if ($env{'form.sortby'} eq 'recipients') {
$recipients = $key;
} else {
- foreach my $user (sort(keys(%{$dcmail{$msgid}{recipients}}))) {
- $recipients .= $dcmail{$msgid}{recipients}{$user}.', ';
+ foreach my $user (sort(keys(%{$dcmail{$msgid}{recipient}}))) {
+ $recipients .= $dcmail{$msgid}{recipient}{$user}.', ';
}
$recipients =~ s/,\s$//;
}
@@ -376,7 +376,7 @@
$output .= qq(<input type="hidden" name="sortby" value="$curr_sortby" />\n);
$output .= qq(
</form>
-</body>
+</body
</html>);
$r->print($output);
return;
@@ -758,7 +758,6 @@
</table>
</td>
</tr>';
- &store_mail($subject,$message,$dom,\@deliveries);
} else {
$output .= 'No mail sent - no recipients identified';
}
@@ -842,8 +841,9 @@
sub store_mail {
my ($subject,$message,$domain,$recipients,$attachmenturl,$ltext) = @_;
my $msgid;
- ($msgid,$message) = &packagemail($subject,$message,$domain,$recipients,
- $attachmenturl);
+ ($msgid,$message) = &Apache::lonmsg::packagemsg($subject,$message,undef,undef,
+ $attachmenturl,$recipients,undef,undef,'dcmail');
+
# Store in dc email db files on primary library server for domain.
my $server = $Apache::lonnet::domain_primary{$domain};
if (defined($server)) {
@@ -858,83 +858,6 @@
}
}
-sub packagemail {
- my ($subject,$message,$dom,$recipients,$attachmenturl) = @_;
- my %record = ();
- my $partsubj=$subject;
- $partsubj=&Apache::lonnet::escape($partsubj);
- $message =&HTML::Entities::encode($message,'<>&"');
- $subject =&HTML::Entities::encode($subject,'<>&"');
- #remove machine specification
- $attachmenturl =~ s|^http://[^/]+/|/|;
- $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
- my $now=time;
- my $msgid= &Apache::lonnet::escape($now).':'.$partsubj.':'.
- &Apache::lonnet::escape($env{'user.name'}).':'.
- &Apache::lonnet::escape($env{'user.domain'}).':'.
- &Apache::lonnet::escape($dom).':'.$$;
- my $result='<sendername>'.$env{'user.name'}.'</sendername>'.
- '<senderdomain>'.$env{'user.domain'}.'</senderdomain>'.
- '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>'.
- '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
- '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
- '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
- '<msgid>'.$msgid.'</msgid>'.
- '<dcdomain>'.$dom.'</dcdomain>'.
- '<subject>'.$subject.'</subject>'.
- '<message>'.$message.'</message>'."\n";
- if (defined($attachmenturl)) {
- $result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>';
- }
- foreach my $recip (@{$recipients}) {
- my ($username,$email) = split(/:/,$recip);
- $username = &Apache::lonnet::unescape($username);
- $email = &Apache::lonnet::unescape($email);
- $username = &HTML::Entities::encode($username,'<>&"');
- $email = &HTML::Entities::encode($email,'<>&"');
- $result .= '<recipient username="'.$username.'">'.
- $email.'</recipient>';
- }
- return ($msgid,$result);
-}
-
-sub unpackagemail {
- my ($message,$notoken,$ltext)=@_;
- my $parser=HTML::TokeParser->new(\$message);
- my $token;
- my %content=();
- %{$content{recipients}} = ();
- while ($token=$parser->get_token()) {
- if ($token->[0] eq 'S') {
- my $entry=$token->[1];
- my $value=$parser->get_text('/'.$entry);
- my ($username,$email);
- if ($entry eq 'recipient') {
- $username = $token->[2]{'username'};
- $username = &HTML::Entities::decode($username,'<>&"');
- $content{recipients}{$username} =
- &HTML::Entities::decode($value,'<>&"');
- } elsif ($entry eq 'subject' || $entry eq 'message') {
- $content{$entry}=&HTML::Entities::decode($value,'<>&"');
- } else {
- $content{$entry}=$value;
- }
- }
- }
- if ($content{'attachmenturl'}) {
- my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|);
- if ($notoken) {
- $content{'message'}.='<p>'.&mt('Attachment').': <tt>'.$fname.'</tt>'; } else {
- &Apache::lonnet::allowuploaded('/adm/notify',
- $content{'attachmenturl'});
- $content{'message'}.='<p>'.&mt('Attachment').
- ': <a href="'.$content{'attachmenturl'}.'"><tt>'.
- $fname.'</tt></a>';
- }
- }
- return %content;
-}
-
sub cr_to_br {
my $incoming = shift;
$incoming =~ s/\n/\<br \/\>/g;
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.161 loncom/interface/lonmsg.pm:1.162
--- loncom/interface/lonmsg.pm:1.161 Mon Dec 5 17:16:52 2005
+++ loncom/interface/lonmsg.pm Fri Dec 9 15:54:26 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.161 2005/12/05 22:16:52 albertel Exp $
+# $Id: lonmsg.pm,v 1.162 2005/12/09 20:54:26 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -97,6 +97,17 @@
it is likely you will not need to programmatically read messages,
since lonmsg already implements that functionality.
+The routines used to package messages and unpackage messages are not
+only used by lonmsg when creating/extracting messages for LON-CAPA's
+internal messaging system, but also by lonnotify.pm which is available
+for use by Domain Coordinators to broadcast standard e-mail to specified
+users in their domain. The XML packaging used in the two cases is very
+similar. The differences are the use of <recuser>$uname</recuser> and
+<recdomain>$udom</recdomain> in stored internal messages, compared
+with <recipient username="$uname:$udom">$email</recipient> in stored
+Domain Coordinator e-mail for teh storage of information about
+recipients of the message/e-mail.
+
=head1 FUNCTIONS
=over 4
@@ -126,7 +137,7 @@
sub packagemsg {
my ($subject,$message,$citation,$baseurl,$attachmenturl,
- $recuser,$recdomain,$msgid)=@_;
+ $recuser,$recdomain,$msgid,$type)=@_;
$message =&HTML::Entities::encode($message,'<>&"');
$citation=&HTML::Entities::encode($citation,'<>&"');
$subject =&HTML::Entities::encode($subject,'<>&"');
@@ -178,8 +189,18 @@
'<msgid>'.$msgid.'</msgid>';
if (ref($recuser) eq 'ARRAY') {
for (my $i=0; $i<@{$recuser}; $i++) {
- $result .= '<recuser>'.$$recuser[$i].'</recuser>'.
- '<recdomain>'.$$recdomain[$i].'</recdomain>';
+ if ($type eq 'dcmail') {
+ my ($username,$email) = split(/:/,$$recuser[$i]);
+ $username = &Apache::lonnet::unescape($username);
+ $email = &Apache::lonnet::unescape($email);
+ $username = &HTML::Entities::encode($username,'<>&"');
+ $email = &HTML::Entities::encode($email,'<>&"');
+ $result .= '<recipient username="'.$username.'">'.
+ $email.'</recipient>';
+ } else {
+ $result .= '<recuser>'.$$recuser[$i].'</recuser>'.
+ '<recdomain>'.$$recdomain[$i].'</recdomain>';
+ }
}
} else {
$result .= '<recuser>'.$recuser.'</recuser>'.
@@ -211,6 +232,10 @@
my $value=$parser->get_text('/'.$entry);
if (($entry eq 'recuser') || ($entry eq 'recdomain')) {
push(@{$content{$entry}},$value);
+ } elsif ($entry eq 'recipient') {
+ my $username = $token->[2]{'username'};
+ $username = &HTML::Entities::decode($username,'<>&"');
+ $content{$entry}{$username} = $value;
} else {
$content{$entry}=$value;
}
--raeburn1134161666--