[LON-CAPA-cvs] cvs: loncom /interface lonmsg.pm lonmsgdisplay.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Tue, 01 May 2007 18:41:05 -0000
This is a MIME encoded message
--raeburn1178044865
Content-Type: text/plain
raeburn Tue May 1 14:41:05 2007 EDT
Modified files:
/loncom/interface lonmsg.pm lonmsgdisplay.pm
Log:
- Bug 3946. Messages sent with multiple recipients now included only once in "Sent Mail" folder, except when mode is "upload".
lonmsgdisplay.pm
- List of recipients included in message in "Sent Mail" folder for additional cases besides Critical and Broadcast.
- If a recipient has forwarding enabled, sender's record of recipients shows original recipient instead of the user account(s) to which it was forwarded.
lonmsg.pm
- Determination of course context of message moved to subroutine.
- User/domain of sent mail folder can be specified when storing sent mail.
--raeburn1178044865
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070501144105.txt"
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.200 loncom/interface/lonmsg.pm:1.201
--- loncom/interface/lonmsg.pm:1.200 Sun Apr 22 09:41:22 2007
+++ loncom/interface/lonmsg.pm Tue May 1 14:40:57 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.200 2007/04/22 13:41:22 raeburn Exp $
+# $Id: lonmsg.pm,v 1.201 2007/05/01 18:40:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -88,23 +88,7 @@
#remove machine specification
$attachmenturl =~ s|^http://[^/]+/|/|;
$attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
- my $course_context;
- if (defined($env{'form.replyid'})) {
- my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
- split(/\:/,&unescape($env{'form.replyid'}));
- $course_context = $origcid;
- }
- foreach my $key (keys(%env)) {
- if ($key=~/^form\.(rep)?rec\_(.*)$/) {
- my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
- split(/\:/,&unescape($2));
- $course_context = $origcid;
- last;
- }
- }
- unless(defined($course_context)) {
- $course_context = $env{'request.course.id'};
- }
+ my $course_context = &get_course_context();
my $now=time;
my $msgcount = &get_uniq();
unless(defined($msgid)) {
@@ -167,7 +151,7 @@
}
if (defined($symb)) {
$result.= '<symb>'.$symb.'</symb>';
- if (defined($course_context)) {
+ if ($course_context ne '') {
if ($course_context eq $env{'request.course.id'}) {
my $resource_title = &Apache::lonnet::gettitle($symb);
if (defined($resource_title)) {
@@ -179,6 +163,27 @@
return ($msgid,$result);
}
+sub get_course_context {
+ my $course_context;
+ if (defined($env{'form.replyid'})) {
+ my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
+ split(/\:/,&unescape($env{'form.replyid'}));
+ $course_context = $origcid;
+ }
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.(rep)?rec\_(.*)$/) {
+ my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
+ split(/\:/,&unescape($2));
+ $course_context = $origcid;
+ last;
+ }
+ }
+ if ($course_context eq '') {
+ $course_context = $env{'request.course.id'};
+ }
+ return $course_context;
+}
+
# ================================================== Unpack message into a hash
sub unpackagemsg {
@@ -430,13 +435,17 @@
my $cdom = $env{'course.'.$cid.'.domain'};
my $subject= &mt('Record').' ['.$uname.':'.$udom.']';
my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg);
+ if ($result eq 'ok' || $result eq 'con_delayed') {
+
+ }
return $result;
}
# ================================================== Critical message to a user
sub user_crit_msg_raw {
- my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
+ my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
+ $nosentstore)=@_;
# Check if allowed missing
my ($status,$packed_message);
my $msgid='undefined';
@@ -453,7 +462,7 @@
if (defined($sentmessage)) {
$$sentmessage = $packed_message;
}
- if ($env{'request.course.id'} eq '') {
+ if (!$nosentstore) {
(undef,my $packed_message_no_citation) =
&packagemsg($subject,$message,undef,undef,undef,$user,$domain,
$msgid);
@@ -490,9 +499,10 @@
=pod
-=item * B<user_crit_msg($user, $domain, $subject, $message, $sendback)>: Sends
- a critical message $message to the $user at $domain. If $sendback is true,
- a reciept will be sent to the current user when $user recieves the message.
+=item * B<user_crit_msg($user, $domain, $subject, $message, $sendback, $nosentstore)>:
+ Sends a critical message $message to the $user at $domain. If $sendback
+ is true, a receipt will be sent to the current user when $user receives
+ the message.
Additionally it will check if the user has a Forwarding address
set, and send the message to that address instead
@@ -505,7 +515,8 @@
=cut
sub user_crit_msg {
- my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
+ my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
+ $nosentstore)=@_;
my @status;
my %userenv = &Apache::lonnet::get('environment',['msgforward'],
$domain,$user);
@@ -515,12 +526,12 @@
my ($forwuser,$forwdomain)=split(/\:/,$addr);
push(@status,
&user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
- $sendback,$toperm,$sentmessage));
+ $sendback,$toperm,$sentmessage,$nosentstore));
}
} else {
push(@status,
&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
- $toperm,$sentmessage));
+ $toperm,$sentmessage,$nosentstore));
}
if (wantarray) {
return @status;
@@ -559,7 +570,7 @@
sub user_normal_msg_raw {
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
$toperm,$currid,$newid,$sentmessage,$crsmsgid,$symb,$restitle,
- $error)=@_;
+ $error,$nosentstore)=@_;
# Check if allowed missing
my ($status,$packed_message);
my $msgid='undefined';
@@ -580,17 +591,8 @@
# Save new message received time
&Apache::lonnet::put
('email_status',{'recnewemail'=>time},$domain,$user);
-# Into sent-mail folder unless a broadcast message or critical message
- unless (($env{'request.course.id'}) &&
- (($env{'form.courserecord'}) &&
- (&Apache::lonnet::allowed('dff',$env{'request.course.id'})
- || &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
- '/'.$env{'request.course.sec'}))) ||
- (($env{'form.sendmode'} eq 'group') ||
- (($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
- (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
- || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
- '/'.$env{'request.course.sec'})))) {
+# Into sent-mail folder if sent mail storage required
+ if (!$nosentstore) {
(undef,my $packed_message_no_citation) =
&packagemsg($subject,$message,undef,$baseurl,$attachmenturl,
$user,$domain,$currid,undef,$crsmsgid,$symb,$error);
@@ -598,10 +600,10 @@
&store_sent_mail($msgid,$packed_message_no_citation);
}
}
- if (defined($newid)) {
+ if (ref($newid) eq 'SCALAR') {
$$newid = $msgid;
}
- if (defined($sentmessage)) {
+ if (ref($sentmessage) eq 'SCALAR') {
$$sentmessage = $packed_message;
}
# Notifications
@@ -630,7 +632,8 @@
=pod
=item * B<user_normal_msg($user, $domain, $subject, $message, $citation,
- $baseurl, $attachmenturl, $toperm, $sentmessage, $symb, $restitle, $error)>:
+ $baseurl, $attachmenturl, $toperm, $sentmessage, $symb, $restitle,
+ $error,$nosentstore)>:
Sends a message to the $user at $domain, with subject $subject and message $message.
Additionally it will check if the user has a Forwarding address
@@ -645,7 +648,7 @@
sub user_normal_msg {
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
- $toperm,$sentmessage,$symb,$restitle,$error)=@_;
+ $toperm,$sentmessage,$symb,$restitle,$error,$nosentstore)=@_;
my @status;
my %userenv = &Apache::lonnet::get('environment',['msgforward'],
$domain,$user);
@@ -656,12 +659,14 @@
push(@status,
&user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
$citation,$baseurl,$attachmenturl,$toperm,
- undef,undef,$sentmessage,undef,$symb,$restitle,$error));
+ undef,undef,$sentmessage,undef,$symb,
+ $restitle,$error,$nosentstore));
}
} else {
push(@status,&user_normal_msg_raw($user,$domain,$subject,$message,
$citation,$baseurl,$attachmenturl,$toperm,
- undef,undef,$sentmessage,undef,$symb,$restitle,$error));
+ undef,undef,$sentmessage,undef,$symb,
+ $restitle,$error,$nosentstore));
}
if (wantarray) {
return @status;
@@ -669,13 +674,37 @@
return join(' ',@status);
}
+sub process_sent_mail {
+ my ($msgsubj,$subj_prefix,$numsent,$stamp,$msgname,$msgdom,$msgcount,$context,$pid,$savemsg,$recusers,$recudoms,$baseurl,$attachmenturl,$symb,$error,$senderuname,$senderdom,$senderhome) = @_;
+ my $sentsubj;
+ if ($numsent > 1) {
+ $sentsubj = $subj_prefix.' ('.$numsent.' sent) '.$msgsubj;
+ }
+ $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
+ my $sentmsgid =
+ &buildmsgid($stamp,$sentsubj,$msgname,$msgdom,$msgcount,$context,$pid);
+ (undef,my $sentmessage) =
+ &packagemsg($msgsubj,$savemsg,undef,$baseurl,$attachmenturl,$recusers,
+ $recudoms,$sentmsgid,undef,undef,$symb,$error);
+ my $status = &store_sent_mail($sentmsgid,$sentmessage,$senderuname,
+ $senderdom,$senderhome);
+ return $status;
+}
+
sub store_sent_mail {
- my ($msgid,$message) = @_;
+ my ($msgid,$message,$senderuname,$senderdom,$senderhome) = @_;
+ if ($senderuname eq '') {
+ $senderuname = $env{'user.name'};
+ }
+ if ($senderdom eq '') {
+ $senderdom = $env{'user.domain'};
+ }
+ if ($senderhome eq '') {
+ $senderhome = $env{'user.home'};
+ }
my $status =' '.&Apache::lonnet::critical(
- 'put:'.$env{'user.domain'}.':'.$env{'user.name'}.
- ':nohist_email_sent:'.
- &escape($msgid).'='.
- &escape($message),$env{'user.home'});
+ 'put:'.$senderdom.':'.$senderuname.':nohist_email_sent:'.
+ &escape($msgid).'='.&escape($message),$senderhome);
return $status;
}
Index: loncom/interface/lonmsgdisplay.pm
diff -u loncom/interface/lonmsgdisplay.pm:1.70 loncom/interface/lonmsgdisplay.pm:1.71
--- loncom/interface/lonmsgdisplay.pm:1.70 Sun Apr 22 09:41:22 2007
+++ loncom/interface/lonmsgdisplay.pm Tue May 1 14:40:57 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging display
#
-# $Id: lonmsgdisplay.pm,v 1.70 2007/04/22 13:41:22 raeburn Exp $
+# $Id: lonmsgdisplay.pm,v 1.71 2007/05/01 18:40:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1229,14 +1229,16 @@
'<p><label><input type="checkbox" name="rsspost" /> '.
&mt('Include in course RSS newsfeed').'</label></p>';
}
- if (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) ||
- &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
- '/'.$env{'request.course.sec'})) {
-
- $dispcrit.='<p><label>'.
- '<input type="checkbox" name="courserecord" value="1" /> '.
- &mt("Include in course's 'User records' for recipient(s)").
- '</label></p>';
+ if ($broadcast ne 'group') {
+ if (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) ||
+ &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
+ '/'.$env{'request.course.sec'})) {
+
+ $dispcrit.='<p><label>'.
+ '<input type="checkbox" name="courserecord" value="1" /> '.
+ &mt("Include in course's 'User records' for recipient(s)").
+ '</label></p>';
+ }
}
my %message;
@@ -2228,8 +2230,9 @@
my ($r,$folder)=@_;
my $suffix=&Apache::lonmsg::foldersuffix($folder);
my $sendstatus='';
- my %specialmsg_status;
- my $numspecial = 0;
+ my %msg_status;
+ my $numsent = 0;
+ my $nosentstore = 1;
my ($cdom,$cnum,$group);
if (exists($env{'form.group'})) {
$group = $env{'form.group'};
@@ -2286,6 +2289,7 @@
}
}
} elsif ($env{'form.sendmode'} eq 'upload') {
+ $nosentstore = 0;
foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
if ($txt) {
@@ -2323,7 +2327,8 @@
} else {
$savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
}
-
+ my @recusers;
+ my @recudoms;
foreach my $address (sort(keys(%toaddr))) {
my ($recuname,$recdomain)=split(/\:/,$address);
my $msgtxt = $savemsg;
@@ -2337,7 +2342,8 @@
$msgsubj,$msgtxt,
$env{'form.sendbck'},
$env{'form.permanent'},
- \$sentmessage{$address});
+ \$sentmessage{$address},
+ $nosentstore);
} else {
$r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
@thismsg=
@@ -2346,101 +2352,93 @@
$content{'citation'},
undef,undef,
$env{'form.permanent'},
- \$sentmessage{$address});
- }
- if (($env{'request.course.id'}) &&
- (($msgtype eq 'critical') ||
- ($env{'form.sendmode'} eq 'group') ||
- ($env{'form.courserecord'}))) {
- $specialmsg_status{$recuname.':'.$recdomain} =
- join(' ',@thismsg);
- foreach my $result (@thismsg) {
- if ($result eq 'ok' || $result eq 'con_delayed') {
- $numspecial++;
- }
- }
+ \$sentmessage{$address},
+ undef,undef,undef,
+ $nosentstore);
+ }
+ $msg_status{$recuname.':'.$recdomain}=join(' ',@thismsg);
+ if ($msg_status{$recuname.':'.$recdomain} =~ /(ok|con_delayed)/) {
+ $numsent++;
+ push(@recusers,$recuname);
+ push(@recudoms,$recdomain);
}
$sendstatus.=' '.join(' ',@thismsg);
}
- if (($env{'request.course.id'}) &&
- (($env{'form.sendmode'} eq 'group') ||
- ($env{'form.courserecord'}) ||
- ($msgtype eq 'critical'))) {
- my $subj_prefix;
- if ($msgtype eq 'critical') {
- $subj_prefix = 'Critical.';
- } elsif ($env{'form.sendmode'} eq 'group') {
- $subj_prefix = 'Broadcast.';
- } else {
- $subj_prefix = 'Archive';
- }
- my ($specialmsgid,$specialresult);
- my $course_str = &escape('['.$cnum.':'.$cdom.']');
+ my $subj_prefix;
+ if ($numsent > 0) {
+ if (($env{'request.course.id'}) &&
+ (($env{'form.sendmode'} eq 'group') ||
+ ($env{'form.courserecord'}) ||
+ ($msgtype eq 'critical'))) {
+ if ($msgtype eq 'critical') {
+ $subj_prefix = 'Critical.';
+ } elsif ($env{'form.sendmode'} eq 'group') {
+ $subj_prefix = 'Broadcast.';
+ } else {
+ $subj_prefix = 'Archive';
+ }
+ my ($specialmsgid,$specialresult);
+ my $course_str = &escape('['.$cnum.':'.$cdom.']');
- if ($numspecial) {
- $specialresult = &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
- ' '.$course_str,$savemsg,undef,undef,undef,
- undef,undef,\$specialmsgid);
+ $specialresult =
+ &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
+ $subj_prefix.' '.$course_str,$savemsg,undef,undef,
+ undef,undef,undef,\$specialmsgid,undef,undef,undef,
+ undef,undef,1);
$specialmsgid = &unescape($specialmsgid);
- }
- if ($specialresult eq 'ok') {
- my $record_sent;
- my @recusers;
- my @recudoms;
- my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
- split(/\:/,&unescape($specialmsgid));
-
- foreach my $recipient (sort(keys(%toaddr))) {
- if ($specialmsg_status{$recipient} =~ /\s*(ok|con_delayed)\s*/) {
- my $usersubj = $subj_prefix.'['.$recipient.']';
- my $usermsgid =
- &Apache::lonmsg::buildmsgid($stamp,$usersubj,
- $msgname,$msgdom,
- $msgcount,$context,
- $pid);
- &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
- ' ['.$recipient.']',$msgsubj,undef,
- undef,undef,undef,$usermsgid,undef,undef,$specialmsgid);
- my ($uname,$udom) = split(/:/,$recipient);
- push(@recusers,$uname);
- push(@recudoms,$udom);
+ if ($specialresult eq 'ok') {
+ my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
+ split(/\:/,&unescape($specialmsgid));
+
+ foreach my $recipient (sort(keys(%toaddr))) {
+ if ($msg_status{$recipient} =~ /\s*(ok|con_delayed)\s*/) {
+ my $usersubj = $subj_prefix.'['.$recipient.']';
+ my $usermsgid =
+ &Apache::lonmsg::buildmsgid($stamp,$usersubj,
+ $msgname,$msgdom,
+ $msgcount,$context,
+ $pid);
+ &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
+ $subj_prefix.' ['.$recipient.']',$msgsubj,
+ undef,undef,undef,undef,$usermsgid,undef,
+ undef,$specialmsgid,undef,undef,undef,1);
+ }
}
- }
- if (@recusers) {
- my $specialmessage;
- my $sentsubj =
- $subj_prefix.' ('.$numspecial.' sent) '.$msgsubj;
- $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
- my $sentmsgid =
- &Apache::lonmsg::buildmsgid($stamp,$sentsubj,$msgname,
- $msgdom,$msgcount,$context,
- $pid);
- ($specialmsgid,$specialmessage) = &Apache::lonmsg::packagemsg($msgsubj,$savemsg,
- undef,undef,undef,\@recusers,\@recudoms,$sentmsgid);
- $record_sent = &Apache::lonmsg::store_sent_mail($specialmsgid,$specialmessage);
+ if (($env{'form.sendmode'} ne 'upload') && (@recusers > 0)) {
+ &Apache::lonmsg::process_sent_mail($msgsubj,
+ $subj_prefix,$numsent,$stamp,$msgname,$msgdom,
+ $msgcount,$context,$pid,$savemsg,\@recusers,
+ \@recudoms);
+ }
+ } else {
+ &Apache::lonnet::logthis('Failed to create record of critical, broadcast or archived message in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' at '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated');
}
} else {
- &Apache::lonnet::logthis('Failed to create record of critical message or broadcast in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' at '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated');
+ my $stamp = time;
+ my $msgcount = &Apache::lonmsg::get_uniq();
+ my $context = &Apache::lonmsg::get_course_context();
+ &Apache::lonmsg::process_sent_mail($msgsubj,$subj_prefix,
+ $numsent,$stamp,$env{'user.name'},
+ $env{'user.domain'},$msgcount,$context,
+ $$,$savemsg,\@recusers,\@recudoms);
}
}
- } else {
- &printheader($r,'','No messages sent.');
- }
- if (!$env{'form.multiforward'}) {
- if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
- $r->print('<br /><span class="LC_success">'.&mt('Completed.').
- '</span>');
- if ($env{'form.displayedcrit'}) {
- &discrit($r);
+ if (!$env{'form.multiforward'}) {
+ if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
+ $r->print('<br /><span class="LC_success">'.&mt('Completed.').
+ '</span>');
+ if ($env{'form.displayedcrit'}) {
+ &discrit($r);
+ }
+ if ($group ne '') {
+ $r->print(&groupmail_sent($group,$cdom,$cnum));
+ } else {
+ &Apache::loncommunicate::menu($r);
+ }
+ } else {
+ $r->print('<p><span class="LC_error">'.&mt('Could not deliver message').'</span> '.
+ &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'</p>');
}
- if ($group ne '') {
- $r->print(&groupmail_sent($group,$cdom,$cnum));
- } else {
- &Apache::loncommunicate::menu($r);
- }
- } else {
- $r->print('<p><span class="LC_error">'.&mt('Could not deliver message').'</span> '.
- &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'</p>');
}
}
return $sendstatus;
--raeburn1178044865--