From 45080ea0d9362bd3633998f33736fe3032ddc89a Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 19 Jul 2006 18:37:33 +0000 Subject: [PATCH] - fix: cs mail needs archive url - fix: cs mail not sending in-reply-to and references headers - fix: cs mail doesn't like code via email - CS mail now sends out the email address of the poster as from, when it exists. --- docs/changelog/7.x.x.txt | 5 ++ lib/WebGUI/Asset/Post.pm | 71 ++++++++++++++++++----- lib/WebGUI/HTML.pm | 4 +- lib/WebGUI/Mail/Send.pm | 50 +++++++++++++++- lib/WebGUI/Workflow/Activity/GetCsMail.pm | 3 +- 5 files changed, 116 insertions(+), 17 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index f6c3742ef..a94bd6e3f 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -27,6 +27,11 @@ privs to the storage associated with it. (Martin Kamerbeek / Procolix) - Added a reverse page loop option to the navigation asset (Martin Kamerbeek / Procolix) + - fix: cs mail needs archive url + - fix: cs mail not sending in-reply-to and references headers + - fix: cs mail doesn't like code via email + - CS mail now sends out the email address of the poster as from, when it + exists. - fix: WebGUI::Image missing methods - Added runOnLogin and runOnLogout config file properties to Authentication to allow for running an external script on successful login or logout. diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index 51f2f5384..012b4cb6e 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -629,29 +629,74 @@ sub notifySubscribers { my $self = shift; my $i18n = WebGUI::International->new($self->session); my $var = $self->getTemplateVars(); - $self->getThread->getParent->appendTemplateLabels($var); - $var->{url} = $self->session->url->getSiteURL().$self->getUrl; + my $thread = $self->getThread; + my $cs = $thread->getParent; + $cs->appendTemplateLabels($var); + my $siteurl = $self->session->url->getSiteURL(); + $var->{url} = $siteurl.$self->getUrl; $var->{'notify.subscription.message'} = $i18n->get(875,"Asset_Post"); - my $message = $self->processTemplate($var, $self->getThread->getParent->get("notificationTemplateId")); - my $unsubscribe = '

'.$i18n->get("unsubscribe","Asset_Collaboration").'

'; - my $from = $self->getThread->getParent->get("mailAddress"); - my $subject = $self->getThread->getParent->get("mailPrefix").$self->get("title"); + my $message = $self->processTemplate($var, $cs->get("notificationTemplateId")); + my $unsubscribe = '

'.$i18n->get("unsubscribe","Asset_Collaboration").'

'; + my $user = WebGUI::User->new($self->session, $self->get("ownerUserId")); + my $from = $user->profileField("email") || $cs->get("mailAddress"); + my $replyTo = $cs->get("mailAddress"); + my $setting = $self->session->setting; + my $listId = $cs->get("mailAddress"); + $listId =~ s/\@/\./; + my $domain = $cs->get("mailAddress"); + $domain =~ s/.*\@(.*)/$1/; + my $messageId = "cs-".$self->getId.'@'.$domain; + my $replyId = ""; + if ($self->isReply) { + $replyId = "cs-".$self->getParent->getId.'@'.$domain; + } + my $subject = $cs->get("mailPrefix").$self->get("title"); my $mail = WebGUI::Mail::Send->create($self->session, { - from=>$from, - toGroup=>$self->getThread->getParent->get("subscriptionGroupId"), + from=>"<".$from.">", + replyTo=>"<".$replyTo.">", + toGroup=>$cs->get("subscriptionGroupId"), subject=>$subject, - messageId=>"cs-".$self->getId + messageId=>$messageId }); + if ($self->isReply) { + $mail->addHeaderField("In-Reply-To", "<".$replyId.">"); + $mail->addHeaderField("References", "<".$replyId.">"); + } + $mail->addHeaderField("List-ID", $cs->getTitle." <".$listId.">"); + $mail->addHeaderField("List-Help", "get("companyEmail").">, <".$setting->get("companyURL").">"); + $mail->addHeaderField("List-Unsubscribe", "<".$siteurl.$cs->getUnsubscribeUrl.">"); + $mail->addHeaderField("List-Subscribe", "<".$siteurl.$cs->getSubscribeUrl.">"); + $mail->addHeaderField("List-Owner", "get("companyEmail").">, <".$setting->get("companyURL")."> (".$setting->get("companyName").")"); + $mail->addHeaderField("List-Post", "get("mailAddress").">"); + $mail->addHeaderField("List-Archive", "<".$siteurl.$cs->getUrl.">"); + $mail->addHeaderField("X-Unsubscribe-Web", "<".$siteurl.$cs->getUnsubscribeUrl.">"); + $mail->addHeaderField("X-Subscribe-Web", "<".$siteurl.$cs->getSubscribeUrl.">"); + $mail->addHeaderField("X-Archives", "<".$siteurl.$cs->getUrl.">"); $mail->addHtml($message.$unsubscribe); $mail->addFooter; $mail->queue; my $mail = WebGUI::Mail::Send->create($self->session, { - from=>$from, - toGroup=>$self->getThread->get("subscriptionGroupId"), + from=>"<".$from.">", + replyTo=>"<".$replyTo.">", + toGroup=>$thread->get("subscriptionGroupId"), subject=>$subject, - messageId=>"cs-".$self->getId + messageId=>$messageId }); - $unsubscribe = '

'.$i18n->get("unsubscribe","Asset_Collaboration").'

'; + $unsubscribe = '

'.$i18n->get("unsubscribe","Asset_Collaboration").'

'; + if ($self->isReply) { + $mail->addHeaderField("In-Reply-To", "<".$replyId.">"); + $mail->addHeaderField("References", "<".$replyId.">"); + } + $mail->addHeaderField("List-ID", $cs->getTitle." <".$listId.">"); + $mail->addHeaderField("List-Help", "get("companyEmail").">, <".$setting->get("companyURL").">"); + $mail->addHeaderField("List-Unsubscribe", "<".$siteurl.$thread->getUnsubscribeUrl.">"); + $mail->addHeaderField("List-Subscribe", "<".$siteurl.$thread->getSubscribeUrl.">"); + $mail->addHeaderField("List-Owner", "get("companyEmail").">, <".$setting->get("companyURL")."> (".$setting->get("companyName").")"); + $mail->addHeaderField("List-Post", "get("mailAddress").">"); + $mail->addHeaderField("List-Archive", "<".$siteurl.$cs->getUrl.">"); + $mail->addHeaderField("X-Unsubscribe-Web", "<".$siteurl.$thread->getUnsubscribeUrl.">"); + $mail->addHeaderField("X-Subscribe-Web", "<".$siteurl.$thread->getSubscribeUrl.">"); + $mail->addHeaderField("X-Archives", "<".$siteurl.$cs->getUrl.">"); $mail->addHtml($message.$unsubscribe); $mail->addFooter; $mail->queue; diff --git a/lib/WebGUI/HTML.pm b/lib/WebGUI/HTML.pm index fe40475b3..40835f758 100644 --- a/lib/WebGUI/HTML.pm +++ b/lib/WebGUI/HTML.pm @@ -157,12 +157,12 @@ sub format { $content =~ s/&/&/g; $content =~ s/\/>/g; - $content =~ s/\n/\
/g; + $content =~ s/\n/\
\n/g; $content =~ s/\t/    /g; } if ($contentType eq "mixed") { unless ($content =~ /\
/g; + $content =~ s/\n/\
\n/g; } } elsif ($contentType eq "text") { $content =~ s/ /  /g; diff --git a/lib/WebGUI/Mail/Send.pm b/lib/WebGUI/Mail/Send.pm index f7d50cd47..d0fd66798 100644 --- a/lib/WebGUI/Mail/Send.pm +++ b/lib/WebGUI/Mail/Send.pm @@ -94,6 +94,30 @@ sub addFooter { $self->addText($text); } +#------------------------------------------------------------------- + +=head2 addHeaderField ( name, value ) + +Adds a header field to the mail message. See also replaceHeaderField(). + +=head3 name + +The name of the field to add. + +=head3 value + +The value of the field to add. + +=cut + +sub addHeaderField { + my $self = shift; + my $name = shift; + my $value = shift; + $self->{_message}->head->add($name, $value); +} + + #------------------------------------------------------------------- =head2 addHtml ( html ) @@ -219,7 +243,7 @@ sub create { my $from = $headers->{from} || $session->setting->get("companyEmail"); my $type = $headers->{contentType} || "multipart/mixed"; my $domain = $from; - $domain =~ s/\@(.*)/$1/; + $domain =~ s/.*\@(.*)/$1/; my $id = $headers->{messageId} || "WebGUI-".$session->id->generate; unless ($id =~ m/\@/) { $id .= '@'.$domain; @@ -285,6 +309,30 @@ sub queue { } +#------------------------------------------------------------------- + +=head2 replaceHeaderField ( name, value ) + +Replaces an existing header field in the mail message, or creates it if it doesn't exist. See also addHeaderField(). + +=head3 name + +The name of the field to replace. + +=head3 value + +The value of the field to replace. + +=cut + +sub replaceHeaderField { + my $self = shift; + my $name = shift; + my $value = shift; + $self->{_message}->head->replace($name, $value); +} + + #------------------------------------------------------------------- =head2 retrieve ( session, messageId ) diff --git a/lib/WebGUI/Workflow/Activity/GetCsMail.pm b/lib/WebGUI/Workflow/Activity/GetCsMail.pm index c0ce46300..977dee865 100644 --- a/lib/WebGUI/Workflow/Activity/GetCsMail.pm +++ b/lib/WebGUI/Workflow/Activity/GetCsMail.pm @@ -20,6 +20,7 @@ use base 'WebGUI::Workflow::Activity'; use WebGUI::Mail::Get; use WebGUI::Mail::Send; use WebGUI::Asset; +use WebGUI::HTML; use WebGUI::International; use WebGUI::User; @@ -78,7 +79,7 @@ sub addPost { if (($part->{type} =~ /^text\/plain/ || $part->{type} =~ /^text\/html/) && $part->{filename} eq "") { my $text = $part->{content}; if ($part->{type} eq "text/plain") { - $text =~ s/\n/\
/g; + $text = WebGUI::HTML::format($text, "text"); } $content .= $text; } else {