From 4193a0180fbb5a6172f4b63aeb9a5fc271d76004 Mon Sep 17 00:00:00 2001 From: "reed%reedloden.com" Date: Wed, 11 Apr 2007 10:07:55 +0000 Subject: [PATCH] Bug 376278 - "Hendrix should be able to submit to alternate destinations depending on product" [p=reed r=gerv] --- webtools/hendrix/index.cgi | 84 +++++++++++++++---- webtools/hendrix/template/index.html.tmpl | 14 ++-- .../hendrix/template/message-headers.txt.tmpl | 17 ++-- 3 files changed, 80 insertions(+), 35 deletions(-) diff --git a/webtools/hendrix/index.cgi b/webtools/hendrix/index.cgi index 047a5288127..c9414159ec9 100755 --- a/webtools/hendrix/index.cgi +++ b/webtools/hendrix/index.cgi @@ -21,7 +21,7 @@ # Portions created by the Initial Developer are Copyright (C) 2004 # the Initial Developer. All Rights Reserved. # -# Contributor(s): +# Contributor(s): Reed Loden # # The Initial Developer wrote this software to the Glory of God. # ***** END LICENSE BLOCK ***** @@ -32,19 +32,54 @@ use strict; # Mail::Send) module. use Template; use CGI; -use Email::Send qw(NNTP); +use Email::Send; use Net::RBLClient; # use CGI::Carp qw(fatalsToBrowser); # Configuration -my $newsgroup = $::ENV{'HENDRIX_NEWSGROUP'} || "mozilla.feedback"; -my $server = $::ENV{'HENDRIX_NNTP_SERVER'} || "news.mozilla.org"; -my $skin = $::ENV{'HENDRIX_SKIN'} || "skin/planet.css"; +# Map products to destination +my %product_destination_map = ( + "Firefox" => "mozilla.feedback", + "Thunderbird" => "mozilla.feedback", + "Mozilla Suite" => "mozilla.feedback", + "SeaMonkey" => "mozilla.feedback", + "Sunbird" => "mozilla.feedback", + "Camino" => "caminofeedback\@mozilla.org", + "Bon Echo" => "mozilla.feedback", + "Gran Paradiso" => "mozilla.feedback", + "Minefield" => "mozilla.feedback", + "eBay Companion" => "mozilla.feedback.companion.ebay", + "Other" => "mozilla.feedback" +); + +# List of products to show on the main Hendrix page (in order) +my @products_list = ( + "Firefox", "Thunderbird", "Mozilla Suite", + "SeaMonkey", "Sunbird", "Camino", "Bon Echo", + "Gran Paradiso", "Minefield", "Other" +); + +# The default newsgroup if the product isn't in the above map (NNTP only) +my $default_newsgroup = $::ENV{'HENDRIX_NEWSGROUP'} || "mozilla.feedback"; + +# The news (NNTP) server to use for posting +my $nntp_server = $::ENV{'HENDRIX_NNTP_SERVER'} || "news.mozilla.org"; + +# The default sender to use if no e-mail address is provided +my $default_sender = $::ENV{'HENDRIX_SENDER'} || "hendrix-no-reply\@mozilla.org"; + +# The mail (SMTP) server to use for posting +my $smtp_server = $::ENV{'HENDRIX_SMTP_SERVER'} || "smtp.mozilla.org"; + +# The CSS file to include in the template +my $skin = $::ENV{'HENDRIX_SKIN'} || "skin/planet.css"; + +# The DNS blacklists by which to check sender IP addresses my $rbl = Net::RBLClient->new( lists => [ - 'opm.blitzed.org', + 'dnsbl.ahbl.org', 'http.dnsbl.sorbs.net', 'socks.dnsbl.sorbs.net', 'misc.dnsbl.sorbs.net', @@ -56,7 +91,7 @@ my $cgi = new CGI; my $form = $cgi->Vars; my $vars; $vars->{'form'} = $form; -$vars->{'newsgroup'} = $newsgroup; +$vars->{'products'} = \@products_list; $vars->{'stylesheet'} = $skin; my $template = Template->new({ @@ -65,7 +100,8 @@ my $template = Template->new({ TRIM => 1, FILTERS => { email => \&emailFilter, - }, + remove_newlines => \&removeNewlinesFilter, + }, }) || die("Template creation failed.\n"); my $action = $cgi->param("action"); @@ -97,7 +133,11 @@ elsif ($action eq "submit") { if (!$form->{'name'} || !$form->{'subject'} || !$form->{'product'}) { throwError("bad_parameters"); } - + + $vars->{'destination'} = $product_destination_map{$form->{'product'}} || $default_newsgroup; + $vars->{'method'} = $vars->{'destination'} =~ /@/ ? "SMTP" : "NNTP"; + $vars->{'email'} = $form->{'email'} =~ /d:^[\w\.\+\-=]+@[\w\.\-]+\.[\w\-]+$:/ ? $form->{'email'} : $default_sender; + my $message; my $headers; @@ -105,16 +145,20 @@ elsif ($action eq "submit") { || die("Template process failed: " . $template->error() . "\n"); $template->process("message.txt.tmpl", $vars, \$message) || die("Template process failed: " . $template->error() . "\n"); - - # Post formatted message to newsgroup - my $newsMsg = Email::Simple->new($headers . "\n\n" . $message); - my $success = send NNTP => $newsMsg, $server; - throwError("cant_post") if (!$success); + # Post formatted message to newsgroup/email + my $theMsg = Email::Simple->new($headers . "\n\n" . $message); + my $sender = Email::Send->new({ + mailer => $vars->{'method'}, + mailer_args => [ Host => $vars->{'method'} eq "SMTP" ? $smtp_server : $nntp_server ], + }); + my $success = $sender->send($theMsg); - # Give user feedback on success + # Give user feedback on success/failure $vars->{'headers'} = $headers; $vars->{'message'} = $message; + + throwError("cant_post") if (!$success); print "Content-Type: text/html\n\n"; $template->process("submit-successful.html.tmpl", $vars) @@ -134,6 +178,16 @@ sub emailFilter { return $var; } +# Remove newlines and replace them with spaces +sub removeNewlinesFilter { + my ($var) = @_; + $var =~ s/\r\n/ /g; + $var =~ s/\n\r/ /g; + $var =~ s/\r/ /g; + $var =~ s/\n/ /g; + return $var; +} + sub throwError { my ($error) = @_; $vars->{'error'} = $error; diff --git a/webtools/hendrix/template/index.html.tmpl b/webtools/hendrix/template/index.html.tmpl index 636f0025d84..a9e80dc27d7 100644 --- a/webtools/hendrix/template/index.html.tmpl +++ b/webtools/hendrix/template/index.html.tmpl @@ -18,7 +18,7 @@ # Portions created by the Initial Developer are Copyright (C) 2004 # the Initial Developer. All Rights Reserved. # - # Contributor(s): + # Contributor(s): Reed Loden # # The Initial Developer wrote this software to the Glory of God. # ***** END LICENSE BLOCK ***** %] @@ -93,14 +93,10 @@ function onLoad() { diff --git a/webtools/hendrix/template/message-headers.txt.tmpl b/webtools/hendrix/template/message-headers.txt.tmpl index eee2bfa4d0c..0e28bb179d7 100644 --- a/webtools/hendrix/template/message-headers.txt.tmpl +++ b/webtools/hendrix/template/message-headers.txt.tmpl @@ -18,17 +18,12 @@ # Portions created by the Initial Developer are Copyright (C) 2004 # the Initial Developer. All Rights Reserved. # - # Contributor(s): + # Contributor(s): Reed Loden # # The Initial Developer wrote this software to the Glory of God. # ***** END LICENSE BLOCK ***** %] -[% from = form.name %] -[% IF form.email %] - [% from = BLOCK %] - [% from %] <[% form.email FILTER email %]> - [% END %] -[% END %] -Newsgroups: [% newsgroup %] -From: [% from %] -X-Hendrix-Product: [% form.product %] -Subject: [Hendrix] [% form.subject %] +[% method == "SMTP" ? "To: <$destination>" : "Newsgroups: $destination" %] +[% filtered_email = email FILTER email FILTER remove_newlines %] +From: [% form.name FILTER remove_newlines %] <[% method == "SMTP" ? email : filtered_email %]> +X-Hendrix-Product: [% form.product FILTER remove_newlines %] +Subject: [Hendrix] [% form.subject FILTER remove_newlines %]