import rt 3.2.2
[freeside.git] / rt / lib / RT / Action / Notify.pm
1 # {{{ BEGIN BPS TAGGED BLOCK
2
3 # COPYRIGHT:
4 #  
5 # This software is Copyright (c) 1996-2004 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., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27
28 # CONTRIBUTION SUBMISSION POLICY:
29
30 # (The following paragraph is not intended to limit the rights granted
31 # to you to modify and distribute this software under the terms of
32 # the GNU General Public License and is only of importance to you if
33 # you choose to contribute your changes and enhancements to the
34 # community by submitting them to Best Practical Solutions, LLC.)
35
36 # By intentionally submitting any modifications, corrections or
37 # derivatives to this work, or any other work intended for use with
38 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 # you are the copyright holder for those contributions and you grant
40 # Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
41 # royalty-free, perpetual, license to use, copy, create derivative
42 # works based on those contributions, and sublicense and distribute
43 # those contributions and any derivatives thereof.
44
45 # }}} END BPS TAGGED BLOCK
46 #
47 package RT::Action::Notify;
48 require RT::Action::SendEmail;
49 use Mail::Address;
50 use strict;
51 use vars qw/@ISA/;
52 @ISA = qw(RT::Action::SendEmail);
53
54
55 =head2 Prepare
56
57 Set up the relevant recipients, then call our parent.
58
59 =cut
60
61
62 sub Prepare {
63     my $self = shift;
64     $self->SetRecipients();
65     $self->SUPER::Prepare();
66 }
67
68 # {{{ sub SetRecipients
69
70 =head2 SetRecipients
71
72 Sets the recipients of this meesage to Owner, Requestor, AdminCc, Cc or All. 
73 Explicitly B<does not> notify the creator of the transaction by default
74
75 =cut
76
77 sub SetRecipients {
78     my $self = shift;
79
80     my $arg = $self->Argument;
81
82     $arg =~ s/\bAll\b/Owner,Requestor,AdminCc,Cc/;
83
84     my ( @To, @PseudoTo, @Cc, @Bcc );
85
86
87     if ( $arg =~ /\bOtherRecipients\b/ ) {
88         if ( $self->TransactionObj->Attachments->First ) {
89             my @cc_addresses = Mail::Address->parse($self->TransactionObj->Attachments->First->GetHeader('RT-Send-Cc'));
90             foreach my $addr (@cc_addresses) {
91                   push @Cc, $addr->address;
92             }
93             my @bcc_addresses = Mail::Address->parse($self->TransactionObj->Attachments->First->GetHeader('RT-Send-Bcc'));
94
95             foreach my $addr (@bcc_addresses) {
96                   push @Bcc, $addr->address;
97             }
98
99         }
100     }
101
102     if ( $arg =~ /\bRequestor\b/ ) {
103         push ( @To, $self->TicketObj->Requestors->MemberEmailAddresses  );
104     }
105
106     
107
108     if ( $arg =~ /\bCc\b/ ) {
109
110         #If we have a To, make the Ccs, Ccs, otherwise, promote them to To
111         if (@To) {
112             push ( @Cc, $self->TicketObj->Cc->MemberEmailAddresses );
113             push ( @Cc, $self->TicketObj->QueueObj->Cc->MemberEmailAddresses  );
114         }
115         else {
116             push ( @Cc, $self->TicketObj->Cc->MemberEmailAddresses  );
117             push ( @To, $self->TicketObj->QueueObj->Cc->MemberEmailAddresses  );
118         }
119     }
120
121     if ( ( $arg =~ /\bOwner\b/ )
122         && ( $self->TicketObj->OwnerObj->id != $RT::Nobody->id ) )
123     {
124
125         # If we're not sending to Ccs or requestors, 
126         # then the Owner can be the To.
127         if (@To) {
128             push ( @Bcc, $self->TicketObj->OwnerObj->EmailAddress );
129         }
130         else {
131             push ( @To, $self->TicketObj->OwnerObj->EmailAddress );
132         }
133
134     }
135
136     if ( $arg =~ /\bAdminCc\b/ ) {
137         push ( @Bcc, $self->TicketObj->AdminCc->MemberEmailAddresses  );
138         push ( @Bcc, $self->TicketObj->QueueObj->AdminCc->MemberEmailAddresses  );
139     }
140
141     if ($RT::UseFriendlyToLine) {
142         unless (@To) {
143             push (
144                 @PseudoTo,
145                 sprintf($RT::FriendlyToLineFormat, $arg, $self->TicketObj->id),
146             );
147         }
148     }
149
150     my $creator = $self->TransactionObj->CreatorObj->EmailAddress();
151
152     #Strip the sender out of the To, Cc and AdminCc and set the 
153     # recipients fields used to build the message by the superclass.
154     # unless a flag is set 
155     if ($RT::NotifyActor) {
156         @{ $self->{'To'} }  = @To;
157         @{ $self->{'Cc'} }  = @Cc;
158         @{ $self->{'Bcc'} } = @Bcc;
159     }
160     else {
161         @{ $self->{'To'} }  = grep ( !/^$creator$/, @To );
162         @{ $self->{'Cc'} }  = grep ( !/^$creator$/, @Cc );
163         @{ $self->{'Bcc'} } = grep ( !/^$creator$/, @Bcc );
164     }
165     @{ $self->{'PseudoTo'} } = @PseudoTo;
166
167
168 }
169
170 # }}}
171
172 eval "require RT::Action::Notify_Vendor";
173 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/Notify_Vendor.pm});
174 eval "require RT::Action::Notify_Local";
175 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/Notify_Local.pm});
176
177 1;