Commit eef25b6c authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 303708: Eliminate deprecated Bugzilla::DB routines from BugzillaEmail.pm,…

Bug 303708: Eliminate deprecated Bugzilla::DB routines from BugzillaEmail.pm, bug_email.pl and bugzilla_email_append.pl in contrib - Patch by Gabriel Sales de Oliveira <gabriel@async.com.br> r=LpSolit a=justdave
parent 9530fd5a
...@@ -32,7 +32,6 @@ require "globals.pl"; ...@@ -32,7 +32,6 @@ require "globals.pl";
use strict; use strict;
my $dbh = Bugzilla->dbh;
my $EMAIL_TRANSFORM_NONE = "email_transform_none"; my $EMAIL_TRANSFORM_NONE = "email_transform_none";
my $EMAIL_TRANSFORM_BASE_DOMAIN = "email_transform_base_domain"; my $EMAIL_TRANSFORM_BASE_DOMAIN = "email_transform_base_domain";
...@@ -41,44 +40,40 @@ my $EMAIL_TRANSFORM_NAME_ONLY = "email_transform_name_only"; ...@@ -41,44 +40,40 @@ my $EMAIL_TRANSFORM_NAME_ONLY = "email_transform_name_only";
# change to do incoming email address fuzzy matching # change to do incoming email address fuzzy matching
my $email_transform = $EMAIL_TRANSFORM_NAME_ONLY; my $email_transform = $EMAIL_TRANSFORM_NAME_ONLY;
# findUser()
# This function takes an email address and returns the user email. # This function takes an email address and returns the user email.
# matching is sloppy based on the $email_transform parameter # matching is sloppy based on the $email_transform parameter
sub findUser($) { sub findUser($) {
my ($address) = @_; my $dbh = Bugzilla->dbh;
# if $email_transform is $EMAIL_TRANSFORM_NONE, return the address, otherwise, return undef my ($address) = @_;
if ($email_transform eq $EMAIL_TRANSFORM_NONE) { # if $email_transform is $EMAIL_TRANSFORM_NONE, return the address, otherwise, return undef
my $stmt = "SELECT login_name FROM profiles WHERE " . if ($email_transform eq $EMAIL_TRANSFORM_NONE) {
$dbh->sql_istrcmp('login_name', $dbh->quote($address)); my $stmt = q{SELECT login_name FROM profiles WHERE } .
SendSQL($stmt); $dbh->sql_istrcmp('login_name', '?');
my $found_address = FetchOneColumn(); my $found_address = $dbh->selectrow_array($stmt, undef, $address);
return $found_address; return $found_address;
} elsif ($email_transform eq $EMAIL_TRANSFORM_BASE_DOMAIN) { } elsif ($email_transform eq $EMAIL_TRANSFORM_BASE_DOMAIN) {
my ($username) = ($address =~ /(.+)@/); my ($username) = ($address =~ /(.+)@/);
my $stmt = "SELECT login_name FROM profiles WHERE " . $dbh->sql_regexp( my $stmt = q{SELECT login_name FROM profiles WHERE } . $dbh->sql_regexp(
$dbh->sql_istring('login_name'), $dbh->sql_istring($dbh->quote($username))); $dbh->sql_istring('login_name'), $dbh->sql_istring('?'));
SendSQL($stmt);
my $domain; my $found_address = $dbh->selectcol_arrayref($stmt, undef, $username);
my $found = undef; my $domain;
my $found_address; my $new_address = undef;
my $new_address = undef; foreach my $addr (@$found_address) {
while ((!$found) && ($found_address = FetchOneColumn())) { ($domain) = ($addr =~ /.+@(.+)/);
($domain) = ($found_address =~ /.+@(.+)/); if ($address =~ /$domain/) {
if ($address =~ /$domain/) { $new_address = $addr;
$found = 1; last;
$new_address = $found_address; }
} }
return $new_address;
} elsif ($email_transform eq $EMAIL_TRANSFORM_NAME_ONLY) {
my ($username) = ($address =~ /(.+)@/);
my $stmt = q{SELECT login_name FROM profiles WHERE } . $dbh->sql_regexp(
$dbh->sql_istring('login_name'), $dbh->sql_istring('?'));
my $found_address = $dbh->selectrow_array($stmt, undef, $username);
return $found_address;
} }
return $new_address;
} elsif ($email_transform eq $EMAIL_TRANSFORM_NAME_ONLY) {
my ($username) = ($address =~ /(.+)@/);
my $stmt = "SELECT login_name FROM profiles WHERE " .$dbh->sql_regexp(
$dbh->sql_istring('login_name'), $dbh->sql_istring($dbh->quote($username)));
SendSQL($stmt);
my $found_address = FetchOneColumn();
return $found_address;
}
} }
1; 1;
...@@ -38,6 +38,7 @@ BEGIN { ...@@ -38,6 +38,7 @@ BEGIN {
} }
require "globals.pl"; require "globals.pl";
use Bugzilla;
use BugzillaEmail; use BugzillaEmail;
use Bugzilla::Config qw(:DEFAULT $datadir); use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::BugMail; use Bugzilla::BugMail;
...@@ -94,18 +95,17 @@ my ($bugid) = ($Subject =~ /\[Bug ([\d]+)\]/); ...@@ -94,18 +95,17 @@ my ($bugid) = ($Subject =~ /\[Bug ([\d]+)\]/);
print "The bugid is $bugid\n"; print "The bugid is $bugid\n";
# make sure the bug exists # make sure the bug exists
my $found_id = $dbh->selectrow_array(q{SELECT bug_id
SendSQL("SELECT bug_id FROM bugs WHERE bug_id = $bugid;"); FROM bugs
my $found_id = FetchOneColumn(); WHERE bug_id = ?}, undef, $bugid);
print "Did we find the bug? $found_id-\n"; print "Did we find the bug? $found_id-\n";
if (!defined($found_id)) { if (!defined($found_id)) {
DealWithError("Bug $bugid does not exist"); DealWithError("Bug $bugid does not exist");
} }
# get the user id # get the user id
SendSQL("SELECT userid FROM profiles WHERE " . my $userid = $dbh->selectrow_array(q{SELECT userid FROM profiles WHERE } .
$dbh->sql_istrcmp('login_name', $dbh->quote($SenderShort))); $dbh->sql_istrcmp('login_name', '?'), undef, $SenderShort);
my $userid = FetchOneColumn();
if (!defined($userid)) { if (!defined($userid)) {
DealWithError("Userid not found for $SenderShort"); DealWithError("Userid not found for $SenderShort");
} }
...@@ -119,8 +119,8 @@ $Subject =~ s/\[Bug [\d]+\]//; ...@@ -119,8 +119,8 @@ $Subject =~ s/\[Bug [\d]+\]//;
my $Body = "Subject: " . $Subject . "\n" . $Comment; my $Body = "Subject: " . $Subject . "\n" . $Comment;
# shove it in the table # shove it in the table
my $long_desc_query = "INSERT INTO longdescs SET bug_id=$found_id, who=$userid, bug_when=NOW(), thetext=" . SqlQuote($Body) . ";"; $dbh->do(q{INSERT INTO longdescs SET bug_id= ?, who= ?, bug_when= NOW(), thetext= ? },
SendSQL($long_desc_query); undef, $found_id, $userid, $Body);
Bugzilla::BugMail::Send( $found_id, { changer => $SenderShort } ); Bugzilla::BugMail::Send( $found_id, { changer => $SenderShort } );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment