--- loncom/interface/lonmsg.pm 2007/05/01 18:40:57 1.201
+++ loncom/interface/lonmsg.pm 2007/05/08 16:50:02 1.205
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.201 2007/05/01 18:40:57 raeburn Exp $
+# $Id: lonmsg.pm,v 1.205 2007/05/08 16:50:02 raeburn 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,'<>&"');
@@ -160,6 +160,20 @@ sub packagemsg {
}
}
}
+ if (defined($recipid)) {
+ $result.= ''.$recipid.'';
+ }
+ if ($env{'form.can_reply'} eq 'N') {
+ $result .= '1';
+ }
+ if ($env{'form.reply_to_addr'}) {
+ my ($replytoname,$replytodom) = split(/:/,$env{'form.reply_to_addr'});
+ if (!($replytoname eq $env{'user.name'} && $replytodom eq $env{'user.domain'})) {
+ if (&Apache::lonnet::homeserver($replytoname,$replytodom) ne 'no_host') {
+ $result .= ''.$env{'form.reply_to_addr'}.'';
+ }
+ }
+ }
return ($msgid,$result);
}
@@ -445,7 +459,7 @@ sub store_instructor_comment {
sub user_crit_msg_raw {
my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
- $nosentstore)=@_;
+ $nosentstore,$recipid)=@_;
# Check if allowed missing
my ($status,$packed_message);
my $msgid='undefined';
@@ -453,7 +467,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:'.
@@ -499,7 +515,7 @@ sub user_crit_msg_raw {
=pod
-=item * B:
+=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.
@@ -516,7 +532,7 @@ sub user_crit_msg_raw {
sub user_crit_msg {
my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
- $nosentstore)=@_;
+ $nosentstore,$recipid)=@_;
my @status;
my %userenv = &Apache::lonnet::get('environment',['msgforward'],
$domain,$user);
@@ -526,12 +542,13 @@ sub user_crit_msg {
my ($forwuser,$forwdomain)=split(/\:/,$addr);
push(@status,
&user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
- $sendback,$toperm,$sentmessage,$nosentstore));
+ $sendback,$toperm,$sentmessage,$nosentstore,
+ $recipid));
}
} else {
push(@status,
&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
- $toperm,$sentmessage,$nosentstore));
+ $toperm,$sentmessage,$nosentstore,$recipid));
}
if (wantarray) {
return @status;
@@ -545,14 +562,24 @@ sub user_crit_received {
my $msgid=shift;
my %message=&Apache::lonnet::get('critical',[$msgid]);
my %contents=&unpackagemsg($message{$msgid},1);
+ my $destname = $contents{'sendername'};
+ my $destdom = $contents{'senderdomain'};
+ if ($contents{'replytoaddr'}) {
+ my ($repname,$repdom) = split(/:/,$contents{'replytoaddr'});
+ if (&Apache::lonnet::homeserver($repname,$repdom) ne 'no_host') {
+ $destname = $repname;
+ $destdom = $repdom;
+ }
+ }
my $status='rec: '.($contents{'sendback'}?
- &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
- &mt('Receipt').': '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.', '.$contents{'subject'},
- &mt('User').' '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.
- ' acknowledged receipt of message'."\n".' "'.
- $contents{'subject'}.'"'."\n".&mt('dated').' '.
- $contents{'time'}.".\n"
- ):'no msg req');
+ &user_normal_msg($destname,$destdom,&mt('Receipt').': '.$env{'user.name'}.
+ ' '.&mt('at').' '.$env{'user.domain'}.', '.
+ $contents{'subject'},&mt('User').' '.$env{'user.name'}.
+ ' '.&mt('at').' '.$env{'user.domain'}.
+ ' acknowledged receipt of message'."\n".' "'.
+ $contents{'subject'}.'"'."\n".&mt('dated').' '.
+ $contents{'time'}.".\n"
+ ):'no msg req');
$status.=' trans: '.
&Apache::lonnet::put(
'nohist_email',{$contents{'msgid'} => $message{$msgid}});
@@ -570,7 +597,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,$nosentstore)=@_;
+ $error,$nosentstore,$recipid)=@_;
# Check if allowed missing
my ($status,$packed_message);
my $msgid='undefined';
@@ -581,7 +608,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(
@@ -633,7 +660,7 @@ sub user_normal_msg_raw {
=item * B:
+ $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
@@ -648,7 +675,7 @@ sub user_normal_msg_raw {
sub user_normal_msg {
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
- $toperm,$sentmessage,$symb,$restitle,$error,$nosentstore)=@_;
+ $toperm,$sentmessage,$symb,$restitle,$error,$nosentstore,$recipid)=@_;
my @status;
my %userenv = &Apache::lonnet::get('environment',['msgforward'],
$domain,$user);
@@ -660,13 +687,13 @@ sub user_normal_msg {
&user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
$citation,$baseurl,$attachmenturl,$toperm,
undef,undef,$sentmessage,undef,$symb,
- $restitle,$error,$nosentstore));
+ $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,$nosentstore));
+ $restitle,$error,$nosentstore,$recipid));
}
if (wantarray) {
return @status;
@@ -679,6 +706,11 @@ sub process_sent_mail {
my $sentsubj;
if ($numsent > 1) {
$sentsubj = $subj_prefix.' ('.$numsent.' sent) '.$msgsubj;
+ } else {
+ if ($subj_prefix) {
+ $sentsubj = $subj_prefix.' ';
+ }
+ $sentsubj .= $msgsubj;
}
$sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
my $sentmsgid =
@@ -708,6 +740,25 @@ sub store_sent_mail {
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 {