import rt 2.0.14
[freeside.git] / rt / lib / RT / Action / Notify.pm
1 #$Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Action/Notify.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
2
3 package RT::Action::Notify;
4 require RT::Action::SendEmail;
5 @ISA = qw(RT::Action::SendEmail);
6
7 # {{{ sub SetRecipients
8
9 =head2 SetRecipients
10
11 Sets the recipients of this meesage to Owner, Requestor, AdminCc, Cc or All. 
12 Explicitly B<does not> notify the creator of the transaction.
13
14 =cut
15
16 sub SetRecipients {
17     my $self = shift;
18
19     $arg = $self->Argument;
20
21     $arg =~ s/\bAll\b/Owner,Requestor,AdminCc,Cc/;
22
23     my ( @To, @PseudoTo, @Cc, @Bcc );
24
25
26     if ($arg =~ /\bOtherRecipients\b/) {
27         if ($self->TransactionObj->Message->First) {
28             push (@Cc, $self->TransactionObj->Message->First->GetHeader('RT-Send-Cc'));
29             push (@Bcc, $self->TransactionObj->Message->First->GetHeader('RT-Send-Bcc'));
30         }
31     }
32
33     if ( $arg =~ /\bRequestor\b/ ) {
34         push ( @To, @{ $self->TicketObj->Requestors->Emails } );
35     }
36
37     
38
39     if ( $arg =~ /\bCc\b/ ) {
40
41         #If we have a To, make the Ccs, Ccs, otherwise, promote them to To
42         if (@To) {
43             push ( @Cc, @{ $self->TicketObj->Cc->Emails } );
44             push ( @Cc, @{ $self->TicketObj->QueueObj->Cc->Emails } );
45         }
46         else {
47             push ( @Cc, @{ $self->TicketObj->Cc->Emails } );
48             push ( @To, @{ $self->TicketObj->QueueObj->Cc->Emails } );
49         }
50     }
51
52     if ( ( $arg =~ /\bOwner\b/ )
53         && ( $self->TicketObj->OwnerObj->id != $RT::Nobody->id ) )
54     {
55
56         # If we're not sending to Ccs or requestors, 
57         # then the Owner can be the To.
58         if (@To) {
59             push ( @Bcc, $self->TicketObj->OwnerObj->EmailAddress );
60         }
61         else {
62             push ( @To, $self->TicketObj->OwnerObj->EmailAddress );
63         }
64
65     }
66
67     if ( $arg =~ /\bAdminCc\b/ ) {
68         push ( @Bcc, @{ $self->TicketObj->AdminCc->Emails } );
69         push ( @Bcc, @{ $self->TicketObj->QueueObj->AdminCc->Emails } );
70     }
71
72     if ($RT::UseFriendlyToLine) {
73         unless (@To) {
74             push ( @PseudoTo,
75                 "\"$arg of $RT::rtname Ticket #"
76                   . $self->TicketObj->id . "\":;" );
77         }
78     }
79
80     my $creator = $self->TransactionObj->CreatorObj->EmailAddress();
81
82     #Strip the sender out of the To, Cc and AdminCc and set the 
83     # recipients fields used to build the message by the superclass.
84
85     $RT::Logger->debug("$self: To is ".join(",",@To));
86     $RT::Logger->debug("$self: Cc is ".join(",",@Cc));
87     $RT::Logger->debug("$self: Bcc is ".join(",",@Bcc));
88
89     @{ $self->{'To'} }  = grep ( !/^$creator$/, @To );
90     @{ $self->{'Cc'} }  = grep ( !/^$creator$/, @Cc );
91     @{ $self->{'Bcc'} } = grep ( !/^$creator$/, @Bcc );
92     @{ $self->{'PseudoTo'} } = @PseudoTo;
93     return (1);
94
95 }
96
97 # }}}
98
99 1;