Permalink
Browse files

Item14216: Support utf-8 webs/topics in mailnotify

Failed to utf-8 encode when run as a rest handler. Also it was not
setting the -charset utf-8 header in the response.
  • Loading branch information...
gac410 committed Nov 16, 2016
1 parent 04fa967 commit 9884d569b36415e4879bb5482747fc4a0d43b454
@@ -1,4 +1,4 @@
-%META:TOPICINFO{author="ProjectContributor" comment="" date="1437500521" format="1.1" version="1"}%
+%META:TOPICINFO{author="ProjectContributor" comment="" date="1479268930" format="1.1" version="1"}%
%META:TOPICPARENT{name="Contribs"}%
---+!! Mailer Contrib
<a href="http://wikiring.com"><img src="%ATTACHURL%/logo.gif" style="float:right" /></a>
@@ -268,6 +268,8 @@ Many thanks to the following sponsors for supporting this work:
| Copyright &copy;: | 2004, Wind River Systems; 2009-2014 Foswiki Contributors |
| Change History: | |
+| 2.83 (15 Nov 2016) | Foswiki 2.1.3 Foswikitask:Item13936: Allow From: address of emails to be separately configured<br />\
+ Foswikitask:Item14216: mailnotify fails with "Wide character in print" |
| 2.82 (14 Jun 2015) | Foswiki 2.0. Foswikitask:Item13423: Perl 5.22 deprecations<br />\
Foswikitask:Item13378: Foswikitask:Item13387: utf-8 foswiki core<br />\
Foswikitask:Item13323: use /usr/bin/env perl in scripts<br />\
@@ -310,5 +312,5 @@ Many thanks to the following sponsors for supporting this work:
%META:FIELD{name="Support" title="Support" value="http://foswiki.org/Support/%25$ROOTMODULE%25"}%
%META:FIELD{name="Version" title="Version" value="%25$VERSION%25"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/distro"}%
-%META:FILEATTACHMENT{name="logo.gif" attr="h" comment="" date="1437500521" size="11437" user="ProjectContributor" version="1"}%
-%META:FILEATTACHMENT{name="wikiringlogo20x20.png" attr="h" comment="" date="1437500521" size="1343" user="ProjectContributor" version="1"}%
+%META:FILEATTACHMENT{name="logo.gif" attr="h" comment="" date="1479268930" size="11437" user="ProjectContributor" version="1"}%
+%META:FILEATTACHMENT{name="wikiringlogo20x20.png" attr="h" comment="" date="1479268930" size="1343" user="ProjectContributor" version="1"}%
@@ -28,8 +28,8 @@ use Foswiki::Contrib::MailerContrib::WebNotify ();
use Foswiki::Contrib::MailerContrib::Change ();
use Foswiki::Contrib::MailerContrib::UpData ();
-our $VERSION = '2.82';
-our $RELEASE = '2.82';
+our $VERSION = '2.83';
+our $RELEASE = '2.83';
our $SHORTDESCRIPTION = 'Supports email notification of changes';
# PROTECTED STATIC ensure the contrib is internally initialised
@@ -225,19 +225,19 @@ sub _processWeb {
return '';
}
- print "Processing $web\n" if $options->{verbose};
+ _UTF8print("Processing $web\n") if $options->{verbose};
# Read the webnotify and load subscriptions
my $wn =
Foswiki::Contrib::MailerContrib::WebNotify->new( $web,
$Foswiki::cfg{NotifyTopicName}, 0 );
if ( $wn->isEmpty() ) {
- print "\t$web has no subscribers\n" if $options->{verbose};
+ _UTF8print("\t$web has no subscribers\n") if $options->{verbose};
}
else {
# create a DB object for parent pointers
- print $wn->stringify(1) if $options->{verbose};
+ _UTF8print( $wn->stringify(1) ) if $options->{verbose};
my $db = Foswiki::Contrib::MailerContrib::UpData->new($web);
_processSubscriptions( $web, $wn, $db, $options );
}
@@ -260,8 +260,9 @@ sub _processSubscriptions {
}
if ( $options->{verbose} ) {
- print "\tLast notification was at "
- . Foswiki::Time::formatTime( $timeOfLastNotify, 'iso' ) . "\n";
+ _UTF8print( "\tLast notification was at "
+ . Foswiki::Time::formatTime( $timeOfLastNotify, 'iso' )
+ . "\n" );
}
my $timeOfLastChange = 0;
@@ -293,9 +294,9 @@ sub _processSubscriptions {
$timeOfLastChange = $change->{time} unless ($timeOfLastChange);
- print "\tChange to $change->{topic} at "
- . Foswiki::Time::formatTime( $change->{time}, 'iso' )
- . ". New revision is $change->{revision}\n"
+ _UTF8print( "\tChange to $change->{topic} at "
+ . Foswiki::Time::formatTime( $change->{time}, 'iso' )
+ . ". New revision is $change->{revision}\n" )
if ( $options->{verbose} );
# Formulate a change record, irrespective of
@@ -458,19 +459,20 @@ sub _sendChangesMails {
$error = Foswiki::Func::sendEmail( $mail, 5 );
}
else {
- print $mail if $options->{verbose};
+ _UTF8print($mail) if $options->{verbose};
}
if ($error) {
print STDERR "Error sending mail for $web: $error\n";
- print "$error\n";
+ _UTF8print("$error\n");
}
else {
- print "Notified $email of changes in $web\n" if $options->{verbose};
+ _UTF8print("Notified $email of changes in $web\n")
+ if $options->{verbose};
$sentMails++;
}
}
- print "\t$sentMails change notifications from $web\n"
+ _UTF8print("\t$sentMails change notifications from $web\n")
if $options->{verbose};
}
@@ -647,20 +649,20 @@ sub _sendNewsletterMail {
$error = Foswiki::Func::sendEmail( $mail, 5 );
}
else {
- print $mail if $options->{verbose};
+ _UTF8print($mail) if $options->{verbose};
}
if ($error) {
print STDERR "Error sending mail for $web: $error\n";
- print "$error\n";
+ _UTF8print("$error\n");
}
else {
- print "Sent newsletter $web.$topic to $email\n"
+ _UTF8print("Sent newsletter $web.$topic to $email\n")
if $options->{verbose};
$sentMails++;
}
}
- print "\t$sentMails newsletters from $web\n";
+ _UTF8print("\t$sentMails newsletters from $web\n");
Foswiki::Func::popTopicContext();
@@ -675,11 +677,20 @@ sub _sendNewsletterMail {
}
}
+sub _UTF8print {
+ if ($Foswiki::UNICODE) {
+ print Foswiki::encode_utf8( $_[0] );
+ }
+ else {
+ print $_[0];
+ }
+}
+
1;
__END__
Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
-Copyright (C) 2008-2015 Foswiki Contributors. All Rights Reserved.
+Copyright (C) 2008-2016 Foswiki Contributors. All Rights Reserved.
Foswiki Contributors are listed in the AUTHORS file in the root
of this distribution. NOTE: Please extend that file, not this notice.
@@ -35,7 +35,11 @@ sub _restNotify {
# Don't use the $response; we want to see things happening
local $| = 1; # autoflush on
require CGI;
- print CGI::header( -status => 200, -type => 'text/plain' );
+ print CGI::header(
+ -status => 200,
+ -type => 'text/plain',
+ -charset => $Foswiki::cfg{Site}{CharSet},
+ );
my $query = Foswiki::Func::getCgiQuery();
my %options = (
@@ -76,7 +80,7 @@ sub _restNotify {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
-Copyright (C) 2008-2015 Foswiki Contributors. Foswiki Contributors
+Copyright (C) 2008-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.

0 comments on commit 9884d56

Please sign in to comment.