summaryrefslogtreecommitdiff
path: root/rt/lib/RT/Action/SendPasswordEmail.pm
blob: 91bb3c1cb03f8f92508b1d9ed5a3a137bef2ff7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Action/Attic/SendPasswordEmail.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
# Copyright 2001  Jesse Vincent <jesse@fsck.com>
# Released under the terms of the GNU Public License

package RT::Action::SendPasswordEmail;
require RT::Action::Generic;

@ISA = qw(RT::Action::Generic);


=head1 NAME

  RT::Action::SendGenericEmail - An Action which users can use to send mail 
  or can subclassed for more specialized mail sending behavior. 



=head1 SYNOPSIS

  require RT::Action::SendPasswordEmail;


=head1 DESCRIPTION

Basically, you create another module RT::Action::YourAction which ISA
RT::Action::SendEmail.

If you want to set the recipients of the mail to something other than
the addresses mentioned in the To, Cc, Bcc and headers in
the template, you should subclass RT::Action::SendEmail and override
either the SetRecipients method or the SetTo, SetCc, etc methods (see
the comments for the SetRecipients sub).


=begin testing

ok (require RT::TestHarness);
ok (require RT::Action::SendPasswordEmail);

=end testing


=head1 AUTHOR

Jesse Vincent <jesse@bestpractical.com>

=head1 SEE ALSO

perl(1).

=cut

# {{{ Scrip methods (_Init, Commit, Prepare, IsApplicable)

# {{{ sub Commit 

#Do what we need to do and send it out.

sub Commit  {
    my $self = shift;
    #send the email
    
    
    

    
    my $MIMEObj = $self->TemplateObj->MIMEObj;
    
    
    $MIMEObj->make_singlepart;
    
    #If we don\'t have any recipients to send to, don\'t send a message;
    unless ($MIMEObj->head->get('To')) {
	$RT::Logger->debug("$self: No recipients found. Not sending.\n");
	return(1);
    }
    
    if ($RT::MailCommand eq 'sendmailpipe') {
	open (MAIL, "|$RT::SendmailPath $RT::SendmailArguments") || return(0);
	print MAIL $MIMEObj->as_string;
	close(MAIL);
    }
    else {
	unless ($MIMEObj->send($RT::MailCommand, $RT::MailParams)) {
	    $RT::Logger->crit("$self: Could not send mail for ".
			      $self->TransactionObj . "\n");
	    return(0);
	}
    }
    
    return (1);
    
}
# }}}

# {{{ sub Prepare 

sub Prepare  {
    my $self = shift;
    
    # This actually populates the MIME::Entity fields in the Template Object
    
    unless ($self->TemplateObj) {
	$RT::Logger->warning("No template object handed to $self\n");
    }
    
    
    unless ($self->TemplateObj->MIMEObj->head->get('Reply-To')) {
	$self->SetHeader('Reply-To',$RT::CorrespondAddress );
    }

    
    $self->SetHeader('Precedence', "bulk");
    $self->SetHeader('X-RT-Loop-Prevention', $RT::rtname); 
    $self->SetHeader
      ('Managed-by',"Request Tracker $RT::VERSION (http://www.fsck.com/projects/rt/)");
    
    $self->TemplateObj->Parse(Argument => $self->Argument);
    
    
    return 1;
}

# }}}

# }}}


# {{{ sub SetTo

=head2 SetTo EMAIL

Sets this message's "To" field to EMAIL

=cut

sub SetTo {
    my $self = shift;
    my $to = shift;
    $self->SetHeader('To',$to);
}

# }}}

# {{{ sub SetHeader

sub SetHeader {
  my $self = shift;
  my $field = shift;
  my $val = shift;

  chomp $val;                                                                  
  chomp $field;                                                                
  $self->TemplateObj->MIMEObj->head->fold_length($field,10000);     
  $self->TemplateObj->MIMEObj->head->add($field, $val);
  return $self->TemplateObj->MIMEObj->head->get($field);
}

# }}}



__END__

# {{{ POD

# }}}

1;