import rt 3.6.4
[freeside.git] / rt / lib / RT / Action / Notify.pm
1 # BEGIN BPS TAGGED BLOCK {{{
2
3 # COPYRIGHT:
4 #  
5 # This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC 
6 #                                          <jesse@bestpractical.com>
7
8 # (Except where explicitly superseded by other copyright notices)
9
10
11 # LICENSE:
12
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
16 # from www.gnu.org.
17
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.
22
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/copyleft/gpl.html.
28
29
30 # CONTRIBUTION SUBMISSION POLICY:
31
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.)
37
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.
46
47 # END BPS TAGGED BLOCK }}}
48 #
49 package RT::Action::Notify;
50 require RT::Action::SendEmail;
51 use Mail::Address;
52 use strict;
53 use vars qw/@ISA/;
54 @ISA = qw(RT::Action::SendEmail);
55
56
57 =head2 Prepare
58
59 Set up the relevant recipients, then call our parent.
60
61 =cut
62
63
64 sub Prepare {
65     my $self = shift;
66     $self->SetRecipients();
67     $self->SUPER::Prepare();
68 }
69
70 # {{{ sub SetRecipients
71
72 =head2 SetRecipients
73
74 Sets the recipients of this meesage to Owner, Requestor, AdminCc, Cc or All. 
75 Explicitly B<does not> notify the creator of the transaction by default
76
77 =cut
78
79 sub SetRecipients {
80     my $self = shift;
81
82     my $arg = $self->Argument;
83
84     $arg =~ s/\bAll\b/Owner,Requestor,AdminCc,Cc/;
85
86     my ( @To, @PseudoTo, @Cc, @Bcc );
87
88
89     if ( $arg =~ /\bOtherRecipients\b/ ) {
90         if ( $self->TransactionObj->Attachments->First ) {
91             my @cc_addresses = Mail::Address->parse($self->TransactionObj->Attachments->First->GetHeader('RT-Send-Cc'));
92             foreach my $addr (@cc_addresses) {
93                   push @Cc, $addr->address;
94             }
95             my @bcc_addresses = Mail::Address->parse($self->TransactionObj->Attachments->First->GetHeader('RT-Send-Bcc'));
96
97             foreach my $addr (@bcc_addresses) {
98                   push @Bcc, $addr->address;
99             }
100
101         }
102     }
103
104     if ( $arg =~ /\bRequestor\b/ ) {
105         push ( @To, $self->TicketObj->Requestors->MemberEmailAddresses  );
106     }
107
108     
109
110     if ( $arg =~ /\bCc\b/ ) {
111
112         #If we have a To, make the Ccs, Ccs, otherwise, promote them to To
113         if (@To) {
114             push ( @Cc, $self->TicketObj->Cc->MemberEmailAddresses );
115             push ( @Cc, $self->TicketObj->QueueObj->Cc->MemberEmailAddresses  );
116         }
117         else {
118             push ( @Cc, $self->TicketObj->Cc->MemberEmailAddresses  );
119             push ( @To, $self->TicketObj->QueueObj->Cc->MemberEmailAddresses  );
120         }
121     }
122
123     if ( ( $arg =~ /\bOwner\b/ )
124         && ( $self->TicketObj->OwnerObj->id != $RT::Nobody->id ) )
125     {
126
127         # If we're not sending to Ccs or requestors, 
128         # then the Owner can be the To.
129         if (@To) {
130             push ( @Bcc, $self->TicketObj->OwnerObj->EmailAddress );
131         }
132         else {
133             push ( @To, $self->TicketObj->OwnerObj->EmailAddress );
134         }
135
136     }
137
138     if ( $arg =~ /\bAdminCc\b/ ) {
139         push ( @Bcc, $self->TicketObj->AdminCc->MemberEmailAddresses  );
140         push ( @Bcc, $self->TicketObj->QueueObj->AdminCc->MemberEmailAddresses  );
141     }
142
143     if ($RT::UseFriendlyToLine) {
144         unless (@To) {
145             push (
146                 @PseudoTo,
147                 sprintf($RT::FriendlyToLineFormat, $arg, $self->TicketObj->id),
148             );
149         }
150     }
151
152     my $creator = $self->TransactionObj->CreatorObj->EmailAddress();
153
154     #Strip the sender out of the To, Cc and AdminCc and set the 
155     # recipients fields used to build the message by the superclass.
156     # unless a flag is set 
157     if ($RT::NotifyActor) {
158         @{ $self->{'To'} }  = @To;
159         @{ $self->{'Cc'} }  = @Cc;
160         @{ $self->{'Bcc'} } = @Bcc;
161     }
162     else {
163         @{ $self->{'To'} }  = grep ( lc $_ ne lc $creator, @To );
164         @{ $self->{'Cc'} }  = grep ( lc $_ ne lc $creator, @Cc );
165         @{ $self->{'Bcc'} } = grep ( lc $_ ne lc $creator, @Bcc );
166     }
167     @{ $self->{'PseudoTo'} } = @PseudoTo;
168
169
170 }
171
172 # }}}
173
174 eval "require RT::Action::Notify_Vendor";
175 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/Notify_Vendor.pm});
176 eval "require RT::Action::Notify_Local";
177 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/Notify_Local.pm});
178
179 1;