--- loncom/interface/lonmsg.pm 2015/06/18 21:42:37 1.240 +++ loncom/interface/lonmsg.pm 2018/12/27 18:14:25 1.244 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.240 2015/06/18 21:42:37 musolffc Exp $ +# $Id: lonmsg.pm,v 1.244 2018/12/27 18:14:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -200,9 +200,9 @@ Returns use strict; use Apache::lonnet; +use Apache::loncommon; use HTML::TokeParser(); use Apache::lonlocal; -use MIME::Entity; use HTML::Entities; use Encode; use LONCAPA qw(:DEFAULT :match); @@ -397,14 +397,17 @@ sub buildmsgid { } sub unpackmsgid { - my ($msgid,$folder,$skipstatus,$status_cache)=@_; + my ($msgid,$folder,$skipstatus,$status_cache,$onlycid)=@_; $msgid=&unescape($msgid); my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid, $processid,$symb,$error) = split(/\:/,&unescape($msgid)); + if (!defined($processid)) { $fromcid = ''; } + if (($onlycid) && ($onlycid ne $fromcid)) { + return ($sendtime,'',$fromname,$fromdomain,'',$fromcid,'',$error); + } $shortsubj = &unescape($shortsubj); $shortsubj = &HTML::Entities::decode($shortsubj); $symb = &unescape($symb); - if (!defined($processid)) { $fromcid = ''; } my %status=(); unless ($skipstatus) { if (ref($status_cache)) { @@ -460,20 +463,15 @@ sub sendemail { $attachmenturl = &Apache::lonnet::filelocation("",$attachmenturl); my $filesize = (stat($attachmenturl))[7]; if ($filesize > 1048576) { + # Don't send if it exceeds 1 MB. print '

' .&mt('Email not sent. Attachment exceeds permitted length.') .'

'; } else { - my $top = MIME::Entity->build( Type => "multipart/mixed", - From => $senderaddress, - To => $to, - Subject => '[LON-CAPA] '.$subject); - $top->attach(Data=>$body); - $top->attach(Path=>$attachmenturl); - - open MAIL, "| /usr/lib/sendmail -t -oi -oem" or die "open: $!"; - $top->print(\*MAIL); - close MAIL; + # Otherwise build and send the email + $subject = '[LON-CAPA] '.$subject; + &Apache::loncommon::mime_email($senderaddress, $to, $subject, $body, ,'', + '', $attachmenturl, '', ''); $msgsent = 1; } return $msgsent; @@ -493,9 +491,10 @@ sub sendnotification { $text=~s/\<\;/\/gs; my $homeserver = &Apache::lonnet::homeserver($touname,$toudom); + my $hostname = &Apache::lonnet::hostname($homeserver); my $protocol = $Apache::lonnet::protocol{$homeserver}; $protocol = 'http' if ($protocol ne 'https'); - my $url = $protocol.'://'.&Apache::lonnet::hostname($homeserver). + my $url = $protocol.'://'.$hostname. '/adm/email?username='.$touname.'&domain='.$toudom. '&display='.&escape($msgid); my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,