--- loncom/interface/lonmsg.pm 2007/04/22 13:41:22 1.200
+++ loncom/interface/lonmsg.pm 2007/05/02 20:26:08 1.203
@@ -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.203 2007/05/02 20:26:08 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -78,7 +78,7 @@ use LONCAPA qw(:DEFAULT :match);
sub packagemsg {
my ($subject,$message,$citation,$baseurl,$attachmenturl,
- $recuser,$recdomain,$msgid,$type,$crsmsgid,$symb,$error)=@_;
+ $recuser,$recdomain,$msgid,$type,$crsmsgid,$symb,$error,$recipid)=@_;
$message =&HTML::Entities::encode($message,'<>&"');
$citation=&HTML::Entities::encode($citation,'<>&"');
$subject =&HTML::Entities::encode($subject,'<>&"');
@@ -88,23 +88,7 @@ sub packagemsg {
#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 @@ sub packagemsg {
}
if (defined($symb)) {
$result.= ''.$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)) {
@@ -176,9 +160,33 @@ sub packagemsg {
}
}
}
+ if (defined($recipid)) {
+ $result.= ''.$recipid.'';
+ }
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 +438,17 @@ sub store_instructor_comment {
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,$recipid)=@_;
# Check if allowed missing
my ($status,$packed_message);
my $msgid='undefined';
@@ -444,7 +456,9 @@ sub user_crit_msg_raw {
my $text=$message;
my $homeserver=&Apache::lonnet::homeserver($user,$domain);
if ($homeserver ne 'no_host') {
- ($msgid,$packed_message)=&packagemsg($subject,$message);
+ ($msgid,$packed_message)=&packagemsg($subject,$message,undef,undef,
+ undef,undef,undef,undef,undef,undef,undef,
+ undef,$recipid);
if ($sendback) { $packed_message.='true'; }
$status=&Apache::lonnet::critical(
'put:'.$domain.':'.$user.':critical:'.
@@ -453,7 +467,7 @@ sub user_crit_msg_raw {
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 +504,10 @@ sub user_crit_msg_raw {
=pod
-=item * B: 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:
+ 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 +520,8 @@ sub user_crit_msg_raw {
=cut
sub user_crit_msg {
- my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
+ my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
+ $nosentstore,$recipid)=@_;
my @status;
my %userenv = &Apache::lonnet::get('environment',['msgforward'],
$domain,$user);
@@ -515,12 +531,13 @@ sub user_crit_msg {
my ($forwuser,$forwdomain)=split(/\:/,$addr);
push(@status,
&user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
- $sendback,$toperm,$sentmessage));
+ $sendback,$toperm,$sentmessage,$nosentstore,
+ $recipid));
}
} else {
push(@status,
&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
- $toperm,$sentmessage));
+ $toperm,$sentmessage,$nosentstore,$recipid));
}
if (wantarray) {
return @status;
@@ -559,7 +576,7 @@ sub user_crit_received {
sub user_normal_msg_raw {
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
$toperm,$currid,$newid,$sentmessage,$crsmsgid,$symb,$restitle,
- $error)=@_;
+ $error,$nosentstore,$recipid)=@_;
# Check if allowed missing
my ($status,$packed_message);
my $msgid='undefined';
@@ -570,7 +587,7 @@ sub user_normal_msg_raw {
($msgid,$packed_message)=
&packagemsg($subject,$message,$citation,$baseurl,
$attachmenturl,$user,$domain,$currid,
- undef,$crsmsgid,$symb,$error);
+ undef,$crsmsgid,$symb,$error,$recipid);
# Store in user folder
$status=&Apache::lonnet::critical(
@@ -580,17 +597,8 @@ sub user_normal_msg_raw {
# 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 +606,10 @@ sub user_normal_msg_raw {
&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 +638,8 @@ sub user_normal_msg_raw {
=pod
=item * B:
+ $baseurl, $attachmenturl, $toperm, $sentmessage, $symb, $restitle,
+ $error,$nosentstore,$recipid)>:
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 +654,7 @@ sub user_normal_msg_raw {
sub user_normal_msg {
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
- $toperm,$sentmessage,$symb,$restitle,$error)=@_;
+ $toperm,$sentmessage,$symb,$restitle,$error,$nosentstore,$recipid)=@_;
my @status;
my %userenv = &Apache::lonnet::get('environment',['msgforward'],
$domain,$user);
@@ -656,12 +665,14 @@ sub user_normal_msg {
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,$recipid));
}
} 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,$recipid));
}
if (wantarray) {
return @status;
@@ -669,16 +680,59 @@ sub user_normal_msg {
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;
}
+sub store_recipients {
+ my ($subject,$sendername,$senderdom,$reciphash) = @_;
+ my $context = &get_course_context();
+ my $now = time();
+ my $msgcount = &get_uniq();
+ my $recipid =
+ &buildmsgid($now,$subject,$sendername,$senderdom,$msgcount,$context,$$);
+ my %recipinfo = (
+ $recipid => $reciphash,
+ );
+ my $status = &Apache::lonnet::put('nohist_emailrecip',\%recipinfo,
+ $senderdom,$sendername);
+ if ($status eq 'ok') {
+ return ($recipid,$status);
+ } else {
+ return (undef,$status);
+ }
+}
+
# =============================================================== Folder suffix
sub foldersuffix {