--- loncom/interface/lonnotify.pm 2005/12/09 00:08:35 1.9 +++ loncom/interface/lonnotify.pm 2005/12/09 20:54:26 1.10 @@ -274,13 +274,13 @@ $breadcrumbs 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 @@ ENDONE 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 .= ''.$date.''.&cr_to_br($dcmail{$msgid}{subject}).''.$sname.':'.$sdom.''.&cr_to_br($dcmail{$msgid}{message}).''.$recipients.''."\n"; @@ -324,8 +324,8 @@ ENDONE 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 @@ ENDONE 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 @@ ENDONE $output .= qq(\n); $output .= qq( - +); $r->print($output); return; @@ -758,7 +758,6 @@ ENDONE '; - &store_mail($subject,$message,$dom,\@deliveries); } else { $output .= 'No mail sent - no recipients identified'; } @@ -842,8 +841,9 @@ sub form_elements { 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 store_mail { } } -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=''.$env{'user.name'}.''. - ''.$env{'user.domain'}.''. - ''. - ''.$ENV{'SERVER_NAME'}.''. - ''.$ENV{'HTTP_HOST'}.''. - ''.$ENV{'REMOTE_ADDR'}.''. - ''.$msgid.''. - ''.$dom.''. - ''.$subject.''. - ''.$message.''."\n"; - if (defined($attachmenturl)) { - $result.= ''.$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 .= ''. - $email.''; - } - 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'}.='

'.&mt('Attachment').': '.$fname.''; } else { - &Apache::lonnet::allowuploaded('/adm/notify', - $content{'attachmenturl'}); - $content{'message'}.='

'.&mt('Attachment'). - ': '. - $fname.''; - } - } - return %content; -} - sub cr_to_br { my $incoming = shift; $incoming =~ s/\n/\
/g;