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";
use strict;
my $dbh = Bugzilla->dbh;
my $EMAIL_TRANSFORM_NONE = "email_transform_none";
my $EMAIL_TRANSFORM_BASE_DOMAIN = "email_transform_base_domain";
......@@ -41,42 +40,38 @@ my $EMAIL_TRANSFORM_NAME_ONLY = "email_transform_name_only";
# change to do incoming email address fuzzy matching
my $email_transform = $EMAIL_TRANSFORM_NAME_ONLY;
# findUser()
# This function takes an email address and returns the user email.
# matching is sloppy based on the $email_transform parameter
sub findUser($) {
my $dbh = Bugzilla->dbh;
my ($address) = @_;
# if $email_transform is $EMAIL_TRANSFORM_NONE, return the address, otherwise, return undef
if ($email_transform eq $EMAIL_TRANSFORM_NONE) {
my $stmt = "SELECT login_name FROM profiles WHERE " .
$dbh->sql_istrcmp('login_name', $dbh->quote($address));
SendSQL($stmt);
my $found_address = FetchOneColumn();
my $stmt = q{SELECT login_name FROM profiles WHERE } .
$dbh->sql_istrcmp('login_name', '?');
my $found_address = $dbh->selectrow_array($stmt, undef, $address);
return $found_address;
} elsif ($email_transform eq $EMAIL_TRANSFORM_BASE_DOMAIN) {
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 $stmt = q{SELECT login_name FROM profiles WHERE } . $dbh->sql_regexp(
$dbh->sql_istring('login_name'), $dbh->sql_istring('?'));
my $found_address = $dbh->selectcol_arrayref($stmt, undef, $username);
my $domain;
my $found = undef;
my $found_address;
my $new_address = undef;
while ((!$found) && ($found_address = FetchOneColumn())) {
($domain) = ($found_address =~ /.+@(.+)/);
foreach my $addr (@$found_address) {
($domain) = ($addr =~ /.+@(.+)/);
if ($address =~ /$domain/) {
$found = 1;
$new_address = $found_address;
$new_address = $addr;
last;
}
}
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();
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;
}
}
......
......@@ -38,6 +38,7 @@ BEGIN {
}
require "globals.pl";
use Bugzilla;
use BugzillaEmail;
use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::BugMail;
......@@ -94,18 +95,17 @@ my ($bugid) = ($Subject =~ /\[Bug ([\d]+)\]/);
print "The bugid is $bugid\n";
# make sure the bug exists
SendSQL("SELECT bug_id FROM bugs WHERE bug_id = $bugid;");
my $found_id = FetchOneColumn();
my $found_id = $dbh->selectrow_array(q{SELECT bug_id
FROM bugs
WHERE bug_id = ?}, undef, $bugid);
print "Did we find the bug? $found_id-\n";
if (!defined($found_id)) {
DealWithError("Bug $bugid does not exist");
}
# get the user id
SendSQL("SELECT userid FROM profiles WHERE " .
$dbh->sql_istrcmp('login_name', $dbh->quote($SenderShort)));
my $userid = FetchOneColumn();
my $userid = $dbh->selectrow_array(q{SELECT userid FROM profiles WHERE } .
$dbh->sql_istrcmp('login_name', '?'), undef, $SenderShort);
if (!defined($userid)) {
DealWithError("Userid not found for $SenderShort");
}
......@@ -119,8 +119,8 @@ $Subject =~ s/\[Bug [\d]+\]//;
my $Body = "Subject: " . $Subject . "\n" . $Comment;
# 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) . ";";
SendSQL($long_desc_query);
$dbh->do(q{INSERT INTO longdescs SET bug_id= ?, who= ?, bug_when= NOW(), thetext= ? },
undef, $found_id, $userid, $Body);
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