hide tickets with selfservice priority indicating closure, RT#79444
[freeside.git] / bin / fakesmtpserver.pl
1 #!/usr/bin/env perl
2
3 =head1 Fake SMTP Server
4
5 While this script is running, creates an SMTP server at localhost port 25.
6
7 Can only accept one client connection at a time.  If necessary,
8 it could be updated to fork on client connections.
9
10 When an e-mail is delivered, the TO and FROM are printed to STDOUT.
11 The TO, FROM and MSG are saved to a file in $message_save_dir
12
13 =cut
14
15 use strict;
16 use warnings;
17
18 use Carp;
19 use Net::SMTP::Server;
20 use Net::SMTP::Server::Client;
21 use Net::SMTP::Server::Relay;
22
23 my $message_save_dir = '/home/freeside/fakesmtpserver';
24
25 mkdir $message_save_dir, 0777;
26
27 my $server = new Net::SMTP::Server('localhost', 25) ||
28     croak("Unable to handle client connection: $!\n");
29
30 while(my $conn = $server->accept()) {
31   my $client = new Net::SMTP::Server::Client($conn) ||
32       croak("Unable to handle client connection: $!\n");
33
34   $client->process || next;
35
36   open my $fh, '>', $message_save_dir.'/'.time().'.txt'
37     or die "error: $!";
38
39   for my $f (qw/TO FROM/) {
40
41       if (ref $client->{$f} eq 'ARRAY') {
42         print "$f: $_\n" for @{$client->{$f}};
43         print $fh "$f: $_\n" for @{$client->{$f}};
44       } else {
45         print "$f: $client->{$f}\n";
46         print $fh "$f: $client->{$f}\n";
47       }
48
49   }
50   print $fh "\n\n$client->{MSG}\n";
51   print "\n";
52   close $fh;
53 }