import rt 2.0.14
[freeside.git] / rt / lib / RT / Action / SendPasswordEmail.pm
1 # $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Action/Attic/SendPasswordEmail.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
2 # Copyright 2001  Jesse Vincent <jesse@fsck.com>
3 # Released under the terms of the GNU Public License
4
5 package RT::Action::SendPasswordEmail;
6 require RT::Action::Generic;
7
8 @ISA = qw(RT::Action::Generic);
9
10
11 =head1 NAME
12
13   RT::Action::SendGenericEmail - An Action which users can use to send mail 
14   or can subclassed for more specialized mail sending behavior. 
15
16
17
18 =head1 SYNOPSIS
19
20   require RT::Action::SendPasswordEmail;
21
22
23 =head1 DESCRIPTION
24
25 Basically, you create another module RT::Action::YourAction which ISA
26 RT::Action::SendEmail.
27
28 If you want to set the recipients of the mail to something other than
29 the addresses mentioned in the To, Cc, Bcc and headers in
30 the template, you should subclass RT::Action::SendEmail and override
31 either the SetRecipients method or the SetTo, SetCc, etc methods (see
32 the comments for the SetRecipients sub).
33
34
35 =begin testing
36
37 ok (require RT::TestHarness);
38 ok (require RT::Action::SendPasswordEmail);
39
40 =end testing
41
42
43 =head1 AUTHOR
44
45 Jesse Vincent <jesse@bestpractical.com>
46
47 =head1 SEE ALSO
48
49 perl(1).
50
51 =cut
52
53 # {{{ Scrip methods (_Init, Commit, Prepare, IsApplicable)
54
55 # {{{ sub Commit 
56
57 #Do what we need to do and send it out.
58
59 sub Commit  {
60     my $self = shift;
61     #send the email
62     
63     
64     
65
66     
67     my $MIMEObj = $self->TemplateObj->MIMEObj;
68     
69     
70     $MIMEObj->make_singlepart;
71     
72     #If we don\'t have any recipients to send to, don\'t send a message;
73     unless ($MIMEObj->head->get('To')) {
74         $RT::Logger->debug("$self: No recipients found. Not sending.\n");
75         return(1);
76     }
77     
78     if ($RT::MailCommand eq 'sendmailpipe') {
79         open (MAIL, "|$RT::SendmailPath $RT::SendmailArguments") || return(0);
80         print MAIL $MIMEObj->as_string;
81         close(MAIL);
82     }
83     else {
84         unless ($MIMEObj->send($RT::MailCommand, $RT::MailParams)) {
85             $RT::Logger->crit("$self: Could not send mail for ".
86                               $self->TransactionObj . "\n");
87             return(0);
88         }
89     }
90     
91     return (1);
92     
93 }
94 # }}}
95
96 # {{{ sub Prepare 
97
98 sub Prepare  {
99     my $self = shift;
100     
101     # This actually populates the MIME::Entity fields in the Template Object
102     
103     unless ($self->TemplateObj) {
104         $RT::Logger->warning("No template object handed to $self\n");
105     }
106     
107     
108     unless ($self->TemplateObj->MIMEObj->head->get('Reply-To')) {
109         $self->SetHeader('Reply-To',$RT::CorrespondAddress );
110     }
111
112     
113     $self->SetHeader('Precedence', "bulk");
114     $self->SetHeader('X-RT-Loop-Prevention', $RT::rtname); 
115     $self->SetHeader
116       ('Managed-by',"Request Tracker $RT::VERSION (http://www.fsck.com/projects/rt/)");
117     
118     $self->TemplateObj->Parse(Argument => $self->Argument);
119     
120     
121     return 1;
122 }
123
124 # }}}
125
126 # }}}
127
128
129 # {{{ sub SetTo
130
131 =head2 SetTo EMAIL
132
133 Sets this message's "To" field to EMAIL
134
135 =cut
136
137 sub SetTo {
138     my $self = shift;
139     my $to = shift;
140     $self->SetHeader('To',$to);
141 }
142
143 # }}}
144
145 # {{{ sub SetHeader
146
147 sub SetHeader {
148   my $self = shift;
149   my $field = shift;
150   my $val = shift;
151
152   chomp $val;                                                                  
153   chomp $field;                                                                
154   $self->TemplateObj->MIMEObj->head->fold_length($field,10000);     
155   $self->TemplateObj->MIMEObj->head->add($field, $val);
156   return $self->TemplateObj->MIMEObj->head->get($field);
157 }
158
159 # }}}
160
161
162
163 __END__
164
165 # {{{ POD
166
167 # }}}
168
169 1;
170