version 1.221, 2009/01/05 20:04:40
|
version 1.235, 2013/07/24 18:21:39
|
Line 194 Returns
|
Line 194 Returns
|
%to - a hash, which keys are addresses of users to send messages to |
%to - a hash, which keys are addresses of users to send messages to |
the keys will look like name:domain |
the keys will look like name:domain |
|
|
=item user_lang() |
|
|
|
=back |
=back |
|
|
=cut |
=cut |
Line 205 use Apache::lonnet;
|
Line 203 use Apache::lonnet;
|
use HTML::TokeParser(); |
use HTML::TokeParser(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
use Mail::Send; |
use Mail::Send; |
|
use HTML::Entities; |
|
use Encode; |
use LONCAPA qw(:DEFAULT :match); |
use LONCAPA qw(:DEFAULT :match); |
|
|
{ |
{ |
Line 455 sub sendemail {
|
Line 455 sub sendemail {
|
"*** ".&mt_user($user_lh,'This is an automatic e-mail generated by the LON-CAPA system.')."\n". |
"*** ".&mt_user($user_lh,'This is an automatic e-mail generated by the LON-CAPA system.')."\n". |
"*** ".($senderaddress?&mt_user($user_lh,'You can reply to this e-mail'):&mt_user($user_lh,'Please do not reply to this address.')."\n*** ". |
"*** ".($senderaddress?&mt_user($user_lh,'You can reply to this e-mail'):&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; |
my $msg = new Mail::Send; |
$msg->to($to); |
$msg->to($to); |
$msg->subject('[LON-CAPA] '.$subject); |
$msg->subject('[LON-CAPA] '.$subject); |
Line 464 sub sendemail {
|
Line 465 sub sendemail {
|
if ($senderaddress) { |
if ($senderaddress) { |
$msg->add('From',$senderaddress); |
$msg->add('From',$senderaddress); |
} |
} |
|
$msg->add('Content-type','text/plain; charset=UTF-8'); |
if (my $fh = $msg->open()) { |
if (my $fh = $msg->open()) { |
print $fh $body; |
print $fh $body; |
$fh->close; |
$fh->close; |
Line 486 sub sendnotification {
|
Line 488 sub sendnotification {
|
my $protocol = $Apache::lonnet::protocol{$homeserver}; |
my $protocol = $Apache::lonnet::protocol{$homeserver}; |
$protocol = 'http' if ($protocol ne 'https'); |
$protocol = 'http' if ($protocol ne 'https'); |
my $url = $protocol.'://'.&Apache::lonnet::hostname($homeserver). |
my $url = $protocol.'://'.&Apache::lonnet::hostname($homeserver). |
'/adm/email?username='.$touname.'&domain='.$toudom; |
'/adm/email?username='.$touname.'&domain='.$toudom. |
|
'&display='.&escape($msgid); |
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid, |
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid, |
$symb,$error) = &Apache::lonmsg::unpackmsgid($msgid); |
$symb,$error) = &Apache::lonmsg::unpackmsgid($msgid); |
my ($coursetext,$body,$bodybegin,$bodysubj,$bodyend); |
my ($coursetext,$body,$bodybegin,$bodysubj,$bodyend); |
my $user_lh = &user_lang($touname,$toudom,$fromcid); |
my $user_lh = &Apache::loncommon::user_lang($touname,$toudom,$fromcid); |
if ($fromcid ne '') { |
if ($fromcid ne '') { |
$coursetext = "\n".&mt_user($user_lh,'Course').': '; |
$coursetext = "\n".&mt_user($user_lh,'Course').': '; |
if ($env{'course.'.$fromcid.'.description'} ne '') { |
if ($env{'course.'.$fromcid.'.description'} ne '') { |
Line 523 sub sendnotification {
|
Line 526 sub sendnotification {
|
|
|
to access the full message.',$url); |
to access the full message.',$url); |
my %userenv = &Apache::lonnet::get('environment',['notifywithhtml'],$toudom,$touname); |
my %userenv = &Apache::lonnet::get('environment',['notifywithhtml'],$toudom,$touname); |
my $subject = &mt_user($user_lh,"'New' $critical message from ").$sender; |
my $subject = &mt_user($user_lh,"'New'$critical message from [_1]",$sender); |
|
unless ($subj eq '') { |
|
$subject = $subj; |
|
} |
|
|
my ($blocked,$blocktext); |
my ($blocked,$blocktext); |
if (!$crit) { |
if (!$crit) { |
Line 539 to access the full message.',$url);
|
Line 545 to access the full message.',$url);
|
} |
} |
if ($userenv{'notifywithhtml'} ne '') { |
if ($userenv{'notifywithhtml'} ne '') { |
my @htmlexcerpt = split(/,/,$userenv{'notifywithhtml'}); |
my @htmlexcerpt = split(/,/,$userenv{'notifywithhtml'}); |
|
my $htmlfree = &make_htmlfree($text); |
foreach my $addr (@recipients) { |
foreach my $addr (@recipients) { |
if ($blocked) { |
if ($blocked) { |
$body = $bodybegin."\n".$blocktext."\n".$bodyend; |
$body = $bodybegin."\n".$blocktext."\n".$bodyend; |
} else { |
} else { |
my $sendtext = $text; |
my $sendtext; |
if (!grep/^\Q$addr\E/,@htmlexcerpt) { |
if (!grep/^\Q$addr\E/,@htmlexcerpt) { |
$sendtext =~ s/\<\/*[^\>]+\>//gs; |
$sendtext = $htmlfree; |
|
} else { |
|
$sendtext = $text; |
} |
} |
$body = $bodybegin.$bodysubj.$sendtext.$bodyend; |
$body = $bodybegin.$bodysubj.$sendtext.$bodyend; |
} |
} |
Line 555 to access the full message.',$url);
|
Line 564 to access the full message.',$url);
|
if ($blocked) { |
if ($blocked) { |
$body = $bodybegin."\n".$blocktext."\n".$bodyend; |
$body = $bodybegin."\n".$blocktext."\n".$bodyend; |
} else { |
} else { |
$text =~ s/\<\/*[^\>]+\>//gs; |
my $htmlfree = &make_htmlfree($text); |
$body = $bodybegin.$bodysubj.$text.$bodyend; |
$body = $bodybegin.$bodysubj.$htmlfree.$bodyend; |
} |
} |
&sendemail($to,$subject,$body,$touname,$toudom,$user_lh); |
&sendemail($to,$subject,$body,$touname,$toudom,$user_lh); |
} |
} |
} |
} |
|
|
|
sub make_htmlfree { |
|
my ($text) = @_; |
|
$text =~ s/\<\/*[^\>]+\>//gs; |
|
$text = &HTML::Entities::decode($text); |
|
$text = &Encode::encode('utf8',$text); |
|
return $text; |
|
} |
|
|
|
sub mynewmail{ |
|
&newmail(); |
|
return $env{'user.mailcheck.lastnewmessagetime'} > $env{'user.mailcheck.lastvisit'}; |
|
} |
|
|
|
|
sub newmail { |
sub newmail { |
if ((time-$env{'user.mailcheck.time'})>300) { |
if ((time-$env{'user.mailcheck.time'})>300) { |
my %what=&Apache::lonnet::get('email_status',['recnewemail']); |
my %what=&Apache::lonnet::get('email_status',['recnewemail']); |
&Apache::lonnet::appenv({'user.mailcheck.time'=>time}); |
&Apache::lonnet::appenv({'user.mailcheck.time'=>time}); |
|
&Apache::lonnet::appenv({'user.mailcheck.lastnewmessagetime'=> $what{'recnewemail'}}); |
if ($what{'recnewemail'}>0) { return 1; } |
if ($what{'recnewemail'}>0) { return 1; } |
} |
} |
return 0; |
return 0; |
Line 966 sub secapply {
|
Line 989 sub secapply {
|
my $rec=shift; |
my $rec=shift; |
my $defaultflag=shift; |
my $defaultflag=shift; |
$rec=~s/\s+//g; |
$rec=~s/\s+//g; |
$rec=~s/\@/\:/g; |
unless ($rec =~ /\:/) { |
|
$rec=~s/\@/\:/g; |
|
} |
my ($adr,$sections_or_groups)=($rec=~/^([^\(]+)\(([^\)]+)\)/); |
my ($adr,$sections_or_groups)=($rec=~/^([^\(]+)\(([^\)]+)\)/); |
if ($sections_or_groups) { |
if ($sections_or_groups) { |
foreach my $item (split(/\;/,$sections_or_groups)) { |
foreach my $item (split(/\;/,$sections_or_groups)) { |
Line 1025 sub decide_receiver {
|
Line 1050 sub decide_receiver {
|
return ($typestyle,%to); |
return ($typestyle,%to); |
} |
} |
|
|
sub user_lang { |
|
my ($touname,$toudom,$fromcid) = @_; |
|
my @userlangs; |
|
if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) { |
|
@userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/, |
|
$env{'course.'.$fromcid.'.languages'})); |
|
} else { |
|
my %langhash = &Apache::loncommon::getlangs($touname,$toudom); |
|
if ($langhash{'languages'} ne '') { |
|
@userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'}); |
|
} else { |
|
my %domdefs = &Apache::lonnet::get_domain_defaults($toudom); |
|
if ($domdefs{'lang_def'} ne '') { |
|
@userlangs = ($domdefs{'lang_def'}); |
|
} |
|
} |
|
} |
|
my @languages=&Apache::lonlocal::get_genlanguages(@userlangs); |
|
my $user_lh = Apache::localize->get_handle(@languages); |
|
return $user_lh; |
|
} |
|
|
|
1; |
1; |
__END__ |
__END__ |
|
|