PMilter/Context.pm untested

filter: Statementstmt 0.0% 0 / 409 Branchbran 0.0% 0 / 148 Conditioncond 0.0% 0 / 70 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 68 Podpod 0.0% 0 / 22 totaltotal 0.0% 0 / 717 CC 75 SCAR 57.1
CC
75
Cov
0%
main
1190.0
call_hooks
156.0
addheader
20.0
CRAP 303.0
1 =pod
2  
3 =head1 LICENSE
4  
5 Copyright (c) 2016-2024 G.W. Haywood. All rights reserved.
6 With thanks to all those who have trodden these paths before,
7 including
8 Copyright (c) 2002-2004 Todd Vierling. All rights reserved.
9  
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12  
13 1. Redistributions of source code must retain the above copyright notices,
14 this list of conditions and the following disclaimer.
15  
16 2. Redistributions in binary form must reproduce the above copyright
17 notices, this list of conditions and the following disclaimer in the
18 documentation and/or other materials provided with the distribution.
19  
20 3. Neither the name of the author nor the names of contributors may be used
21 to endorse or promote products derived from this software without specific
22 prior written permission. In the case of G.W. Haywood this permission is
23 hereby now granted.
24  
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 POSSIBILITY OF SUCH DAMAGE.
36  
37 =cut
38  
39 package Sendmail::PMilter::Context;
40  
41 use 5.014; # Don't use 5.016 yet. That would enable feature 'unicode_strings', and we
42 # probably aren't quite ready for that. We're counting *characters* passed
43 # between us and Sendmail, and Sendmail thinks that they're *bytes*.
44 use parent 'Exporter';
45  
46 use strict;
47 use warnings;
48  
49 use Carp;
50 use Socket;
51 use UNIVERSAL;
52  
53 use Sendmail::PMilter 1.27 qw(:all);
54  
55 # use Data::Dumper;
56  
57 our $VERSION = '1.27';
58 $VERSION = eval $VERSION;
59  
60 =pod
61  
62 =head1 SYNOPSIS
63  
64 Sendmail::PMilter::Context - per-connection milter context
65  
66 =head1 DESCRIPTION
67  
68 A Sendmail::PMilter::Context is the context object passed to milter callback
69 functions as the first argument, typically named "$ctx" for convenience.
70 This document details the publicly accessible operations on this object.
71  
72 =head1 METHODS
73  
74 =cut
75  
76 ##### Symbols exported to the caller
77  
78 use constant SMFIA_UNKNOWN => 'U';
79 use constant SMFIA_UNIX => 'L';
80 use constant SMFIA_INET => '4';
81 use constant SMFIA_INET6 => '6';
82  
83 our @EXPORT_OK = qw(
84 SMFIA_UNKNOWN
85 SMFIA_UNIX
86 SMFIA_INET
87 SMFIA_INET6
88 );
89 our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
90  
91 ##### Protocol constants
92 # Commands:
93 use constant SMFIC_ABORT => 'A';
94 use constant SMFIC_BODY => 'B';
95 use constant SMFIC_CONNECT => 'C';
96 use constant SMFIC_MACRO => 'D';
97 use constant SMFIC_BODYEOB => 'E';
98 use constant SMFIC_HELO => 'H';
99 use constant SMFIC_HEADER => 'L';
100 use constant SMFIC_MAIL => 'M';
101 use constant SMFIC_EOH => 'N';
102 use constant SMFIC_OPTNEG => 'O';
103 use constant SMFIC_RCPT => 'R';
104 use constant SMFIC_QUIT => 'Q';
105 use constant SMFIC_DATA => 'T'; # v4
106 use constant SMFIC_UNKNOWN => 'U'; # v3
107 # Responses:
108 use constant SMFIR_ADDRCPT => '+';
109 use constant SMFIR_DELRCPT => '-';
110 use constant SMFIR_ADDRCPT_PAR => '2';
111 use constant SMFIR_ACCEPT => 'a';
112 use constant SMFIR_REPLBODY => 'b';
113 use constant SMFIR_CONTINUE => 'c';
114 use constant SMFIR_DISCARD => 'd';
115 use constant SMFIR_ADDHEADER => 'h';
116 use constant SMFIR_INSHEADER => 'i'; # v3, or v2 and Sendmail 8.13+
117 use constant SMFIR_SETSYMLIST => 'l';
118 use constant SMFIR_CHGHEADER => 'm';
119 use constant SMFIR_PROGRESS => 'p';
120 use constant SMFIR_QUARANTINE => 'q';
121 use constant SMFIR_REJECT => 'r';
122 use constant SMFIR_CHGFROM => 'e'; # Sendmail 8.14+
123 use constant SMFIR_TEMPFAIL => 't';
124 use constant SMFIR_REPLYCODE => 'y';
125  
126 ##### Private data
127  
128 no strict 'refs';
129 my %replynames = map { &{$_} => $_ } qw(
130 SMFIR_ADDRCPT
131 SMFIR_DELRCPT
132 SMFIR_ADDRCPT_PAR
133 SMFIR_ACCEPT
134 SMFIR_REPLBODY
135 SMFIR_CONTINUE
136 SMFIR_DISCARD
137 SMFIR_ADDHEADER
138 SMFIR_INSHEADER
139 SMFIR_SETSYMLIST
140 SMFIR_CHGHEADER
141 SMFIR_PROGRESS
142 SMFIR_QUARANTINE
143 SMFIR_REJECT
144 SMFIR_CHGFROM
145 SMFIR_TEMPFAIL
146 SMFIR_REPLYCODE
147 );
148 use strict 'refs';
149  
150 ##### Constructor, main loop, and internal calls
151  
152 sub new ($$$$$) {
153 my $this = bless {}, shift;
154 # The means of communicating with the MTA.
155 $this->{socket} = shift;
156 # A hash containing $key,$value pairs where $value is a reference to a
157 # callback sub in the milter e.g. \&xm_connect_callback and $key is a
158 # name for the callback (as passed to sub call_hooks below), e.g. 'connect'.
159 my $callbacks = $this->{callbacks} = shift;
160 # The capabilities we're going to request from the MTA.
161 $this->{callback_flags} = shift;
162 # The protocol version we're going to be using. Probably 6, could be 2.
163 $this->{'milter protocol version'} = shift;
164  
165 # Making the wild assumption that we're using a recent Sendmail version, offer to the milter all 'protocol' bits set.
166 $this->{protocol} = SMFI_CURR_PROT; # 0x001FFFFF
167 # Also all possible data chunk size bits. Two are available in milter protocol version 6.
168 $this->{protocol} |= SMFIP_MDS_256K; # 0x10000000 MILTER_MAX_DATA_SIZE=262143 bytes.
169 $this->{protocol} |= SMFIP_MDS_1M; # 0x20000000 MILTER_MAX_DATA_SIZE=1048575 bytes.
170  
171 $this;
172 }
173  
174 sub main ($) {
175 my $this = shift;
176 my $socket = $this->{socket} || return undef;
177  
178 my $buf = '';
179 my $gotquit = 0;
180  
181 my $split_buf = sub {
182 $buf =~ s/\0$//; # remove trailing NUL
183 return [ split(/\0/, $buf) ];
184 };
185  
186 $socket->autoflush(1);
187  
188 $this->{lastsymbol} = '';
189  
190 #my $time_now = localtime;
191  
192 eval {
193  
194 #$time_now = localtime;
195 #printf( "%s PID=%d Context.pm(%3d): main(eval): entered eval, about to enter main loop.\n", $time_now, $$, __LINE__ );
196 while (1) {
197 #$time_now = localtime;
198 #printf( "%s PID=%d Context.pm(%3d): main(eval): top of main loop\n", $time_now, $$, __LINE__ );
199 # Loop, reading packets 'from the wire' into $buf and then extracting the commands and any data from them.
200 # Note that commands are known by the symbolic constants 'SMFIC_something'. There are 14 of these commands;
201 # all are listed in the 'Commands' section under 'Protocol constants' above. Correspondigly the responses
202 # are known by symbolic constants 'SMFIR_something'. The 17 possible responses are listed in the 'Responses'
203 # section under 'Protocol data' above. There is just one little wrinkle in all this; the (success) response
204 # to the 'SMFIC_OPTNEG' command is also 'SMFIC_OPTNEG'. There is no 'SMFIR_OPTNEG' response defined.
205 $this->read_block(\$buf, 4) || last;
206 my $len = unpack('N', $buf);
207  
208 die "bad packet length $len\n" if ($len <= 0);
209  
210 # save the overhead of stripping the first byte from $buf
211 $this->read_block(\$buf, 1) || last;
212 my $cmd = $buf;
213  
214 #$time_now = localtime;
215 #printf( "%s PID=%d Context.pm(%3d): main(eval): got command=[%s]\n", $time_now, $$, __LINE__, $cmd );
216  
217 # get actual data
218 $this->read_block(\$buf, $len - 1) || die "EOF in stream\n";
219  
220 if ($cmd eq SMFIC_ABORT) {
221 # delete $this->{symbols}{&SMFIC_CONNECT};
222 # delete $this->{symbols}{&SMFIC_HELO};
223 delete $this->{symbols}{&SMFIC_MAIL};
224 # delete $this->{symbols}{&SMFIC_RCPT};
225 # delete $this->{symbols}{&SMFIC_DATA};
226 # delete $this->{symbols}{&SMFIC_EOH};
227 # delete $this->{symbols}{&SMFIC_BODYEOB};
228 $this->call_hooks('abort');
229 } elsif ($cmd eq SMFIC_BODY) {
230 $this->call_hooks('body', $buf, length($buf));
231 } elsif ($cmd eq SMFIC_CONNECT) {
232 # Perl RE doesn't like matching multiple \0 instances.
233 # To avoid problems, we slice the string to the first null,
234 # then use unpack for the rest.
235 unless ($buf =~ s/^([^\0]*)\0(.)//) {
236 die "SMFIC_CONNECT: invalid connect info\n";
237 # XXX should print a hexdump here?
238 }
239  
240 my $host = $1;
241 my $af = $2;
242 my ($port, $addr) = unpack('nZ*', $buf);
243 my $pack; # default undef
244  
245 if ($af eq SMFIA_INET) {
246 $pack = pack_sockaddr_in($port, inet_aton($addr));
247 } elsif ($af eq SMFIA_INET6) {
248 $pack = eval {
249 require Socket6;
250 $addr =~ s/^IPv6://;
251 Socket6::pack_sockaddr_in6($port,
252 Socket6::inet_pton(&Socket6::AF_INET6, $addr));
253 };
254 } elsif ($af eq SMFIA_UNIX) {
255 $pack = eval {
256 sockaddr_un($addr);
257 };
258 }
259 $this->call_hooks('connect', $host, $pack);
260 # delete $this->{symbols}{&SMFIC_CONNECT};
261 } elsif ($cmd eq SMFIC_MACRO) {
262 die "SMFIC_MACRO: empty packet\n" unless ($buf =~ s/^(.)//);
263 my $code = $this->{lastsymbol} = $1;
264 my $marray = &$split_buf;
265  
266 # odd number of entries: give last empty value
267 push(@$marray, '') if ((@$marray & 1) != 0);
268  
269 my %macros = @$marray;
270  
271 while (my ($name, $value) = each(%macros)) {
272 $this->{symbols}{$code}{$name} = $value;
273 }
274 } elsif ($cmd eq SMFIC_BODYEOB) {
275 $this->call_hooks('eom');
276 # delete $this->{symbols}{&SMFIC_MAIL};
277 # delete $this->{symbols}{&SMFIC_DATA};
278 # delete $this->{symbols}{&SMFIC_EOH};
279 # delete $this->{symbols}{&SMFIC_BODYEOB};
280 } elsif ($cmd eq SMFIC_HELO) {
281 my $helo = &$split_buf;
282 die "SMFIC_HELO: bad packet\n" unless (@$helo == 1);
283 $this->call_hooks('helo', @$helo);
284 # delete $this->{symbols}{&SMFIC_HELO};
285 } elsif ($cmd eq SMFIC_HEADER) {
286 my $header = &$split_buf;
287  
288 # empty value: ensure an empty string
289 push(@$header, '') if (@$header == 1);
290 $this->call_hooks('header', @$header);
291 } elsif ($cmd eq SMFIC_MAIL) {
292 if ($this->{lastsymbol} ne SMFIC_MAIL) { delete $this->{symbols}{&SMFIC_MAIL}; }
293 my $envfrom = &$split_buf;
294 $this->call_hooks('envfrom', @$envfrom)
295 if scalar @$envfrom >= 1;
296  
297 # delete $this->{symbols}{&SMFIC_MAIL};
298 } elsif ($cmd eq SMFIC_EOH) {
299 $this->call_hooks('eoh');
300 # delete $this->{symbols}{&SMFIC_EOH};
301
302 } elsif ($cmd eq SMFIC_OPTNEG) {
303  
304 # Here we've established that the 'NEGOTIATE' command (SMFIC_OPTNEG) has been received in the incoming packet from the MTA.
305 # If it happens at all, the negotiation step should happen once (and only once) at the beginning of a connection.
306  
307 # Bleat about the packet size if it's not what's expected, perhaps somebody has, er, 'improved' the MTA.
308 # The expected size (including the command byte that we've already stripped off) is 13, so we
309 # expect 12 bytes to remain in the packet buffer $buf. Add 1 to the size and test for != 13.
310 my $packet_size = length( $buf ) + 1;
311 if( $packet_size != 13 ) {die "SMFIC_OPTNEG: unsupported packet size $packet_size\n"; }
312 # Extract the integers from the buffer into the @negotiate array.
313 my @negotiate = unpack( 'NNN', $buf ); # Three 32-bit numbers of four bytes each.
314 my $arraysize = scalar( @negotiate );
315 if( $arraysize != 3 ) { die "SMFIC_OPTNEG: bad packet: expected 3 integer values, found $arraysize.\n"; }
316 # Named scalars for clarity, could as easily have used the array elements themselves.
317 my $milter_protocol_version = $negotiate[0];
318 my $actions_available = $negotiate[1];
319 my $protocol_steps_available = $negotiate[2];
320  
321 $this->{'milter_protocol_version_ref'} # 6. We hope. Later we may insist.
322 = \$milter_protocol_version; #
323 $this->{'actions_available_ref'} # 1FF. We hope. Later we may insist.
324 = \$actions_available; # $actions_available contains an integer consisting of bits which flag various protocol capabilities ('actions' in Sendmail parlance) available from the MTA.
325 # These are things which the milter can ask the MTA to do to the message, such as add a message header (milters very commonly add headers) or replace the message body.
326 # Symbolic constants for these bits are all SMFIF_something. Over the years,the list of available actions has been extended as Sendmail has developed, and a 'version'
327 # of the milter protocol - a single digit - is implied by the state of development of the milter protocol (i.e. the capabilities which are available) in any particular
328 # version of Sendmail. Milter protocol Version 6 was introduced by Sendmail 8.14.0 in January 2007, and as of 2019 only versions of Sendmail which support this milter
329 # protocol version are in widespread use. For security reasons alone you probably should not be using older versions of Sendmail which do not support milter protocol
330 # version 6, but other MTAs may not support all the V6 capabilities so it is probably best to check their availability in your milter before attempting to use them.
331 # The available protocol actions, symbolic constants, and the corresponding bit values for the flags are:
332 # Action Symbolic constant Value Available in milter protocol version. There's a bit of a muddle about V3, but nobody's using it any more.
333 # - SMFIF_NONE 0x0000
334 # Add header SMFIF_ADDHDRS 0x0001 V1 A message header can be added at the end of the message headers, or inserted at a specified position.
335 # Replace body SMFIF_CHGBODY 0x0002 V2 The message body can be replaced.
336 # Add recipient SMFIF_ADDRCPT 0x0004 V1 A recipient can be added. ESMTP arguments cannot be included (see SMFIF_ADDRCPT_PAR below).
337 # Delete recipient SMFIF_DELRCPT 0x0008 V1 A recipient can be deleted.
338 # Change header SMFIF_CHGHDRS 0x0010 V2 A header can be modified.
339 # Replace body SMFIF_MODBODY == SMFIF_CHGBODY Historical - Milter Protocol V1 - exists for backward compatibility, do not use in new code.
340 # Quarantine message SMFIF_QUARANTINE 0x0020 V2 The MTA will not deliver the message, but instead place it in a holding area.
341 # Change envelope from SMFIF_CHGFROM 0x0040 V6 The sender (and ESMTP arguments) given by the client in the "MAIL FROM" command can be replaced.
342 # Add recipient + args SMFIF_ADDRCPT_PAR 0x0080 V6 A recipient (such as may have been received in a client "RCPT TO" command with ESMTP arguments) can be added.
343 # Request macro values SMFIF_SETSYMLIST 0x0100 V6 The MTA can provide a list of macros valid for a given protocol 'step'. See below for the protocol steps.
344 #
345 $this->{'protocol_steps_available_ref'} # 1FFFFF. We hope - later, we may even insist.
346 = \$protocol_steps_available; # $protocol_steps_available contains an integer consisting of bits which refer to four different types of configurable behaviour.
347 # Symbolic constants for these bits are all SMFIP_something. The first three of the four configuration types affect the protocol
348 # and are listed below in the same order as they are listed in the libmilter source (see st_optionneg() in libmilter/engine.c).
349 # A fourth type which is not related to protocol steps, and is not mentioned in that list, is included here for completness.
350 # Note that the positions of these bits in the integer are not significant - they merely reflect Sendmail development history.
351 # 1. The MTA offers to the milter the option for the milter to ask the MTA not to send a particular protocol step command to run one of the callbacks.
352 # The request may be made even if a callback for that step is defined in the milter, and has been 'hooked' by the MTA at startup.
353 # Symbolic constants for these bits are all SMFIP_NOsomething. There are NINE of these "Do not send protocol step command" features.
354 # The protocol step commands, symbolic constants, and the corresponding bits in this integer are:
355 # Step Symbolic constant Value Available in milter protocol version. There's a bit of a muddle about V3, but nobody's using it any more.
356 # CONNECT SMFIP_NOCONNECT 0x00000001 V1 It's difficult to imagine a milter not wanting to know that a connection has been made, but there you are.
357 # HELO SMFIP_NOHELO 0x00000002
358 # MAIL FROM SMFIP_NOMAIL 0x00000004
359 # RCPT TO SMFIP_NORCPT 0x00000008
360 # DATA SMFIP_NODATA 0x00000200
361 # HEADER SMFIP_NOHDRS 0x00000020
362 # EOH SMFIP_NOEOH 0x00000040
363 # BODY SMFIP_NOBODY 0x00000010
364 # UNKNOWN COMMAND SMFIP_NOUNKNOWN 0x00000100
365 # 2. The MTA understands if the milter requests certain additional features in the protocol.
366 # There are THREE of these features.
367 # Symbolic constants for these bits have, like the corresponding protocol features, nothing in common beyond the SMFIP_ prefix.
368 # The protocol step commands, the symbolic constants, and the corresponding bits are:
369 # SKIP SMFIP_SKIP 0x00000400 The MTA understands the 'SKIP' command, see Sendmail's libmilter documentation.
370 # SEND REJECTED RECIPIENT SMFIP_RCPT_REJ 0x00000800 The MTA should send the SMFIC_MAIL command even if the MTA has already decided to reject it as e.g. unknown.
371 # This will take effect only if Sendmail has been compiled with _FFR_MILTER_CHECK_REJECTIONS_TOO.
372 # HEADER LEADING SPACE SMFIP_HDR_LEADSPC 0x00100000 The MTA will not add leading spaces to header values, the milter must do that. See the Sendmail documentation.
373 # 3. The MTA will by prior negotiation permit the milter to make no reply to the MTA after a given individual milter callback has been run in response to an MTA command.
374 # Symbolic constants for these bits are all SMFIP_NR_something. There are NINE of these 'SEND NO REPLY' features.
375 # If the MTA and milter agree that the milter will not to send a reply to the MTA at a particular protocol step, it MUST NOT reply to that step.
376 # The protocol step 'NO REPLY' commands, the symbolic constants, and the corresponding bits are:
377 # No reply for CONNECT SMFIP_NR_CONN 0x00001000
378 # No reply for HELO SMFIP_NR_HELO 0x00002000
379 # No reply for MAIL SMFIP_NR_MAIL 0x00004000
380 # No reply for RCPT SMFIP_NR_RCPT 0x00008000
381 # No reply for DATA SMFIP_NR_DATA 0x00010000
382 # No reply for HEADER SMFIP_NR_HDR 0x00000080
383 # No reply for HEADER SMFIP_NOHREPL == SMFIP_NR_HDR Historical - exists for backward compatibility, do not use in new code.
384 # No reply for EOH SMFIP_NR_EOH 0x00040000
385 # No reply for BODY SMFIP_NR_BODY 0x00080000
386 # No reply for UNKNOWN SMFIP_NR_UNKN 0x00020000 An unknown command received from the client which is attempting to send mail.
387 # 4. The MTA offers to the milter the ability to use a data buffer larger than the default 65535 bytes.
388 # Here be dragons. The facility is not available in default Sendmail builds, it must be compiled with at least _FFR_MDS_NEGOTIATE to make use of this facility.
389 # Max data size 256K SMFIP_MDS_256K 0x10000000 262143 bytes.
390 # Max data size 1M SMFIP_MDS_1M 0x20000000 1048575 bytes. No sizes other than the three given are permitted.
391  
392 if( ${$this->{'milter_protocol_version_ref'}} != 2 && ${$this->{'milter_protocol_version_ref'}} != 6) { die "SMFIC_OPTNEG: unsupported milter protocol version " . ${$this->{'milter_protocol_version_ref'}} . "\n"; }
393  
394 # Next we call the milter's 'negotiate' callback, if there is one, via the 'call_hooks' sub. The 'call_hooks' sub is defined about 78 lines below in this file.
395 # The 'call_hooks' sub returns to the MTA a packet which contains (subject to translation of some symbolic constants) whatever the milter callback returned.
396 # The 'call_hooks' sub will unpack that packet into the three class variables $this->{'something_ref'} (where 'something' is one of 'milter_protocol_version', 'actions_available' and 'protocol_steps_available').
397 my @negotiate_refs = ();
398 if( ! defined $this->{callbacks}{'negotiate'} )
399 { # Default protocol steps if no negotiate callback registered.
400 ${$this->{'protocol_steps_available_ref'}} &= SMFIP_DEFAULTS;
401 }
402 push( @negotiate_refs, $this->{'milter_protocol_version_ref'}, $this->{'actions_available_ref'}, $this->{'protocol_steps_available_ref'} );
403 $this->call_hooks('negotiate', @negotiate_refs);
404  
405 } elsif ($cmd eq SMFIC_RCPT) {
406 my $envrcpt = &$split_buf;
407 $this->call_hooks('envrcpt', @$envrcpt)
408 if scalar @$envrcpt >= 1;
409 delete $this->{symbols}{&SMFIC_RCPT};
410  
411 } elsif ($cmd eq SMFIC_DATA) {
412 $this->call_hooks('data');
413 # delete $this->{symbols}{&SMFIC_DATA};
414 } elsif ($cmd eq SMFIC_QUIT) {
415 $this->call_hooks('quit'); # A long-felt want, but I'm not sure it will really do what I want. Is it called if the client does *not* send the 'QUIT' command?
416 last;
417 # that's all, folks!
418 } elsif ($cmd eq SMFIC_UNKNOWN) {
419 # This is not an unknown packet, but a packet to tell the milter that an unknown smtp command has been received.
420 # The argument passed to the milter is the unknown command plus any arguments there may have been, both of which can be null so we don't count arguments.
421 my $unknown = &$split_buf;
422 $this->call_hooks('unknown', @$unknown );
423 } else {
424 die "unknown milter packet type $cmd\n";
425 }
426 }
427  
428 #$time_now = localtime;
429 #printf( "%s PID=%d Context.pm(%3d): main: exited main loop.\n", $time_now, $$, __LINE__ );
430  
431 };
432  
433 my $err = $@;
434  
435 #$time_now = localtime;
436 #printf( "%s PID=%d Context.pm(%3d): main: exited eval, err=[%s], about to call 'close' callback.\n", $time_now, $$, __LINE__, $err );
437  
438 $this->call_hooks('close');
439  
440 # XXX better error handling? die here to let an eval further up get it?
441 if ($err) {
442 $this->write_packet(SMFIR_TEMPFAIL) if defined($socket);
443 #$time_now = localtime;
444 #printf( "%s PID=%d Context.pm(%3d): main: error found at loop exit: [%s]\n", $time_now, $$, __LINE__, $err );
445 warn $err;
446 die $err;
447 } else {
448 $this->write_packet(SMFIR_CONTINUE) if defined($socket);
449 }
450  
451 #$time_now = localtime;
452 #printf( "%s PID=%d Context.pm(%3d): main: exit.\n", $time_now, $$, __LINE__ );
453 undef;
454 }
455  
456 sub read_block {
457 my $this = shift;
458 my $bufref = shift;
459 my $len = shift;
460  
461 my $socket = $this->{socket};
462 my $sofar = 0;
463  
464 $$bufref = '';
465  
466 while ($len > $sofar) {
467 my $read = $socket->sysread($$bufref, $len - $sofar, $sofar);
468 return undef if (!defined($read) || $read <= 0); # if EOF
469 $sofar += $read;
470 }
471 1;
472 }
473  
474 sub write_packet {
475 my $this = shift;
476 my $code = shift;
477 my $out = shift;
478 $out = '' unless defined($out);
479 my $len = pack('N', length($out) + 1);
480 my $socket = $this->{socket};
481 $socket->syswrite($len);
482 $socket->syswrite($code);
483 $socket->syswrite($out);
484 return length($code) + length($out); # XXXX
485 }
486  
487 sub call_hooks ($$;@) {
488 my $this = shift;
489 my $what = $this->{cb} = shift;
490  
491 #my $time_now = localtime;
492 #printf( "%s PID=%d Context.pm(%3d): call_hooks: callback=[%s]\n", $time_now, $$, __LINE__, $what );
493  
494 my $rc = SMFIS_CONTINUE; # SMFIS_CONTINUE is the default behaviour if no callback is defined.
495 my $sub = $this->{callbacks}{$what};
496 #$time_now = localtime;
497 if( defined($sub) )
498 {
499 $rc = SMFIS_TEMPFAIL; # 2023.03.11: Without this assignment we would accept messages if the milter bombs out with some dumb Perl error. Under these circumstances I'd rather TEMPFAIL. Configuration?
500 #printf( "%s PID=%d Context.pm(%3d): call_hooks: about to call callback=[%s], rc=[%s]\n", $time_now, $$, __LINE__, $what, $rc );
501 $rc = &$sub($this, @_);
502 #$time_now = localtime;
503 #printf( "%s PID=%d Context.pm(%3d): call_hooks: after calling callback=[%s], rc=[%s]\n", $time_now, $$, __LINE__, $what, $rc );
504 }
505 else
506 {
507 #printf( "%s PID=%d Context.pm(%3d): call_hooks: (non-existent callback=[%s])\n", $time_now, $$, __LINE__, $what );
508 }
509  
510 # translate to response codes
511 if ($rc eq SMFIS_CONTINUE) {
512 $rc = SMFIR_CONTINUE;
513 } elsif ($rc eq SMFIS_ACCEPT) {
514 $rc = SMFIR_ACCEPT;
515 } elsif ($rc eq SMFIS_DISCARD) {
516 $rc = SMFIR_DISCARD;
517 } elsif ($rc eq SMFIS_REJECT) {
518 if (defined($this->{reply})) {
519 $rc = SMFIR_REPLYCODE;
520 } else {
521 $rc = SMFIR_REJECT;
522 }
523 } elsif ($rc eq SMFIS_TEMPFAIL) {
524 if (defined($this->{reply})) {
525 $rc = SMFIR_REPLYCODE;
526 } else {
527 $rc = SMFIR_TEMPFAIL;
528 }
529 } else {
530 die "invalid callback return $rc"; # XXXX Need to handle SMFIF_ALL_OPTS
531 }
532  
533 my $len = 0;
534 #$time_now = localtime;
535  
536 if( $what eq 'negotiate' )
537 {
538 $this->{protocol} = ${$this->{'protocol_steps_available_ref'}};
539 #printf( "%s PID=%d Context.pm(%3d): call_hooks: calling write_packet at [%s] callback, rc=[%s]\n", $time_now, $$, __LINE__, $what, $rc );
540 #print Dumper($this->{symbols})."\n";
541 $len = $this->write_packet
542 (
543 SMFIC_OPTNEG,
544 pack(
545 'NNN',
546 ${$this->{'milter_protocol_version_ref'}},
547 ${$this->{'actions_available_ref'}},
548 $this->{'protocol'}
549 )
550 );
551 }
552 elsif( $what eq 'abort' ) { ; } # According to the Sendmail docs the abort callback reply is ignored.
553 elsif( $rc ne SMFIR_REPLYCODE || $what eq 'close' )
554 {
555 #printf( "%s PID=%d Context.pm(%3d): call_hooks: calling write_packet at [%s] callback, rc=[%s]\n", $time_now, $$, __LINE__, $what, $rc );
556 ##printf( "%s Context.pm(%3d): call_hooks: calling write_packet at [%s] callback, rc=[%s] (symval{'_'}=[%s])\n", $time_now, __LINE__, $what, $rc, $this->{symbols}{SMFIC_CONNECT}{'_'}//'null' );
557 #print Dumper($this->{symbols})."\n";
558 $len = $this->write_packet($rc);
559 }
560 else
561 {
562 #printf( "%s PID=%d Context.pm(%3d): call_hooks: calling write_packet at [%s] callback, rc=[%s]\n", $time_now, $$, __LINE__, $what, $rc );
563 #print Dumper($this->{symbols})."\n";
564 $len = $this->write_packet($rc, $this->{reply}."\0");
565 }
566 #$time_now = localtime;
567 #printf( "%s PID=%d Context.pm(%3d): call_hooks: packet length written=[%2d]\n", $time_now, $$, __LINE__, $len );
568 undef $this->{reply};
569 }
570  
571 ##### General methods
572  
573 =pod
574  
575 =over 4
576  
577 =item $ctx->getpriv
578  
579 Returns the private data object for this milter instance, set by
580 $ctx->setpriv() (see below). Returns undef if setpriv has never been called
581 by this milter instance.
582  
583 =cut
584  
585 sub getpriv ($) {
586 my $this = shift;
587  
588 $this->{priv};
589 }
590  
591 =pod
592  
593 =item $ctx->getsymval(NAME)
594  
595 (The word 'macro' in Sendmail parlance refers to named variables which are
596 essentially text strings. They can be defined by the MTA, and populated as
597 messages are processed, or by milters, or by the MTA's configuration files.)
598  
599 The getsymval method retrieves the macro symbol named NAME from the macros
600 available from the MTA for the current callback. NAME is either a one-
601 character macro name, or a multi-character name enclosed in {curly braces}.
602 If macro NAME is undefined when getsymval is called, it returns undef.
603  
604 Some common macros are given below. The milter protocol was first
605 implemented in the Sendmail MTA, so these macro names are those used by
606 Sendmail itself; other MTAs e.g. Postfix may provide similar macros.
607  
608 =over 2
609  
610 =item $ctx->getsymval('_')
611  
612 The remote host name and address, in standard SMTP "name [address]" form.
613  
614 =item $ctx->getsymval('i')
615  
616 The MTA's queue ID for the current message.
617  
618 =item $ctx->getsymval('j')
619  
620 The MTA's idea of local host name.
621  
622 =item $ctx->getsymval('{if_addr}')
623  
624 The local address of the network interface upon which the connection was
625 received.
626  
627 =item $ctx->getsymval('{if_name}')
628  
629 The local hostname of the network interface upon which the connection was
630 received.
631  
632 =item $ctx->getsymval('{mail_addr}')
633  
634 The MAIL FROM: sender's address, canonicalized and angle bracket stripped.
635 (This is typically not the same value as the second argument to the
636 "envfrom" callback.) Will be defined to the empty string '' if the client
637 issued a MAIL FROM:<> null return path command.
638  
639 =item $ctx->getsymval('{rcpt_addr}')
640  
641 The RCPT TO: recipient's address, canonicalized and angle bracket stripped.
642 (This is typically not the same value as the second argument to the
643 "envrcpt" callback.)
644  
645 =back
646  
647 Not all macros may be available at all times. Some macros are only
648 available after a specific phase is reached, and some macros may only
649 be available from certain MTA implementations. Check returned values
650 for 'undef'. This version of the Sendmail::PMilter package collects
651 macro values only for the following callbacks:
652  
653 CONNECT
654 HELO
655 ENVFROM
656 ENVRCPT
657 DATA
658 EOH
659 EOM
660  
661 =cut
662  
663 sub getsymval ($$) {
664 my $this = shift;
665 my $key = shift;
666 foreach my $code (SMFIC_CONNECT, SMFIC_HELO, SMFIC_MAIL, SMFIC_RCPT, SMFIC_DATA, SMFIC_EOH, SMFIC_BODYEOB)
667 {
668 my $val = $this->{symbols}{$code}{$key};
669 if( defined $val ) { return $val; }
670 }
671 undef;
672 }
673  
674 =pod
675  
676 =item $ctx->setpriv(DATA)
677  
678 This is the place to store milter-private data that is sensitive to the
679 current SMTP client connection. Only one value can be stored, so typically
680 an arrayref or hashref is initialized in the "connect" callback and set with
681 $ctx->setpriv.
682  
683 This value can be retrieved on subsequent callback runs with $ctx->getpriv.
684  
685 =cut
686  
687 sub setpriv ($$) {
688 my $this = shift;
689 $this->{priv} = shift;
690 1;
691 }
692  
693 =pod
694  
695 =item $ctx->setreply(RCODE, XCODE, MESSAGE)
696  
697 Set an extended SMTP status reply (before returning SMFIS_REJECT or
698 SMFIS_TEMPFAIL). RCODE should be a short (4xx or 5xx) numeric reply
699 code, XCODE should be a long ('4.x.y' or '5.x.y') ESMTP reply code.
700 The first digit of RCODE must be the same as the first digit of XCODE.
701 There is no such restriction on the other digits. In RCODE and XCODE,
702 'x' should be one decimal digit; in XCODE 'y' should be either one or
703 two decimal digits. MESSAGE is the full text of the message to send.
704 Refer to the appropriate RFCs for actual codes and suggested messages.
705 Examples:
706  
707 $ctx->setreply(451, '4.7.0', 'Cannot authenticate you right now');
708 return SMFIS_TEMPFAIL;
709  
710 $ctx->setreply(550, '5.7.26', 'Multiple authentication failures');
711 return SMFIS_REJECT;
712  
713 Note that after setting a reply with this method, the SMTP result code
714 comes from RCODE, not from the symbolic constants SMFIS_REJECT and
715 SMFIS_TEMPFAIL. However for consistency, callbacks that set a 4xx
716 response code should use SMFIS_TEMPFAIL, and those that set a 5xx code
717 should return SMFIS_REJECT.
718  
719 Returns 1 on success, undef on failure. In the case of failure, which
720 is typically only caused by bad parameters, a generic message will be
721 sent based on the SMFIS_* return code.
722  
723 =cut
724  
725 sub setreply ($$$$) {
726 my $this = shift;
727 my $rcode = shift || '';
728 my $xcode = shift || '';
729 my $message = shift || '';
730  
731 if ($rcode !~ /^[45]\d\d$/ || $xcode !~ /^[45]\.\d\.\d{1,2}$/ || substr($rcode, 0, 1) ne substr($xcode, 0, 1)) {
732 warn 'setreply: bad reply arguments';
733 return undef;
734 }
735  
736 $this->{reply} = "$rcode $xcode $message";
737 1;
738 }
739  
740 =pod
741  
742 =item $ctx->setmlreply(RCODE, XCODE, MESSAGES)
743  
744 Set an extended SMTP status reply (before returning SMFIS_REJECT or
745 SMFIS_TEMPFAIL). See setreply() above for more information about the
746 reply codes RCODE and XCODE. MESSAGES is an array which contains a
747 multi-line reply. This array must contain no less than two string
748 elements. Sendmail dictates that it must contain no more than 32
749 elements, and that each string element must contain no more than 980
750 characters (although any of the strings may be NULL), and no string
751 may contain a newline ("\n") or a carriage return ("\r") character.
752  
753 Example:
754  
755 $ctx->setmlreply(451, '4.7.0', \('Cannot authenticate sender.',
756 'Please refer to our published policies at',
757 'http://www.example.com/policies')
758 );
759 return SMFIS_TEMPFAIL;
760  
761 Note that after setting a reply with this method, the SMTP result code
762 comes from RCODE, not from the symbolic constants SMFIS_REJECT and
763 SMFIS_TEMPFAIL. However for consistency, callbacks that set a 4xx
764 response code should use SMFIS_TEMPFAIL, and those that set a 5xx code
765 should return SMFIS_REJECT.
766  
767 Returns 1 on success, undef on failure. In the case of failure, which
768 is typically caused by bad parameters, a generic message will be sent
769 based on the SMFIS_* return code.
770  
771 =cut
772  
773 # See Sendmail::PMilter and .../libmilter/smfi.c in the Sendmail
774 # source for MAXREPLIES and MAXREPLYLEN.
775  
776 sub setmlreply ($$$$) {
777 my $this = shift;
778 my $rcode = shift || '';
779 my $xcode = shift || '';
780 my $messageref = shift || '';
781 if
782 (
783 ref( $messageref ) ne 'ARRAY' ||
784 $rcode !~ /^[45]\d\d$/ ||
785 $xcode !~ /^[45]\.\d\.\d{1,2}$/ ||
786 substr($rcode, 0, 1) ne substr($xcode, 0, 1) ||
787 @{$messageref} < 2 ||
788 @{$messageref} > MAXREPLIES
789 )
790 {
791 warn 'setmlreply: bad reply arguments';
792 return undef;
793 }
794 my $message = $rcode . '-' . $xcode . ' '; # Admittedly this is a bit willful.
795 foreach( @{$messageref} )
796 {
797 if( /[\r\n]/ ) # Sendmail does not allow these characters in the reply strings.
798 {
799 warn 'setmlreply: bad reply arguments';
800 return undef;
801 }
802 $message .= "\r\n" . $rcode . '-' . $xcode . ' ' . $_;
803 }
804 $message .= "\r\n" . $rcode . ' ' . $xcode . ' ';
805 $this->{reply} = $message;
806 1;
807 }
808  
809 =item $ctx->shutdown()
810  
811 A special case of C<< $ctx->setreply() >> which sets the short numeric reply
812 code to 421 and the ESMTP code to 4.7.0. Under Sendmail 8.13 and higher
813 (and you should not be using any version of Sendmail older than that),
814 this will close the MTA's communication channel quickly, which should
815 immediately result in a "close" callback and end of milter execution.
816  
817 Returns 1.
818  
819 =cut
820  
821 sub shutdown ($) {
822 my $this = shift;
823 $this->setreply(421, '4.7.0', 'Closing communications channel');
824 1;
825 }
826  
827 ##### Protocol action methods
828  
829 =pod
830  
831 =item $ctx->addheader(HEADER, VALUE)
832  
833 Add header HEADER with value VALUE to this mail. Does not change any
834 existing headers with the same name. Only callable from the "eom" callback.
835  
836 Returns 1 on success, undef on failure.
837  
838 =cut
839  
840 sub addheader ($$$) {
841 my $this = shift;
842 my $header = shift || die "addheader: no header name\n";
843 my $value = shift;
844 die "addheader: called outside of EOM\n" if ($this->{cb} ne 'eom');
845 die "addheader: SMFIF_ADDHDRS not in capability list\n" unless ($this->{callback_flags} & SMFIF_ADDHDRS);
846 die "addheader: no header value\n" unless defined $value;
847  
848 $this->write_packet(SMFIR_ADDHEADER, "$header\0$value\0");
849 1;
850 }
851  
852 =pod
853  
854 =item $ctx->insheader(HEADER, VALUE, POSITION)
855  
856 Insert header HEADER at position POSITION with value VALUE to this mail.
857 Does not change any existing headers with the same name. Only callable
858 from the "eom" callback. HEADER and VALUE are requred, but POSITION is
859 optional. A POSITION value of zero is acceptable and is the default if
860 not supplied - this inserts the HEADER before all existing headers.
861  
862 Returns 1 on success, undef on failure.
863  
864 =cut
865  
866 sub insheader ($$$;$) {
867 my $this = shift;
868 my $header = shift || die "insheader: no header name\n";
869 my $value = shift || die "insheader: no header value\n";
870 my $position = shift;
871 if( not defined $position ) { $position = 0; }
872  
873 die "insheader: called outside of EOM\n" if ($this->{cb} ne 'eom');
874 die "addheader: SMFIF_ADDHDRS not in capability list\n" unless ($this->{callback_flags} & SMFIF_ADDHDRS);
875  
876 $this->write_packet(SMFIR_INSHEADER, pack('N',$position)."$header\0$value\0");
877 1;
878 }
879  
880 =pod
881  
882 =item $ctx->chgheader(HEADER, INDEX, VALUE)
883  
884 Change the INDEX'th header of name HEADER to the value VALUE. Only callable
885 from the "eom" callback. If INDEX exceeds the number of existing headers of
886 name HEADER, adds another header of that name.
887  
888 Returns 1 on success, undef on failure.
889  
890 =cut
891  
892 sub chgheader ($$$$) {
893 my $this = shift;
894 my $header = shift || die "chgheader: no header name\n";
895 my $num = shift || 0;
896 my $value = shift;
897  
898 $value = '' unless defined($value);
899  
900 die "chgheader: called outside of EOM\n" if ($this->{cb} ne 'eom');
901 die "chgheader: SMFIF_CHGHDRS not in capability list\n" unless ($this->{callback_flags} & SMFIF_CHGHDRS);
902  
903 $this->write_packet(SMFIR_CHGHEADER, pack('N', $num)."$header\0$value\0");
904 1;
905 }
906  
907 =pod
908  
909 =item $ctx->addrcpt(ADDRESS)
910  
911 Add address ADDRESS to the list of recipients for this mail. Only callable
912 from the "eom" callback.
913  
914 Returns 1 on success, undef on failure.
915  
916 =cut
917  
918 sub addrcpt ($$) {
919 my $this = shift;
920 my $rcpt = shift || die "addrcpt: no recipient specified\n";
921  
922 die "addrcpt: called outside of EOM\n" if ($this->{cb} ne 'eom');
923 die "addrcpt: SMFIF_ADDRCPT not in capability list\n" unless ($this->{callback_flags} & SMFIF_ADDRCPT);
924  
925 $this->write_packet(SMFIR_ADDRCPT, "$rcpt\0");
926 1;
927 }
928  
929 =pod
930  
931 =item $ctx->addrcpt_par(ADDRESS,PARAMS)
932  
933 Add an address ADDRESS and its ESMTP arguments PARAMS to the list of
934 recipients for this mail. Only callable from the "eom" callback.
935  
936 Returns 1 on success, undef on failure.
937  
938 =cut
939  
940 sub addrcpt_par ($$$) {
941 my $this = shift;
942 my $rcpt = shift || die "addrcpt: no recipient specified\n";
943 my $params = shift;
944  
945 die "addrcpt_par: called outside of EOM\n" if ($this->{cb} ne 'eom');
946 die "addrcpt_par: SMFIF_ADDRCPT_PAR not in capability list\n" unless ($this->{callback_flags} & SMFIF_ADDRCPT_PAR);
947  
948 $this->write_packet(SMFIR_ADDRCPT_PAR, "$rcpt\0");
949 1;
950 }
951  
952 =pod
953  
954 =item $ctx->delrcpt(ADDRESS)
955  
956 Remove address ADDRESS from the list of recipients for this mail. The
957 ADDRESS argument must match a prior argument to the "envrcpt" callback
958 exactly (case sensitive, and including angle brackets if present). Only
959 callable from the "eom" callback.
960  
961 Returns 1 on success, undef on failure. A success return means that
962 the command was queued for processing. It does not necessarily mean
963 that the recipient was successfully removed, that information is not
964 available from Sendmail.
965  
966 =cut
967  
968 sub delrcpt ($$) {
969 my $this = shift;
970 my $rcpt = shift || die "delrcpt: no recipient specified\n";
971  
972 die "delrcpt: called outside of EOM\n" if ($this->{cb} ne 'eom');
973 die "delrcpt: SMFIF_DELRCPT not in capability list\n" unless ($this->{callback_flags} & SMFIF_DELRCPT);
974  
975 $this->write_packet(SMFIR_DELRCPT, "$rcpt\0");
976 1;
977 }
978  
979 =pod
980  
981 =item $ctx->progress()
982  
983 Sends an asynchronous "progress" message to the MTA, to allow longer
984 than normal operations such as extensive message body scanning or a
985 deliberate delay. This command should only be issued during the EOM
986 callback, it will fail (and return undef) if called at other times.
987  
988 Returns 1 if the call is made during EOM and is permitted, else undef.
989  
990 =cut
991  
992 sub progress ($) {
993 my $this = shift;
994 die "progress: called outside of EOM\n" if ($this->{cb} ne 'eom');
995 $this->write_packet(SMFIR_PROGRESS);
996 1;
997 }
998  
999 =pod
1000  
1001 =item $ctx->quarantine(REASON)
1002  
1003 Quarantine the current message in the MTA-defined quarantine area, using
1004 the given REASON as a text string describing the quarantine status. Only
1005 callable from the "eom" callback.
1006  
1007 Returns 1 on success, undef on failure.
1008  
1009 This method is an extension that is not available in the standard
1010 Sendmail::Milter package.
1011  
1012 =cut
1013  
1014 sub quarantine ($$) {
1015 my $this = shift;
1016 my $reason = shift;
1017  
1018 die "quarantine: called outside of EOM\n" if ($this->{cb} ne 'eom');
1019 die "quarantine: SMFIF_QUARANTINE not in capability list\n" unless ($this->{callback_flags} & SMFIF_QUARANTINE);
1020  
1021 $this->write_packet(SMFIR_QUARANTINE, "$reason\0");
1022 1;
1023 }
1024  
1025 =pod
1026  
1027 =item $ctx->replacebody(BUFFER)
1028  
1029 Replace the message body with the data in BUFFER (a scalar). This method
1030 may be called multiple times, each call appending to the replacement buffer.
1031 End-of-line should be represented by CR-LF ("\r\n"). Only callable from the
1032 "eom" callback.
1033  
1034 Returns 1 on success, undef on failure.
1035  
1036 =cut
1037  
1038 sub replacebody ($$) {
1039 my $this = shift;
1040 my $chunk = shift;
1041  
1042 die "replacebody: called outside of EOM\n" if ($this->{cb} ne 'eom');
1043 die "replacebody: SMFIF_CHGBODY not in capability list\n" unless ($this->{callback_flags} & SMFIF_CHGBODY);
1044  
1045 my $len = length($chunk);
1046 my $socket = $this->{socket};
1047  
1048 $len = pack('N', ($len + 1));
1049 $socket->syswrite($len);
1050 $socket->syswrite(SMFIR_REPLBODY);
1051 $socket->syswrite($chunk);
1052 1;
1053 }
1054  
1055 =pod
1056  
1057 =item $ctx->chgfrom(ADDRESS)
1058 =item $ctx->setsender(ADDRESS) (Deprecated)
1059  
1060 Replace the envelope sender address for the given mail message.
1061  
1062 Returns 1 on success, undef on failure. Successful return means that
1063 the command was queued for processing. It does not necessarily mean
1064 that the operation was successfully completed, that information is not
1065 available from Sendmail.
1066  
1067 =cut
1068  
1069 sub chgfrom ($$) {
1070 my $this = shift;
1071 my $sender = shift || die "chgfrom: no sender specified\n";
1072  
1073 die "chgfrom: called outside of EOM\n" if ($this->{cb} ne 'eom');
1074 die "chgfrom: SMFIF_CHGFROM not in capability list\n" unless ($this->{callback_flags} & SMFIF_CHGFROM);
1075  
1076 $this->write_packet(SMFIR_CHGFROM, "$sender\0");
1077 1;
1078 }
1079  
1080 # Deprecated, may be removed from a future version with little or no warning.
1081 sub setsender ($$) {
1082 my $this = shift;
1083 my $sender = shift || die "setsender: no sender specified\n";
1084  
1085 die "setsender: called outside of EOM\n" if ($this->{cb} ne 'eom');
1086 die "setsender: SMFIF_CHGFROM not in capability list\n" unless ($this->{callback_flags} & SMFIF_CHGFROM);
1087  
1088 $this->write_packet(SMFIR_CHGFROM, "$sender\0");
1089 1;
1090 }
1091  
1092 1;
1093  
1094 __END__