From e306adca00703fa41fc4053798e76cd652049f98 Mon Sep 17 00:00:00 2001 From: vfilippov Date: Mon, 2 Mar 2009 12:40:56 +0000 Subject: [PATCH] Bug 47074 debug email_in no nested transactions in Bugzilla :-( git-svn-id: svn://svn.office.custis.ru/3rdparty/bugzilla.org/trunk@138 6955db30-a419-402b-8a0d-67ecbb4d7f56 --- Bugzilla/Attachment.pm | 2 +- email_in.pl | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Bugzilla/Attachment.pm b/Bugzilla/Attachment.pm index cf0e85d6c..962e04fc1 100644 --- a/Bugzilla/Attachment.pm +++ b/Bugzilla/Attachment.pm @@ -447,7 +447,7 @@ sub _validate_filename { || ($cgi->param('text_attachment') !~ /^\s*$/so) || ($throw_error ? ThrowUserError("file_not_specified") : return 0); - my $filename = $cgi->upload('data'); + my $filename = $cgi->upload('data') || $cgi->param('filename'); $filename = $cgi->param('description') if !$filename && $cgi->param('text_attachment') !~ /^\s*$/so; diff --git a/email_in.pl b/email_in.pl index 37b7c0e7e..052e44dbb 100755 --- a/email_in.pl +++ b/email_in.pl @@ -26,7 +26,8 @@ use warnings; # run from this one so that it can find its modules. BEGIN { require File::Basename; - chdir(File::Basename::dirname($0)); + my ($a) = $0 =~ /^(.*)$/iso; + chdir(File::Basename::dirname($a)); } use lib qw(. lib); @@ -48,6 +49,7 @@ use Bugzilla::Mailer; use Bugzilla::User; use Bugzilla::Util; use Bugzilla::Token; +use POSIX qw(geteuid); ############# # Constants # @@ -64,6 +66,9 @@ our ($input_email, %switch); # Main Subroutines # #################### +open STDERR, ">>/home/mail/debug" or die; +open STDOUT, ">>/home/mail/debug" or die; + sub parse_mail { my ($mail_text) = @_; debug_print('Parsing Email'); @@ -84,6 +89,7 @@ sub parse_mail { $fields{'bug_id'} = $1; $summary = trim($2); } + $fields{_subject} = $summary; # Add CC's from email Cc: header $fields{newcc} = (join ', ', map { [ Email::Address->parse($_) ] -> [0] } @@ -168,7 +174,6 @@ sub post_bug { $cgi->param(-name => 'inbound_email', -value => 1); - Bugzilla->dbh->bz_start_transaction(); my $bug_id = do 'post_bug.cgi'; debug_print($@) if $@; if ($fields{attachments} && @{$fields{attachments}}) @@ -176,27 +181,28 @@ sub post_bug { $cgi->delete(keys %fields); insert_attachments_for_bug($bug_id, @{$fields{attachments}}); } - Bugzilla->dbh->bz_commit_transaction(); } sub insert_attachments_for_bug { my $bug_id = shift; + my $subject = shift; my ($tt) = Bugzilla->dbh->selectrow_array( "SELECT short_desc FROM bugs WHERE bug_id=? LIMIT 1", undef, $bug_id); my $cgi = Bugzilla->cgi; for (@_) { $cgi->delete(qw(action bugid description filename contenttypeentry - contenttypemethod text_attachment token)); + contenttypemethod text_attachment token comment)); $cgi->param(action => 'insert'); $cgi->param(bugid => $bug_id); - $cgi->param(description => $tt); + $cgi->param(description => $subject || $tt); $cgi->param(filename => $_->{filename}); $cgi->param(contenttypeentry => $_->{content_type}); $cgi->param(contenttypemethod => 'manual'); $cgi->param(text_attachment => $_->{payload}); $cgi->param(token => issue_session_token('createattachment:')); + debug_print("Inserting attachment for bug $bug_id"); do 'attachment.cgi'; debug_print($@) if $@; } @@ -213,7 +219,6 @@ sub process_bug { debug_print("Updating Bug $fields{id}..."); - Bugzilla->dbh->bz_start_transaction(); ValidateBugID($bug_id); my $bug = new Bugzilla::Bug($bug_id); @@ -251,9 +256,8 @@ sub process_bug { if ($fields{attachments} && @{$fields{attachments}}) { $cgi->delete(keys %fields); - insert_attachments_for_bug($bug_id, @{$fields{attachments}}); + insert_attachments_for_bug($bug_id, $fields{_subject}, @{$fields{attachments}}); } - Bugzilla->dbh->bz_commit_transaction(); } ###################### @@ -391,13 +395,13 @@ $switch{'verbose'} ||= 0; pod2usage({-verbose => 0, -exitval => 1}) if $switch{'help'}; # Get a next-in-pipe command from commandline -my $pipe = join ' ', @ARGV; +my ($pipe) = join(' ', @ARGV) =~ /^(.*)$/iso; @ARGV = (); Bugzilla->usage_mode(USAGE_MODE_EMAIL); my @mail_lines = ; -my $mail_text = join("", @mail_lines); +my ($mail_text) = join("", @mail_lines) =~ /^(.*)$/iso; if ($pipe && open PIPE, "| $pipe") {