version 1.8, 2005/11/15 21:08:47
|
version 1.10, 2005/12/09 20:54:26
|
Line 273 $breadcrumbs
|
Line 273 $breadcrumbs
|
<form method="post" name="$formname"> |
<form method="post" name="$formname"> |
ENDONE |
ENDONE |
|
|
foreach my $server (keys(%sentmail)) { |
foreach my $msgid (keys(%sentmail)) { |
foreach my $msgid (keys(%{$sentmail{$server}})) { |
my %content = &Apache::lonmsg::unpackagemsg($sentmail{$msgid}); |
my %content = &unpackagemail($sentmail{$server}{$msgid}); |
$msgcount ++; |
if (defined($dcmail{$msgid})) { |
%{$dcmail{$msgid}} = (); |
foreach my $user (keys(%{$content{'recipients'}})) { |
foreach my $item (keys(%content)) { |
$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 { |
} else { |
$msgcount ++; |
$dcmail{$msgid}{$item} = $content{$item}; |
%{$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}; |
|
} |
|
} |
|
} |
} |
} |
} |
} |
} |
Line 316 ENDONE
|
Line 308 ENDONE
|
my $recipients = ''; |
my $recipients = ''; |
my ($date,$subj,$sname,$sdom,$cdom) = split(/:/,$msgid,5); |
my ($date,$subj,$sname,$sdom,$cdom) = split(/:/,$msgid,5); |
$date = &Apache::lonlocal::locallocaltime($date); |
$date = &Apache::lonlocal::locallocaltime($date); |
foreach my $user (sort(keys(%{$dcmail{$msgid}{recipients}}))) { |
foreach my $user (sort(keys(%{$dcmail{$msgid}{recipient}}))) { |
$recipients .= $dcmail{$msgid}{recipients}{$user}.', '; |
$recipients .= $dcmail{$msgid}{recipient}{$user}.', '; |
} |
} |
$recipients =~ s/,\s$//; |
$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"; |
$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"; |
Line 332 ENDONE
|
Line 324 ENDONE
|
push @{$Sortby{$dcmail{$msgid}{message}}},$msgid; |
push @{$Sortby{$dcmail{$msgid}{message}}},$msgid; |
} elsif ($env{'form.sortby'} eq 'recipients') { |
} elsif ($env{'form.sortby'} eq 'recipients') { |
my $recipients =''; |
my $recipients =''; |
foreach my $user (sort(keys(%{$dcmail{$msgid}{recipients}}))) { |
foreach my $user (sort(keys(%{$dcmail{$msgid}{recipient}}))) { |
$recipients .= $dcmail{$msgid}{recipients}{$user}.', '; |
$recipients .= $dcmail{$msgid}{recipient}{$user}.', '; |
} |
} |
$recipients =~ s/,\s$//; |
$recipients =~ s/,\s$//; |
push @{$Sortby{$recipients}},$msgid; |
push @{$Sortby{$recipients}},$msgid; |
Line 354 ENDONE
|
Line 346 ENDONE
|
if ($env{'form.sortby'} eq 'recipients') { |
if ($env{'form.sortby'} eq 'recipients') { |
$recipients = $key; |
$recipients = $key; |
} else { |
} else { |
foreach my $user (sort(keys(%{$dcmail{$msgid}{recipients}}))) { |
foreach my $user (sort(keys(%{$dcmail{$msgid}{recipient}}))) { |
$recipients .= $dcmail{$msgid}{recipients}{$user}.', '; |
$recipients .= $dcmail{$msgid}{recipient}{$user}.', '; |
} |
} |
$recipients =~ s/,\s$//; |
$recipients =~ s/,\s$//; |
} |
} |
Line 384 ENDONE
|
Line 376 ENDONE
|
$output .= qq(<input type="hidden" name="sortby" value="$curr_sortby" />\n); |
$output .= qq(<input type="hidden" name="sortby" value="$curr_sortby" />\n); |
$output .= qq( |
$output .= qq( |
</form> |
</form> |
</body> |
</body |
</html>); |
</html>); |
$r->print($output); |
$r->print($output); |
return; |
return; |
Line 766 ENDONE
|
Line 758 ENDONE
|
</table> |
</table> |
</td> |
</td> |
</tr>'; |
</tr>'; |
&store_mail($subject,$message,$dom,\@deliveries); |
|
} else { |
} else { |
$output .= 'No mail sent - no recipients identified'; |
$output .= 'No mail sent - no recipients identified'; |
} |
} |
Line 849 sub form_elements {
|
Line 840 sub form_elements {
|
|
|
sub store_mail { |
sub store_mail { |
my ($subject,$message,$domain,$recipients,$attachmenturl,$ltext) = @_; |
my ($subject,$message,$domain,$recipients,$attachmenturl,$ltext) = @_; |
my %servers = (); |
my $msgid; |
my $msgid=&packagemail($subject,$message,$domain, |
($msgid,$message) = &Apache::lonmsg::packagemsg($subject,$message,undef,undef, |
$recipients,\%servers,$attachmenturl); |
$attachmenturl,$recipients,undef,undef,'dcmail'); |
# Store in dc email db files on appropriate servers. |
|
foreach my $server (keys(%servers)) { |
# Store in dc email db files on primary library server for domain. |
unless (&Apache::lonnet::dcmailput($domain,$msgid,\%servers,$server) eq 'ok') { |
my $server = $Apache::lonnet::domain_primary{$domain}; |
&Apache::lonnet::logthis('Storage of dc mail failed for domain'.$domain.' for server: '. |
if (defined($server)) { |
$server.'. Message ID was '.$msgid); |
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); |
|
|
sub packagemail { |
|
my ($subject,$message,$dom,$recipients,$servers,$attachmenturl,$ltext) = @_; |
|
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); |
|
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.'">'. |
|
$email.'</recipient>'; |
|
} |
|
} |
|
foreach my $server (keys(%record)) { |
|
$$servers{$server} = $result.$record{$server}; |
|
} |
|
return $msgid; |
|
} |
|
|
|
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>'; |
|
} |
} |
|
} else { |
|
&Apache::lonnet::logthis('Storage of dc mail failed for domain'. |
|
$domain.' as no primary server identified. Message ID was '.$msgid); |
} |
} |
return %content; |
|
} |
} |
|
|
sub cr_to_br { |
sub cr_to_br { |