| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::MonM::Notifier::Channel::File; # $Id: File.pm 60 2019-07-14 09:57:26Z abalama $ | 
| 2 | 1 |  |  | 1 |  | 7 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 25 |  | 
| 3 | 1 |  |  | 1 |  | 4 | use utf8; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =encoding utf-8 | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 NAME | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | App::MonM::Notifier::Channel::File - monotifier file channel | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 VERSION | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | Version 1.02 | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | Type    File | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # Real To and From | 
| 21 |  |  |  |  |  |  | To      testuser | 
| 22 |  |  |  |  |  |  | From    root | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | # File options | 
| 25 |  |  |  |  |  |  | #Encoding base64 | 
| 26 |  |  |  |  |  |  | #Dir      /path/to/messages/dir | 
| 27 |  |  |  |  |  |  | #File     [TO]_[DATETIME]_[ID].[EXT] | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | X-Foo foo | 
| 31 |  |  |  |  |  |  | X-Bar bar | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | This module provides a method that writes the content | 
| 38 |  |  |  |  |  |  | of the message to an external file | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =head2 DIRECTIVES | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =over 4 | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =item B, B | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | Defines path to save the message files | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | Default: your temp directory | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =item B, B | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | Defines special mask of the message's filename | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | Default: "[TO]_[DATETIME]_[ID].[EXT]" | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | Available variables: | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | - ID -- Internal ID of the message | 
| 59 |  |  |  |  |  |  | - TO -- The real "to" field | 
| 60 |  |  |  |  |  |  | - EXT -- file extension (default: msg) | 
| 61 |  |  |  |  |  |  | - TIME -- Current time (in unix time format) | 
| 62 |  |  |  |  |  |  | - DATETIME -- date and time in short-format (YYYMMDDHHMMSS) | 
| 63 |  |  |  |  |  |  | - DATE -- Date in short-format (YYYMMDD) | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =item B | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | Sender address or name | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =item B | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | Recipient address or name | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =item B | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | Defines type of channel. MUST BE set to "File" value | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =back | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | About other options (base) see L | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =head2 METHODS | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =over 4 | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =item B | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | For internal use only! | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =back | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =head1 HISTORY | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | See C file | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head1 DEPENDENCIES | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | L | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =head1 TO DO | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | See C file | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | L, L, L | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =head1 AUTHOR | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | Copyright (C) 1998-2019 D&D Corporation. All Rights Reserved | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =head1 LICENSE | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or | 
| 118 |  |  |  |  |  |  | modify it under the same terms as Perl itself. | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | See C file and L | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | =cut | 
| 123 |  |  |  |  |  |  |  | 
| 124 | 1 |  |  | 1 |  | 37 | use vars qw/$VERSION/; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 62 |  | 
| 125 |  |  |  |  |  |  | $VERSION = '1.02'; | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 1 |  |  | 1 |  | 6 | use File::Spec; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 128 | 1 |  |  | 1 |  | 5 | use IO::File; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 118 |  | 
| 129 |  |  |  |  |  |  |  | 
| 130 | 1 |  |  | 1 |  | 6 | use CTK::ConfGenUtil; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 61 |  | 
| 131 | 1 |  |  | 1 |  | 6 | use CTK::Util qw/ dformat date_time2dig date2dig /; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 49 |  | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | use constant { | 
| 134 | 1 |  |  |  |  | 378 | FILEEXT     => "msg", | 
| 135 |  |  |  |  |  |  | FILEMASK    => "[TO]_[DATETIME]_[ID].[EXT]", | 
| 136 | 1 |  |  | 1 |  | 5 | }; | 
|  | 1 |  |  |  |  | 1 |  | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | sub process { | 
| 139 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 140 | 0 |  |  |  |  |  | my $type = $self->type; | 
| 141 | 0 | 0 |  |  |  |  | return $self->maybe::next::method() unless $type eq 'file'; | 
| 142 | 0 |  |  |  |  |  | my $message = $self->message; | 
| 143 | 0 | 0 |  |  |  |  | unless ($message) { | 
| 144 | 0 |  |  |  |  |  | $self->error("Incorrect Email::MIME object"); | 
| 145 | 0 |  |  |  |  |  | return; | 
| 146 |  |  |  |  |  |  | } | 
| 147 |  |  |  |  |  |  | my $message_id = $self->genId( | 
| 148 |  |  |  |  |  |  | $self->data->{id} || 0, | 
| 149 |  |  |  |  |  |  | $self->data->{pubdate} || 0, | 
| 150 | 0 |  | 0 |  |  |  | $self->data->{to} || "anonymous", | 
|  |  |  | 0 |  |  |  |  | 
|  |  |  | 0 |  |  |  |  | 
| 151 |  |  |  |  |  |  | ); | 
| 152 |  |  |  |  |  |  |  | 
| 153 | 0 |  | 0 |  |  |  | my $filemask = value($self->config, "filemask") || value($self->config, "file") || FILEMASK; | 
| 154 |  |  |  |  |  |  | my $filename = dformat( $filemask, { | 
| 155 |  |  |  |  |  |  | ID      => $message_id, | 
| 156 |  |  |  |  |  |  | TO      => $self->data->{to}, | 
| 157 | 0 |  |  |  |  |  | EXT     => FILEEXT, | 
| 158 |  |  |  |  |  |  | TIME    => time(), | 
| 159 |  |  |  |  |  |  | DATETIME=> date_time2dig(), | 
| 160 |  |  |  |  |  |  | DATE    => date2dig(), | 
| 161 |  |  |  |  |  |  | } ); | 
| 162 | 0 |  | 0 |  |  |  | my $dir = value($self->config, "directory") || value($self->config, "dir") || File::Spec->tmpdir; | 
| 163 | 0 |  |  |  |  |  | my $file; | 
| 164 | 0 | 0 |  |  |  |  | if (File::Spec->file_name_is_absolute($filename)) { | 
| 165 | 0 |  |  |  |  |  | $file = $filename; | 
| 166 |  |  |  |  |  |  | } else { | 
| 167 | 0 | 0 | 0 |  |  |  | unless (-e $dir and -w $dir) { | 
| 168 | 0 |  |  |  |  |  | $self->error(sprintf("Can't use directory: %s", $dir)); | 
| 169 | 0 |  |  |  |  |  | return; | 
| 170 |  |  |  |  |  |  | } | 
| 171 | 0 |  |  |  |  |  | $file = File::Spec->catfile($dir, $filename); | 
| 172 |  |  |  |  |  |  | } | 
| 173 |  |  |  |  |  |  |  | 
| 174 | 0 |  |  |  |  |  | my $fh = IO::File->new($file, "w"); | 
| 175 | 0 | 0 |  |  |  |  | if (defined $fh) { | 
| 176 | 0 |  |  |  |  |  | $fh->binmode(); | 
| 177 | 0 |  |  |  |  |  | $fh->print($message->as_string); | 
| 178 | 0 |  |  |  |  |  | undef $fh; | 
| 179 |  |  |  |  |  |  | } else { | 
| 180 | 0 |  |  |  |  |  | $self->error("Can't use FileHandle handler for writing file $file: $!"); | 
| 181 |  |  |  |  |  |  | return | 
| 182 | 0 |  |  |  |  |  | } | 
| 183 |  |  |  |  |  |  |  | 
| 184 | 0 |  |  |  |  |  | return $self->status(1); | 
| 185 |  |  |  |  |  |  | } | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | 1; | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | __END__ |