[Codestriker-commits] CVS update: codestriker/lib/Codestriker/TopicListeners Email.pm
Brought to you by:
sits
|
From: <si...@us...> - 2006-05-22 23:22:10
|
User: sits
Date: 06/05/22 16:19:06
Modified: lib/Codestriker/Action ListTopicsRSS.pm SubmitNewComment.pm
SubmitNewTopic.pm ViewTopicComments.pm
lib/Codestriker/DB MySQL.pm
lib/Codestriker/Model Comment.pm Project.pm Topic.pm
lib/Codestriker/TopicListeners Email.pm
Log:
Initial UTF-8 support. Can now create topics with unicode titles and
descriptions, can add unicode comments, and projects can have unicode
titles and descriptions. Emails are also encoded appropriately.
Something still outstanding is if the topic text itself is encoded.
Index: ListTopicsRSS.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Action/ListTopicsRSS.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ListTopicsRSS.pm 22 Dec 2004 00:19:07 -0000 1.2
+++ ListTopicsRSS.pm 22 May 2006 23:19:05 -0000 1.3
@@ -11,7 +11,7 @@
use strict;
use Codestriker::Http::Template;
-use Codestriker::Model::Topic;
+use Codestriker::Model::Topic;
use XML::RSS;
# If the input is valid, list the appropriate topics.
@@ -25,22 +25,22 @@
$http_response->error("This function has been disabled");
}
- # Query the model for the specified data.
-
- my $mode = $http_input->get('mode');
-
- my ( $sauthor, $sreviewer, $scc, $sbugid,
- $sstate, $sproject, $stext,
- $stitle, $sdescription,
- $scomments, $sbody, $sfilename,
- $sort_order) = Codestriker::Action::ListTopics::get_topic_list_query_params($http_input);
-
- # Query the model for the specified data.
- my @topics = Codestriker::Model::Topic->query($sauthor, $sreviewer, $scc, $sbugid,
- $sstate, $sproject, $stext,
- $stitle, $sdescription,
- $scomments, $sbody, $sfilename,
- $sort_order);
+ # Query the model for the specified data.
+
+ my $mode = $http_input->get('mode');
+
+ my ( $sauthor, $sreviewer, $scc, $sbugid,
+ $sstate, $sproject, $stext,
+ $stitle, $sdescription,
+ $scomments, $sbody, $sfilename,
+ $sort_order) = Codestriker::Action::ListTopics::get_topic_list_query_params($http_input);
+
+ # Query the model for the specified data.
+ my @topics = Codestriker::Model::Topic->query($sauthor, $sreviewer, $scc, $sbugid,
+ $sstate, $sproject, $stext,
+ $stitle, $sdescription,
+ $scomments, $sbody, $sfilename,
+ $sort_order);
# Display the data, with each topic title linked to the view topic screen.
# If only a single project id is being searched over, set that id in the
@@ -49,74 +49,74 @@
if ($sproject ne "") {
@project_ids = split ',', $sproject;
}
-
- # Print the header. Should really be application/rss+xml, except when
- # people click on the link they get a pop-up asking for an application
- # that knows how to show application/rss+xml. Very confusing, so we
- # will just say it is xml, (which it is of coarse). The link tag in
- # the template lists it as application/rss+xml.
- print $query->header(-type=>'application/xml');
-
- # Obtain a new URL builder object.
- my $url_builder = Codestriker::Http::UrlBuilder->new($query);
-
- my $rss = new XML::RSS(version => '2.0');
-
- my $this_url =
- $url_builder->list_topics_url_rss($sauthor, $sreviewer, $scc, $sbugid,
- $stext, $stitle,
- $sdescription, $scomments,
- $sbody, $sfilename,
- [ split ',', $sstate] , \@project_ids);
-
-
- $rss->channel(title=>$Codestriker::title, language=>"en",link=>$this_url);
-
- # For each topic, collect all the reviewers, CC, and bugs, and display it
- # as a row in the table. Each bug should be linked appropriately.
- foreach my $topic (@topics) {
-
- # do the easy stuff first, 1 to 1 mapping into the template.
- my $link =
- $url_builder->view_url($topic->{topicid}, -1, $mode,
- $Codestriker::default_topic_br_mode);
-
- my $comment_link = $url_builder->view_comments_url($topic->{topicid});
-
- my $description = $topic->{description};
- my $title = $topic->{title};
-
- # Change to 1 to send out the list of files changes in the RSS description.
- if (0) {
- my (@filenames, @revisions, @offsets, @binary);
- $topic->get_filestable(
- \@filenames,
- \@revisions,
- \@offsets,
- \@binary);
-
- $description .= "<p>" . join( "\n",@filenames);
- }
-
- my @comments = $topic->read_comments();
-
- $description .= "<p>Comments: " . scalar( @comments ) . ", ";
- $description .= "State: " . $topic->{topic_state} . ", ";
- $description .= "Author: " . Codestriker->filter_email($topic->{author});
-
- $rss->add_item(
- title=>$title,
- permaLink=>$link,
- description=>$description,
- author=> Codestriker->filter_email($topic->{author}),
- pubDate=>Codestriker->format_short_timestamp($topic->{creation_ts}),
- category=>$topic->{project_name},
- comments=>$comment_link
- );
-
- }
-
- print $rss->as_string();
+
+ # Print the header. Should really be application/rss+xml, except when
+ # people click on the link they get a pop-up asking for an application
+ # that knows how to show application/rss+xml. Very confusing, so we
+ # will just say it is xml, (which it is of coarse). The link tag in
+ # the template lists it as application/rss+xml.
+ print $query->header(-type=>'application/xml');
+
+ # Obtain a new URL builder object.
+ my $url_builder = Codestriker::Http::UrlBuilder->new($query);
+
+ my $rss = new XML::RSS(version => '2.0');
+
+ my $this_url =
+ $url_builder->list_topics_url_rss($sauthor, $sreviewer, $scc, $sbugid,
+ $stext, $stitle,
+ $sdescription, $scomments,
+ $sbody, $sfilename,
+ [ split ',', $sstate] , \@project_ids);
+
+
+ $rss->channel(title=>$Codestriker::title, language=>"en",link=>$this_url);
+
+ # For each topic, collect all the reviewers, CC, and bugs, and display it
+ # as a row in the table. Each bug should be linked appropriately.
+ foreach my $topic (@topics) {
+
+ # do the easy stuff first, 1 to 1 mapping into the template.
+ my $link =
+ $url_builder->view_url($topic->{topicid}, -1, $mode,
+ $Codestriker::default_topic_br_mode);
+
+ my $comment_link = $url_builder->view_comments_url($topic->{topicid});
+
+ my $description = decode_utf8($topic->{description});
+ my $title = decode_utf8($topic->{title});
+
+ # Change to 1 to send out the list of files changes in the RSS description.
+ if (0) {
+ my (@filenames, @revisions, @offsets, @binary);
+ $topic->get_filestable(
+ \@filenames,
+ \@revisions,
+ \@offsets,
+ \@binary);
+
+ $description .= "<p>" . join( "\n",@filenames);
+ }
+
+ my @comments = $topic->read_comments();
+
+ $description .= "<p>Comments: " . scalar( @comments ) . ", ";
+ $description .= "State: " . $topic->{topic_state} . ", ";
+ $description .= "Author: " . Codestriker->filter_email($topic->{author});
+
+ $rss->add_item(
+ title=>$title,
+ permaLink=>$link,
+ description=>$description,
+ author=> Codestriker->filter_email($topic->{author}),
+ pubDate=>Codestriker->format_short_timestamp($topic->{creation_ts}),
+ category=>decode_utf8($topic->{project_name}),
+ comments=>$comment_link
+ );
+
+ }
+
+ print $rss->as_string();
}
1;
Index: SubmitNewComment.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Action/SubmitNewComment.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- SubmitNewComment.pm 16 Jan 2006 10:37:45 -0000 1.10
+++ SubmitNewComment.pm 22 May 2006 23:19:05 -0000 1.11
@@ -105,7 +105,7 @@
my $vars = {};
$vars->{'view_topic_url'} = $view_topic_url;
$vars->{'view_comments_url'} = $view_comments_url;
- $vars->{'comment'} = $comments;
+ $vars->{'comment'} = $comment->{data};
my $template = Codestriker::Http::Template->new("submitnewcomment");
$template->process($vars);
Index: SubmitNewTopic.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Action/SubmitNewTopic.pm,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- SubmitNewTopic.pm 19 May 2006 00:40:15 -0000 1.25
+++ SubmitNewTopic.pm 22 May 2006 23:19:05 -0000 1.26
@@ -10,6 +10,7 @@
package Codestriker::Action::SubmitNewTopic;
use strict;
+use Encode;
use File::Temp qw/ tempfile /;
use FileHandle;
@@ -339,7 +340,7 @@
# Indicate to the user that the topic has been created and an email has
# been sent.
my $vars = {};
- $vars->{'topic_title'} = $topic_title;
+ $vars->{'topic_title'} = $topic->{title};
$vars->{'email'} = $email;
$vars->{'topic_url'} = $topic_url;
$vars->{'reviewers'} = $reviewers;
Index: ViewTopicComments.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Action/ViewTopicComments.pm,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ViewTopicComments.pm 2 Jun 2005 11:31:00 -0000 1.16
+++ ViewTopicComments.pm 22 May 2006 23:19:05 -0000 1.17
@@ -10,6 +10,7 @@
package Codestriker::Action::ViewTopicComments;
use strict;
+
use Codestriker::Http::Template;
use Codestriker::Http::Render;
use Codestriker::Model::Comment;
Index: MySQL.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/DB/MySQL.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- MySQL.pm 28 Sep 2004 22:15:18 -0000 1.6
+++ MySQL.pm 22 May 2006 23:19:05 -0000 1.7
@@ -46,7 +46,10 @@
# Not all versions of MySQL upport transactions. Its easiest for now to
# just enable AUTO_COMMIT.
- return $self->_get_connection(1, 1);
+ my $dbh = $self->_get_connection(1, 1);
+ $dbh->do("SET NAMES 'utf8'");
+ $dbh->do("SET character_set_results='utf8'");
+ return $dbh;
}
# Return the mapping for a specific type.
Index: Comment.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Model/Comment.pm,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- Comment.pm 21 Feb 2005 11:25:26 -0000 1.20
+++ Comment.pm 22 May 2006 23:19:05 -0000 1.21
@@ -10,6 +10,7 @@
package Codestriker::Model::Comment;
use strict;
+use Encode qw(decode_utf8);
use Codestriker::DB::DBI;
@@ -130,7 +131,7 @@
$self->{filenumber} = $filenumber;
$self->{filenew} = $filenew;
$self->{author} = $author;
- $self->{data} = $data;
+ $self->{data} = decode_utf8($data);
$self->{date} = $timestamp;
$self->{version} = $version;
$self->{db_creation_ts} = $creation_ts;
@@ -301,7 +302,7 @@
while (@data = $select_comment->fetchrow_array()) {
my $comment = Codestriker::Model::Comment->new();
$comment->{topicid} = $topicid;
- $comment->{data} = $data[0];
+ $comment->{data} = decode_utf8($data[0]);
$comment->{author} = $data[1];
$comment->{fileline} = $data[2];
$comment->{filenumber} = $data[3];
Index: Project.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Model/Project.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Project.pm 30 Sep 2004 10:27:09 -0000 1.4
+++ Project.pm 22 May 2006 23:19:05 -0000 1.5
@@ -10,6 +10,7 @@
package Codestriker::Model::Project;
use strict;
+use Encode qw(decode_utf8);
use Codestriker::DB::DBI;
@@ -93,8 +94,8 @@
while (@data = $select->fetchrow_array()) {
my $project = {};
$project->{id} = $data[0];
- $project->{name} = $data[1];
- $project->{description} = $data[2];
+ $project->{name} = decode_utf8($data[1]);
+ $project->{description} = decode_utf8($data[2]);
$project->{version} = $data[3];
$project->{state} = _state_id_to_string($data[4]);
if (!defined $state || $project->{state} eq $state)
@@ -135,8 +136,8 @@
if ($success) {
# Populate return object.
$project->{id} = $id;
- $project->{name} = $name;
- $project->{description} = $description;
+ $project->{name} = decode_utf8($name);
+ $project->{description} = decode_utf8($description);
$project->{version} = $version;
$project->{state} = _state_id_to_string($state);
}
Index: Topic.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Model/Topic.pm,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- Topic.pm 15 Feb 2005 09:00:04 -0000 1.43
+++ Topic.pm 22 May 2006 23:19:05 -0000 1.44
@@ -10,6 +10,7 @@
package Codestriker::Model::Topic;
use strict;
+use Encode qw(decode_utf8);
use Codestriker::DB::DBI;
use Codestriker::Model::File;
@@ -202,6 +203,11 @@
Codestriker::DB::DBI->release_connection($dbh, $success);
+ # Mark the user fields as UTF8.
+ $self->{title} = decode_utf8($title);
+ $self->{description} = decode_utf8($description);
+ $self->{document} = decode_utf8($document);
+
die $dbh->errstr unless $success;
}
@@ -321,12 +327,12 @@
# successful.
if ($success) {
$self->{author} = $author;
- $self->{title} = $title;
+ $self->{title} = decode_utf8($title);
$self->{bug_ids} = join ', ', @bugs;
$self->{reviewers} = join ', ', @reviewers;
$self->{cc} = join ', ', @cc;
- $self->{description} = $description;
- $self->{document} = $document;
+ $self->{description} = decode_utf8($description);
+ $self->{document} = decode_utf8($document);
$self->{creation_ts} = $creationtime;
$self->{modified_ts} = $modifiedtime;
$self->{topic_state} = $Codestriker::topic_states[$state];
@@ -634,11 +640,11 @@
}
# Update the topic object's properties.
- $self->{title} = $new_title;
+ $self->{title} = decode_utf8($new_title);
$self->{author} = $new_author;
$self->{repository} = $new_repository;
$self->{project_id} = $new_projectid;
- $self->{description} = $new_description;
+ $self->{description} = decode_utf8($new_description);
$self->{modified_ts} = $modified_ts;
$self->{topic_state} = $new_state;
$self->{topic_state_id} = $new_stateid;
Index: Email.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/TopicListeners/Email.pm,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Email.pm 22 May 2006 11:34:16 -0000 1.18
+++ Email.pm 22 May 2006 23:19:06 -0000 1.19
@@ -14,7 +14,9 @@
use MIME::QuotedPrint qw(encode_qp);
use Net::SMTP;
+use MIME::Base64;
use Sys::Hostname;
+use Encode qw(encode);
use Codestriker::TopicListeners::TopicListener;
@@ -481,9 +483,8 @@
# Make sure the subject is appropriately encoded to handle UTF-8
# characters.
- # TODO: use Encode qw(encode);
- # TODO: should be encode_qp(encode("UTF-8", $subject), '')
- $smtp->datasend('Subject: =?UTF-8?Q?' . encode_qp($subject, '') .
+ $smtp->datasend('Subject: =?UTF-8?Q?' .
+ encode_qp(encode("UTF-8", $subject), '') .
'?=' . "\n");
# Set the content type to be text/plain with UTF8 encoding, to handle
@@ -494,8 +495,9 @@
# Insert a blank line for the body.
$smtp->datasend("\n");
- # TODO: should be $smtp->datasend(encode_qp(encode("UTF-8", $body)));
- $smtp->datasend(encode_qp($body));
+ # Encode the mail body using quoted-printable to handle unicode
+ # characters.
+ $smtp->datasend(encode_qp(encode("UTF-8", $body)));
$smtp->dataend();
$smtp->ok() || return "Couldn't send email $!, " . smtp->message();
|