1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 # <jesse@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
48 package RT::Interface::Email::Auth::MailFrom;
49 use RT::Interface::Email qw(ParseSenderAddressFromHead CreateUser);
51 # This is what the ordinary, non-enhanced gateway does at the moment.
54 my %args = ( Message => undef,
63 # We don't need to do any external lookups
64 my ( $Address, $Name ) = ParseSenderAddressFromHead( $args{'Message'}->head );
67 return ( $args{'CurrentUser'}, -1 );
70 my $CurrentUser = RT::CurrentUser->new();
71 $CurrentUser->LoadByEmail($Address);
73 unless ( $CurrentUser->Id ) {
74 $CurrentUser->LoadByName($Address);
77 if ( $CurrentUser->Id ) {
78 return ( $CurrentUser, 1 );
83 # If the user can't be loaded, we may need to create one. Figure out the acl situation.
84 my $unpriv = RT::Group->new($RT::SystemUser);
85 $unpriv->LoadSystemInternalGroup('Unprivileged');
86 unless ( $unpriv->Id ) {
87 $RT::Logger->crit( "Auth::MailFrom couldn't find the 'Unprivileged' internal group" );
88 return ( $args{'CurrentUser'}, -1 );
91 my $everyone = RT::Group->new($RT::SystemUser);
92 $everyone->LoadSystemInternalGroup('Everyone');
93 unless ( $everyone->Id ) {
94 $RT::Logger->crit( "Auth::MailFrom couldn't find the 'Everyone' internal group");
95 return ( $args{'CurrentUser'}, -1 );
98 # but before we do that, we need to make sure that the created user would have the right
99 # to do what we're doing.
100 if ( $args{'Ticket'} && $args{'Ticket'}->Id ) {
101 # We have a ticket. that means we're commenting or corresponding
102 if ( $args{'Action'} =~ /^comment$/i ) {
104 # check to see whether "Everyone" or "Unprivileged users" can comment on tickets
105 unless ( $everyone->PrincipalObj->HasRight(
106 Object => $args{'Queue'},
107 Right => 'CommentOnTicket'
109 || $unpriv->PrincipalObj->HasRight(
110 Object => $args{'Queue'},
111 Right => 'CommentOnTicket'
114 return ( $args{'CurrentUser'}, 0 );
117 elsif ( $args{'Action'} =~ /^correspond$/i ) {
119 # check to see whether "Everybody" or "Unprivileged users" can correspond on tickets
120 unless ( $everyone->PrincipalObj->HasRight(Object => $args{'Queue'},
121 Right => 'ReplyToTicket'
123 || $unpriv->PrincipalObj->HasRight(
124 Object => $args{'Queue'},
125 Right => 'ReplyToTicket'
128 return ( $args{'CurrentUser'}, 0 );
132 elsif ( $args{'Action'} =~ /^take$/i ) {
134 # check to see whether "Everybody" or "Unprivileged users" can correspond on tickets
135 unless ( $everyone->PrincipalObj->HasRight(Object => $args{'Queue'},
138 || $unpriv->PrincipalObj->HasRight(
139 Object => $args{'Queue'},
143 return ( $args{'CurrentUser'}, 0 );
147 elsif ( $args{'Action'} =~ /^resolve$/i ) {
149 # check to see whether "Everybody" or "Unprivileged users" can correspond on tickets
150 unless ( $everyone->PrincipalObj->HasRight(Object => $args{'Queue'},
151 Right => 'ModifyTicket'
153 || $unpriv->PrincipalObj->HasRight(
154 Object => $args{'Queue'},
155 Right => 'ModifyTicket'
158 return ( $args{'CurrentUser'}, 0 );
163 return ( $args{'CurrentUser'}, 0 );
167 # We're creating a ticket
168 elsif ( $args{'Queue'} && $args{'Queue'}->Id ) {
170 # check to see whether "Everybody" or "Unprivileged users" can create tickets in this queue
171 unless ( $everyone->PrincipalObj->HasRight( Object => $args{'Queue'},
172 Right => 'CreateTicket' )
174 return ( $args{'CurrentUser'}, 0 );
179 $CurrentUser = CreateUser( undef, $Address, $Name, $Address, $args{'Message'} );
181 return ( $CurrentUser, 1 );
184 eval "require RT::Interface::Email::Auth::MailFrom_Vendor";
185 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Interface/Email/Auth/MailFrom_Vendor.pm});
186 eval "require RT::Interface::Email::Auth::MailFrom_Local";
187 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Interface/Email/Auth/MailFrom_Local.pm});