Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
bugzilla
Commits
dc739537
Commit
dc739537
authored
Nov 04, 2010
by
Frédéric Buclin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 596611: Add a hook to email_in.pl
r/a=mkanat
parent
a3c3abff
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
0 deletions
+76
-0
Hook.pm
Bugzilla/Hook.pm
+28
-0
email_in.pl
email_in.pl
+6
-0
Extension.pm
extensions/Example/Extension.pm
+42
-0
No files found.
Bugzilla/Hook.pm
View file @
dc739537
...
...
@@ -569,6 +569,34 @@ L</config_add_panels> if you want to add new panels.
=back
=head2 email_in_before_parse
This happens right after an inbound email is converted into an Email::MIME
object, but before we start parsing the email to extract field data. This
means the email has already been decoded for you. It gives you a chance
to interact with the email itself before L<email_in> starts parsing its content.
=over
=item C<mail> - An Email::MIME object. The decoded incoming email.
=item C<fields> - A hashref. The hash which will contain extracted data.
=back
=head2 email_in_after_parse
This happens after all the data has been extracted from the email, but before
the reporter is validated, during L<email_in>. This lets you do things after
the normal parsing of the email, such as sanitizing field data, changing the
user account being used to file a bug, etc.
=over
=item C<fields> - A hashref. The hash containing the extracted field data.
=back
=head2 enter_bug_entrydefaultvars
B<DEPRECATED> - Use L</template_before_process> instead.
...
...
email_in.pl
View file @
dc739537
...
...
@@ -54,6 +54,7 @@ use Bugzilla::Mailer;
use
Bugzilla::
Token
;
use
Bugzilla::
User
;
use
Bugzilla::
Util
;
use
Bugzilla::
Hook
;
#############
# Constants #
...
...
@@ -76,6 +77,8 @@ sub parse_mail {
$input_email
=
Email::
MIME
->
new
(
$mail_text
);
my
%
fields
=
%
{
$switch
{
'default'
}
||
{}
};
Bugzilla::Hook::
process
(
'email_in_before_parse'
,
{
mail
=>
$input_email
,
fields
=>
\%
fields
});
my
$summary
=
$input_email
->
header
(
'Subject'
);
if
(
$summary
=~
/\[\S+ (\d+)\](.*)/i
)
{
...
...
@@ -394,6 +397,9 @@ Bugzilla->usage_mode(USAGE_MODE_EMAIL);
my
@mail_lines
=
<
STDIN
>
;
my
$mail_text
=
join
(
""
,
@mail_lines
);
my
$mail_fields
=
parse_mail
(
$mail_text
);
Bugzilla::Hook::
process
(
'email_in_after_parse'
,
{
fields
=>
$mail_fields
});
my
$attachments
=
delete
$mail_fields
->
{
'attachments'
};
my
$username
=
$mail_fields
->
{
'reporter'
};
...
...
extensions/Example/Extension.pm
View file @
dc739537
...
...
@@ -278,6 +278,48 @@ sub config_modify_panels {
push
(
@
{
$verify_class
->
{
choices
}
},
'Example'
);
}
sub
email_in_before_parse
{
my
(
$self
,
$args
)
=
@_
;
my
$subject
=
$args
->
{
mail
}
->
header
(
'Subject'
);
# Correctly extract the bug ID from email subjects of the form [Bug comp/NNN].
if
(
$subject
=~
/\[.*(\d+)\].*/
)
{
$args
->
{
fields
}
->
{
bug_id
}
=
$1
;
}
}
sub
email_in_after_parse
{
my
(
$self
,
$args
)
=
@_
;
my
$reporter
=
$args
->
{
fields
}
->
{
reporter
};
my
$dbh
=
Bugzilla
->
dbh
;
# No other check needed if this is a valid regular user.
return
if
login_to_id
(
$reporter
);
# The reporter is not a regular user. We create an account for him,
# but he can only comment on existing bugs.
# This is useful for people who reply by email to bugmails received
# in mailing-lists.
if
(
$args
->
{
fields
}
->
{
bug_id
})
{
# WARNING: we return now to skip the remaining code below.
# You must understand that removing this line would make the code
# below effective! Do it only if you are OK with the behavior
# described here.
return
;
Bugzilla::
User
->
create
({
login_name
=>
$reporter
,
cryptpassword
=>
'*'
});
# For security reasons, delete all fields unrelated to comments.
foreach
my
$field
(
keys
%
{
$args
->
{
fields
}})
{
next
if
$field
=~
/^(?:bug_id|comment|reporter)$/
;
delete
$args
->
{
fields
}
->
{
$field
};
}
}
else
{
ThrowUserError
(
'invalid_username'
,
{
name
=>
$reporter
});
}
}
sub
flag_end_of_update
{
my
(
$self
,
$args
)
=
@_
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment