reverting to vendor branch rt 3.0.4, hopefully
[freeside.git] / rt / lib / RT / Action / Notify.pm
1 # BEGIN LICENSE BLOCK
2
3 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4
5 # (Except where explictly superceded by other copyright notices)
6
7 # This work is made available to you under the terms of Version 2 of
8 # the GNU General Public License. A copy of that license should have
9 # been provided with this software, but in any event can be snarfed
10 # from www.gnu.org.
11
12 # This work is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # General Public License for more details.
16
17 # Unless otherwise specified, all modifications, corrections or
18 # extensions to this work which alter its source code become the
19 # property of Best Practical Solutions, LLC when submitted for
20 # inclusion in the work.
21
22
23 # END LICENSE BLOCK
24 package RT::Action::Notify;
25 require RT::Action::SendEmail;
26
27 use strict;
28 use vars qw/@ISA/;
29 @ISA = qw(RT::Action::SendEmail);
30
31 # {{{ sub SetRecipients
32
33 =head2 SetRecipients
34
35 Sets the recipients of this meesage to Owner, Requestor, AdminCc, Cc or All. 
36 Explicitly B<does not> notify the creator of the transaction by default
37
38 =cut
39
40 sub SetRecipients {
41     my $self = shift;
42
43     my $arg = $self->Argument;
44
45     $arg =~ s/\bAll\b/Owner,Requestor,AdminCc,Cc/;
46
47     my ( @To, @PseudoTo, @Cc, @Bcc );
48
49
50     if ($arg =~ /\bOtherRecipients\b/) {
51         if ($self->TransactionObj->Attachments->First) {
52             push (@Cc, $self->TransactionObj->Attachments->First->GetHeader('RT-Send-Cc'));
53             push (@Bcc, $self->TransactionObj->Attachments->First->GetHeader('RT-Send-Bcc'));
54         }
55     }
56
57     if ( $arg =~ /\bRequestor\b/ ) {
58         push ( @To, $self->TicketObj->Requestors->MemberEmailAddresses  );
59     }
60
61     
62
63     if ( $arg =~ /\bCc\b/ ) {
64
65         #If we have a To, make the Ccs, Ccs, otherwise, promote them to To
66         if (@To) {
67             push ( @Cc, $self->TicketObj->Cc->MemberEmailAddresses );
68             push ( @Cc, $self->TicketObj->QueueObj->Cc->MemberEmailAddresses  );
69         }
70         else {
71             push ( @Cc, $self->TicketObj->Cc->MemberEmailAddresses  );
72             push ( @To, $self->TicketObj->QueueObj->Cc->MemberEmailAddresses  );
73         }
74     }
75
76     if ( ( $arg =~ /\bOwner\b/ )
77         && ( $self->TicketObj->OwnerObj->id != $RT::Nobody->id ) )
78     {
79
80         # If we're not sending to Ccs or requestors, 
81         # then the Owner can be the To.
82         if (@To) {
83             push ( @Bcc, $self->TicketObj->OwnerObj->EmailAddress );
84         }
85         else {
86             push ( @To, $self->TicketObj->OwnerObj->EmailAddress );
87         }
88
89     }
90
91     if ( $arg =~ /\bAdminCc\b/ ) {
92         push ( @Bcc, $self->TicketObj->AdminCc->MemberEmailAddresses  );
93         push ( @Bcc, $self->TicketObj->QueueObj->AdminCc->MemberEmailAddresses  );
94     }
95
96     if ($RT::UseFriendlyToLine) {
97         unless (@To) {
98             push (
99                 @PseudoTo,
100                 sprintf($RT::FriendlyToLineFormat, $arg, $self->TicketObj->id),
101             );
102         }
103     }
104
105     my $creator = $self->TransactionObj->CreatorObj->EmailAddress();
106
107     #Strip the sender out of the To, Cc and AdminCc and set the 
108     # recipients fields used to build the message by the superclass.
109     # unless a flag is set 
110     if ($RT::NotifyActor) {
111         @{ $self->{'To'} }  = @To;
112         @{ $self->{'Cc'} }  = @Cc;
113         @{ $self->{'Bcc'} } = @Bcc;
114     }
115     else {
116         @{ $self->{'To'} }  = grep ( !/^$creator$/, @To );
117         @{ $self->{'Cc'} }  = grep ( !/^$creator$/, @Cc );
118         @{ $self->{'Bcc'} } = grep ( !/^$creator$/, @Bcc );
119     }
120     @{ $self->{'PseudoTo'} } = @PseudoTo;
121     return (1);
122
123 }
124
125 # }}}
126
127 eval "require RT::Action::Notify_Vendor";
128 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/Notify_Vendor.pm});
129 eval "require RT::Action::Notify_Local";
130 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/Notify_Local.pm});
131
132 1;