| 1 | package App::MonM::Channel::File; | ||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | App::MonM::Channel::File - MonM file channel | ||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | =head1 VERSION | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | Version 1.00 | ||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | <Channel MyFile> | ||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | Type File | ||||||||||||||||||||||||||||||||||
| 20 | Enable on | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | # Real To Email address | ||||||||||||||||||||||||||||||||||
| 23 | To testuser@localhost | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | # Schedule | ||||||||||||||||||||||||||||||||||
| 26 | #At Sun-Sat[00:00-23:59] | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | # MIME options | ||||||||||||||||||||||||||||||||||
| 29 | #Encoding 8bit | ||||||||||||||||||||||||||||||||||
| 30 | # 8bit, quoted-printable, 7bit, base64 | ||||||||||||||||||||||||||||||||||
| 31 | #ContentType text/plain | ||||||||||||||||||||||||||||||||||
| 32 | #Charset utf-8 | ||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | # Output File Options | ||||||||||||||||||||||||||||||||||
| 35 | #Dir /path/to/my/messages | ||||||||||||||||||||||||||||||||||
| 36 | #File [DATETIME]-[ID].[EXT] | ||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | </Channel> | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | This module provides a method that writes the content | ||||||||||||||||||||||||||||||||||
| 43 | of the message to an external file | ||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | =over 4 | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | =item B<sendmsg> | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | For internal use only! | ||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | =back | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | =head1 CONFIGURATION DIRECTIVES | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | The basic Channel configuration options (directives) detailed describes in L<App::MonM::Channel/CONFIGURATION DIRECTIVES> | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | =over 4 | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | =item B<Dir>, B<Directory> | ||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | Dir /tmp | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | Defines path to save the message files | ||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | Default: your temp directory | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | =item B<File>, B<Filemask> | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | File [DATETIME]-[ID].[EXT] | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | Defines special mask of the message's filename | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | Default: "[DATETIME]-[ID].[EXT]" | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | Available variables: | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | [ID] -- Internal ID of the message | ||||||||||||||||||||||||||||||||||
| 78 | [TO] -- The real "to" field of message | ||||||||||||||||||||||||||||||||||
| 79 | [RCPT], [RECIPIENT] -- Recipient (name, account, id, number and etc.) | ||||||||||||||||||||||||||||||||||
| 80 | [EXT] -- file extension (default: msg) | ||||||||||||||||||||||||||||||||||
| 81 | [TIME] -- Current time (in unix time format) | ||||||||||||||||||||||||||||||||||
| 82 | [DATETIME] -- date and time in short-format (YYYMMDDHHMMSS) | ||||||||||||||||||||||||||||||||||
| 83 | [DATE] -- Date in short-format (YYYMMDD) | ||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | =item B<From> | ||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | Sender address (Email) | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | =item B<To> | ||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | Recipient address (Email) or name | ||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | =item B<Type> | ||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | Type File | ||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | Required directive! | ||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | Defines type of channel. MUST BE set to "File" value | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | =back | ||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | About common directives see L<App::MonM::Channel/CONFIGURATION DIRECTIVES> | ||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | =head1 HISTORY | ||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | See C<Changes> file | ||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | L<Compress::Raw::Zlib> | ||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||
| 113 | =head1 TO DO | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | See C<TODO> file | ||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||
| 117 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | L<Compress::Raw::Zlib> | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||
| 127 | Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||
| 132 | modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||
| 134 | See C<LICENSE> file and L<https://dev.perl.org/licenses/> | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | 1 | ▶ | use vars qw/$VERSION/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 139 | 1 | $VERSION = '1.00'; | |||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | use CTK::ConfGenUtil; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 144 | 1 | ▶ | use CTK::Util qw/ dformat date_time2dig date2dig /; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 145 | 1 | ▶ | use App::MonM::Util qw/ set2attr /; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 148 | 1 | FILEEXT => "msg", | |||||||||||||||||||||||||||||||||
| 149 | FILEMASK => "[DATETIME]-[ID].[EXT]", | ||||||||||||||||||||||||||||||||||
| 150 | 1 | }; | |||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub sendmsg { | ||||||||||||||||||||||||||||||||
|
Subroutine
sendmsg: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 153 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | return $self->maybe::next::method() unless $self->type eq 'file'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 155 | 0 | my $message = $self->message; | |||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||
| 157 | # Options | ||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my $options = set2attr($self->chconf) || {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
set2attr($self->chconf) || {}
MC/DC0%0/1
set2attr($self->chconf) || {}
set2attr($self->chconf)
Truth table0%0/2
A
A= set2attr($self->chconf)
| |||||||||||||||||||||||||||||||||||
| 159 | #print App::MonM::Util::explain($options); | ||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | # File | ||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my $filemask = value($self->chconf, "filemask") || value($self->chconf, "file") || FILEMASK; | ||||||||||||||||||||||||||||||||
|
Condition0%0/5
value($self->chconf, 'filemask') || value($self->chconf, 'file') || '[DATETIME]-[ID].[EXT]'
value($self->chconf, "filemask") or value($self->chconf, "file")
MC/DC0%0/2
value($self->chconf, 'filemask') || value($self->chconf, 'file') || '[DATETIME]-[ID].[EXT]'
value($self->chconf, "filemask")
value($self->chconf, "file")
Truth table0%0/3
A or B
A= value($self->chconf, "filemask")B= value($self->chconf, "file")
| |||||||||||||||||||||||||||||||||||
| 163 | 0 | my $filename = dformat($filemask, { | |||||||||||||||||||||||||||||||||
| 164 | ID => $self->message->msgid, | ||||||||||||||||||||||||||||||||||
| 165 | TO => $self->message->to, | ||||||||||||||||||||||||||||||||||
| 166 | RCPT => $self->message->recipient, RECIPIENT => $self->message->recipient, | ||||||||||||||||||||||||||||||||||
| 167 | EXT => FILEEXT, | ||||||||||||||||||||||||||||||||||
| 168 | TIME => time(), DATETIME=> date_time2dig(), DATE => date2dig(), | ||||||||||||||||||||||||||||||||||
| 169 | }); | ||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my $dir = value($self->chconf, "directory") || value($self->chconf, "dir") || File::Spec->tmpdir; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
value($self->chconf, 'directory') || value($self->chconf, 'dir') || 'File::Spec'->tmpdir
value($self->chconf, "directory") or value($self->chconf, "dir")
MC/DC0%0/3
value($self->chconf, 'directory') || value($self->chconf, 'dir') || 'File::Spec'->tmpdir
value($self->chconf, "directory")
value($self->chconf, "dir")
'File::Spec'->tmpdir
Truth table0%0/4
A or B || C
A= value($self->chconf, "directory")B= value($self->chconf, "dir")C= 'File::Spec'->tmpdir
| |||||||||||||||||||||||||||||||||||
| 171 | 0 | my $file; | |||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if (File::Spec->file_name_is_absolute($filename)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 173 | 0 | $file = $filename; | |||||||||||||||||||||||||||||||||
| 174 | } else { | ||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | unless (-e $dir and -w $dir) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $dir and -w $dir
MC/DC0%0/2
-e $dir and -w $dir
-e $dir
-w $dir
Truth table0%0/3
A and B
A= -e $dirB= -w $dir
| |||||||||||||||||||||||||||||||||||
| 176 | 0 | $self->error(sprintf("Can't use directory: %s", $dir)); | |||||||||||||||||||||||||||||||||
| 177 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||
| 179 | 0 | $file = File::Spec->catfile($dir, $filename); | |||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | # Save | ||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $message->save($file) or do { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 184 | 0 | $self->error($message->error); | |||||||||||||||||||||||||||||||||
| 185 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 186 | }; | ||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | #printf "Send message %s to %s (%s) via %s\n", $self->message->msgid, $self->message->to, $self->message->recipient, $self->type; | ||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||
| 193 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||||||||||||||||