Quiq/Sendmail.pm

filter: Statementstmt 43.1% 19 / 44 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 42.1% 27 / 64 CC 6 SCAR 30.0
CC
6
Cov
35%
send
42.0
new
2.0
BEGIN
1.0
CRAP 20.0
« Quiq/Parallel.pm ↑ Summary Quiq/Parameters.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Sendmail - Versende Mail mit sendmail
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Object>
12  
13 =head1 SYNOPSIS
14  
15 use Quiq::Sendmail;
16
17 Quiq::Sendmail->send($to,$subject,$body,
18 -contentType => 'text/html; charset=utf-8',
19 );
20  
21 =cut
22  
23 # -----------------------------------------------------------------------------
24  
25 package Quiq::Sendmail;
26 1 ▶use base qw/Quiq::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 our $VERSION = '1.240';
33  
34 1 ▶use Quiq::FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 # -----------------------------------------------------------------------------
38  
39 =head1 METHODS
40  
41 =head2 Konstruktor
42  
43 =head3 new() - Instantiiere Objekt
44  
45 =head4 Synopsis
46  
47 $s = $class->new;
48  
49 =head4 Returns
50  
51 Objekt
52  
53 =head4 Description
54  
55 Instantiiere ein Objekt der Klasse und liefere eine Referenz auf
56 dieses Objekt zurück. Da die Klasse ausschließlich Klassenmethoden
57 enthält, hat das Objekt ausschließlich die Funktion, eine abkürzende
58 Aufrufschreibweise für diese Methoden zu ermöglichen.
59  
60 =cut
61  
62 # -----------------------------------------------------------------------------
63  
64 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
65 0 my $class = shift;
66 0 return bless \(my $dummy),$class;
67 }
68  
69 # -----------------------------------------------------------------------------
70  
71 =head2 Klassenmethoden
72  
73 =head3 send() - Versende Mail
74  
75 =head4 Synopsis
76  
77 $this->send($to,$subject,$body,@opt);
78  
79 =head4 Arguments
80  
81 =over 4
82  
83 =item $to
84  
85 Empfänger der E-Mail.
86  
87 =item $subject
88  
89 Betreff der E-Mail.
90  
91 =item $body
92  
93 Inhalt der E-Mail.
94  
95 =back
96  
97 =head4 Options
98  
99 =over 4
100  
101 =item -contentType => $contentType (Default: 'text/plain')
102  
103 Content-Type von $subject und $body. Wenn leer, wird
104 kein Content-Type-Header gesetzt.
105  
106 =item -encoding => $charset (Default: 'utf-8')
107  
108 Encoding von $subject und $body. Wenn leer, wird vor dem Senden
109 encode() nicht auf $subject und $body angewendet.
110  
111 =item -from => $address
112  
113 Absender, z.B. 'Frank Seitz <fs@fseitz.de>'.
114  
115 =item -replyTo => $address
116  
117 Reply-To Adresse.
118  
119 =back
120  
121 =head4 Description
122  
123 Versende eine E-Mail an Empfänger $to mit dem Betreff $subject und
124 dem Inhalt $body.
125  
126 =cut
127  
128 # -----------------------------------------------------------------------------
129  
130 0 ▶sub send {
Subroutine send: not called CC=6 SCAR=37.4
Pod documented
131 0 my ($this,$to,$subject,$body) = splice @_,0,4;
132  
133 # Optionen
134  
135 0 my $contentType = 'text/plain';
136 0 my $encoding = 'utf-8';
137 0 my $from = undef;
138 0 my $replyTo = undef;
139  
140 0 my $optA = $this->parameters(\@_,
141 -contentType => \$contentType,
142 -encoding => \$encoding,
143 -from => $from,
144 -replyTo => \$replyTo,
145 );
146
147 # Operation ausführen
148  
149 0 ▶ if ($encoding) {
Branch: 1 branch
BranchTrueFalseTotal
if ($encoding) 0 0 0
150 0 $subject = Encode::encode($encoding,$subject);
151 0 $body = Encode::encode($encoding,$body);
152 }
153  
154 0 my $fh = Quiq::FileHandle->new('|-','/usr/sbin/sendmail -t');
155 0 ▶ if ($from) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from) 0 0 0
156 0 $fh->print("From: $from\n");
157 }
158 0 $fh->print("To: $to\n");
159 0 ▶ if ($replyTo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($replyTo) 0 0 0
160 0 $fh->print("Reply-To: $replyTo\n");
161 }
162 0 $fh->print("Subject: $subject\n");
163 0 ▶ if ($contentType) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contentType) 0 0 0
164 0 ▶ if ($encoding) {
Branch: 1 branch
BranchTrueFalseTotal
if ($encoding) 0 0 0
165 0 $contentType .= "; charset=$encoding";
166 }
167 0 $fh->print("Content-Type: $contentType\n\n");
168 }
169 0 $fh->print($body);
170 0 $fh->close;
171  
172 0 return;
173 }
174  
175 # -----------------------------------------------------------------------------
176  
177 =head1 VERSION
178  
179 1.240
180  
181 =head1 AUTHOR
182  
183 Frank Seitz, L<http://fseitz.de/>
184  
185 =head1 COPYRIGHT
186  
187 Copyright (C) 2026 Frank Seitz
188  
189 =head1 LICENSE
190  
191 This code is free software; you can redistribute it and/or modify
192 it under the same terms as Perl itself.
193  
194 =cut
195  
196 # -----------------------------------------------------------------------------
197  
198 1 1;
199  
200 # eof
« Quiq/Parallel.pm ↑ Summary Quiq/Parameters.pm »