CGI-FormBuilder-Mail-FormatMultiPart
view release on metacpan or search on metacpan
lib/CGI/FormBuilder/Mail/FormatMultiPart.pm view on Meta::CPAN
my $data_files = $self->_data_files();
if (defined $data_files) {
$html .= qq{<H2 CLASS="$base_css_class">Uploaded Files:</H2>\n};
$html .= $qt->render( $data_files );
}
my $data_env = $self->_data_env();
if (defined $data_env) {
$html .= qq{<H2 CLASS="$base_css_class">Browser/Connect Info:</H2>\n};
$html .= $qt->render( $data_env );
}
$html .= qq{<H2 CLASS="$base_css_class">Time:</H2>\n};
$html .= $qt->render( $self->_data_time() );
#print $html;
return $html;
}
sub _skipfields_lookup {
my ($self) = @_;
return $self->{_skipfields_lookup} if exists $self->{_skipfields_lookup};
my $skipfields_lookup
= $self->{_skipfields_lookup}
= { map { ( $_ => 1 ) } @{ $self->{skipfields} } };
return $skipfields_lookup;
}
sub _file_field_names {
my ($self) = @_;
my $fbflds = $self->{_fbflds};
my $skipfields_lookup = $self->_skipfields_lookup;
return (
grep { !exists $skipfields_lookup->{$_} } # is not skipped
grep { $fbflds->{$_}->type eq 'file' } # type is file
$self->{form}->fields # in order of fields
);
}
sub _file_attachments {
my ($self) = @_;
my ($form, $fbflds) = @{$self}{qw( form _fbflds )};
return ( # return array of hashrefs suitable for MIME::Type attachments
map { { Type => 'AUTO',
FH => $form->field($_),
Filename => $form->field($_),
Id => $_,
Disposition => 'attachment',
}
}
grep { $fbflds->{$_}->value } # only files actually uploaded
$self->_file_field_names()
);
}
sub _data_form {
my ($self) = @_;
# might be called twice in 'both', so no need to re-generate
return $self->{_data_form} if exists $self->{_data_form};
my ($form, $fbflds) = @{$self}{qw( form _fbflds )};
my $skipfields_lookup = $self->_skipfields_lookup;
my $data = [
[ 'Field' => 'Value' ]
];
my @field_names = $form->fields;
FIELD:
foreach my $name ( @field_names ) {
next FIELD if exists $skipfields_lookup->{$name};
next FIELD if $fbflds->{$name}->type eq 'file';
my @values = $form->field($name);
my $value = join("\n",@values);
$value = ' ' if !$value;
push @{$data}, [ "$name" => $value ];
}
# cache in self
$self->{_data_form} = $data;
return $data;
}
sub _data_files {
my ($self) = @_;
return $self->{_data_files} if exists $self->{_data_files};
my ($form) = @{$self}{qw( form )};
my $data = undef;
my @file_field_names = $self->_file_field_names();
if (scalar @file_field_names) {
$data = [
[ 'Field' => 'Attachment Status', ],
];
foreach my $name (@file_field_names) {
my $value = $form->field($name);
$value = 'Not Uploaded' if !defined $value;
push @{$data}, [ "$name" => "attached as $value" ];
}
}
$self->{_data_files} = $data;
return $data;
lib/CGI/FormBuilder/Mail/FormatMultiPart.pm view on Meta::CPAN
[ 'Time Zone' => 'Time' ],
[ 'Local System' => scalar localtime ],
[ 'Greenwich Mean' => scalar gmtime ],
];
$self->{_data_time} = $data;
return $data;
}
1;
__END__
=head1 NAME
CGI::FormBuilder::Mail::FormatMultiPart
Plugin for CGI::FormBuilder->mailresults()
=head1 SYNOPSIS
use CGI::FormBuilder;
my $form = CGI::FormBuilder->new(
...
# see CGI::FormBuilder manpage
);
if ($form->submitted && $form->validate) {
$form->mailresults(
plugin => 'FormatMultiPart',
from => $from_address,
to => $to_address,
cc => $cc_address_or_comma_sep_scalar,
bcc => $bcc_address_or_comma_sep_scalar,
smtp => $smtp_host_or_ip,
subject => 'subject', # optional
skipfields => ['field1','field2'], # optional
format => 'plain', # or 'html' or 'both'
html_qt_format => { }, # HTML::QuickTable args
css => $css, # scalar in-line css
);
}
=head1 DESCRIPTION
A plugin for CGI::FormBuilder to prettily send the form submission
via e-mail, without requiring the presence of sendmail on the system
or using a shell escape (i.e. Windows). It uses MIME::Lite to build
the message and that module's interface to Net::SMTP to send it.
Default message format is 'plain' but you can specify 'html' or 'both',
which results in a multipart message. (Not sure if I have that right yet.)
If HTML, can pass a stylesheet that is printed in-line, as well as
arguments to HTML::QuickTable. ('header' is ignored.) The default
style class is 'fb_mail' for all elements. You can use a partial CSS spec
to override this class's styles; defaults will otherwise still apply.
Will attach all file uploads as multipart MIME attachments.
The file names are listed in the form data table.
If it cannot be used, it will puke a warning message and die.
=head1 INSTALLATION
If you cannot use CPAN or PPM in the normal way, then:
perl Build.PL
./Build
./Build test
./Build install
You need superuser/administrator privileges for the last step.
=head1 WRITING YOUR OWN PLUGIN
This establishes a simple mail plugin implementation standard
for your own mailresults() plugins. The plugin should reside
under the CGI::FormBuilder::Mail::* namespace.
It should have a constructor new() which accepts
a hash-as-array of named arg parameters, including form => $form.
It should have a mailresults() object method that does the right thing.
It should use CGI::FormBuilder::Util and puke() if something goes wrong.
Calling $form->mailresults( plugin => 'Foo', ... ) will use
CGI::FormBuilder::Mail::Foo and will pass the FormBuilder object
as a named param 'form' with all other parameters passed intact.
If it should croak, confess, die or otherwise break if something
goes wrong, FormBuilder.pm will warn any errors and the built-in
mailresults() method will still try.
=head1 BUGS
Styles don't do anything in my copy of Evolution, at least.
But they do have the intended effect in Mozilla Mailnews,
so I guess it's good to go.
=head1 DEPENDENCIES
L<MIME::Types>,
L<Net::SMTP>,
L<MIME::Lite>,
L<Text::FormatTable>,
L<HTML::QuickTable>,
L<CGI::FormBuilder version 3.0301 or higher>
=head1 SEE ALSO
L<CGI::FormBuilder>,
L<MIME::Lite>,
L<Text::FormatTable>,
L<HTML::QuickTable>
=head1 AUTHOR
Copyright (c) 2006 Mark Hedges <hedges@ucsd.edu>.
This module is free software; you may copy this under the terms of
( run in 1.339 second using v1.01-cache-2.11-cpan-b16cb0d3907 )