| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package meon::Web::Form::SendEmail; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
10723717
|
use strict; |
|
|
2
|
|
|
|
|
20
|
|
|
|
2
|
|
|
|
|
153
|
|
|
4
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
|
2
|
|
|
|
|
15
|
|
|
|
2
|
|
|
|
|
149
|
|
|
5
|
2
|
|
|
2
|
|
184
|
use 5.010; |
|
|
2
|
|
|
|
|
11
|
|
|
|
2
|
|
|
|
|
101
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1400
|
use List::MoreUtils 'uniq'; |
|
|
2
|
|
|
|
|
2932
|
|
|
|
2
|
|
|
|
|
400
|
|
|
8
|
2
|
|
|
2
|
|
1362
|
use Email::MIME; |
|
|
2
|
|
|
|
|
104129
|
|
|
|
2
|
|
|
|
|
11
|
|
|
9
|
2
|
|
|
2
|
|
945
|
use Email::Sender::Simple qw(sendmail); |
|
|
2
|
|
|
|
|
211894
|
|
|
|
2
|
|
|
|
|
31
|
|
|
10
|
2
|
|
|
2
|
|
1820
|
use Data::Dumper; |
|
|
2
|
|
|
|
|
9775
|
|
|
|
2
|
|
|
|
|
120
|
|
|
11
|
2
|
|
|
2
|
|
748
|
use meon::Web::Util; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use meon::Web::Member; |
|
13
|
|
|
|
|
|
|
use Path::Class 'dir'; |
|
14
|
|
|
|
|
|
|
use File::MimeInfo 'mimetype'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use HTML::FormHandler::Moose; |
|
17
|
|
|
|
|
|
|
extends 'HTML::FormHandler'; |
|
18
|
|
|
|
|
|
|
with 'meon::Web::Role::Form'; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has_field 'submit' => ( type => 'Submit', value => 'Submit', ); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
before 'validate' => sub { |
|
23
|
|
|
|
|
|
|
my ($self) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$self->add_form_error('Are you real?') |
|
26
|
|
|
|
|
|
|
if $self->c->req->param('yreo'); |
|
27
|
|
|
|
|
|
|
}; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub submitted { |
|
30
|
|
|
|
|
|
|
my ($self) = @_; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $c = $self->c; |
|
33
|
|
|
|
|
|
|
my $xpc = meon::Web::Util->xpc; |
|
34
|
|
|
|
|
|
|
$c->log->debug(__PACKAGE__.' '.Data::Dumper::Dumper($c->req->params)) |
|
35
|
|
|
|
|
|
|
if $c->debug; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $from = ($c->user_exists ? $c->member->email : 'no-reply@meon.eu'); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $xml = $c->model('ResponseXML')->dom; |
|
40
|
|
|
|
|
|
|
my $rcpt_to = $self->get_config_text('rcpt-to'); |
|
41
|
|
|
|
|
|
|
my $subject = $self->get_config_text('subject'); |
|
42
|
|
|
|
|
|
|
$subject .= ' - '.$c->req->param('email') |
|
43
|
|
|
|
|
|
|
if $c->req->param('name'); |
|
44
|
|
|
|
|
|
|
$subject .= ' - '.$c->req->param('subject') |
|
45
|
|
|
|
|
|
|
if $c->req->param('subject'); |
|
46
|
|
|
|
|
|
|
my $detach = $self->get_config_text('detach'); |
|
47
|
|
|
|
|
|
|
my $email_content = ''; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my @input_names; |
|
50
|
|
|
|
|
|
|
my @file_attachments; |
|
51
|
|
|
|
|
|
|
foreach my $input ($xpc->findnodes('//x:form//x:input | //x:form//x:textarea',$xml)) { |
|
52
|
|
|
|
|
|
|
my $field_name = $input->getAttribute('name'); |
|
53
|
|
|
|
|
|
|
my $field_type = lc($input->getAttribute('type') // ''); |
|
54
|
|
|
|
|
|
|
next unless $input; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
if ($field_type eq 'file') { |
|
57
|
|
|
|
|
|
|
my $upload = $c->req->upload($field_name); |
|
58
|
|
|
|
|
|
|
if ($upload) { |
|
59
|
|
|
|
|
|
|
push(@file_attachments, Email::MIME->create( |
|
60
|
|
|
|
|
|
|
attributes => { |
|
61
|
|
|
|
|
|
|
filename => $upload->filename, |
|
62
|
|
|
|
|
|
|
name => $upload->filename, |
|
63
|
|
|
|
|
|
|
content_type => $upload->type, |
|
64
|
|
|
|
|
|
|
encoding => 'base64', |
|
65
|
|
|
|
|
|
|
}, |
|
66
|
|
|
|
|
|
|
body => $upload->slurp, |
|
67
|
|
|
|
|
|
|
)); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
elsif ($field_type ne 'submit') { |
|
71
|
|
|
|
|
|
|
push(@input_names, $field_name); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my @args; |
|
76
|
|
|
|
|
|
|
foreach my $input_name (@input_names) { |
|
77
|
|
|
|
|
|
|
my $input_value = $c->req->param($input_name) // ''; |
|
78
|
|
|
|
|
|
|
next unless length $input_value; |
|
79
|
|
|
|
|
|
|
push(@args, [ $input_name => $input_value ]); |
|
80
|
|
|
|
|
|
|
$email_content .= $input_name.': '.$input_value."\n"; # FIXME use Data::Header::Fields |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $email = Email::MIME->create( |
|
84
|
|
|
|
|
|
|
header_str => [ |
|
85
|
|
|
|
|
|
|
From => $from, |
|
86
|
|
|
|
|
|
|
To => $rcpt_to, |
|
87
|
|
|
|
|
|
|
Subject => $subject, |
|
88
|
|
|
|
|
|
|
], |
|
89
|
|
|
|
|
|
|
parts => [ |
|
90
|
|
|
|
|
|
|
Email::MIME->create( |
|
91
|
|
|
|
|
|
|
attributes => { |
|
92
|
|
|
|
|
|
|
content_type => "text/plain", |
|
93
|
|
|
|
|
|
|
charset => "UTF-8", |
|
94
|
|
|
|
|
|
|
encoding => "8bit", |
|
95
|
|
|
|
|
|
|
}, |
|
96
|
|
|
|
|
|
|
body_str => $email_content, |
|
97
|
|
|
|
|
|
|
), |
|
98
|
|
|
|
|
|
|
@file_attachments, |
|
99
|
|
|
|
|
|
|
], |
|
100
|
|
|
|
|
|
|
); |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
if (Run::Env->prod) { |
|
103
|
|
|
|
|
|
|
sendmail($email->as_string); |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
else { |
|
106
|
|
|
|
|
|
|
warn $email->as_string; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$self->detach($detach); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
no HTML::FormHandler::Moose; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |