package Newsletter::Html::Templ; use warnings; use strict; use CGI; use Newsletter; use File::Path; use File::Type; sub init { my ($self) = @_; $self->{'cgi'} = new CGI; } sub forumBegin { my ($self, %param) = @_; $self->_out( $self->{'cgi'}->start_form( -method=> 'GET', %param ) ); } sub forumEnd { my ($self) = @_; $self->_out( "" ); } sub startpage { my ($self) = @_; $self->forumBegin; $self->_out( qq~ ~); $self->forumEnd; $self->forumBegin; $self->_out( qq~ ~ ); $self->forumEnd; $self->_out( qq~

Email Lists

~); $self->forumEnd; $self->forumBegin; $self->_out( qq~

Available Lists


Send Edit



Create a new Newsletter List

List
List name is equal to the "from" field in the email! E.g. a valid list name: foo\@bar.com

Email Templates

Schema



All Files



[H]=Header [F]=Footer
~); $self->forumEnd; $self->forumBegin; $self->_out( qq~


~); $self->forumEnd; $self->forumBegin; $self->_out( qq~

Email Archiv

~ ); my $path = $self->{'nl'}->archiv( get => "archivPath" ); my %mailByTime = $self->{'nl'}->archiv( get => "mails" ); my $countMail = 8; foreach my $mail ( sort {$b cmp $a} keys %mailByTime ) { $mailByTime{ $mail } =~/(.+\d\d\d\d)\_(.*)/; my $mailDate = $1; my $linkName = $2; $self->_out( qq~ [$linkName] ~ ); if( -e "$path/$mailByTime{ $mail }/explode/file.html") { $self->_out( qq~ [html] ~ ); } if( -e "$path/$mailByTime{ $mail }/explode/file.txt") { $self->_out( qq~ [text] ~ ); } $self->_out( qq~
($mailDate)
~ ); last if($countMail == 0); $countMail--; } $self->_out( qq~

[ complete archiv ]
~ ); if( $self->{'nl'}->error ) { $self->_info( $self->{'nl'}->error ); } } sub openList { my ($self) = @_; my $listname = $self->{'persistent'}->{"pOpenList"}; $self->forumBegin; $self->_out( qq~

List Members from

$listname
search


search Selected delete

Add new members

~ ); $self->forumEnd; $self->forumBegin; for( my $m = 1; $m < 7; $m++ ) { my $formatedNr = sprintf("%04d",$m); $self->_out( qq~

~); } $self->_out( qq~ ~ ); $self->forumEnd; if( $listname ) { $self->forumBegin; $self->_out( qq~

Delete List

Delete:No Yes

~ ); $self->forumEnd; } $self->_out( qq~
~ ); if( $self->{'nl'}->error ) { $self->_info( $self->{'nl'}->error(1) ); } } sub editTmpl { my ($self) = @_; $self->forumBegin; $self->_out( qq~ ~ ); $self->forumEnd; my $html = +HTML_TMPL; my $text = +TEXT_TMPL; my $header = +HEADER; my $footer = +FOOTER; $self->forumBegin( -enctype => "multipart/form-data", -method => "post" ); $self->_out( qq~

All Templates Files

Header Files

Footer Files

[H]=Header [F]=Footer

open delete

Add new Template File



Html Text

Header Footer

Create new Schema


Add to existing Schema



~ ); $self->forumEnd; $self->_out( qq~
~ ); } sub openTmpl { my ($self, $path, $type) = @_; my $nr = int(rand(10000) + 1); $self->_out( qq~ ~); } sub fileuploadTmpl { my ($self) = @_; my $fileName = $self->fileUpload("tmplFileUpload"); $self->forumBegin( -enctype => "multipart/form-data", -method => "post" ); $self->_out( qq~

Add embedded Files

Filename:$fileName
Is:$self->{'persistent'}->{"pTmplFileUploadIs"}
Type:$self->{'persistent'}->{"pTmplFileUploadType"}
Schema: ~); if( $self->{'persistent'}->{"pTmplFileUploadSchemaNew"} ) { $self->_out( qq~ $self->{'persistent'}->{"pTmplFileUploadSchemaNew"}
~); } elsif( $self->{'persistent'}->{"pTmplFileUploadSchema"} ne "none") { $self->_out( qq~ $self->{'persistent'}->{"pTmplFileUploadSchema"}
~); } else { $self->_out( qq~ None
~); } $self->_out( qq~

Upload Embedded

~); for(my $a = 0; $a < 10; $a++ ) { $self->_out( qq~
~); } $self->_out( qq~

~); $self->forumEnd; } sub sendList { my ($self) = @_; if(! exists $self->{'persistent'}->{"pOpenList"} ) { $self->startpage; $self->_info( "No Mailing List is selected!" ); return; } if(! $self->{'persistent'}->{"pOpenList"} ) { $self->startpage; $self->_info( "No Mailing List is selected!" ); return; } $self->forumBegin( -enctype => "multipart/form-data", -method => "post" ); my %mailType = ( 'text' => 'Text', 'multipart/related' => 'Html', 'multipart/mixed' => 'Html + Text' ); $self->_out( qq~

Create Email

~); if( $self->{'persistent'}->{"pMailSubject"} ) { $self->_out( qq~ ~); } else { $self->_out( qq~ ~); } $self->_out( qq~ ~); if( $self->{'persistent'}->{"pMailBodyHtml"} ) { $self->_out( qq~ ~); } else { $self->_out( qq~ ~); } $self->_out( qq~ ~); if( $self->{'persistent'}->{"pMailBodyText"} ) { $self->_out( qq~ ~); } else { $self->_out( qq~ ~); } $self->_out( qq~
Mail Type
Subject
Mail from File Html
Text
Mail Html Body
Mail Text Body
Embedded Files



Attachments

~); $self->forumEnd; $self->sendListSetting; $self->_out( qq~
~); } sub sendListSetting { my($self) = @_; $self->forumBegin(); $self->_out( qq~

Settings

~); if( $self->{'persistent'}->{"pOpenSchema"} ) { $self->_out( qq~ ~); } else { if( $self->{'persistent'}->{"plOpenFile"}->[0] ) { $self->_out( qq~ ~); } } $self->_out( qq~ ~); if( $self->{'persistent'}->{'pMailFromFileHtml'} ) { $self->_out( qq~ ~); } if( $self->{'persistent'}->{'pMailFromFileText'} ) { $self->_out( qq~ ~); } if( $self->{'persistent'}->{"pMailEmbFile1"} ) { $self->_out( qq~ ~); } if( $self->{'persistent'}->{"pMailAttFile1"} ) { $self->_out( qq~ ~); } $self->_out( qq~
Maillist $self->{'persistent'}->{"pOpenList"}
Schema $self->{'persistent'}->{"pOpenSchema"}
Schema Files ~); foreach my $name ( $self->{'nl'}->template( get => { schema => $self->{'persistent'}->{"pOpenSchema"} } ) ) { $self->_out( qq~ $name->{'filename'}
~); } $self->_out( qq~
Selected Files ~); foreach my $tf ( @{ $self->{'persistent'}->{"plOpenFile"} } ) { my @tmp = split(/-is-/,$tf); $self->_out( qq~ $tmp[0]
~); } $self->_out( qq~

Body Html File $self->{'persistent'}->{'pMailFromFileHtml'}
Delete: No Yes
Body Text File $self->{'persistent'}->{'pMailFromFileText'}
Delete: No Yes
Embedded ~); for( my $a = 1; $a < 11; $a++ ) { if( $self->{'persistent'}->{"pMailEmbFile$a"} ) { $self->_out( qq~ $self->{'persistent'}->{"pMailEmbFile$a"} - {'persistent'}->{"pMailEmbFile$a"}> Delete {'persistent'}->{"pMailEmbFile$a"} checked="checked">No Yes
~); } } $self->_out( qq~
Attachments ~); for( my $a = 1; $a < 5; $a++ ) { if( $self->{'persistent'}->{"pMailAttFile$a"} ) { $self->_out( qq~ $self->{'persistent'}->{"pMailAttFile$a"} - {'persistent'}->{"pMailAttFile$a"}> Delete {'persistent'}->{"pMailAttFile$a"} checked="checked">No Yes
~); } } $self->_out( qq~

~); if( $self->{'persistent'}->{"pSection"} eq "sendListEdit" || $self->{'persistent'}->{"pSection"} eq "sendListPreview") { $self->_out( qq~ Preview Edit (Go back!)
~); } else { $self->_out( qq~ ~); } $self->_out( qq~
~); $self->forumEnd; } sub sendListFileupload { my($self) = @_; if( $self->{'cgi'}->param("mailFromFileHtml") ) { $self->{'persistent'}->{'pMailFromFileHtml'} = $self->fileUpload("mailFromFileHtml"); $self->_out( qq~ ~); } if( $self->{'cgi'}->param("mailFromFileText") ) { $self->{'persistent'}->{'pMailFromFileText'} = $self->fileUpload("mailFromFileText"); $self->_out( qq~ ~); } for( my $a = 1; $a < 11; $a++ ) { if( $self->{'cgi'}->param("mailEmbFile$a") ) { $self->{'persistent'}->{"pMailEmbFile$a"} = $self->fileUpload("mailEmbFile$a"); $self->_out( qq~ {'persistent'}->{"pMailEmbFile$a"}> ~); } if( $self->{'cgi'}->param("mailAttFile$a") ) { $self->{'persistent'}->{"pMailAttFile$a"} = $self->fileUpload("mailAttFile$a"); $self->_out( qq~ {'persistent'}->{"pMailAttFile$a"}> ~); } } } sub sendListFileDelete { my($self) = @_; if( $self->{'cgi'}->param("delMailFromFileHtml") ) { my $file = $self->{'cgi'}->param("delMailFromFileHtml"); $self->_out( qx "rm $self->{'uploadPath'}/$file 2>&1" ); } if( $self->{'cgi'}->param("delMailFromFileText") ) { my $file = $self->{'cgi'}->param("delMailFromFileText"); $self->_out( qx "rm $self->{'uploadPath'}/$file 2>&1" ); } for( my $a = 1; $a < 11; $a++ ) { if( $self->{'cgi'}->param("delMailEmbFile$a") ) { my $file = $self->{'cgi'}->param("delMailEmbFile$a"); $self->_out( qx "rm $self->{'uploadPath'}/$file 2>&1" ); } } for( my $a = 1; $a < 5; $a++ ) { if( $self->{'cgi'}->param("delMailAttFile$a") ) { my $file = $self->{'cgi'}->param("delMailAttFile$a"); $self->_out( qx "rm $self->{'uploadPath'}/$file 2>&1" ); } } } sub sendListPreview { my($self) = @_; if(! $self->{'persistent'}->{"pMailSubject"} ) { $self->sendList; $self->_info( "Alert no mail subject!" ); return; } $self->forumBegin( ); $self->sendListFileupload; $self->sendListBuild; $self->_out( qq~

Preview Email

~); my $mailFile = $self->{'nl'}->previewMailFile( preview => 1 ); if( $mailFile ) { $self->_out( qq~ ~); if( $self->{'nl'}->error ) { $self->_info( $self->{'nl'}->error(1) ); } my %explodeFiles; my $headers = $self->{'nl'}->previewMailFileExplode( $mailFile ); for my $part ( sort{ $a cmp $b } keys( %{ $headers } ) ) { for my $k ( keys( %{ $headers->{$part} } ) ) { if( $k eq 'content-disposition' ) { if( exists $headers->{$part}->{'content-disposition'}->{'filename'} ) { #warn $headers->{$part}->{'content-disposition'}->{'filename'}; if( !exists $explodeFiles{ $headers->{$part}->{'content-disposition'}->{'filename'} } ) { $explodeFiles{ $headers->{$part}->{'content-disposition'}->{'filename'} } = 1; } } } } } my $explodePath = $self->{'nl'}->previewMailFile( getpath => 1 )."/explode"; # remove attachment files from list! for( my $a = 1; $a < 5; $a++ ) { if( $self->{'persistent'}->{"pMailAttFile$a"} ) { if( exists $explodeFiles{ $self->{'persistent'}->{"pMailAttFile$a"} } ) { delete $explodeFiles{ $self->{'persistent'}->{"pMailAttFile$a"} }; } } } foreach my $file ( sort keys %explodeFiles ) { #warn "[$file]\n"; if( $file =~ /\.html/) { $self->_out( qq~ ~); } elsif( $file =~ /\.txt/ || $file !~ /\./ ) { $self->_out( qq~ ~); } } if( $self->{'nl'}->error ) { $self->_info( $self->{'nl'}->error ); } } else { if( $self->{'nl'}->error ) { $self->_info( $self->{'nl'}->error ); } } # $self->_out( qq~ # # # # # ~); $self->_out( qq~
Subject $self->{'persistent'}->{"pMailSubject"}
Preview Mail [Open Mail]
Preview HTML ~); open(FILE, "<$explodePath/$file") or die "preview html file:$explodePath/$file:$!\n"; while( defined( my $line = ) ) { $line =~ s/src="cid:/src="$explodePath\//gi; $self->_out( qq~ $line ~); } close(FILE); $self->_out( qq~
Preview Text
 ~);

				open(FILE, "<$explodePath/$file") or warn "preview text file:$explodePath/$file:$!\n";
                                while( defined( my $line = ) ) {
                                        $self->_out( qq~ $line ~);
                                }
                                close(FILE);
				$self->_out( qq~
                                    
Mail Source # #
~); $self->forumEnd; $self->sendListSetting; $self->_out( qq~
~); } sub sendListBuild { my($self) = @_; # Set Sender type $self->{'nl'}->sender( type => $self->{'persistent'}->{"pMailType"} ); # Load Footer / Header if( $self->{'persistent'}->{"pOpenSchema"} ) { $self->{'nl'}->template( use => { schema => $self->{'persistent'}->{"pOpenSchema"} } ); } else { if( $self->{'persistent'}->{"plOpenFile"}->[0] ) { foreach my $tf ( @{ $self->{'persistent'}->{"plOpenFile"} } ) { my @tmp = split(/-is-/,$tf); $self->{'nl'}->template( use => { is => $tmp[1], filename => $tmp[0] } ); } } } # Load Subject if( $self->{'persistent'}->{"pMailSubject"} ) { $self->{'nl'}->body( subject => $self->{'persistent'}->{"pMailSubject"} ); } # Load Body Html my @embHtml = (); for( my $a = 1; $a < 11; $a++ ) { if( $self->{'persistent'}->{"pMailEmbFile$a"} ) { push( @embHtml, $self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailEmbFile$a"} ); } } if( exists $self->{'persistent'}->{'pMailFromFileHtml'} ) { if( $self->{'persistent'}->{'pMailFromFileHtml'} ) { $self->{'nl'}->body( file => { path => $self->{'uploadPath'}.'/'.$self->{'persistent'}->{'pMailFromFileHtml'}, type => 'html', embedded => \@embHtml, } ); } else { $self->{'nl'}->body( data => { value => $self->{'persistent'}->{'pMailBodyHtml'}, type => 'html', embedded => \@embHtml, } ); } } else { $self->{'nl'}->body( data => { value => $self->{'persistent'}->{'pMailBodyHtml'}, type => 'html', embedded => \@embHtml, } ); } # Load Body Text if( exists $self->{'persistent'}->{'pMailFromFileText'} ) { if( $self->{'persistent'}->{'pMailFromFileText'} ) { $self->{'nl'}->body( file => { path => $self->{'uploadPath'}.'/'.$self->{'persistent'}->{'pMailFromFileText'}, type => 'text', } ); } else { $self->{'nl'}->body( data => { value => $self->{'persistent'}->{'pMailBodyText'}, type => 'text', } ); } } else { $self->{'nl'}->body( data => { value => $self->{'persistent'}->{'pMailBodyText'}, type => 'text', } ); } # add attachments my $msg = $self->{'nl'}->sender; if( $msg ) { my $ft = File::Type->new(); for( my $a = 1; $a < 5; $a++ ) { if( $self->{'persistent'}->{"pMailAttFile$a"} ) { # 'file' and 'file.html' not allowed if( $self->{'persistent'}->{"pMailAttFile$a"} =~ /file/ || $self->{'persistent'}->{"pMailAttFile$a"} =~ /file\.html/ ) { next; $self->_info( "'file' and 'file.html' not allowed as attachment filenames\n" ); } $msg->attach( Type => $ft->checktype_filename( $self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailAttFile$a"} ), Path => $self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailAttFile$a"} ); warn "Path => ".$self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailAttFile$a"}; } } } if( $self->{'nl'}->error ) { $self->_info( $self->{'nl'}->error ); } } sub sendListMail { my($self) = @_; $self->sendListBuild; # add attachments # my $msg = $self->{'nl'}->sender; # if( $msg ) { # for( my $a = 1; $a < 5; $a++ ) { # if( $self->{'persistent'}->{"pMailAttFile$a"} ) { # # # 'file' and 'file.html' not allowed # if( $self->{'persistent'}->{"pMailAttFile$a"} =~ /file/ || # $self->{'persistent'}->{"pMailAttFile$a"} =~ /file\.html/ # ) { # next; # $self->_info( "'file' and 'file.html' not allowed as attachment filenames\n" ); # } # # $msg->attach( # Path => $self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailAttFile$a"} # ); # warn "Path => ".$self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailAttFile$a"}; # } # } # } # open mail list $self->{'nl'}->list( list => { name => $self->{'persistent'}->{"pOpenList"} } ); if( $self->{'nl'}->error ) { $self->_info( $self->{'nl'}->error ); } # send !!! print qq~
~;
	$self->{'nl'}->send(1);
	print qq~ 
~; if( $self->{'nl'}->error ) { $self->_info( $self->{'nl'}->error ); } # copy to archiv $self->{'nl'}->archiv( save => 1 ); if( $self->{'nl'}->error ) { $self->_info( $self->{'nl'}->error ); } # cleanup upload files $self->sendListClean(); } sub sendListClean { my($self) = @_; rmtree $self->{'uploadPath'}; } =head1 NAME Newsletter::Html::Templ - Html parts! =head1 VERSION Version 0.01 =cut our $VERSION = '0.01'; =head1 SYNOPSIS The html parts for the newsletter module Perhaps a little code snippet. use Newsletter::Html::Templ; my $foo = Newsletter::Html::Templ->new(); ... =head1 EXPORT A list of functions that can be exported. You can delete this section if you don't export anything, such as for a purely object-oriented module. =head1 FUNCTIONS =head1 AUTHOR Dominik Hochreiter, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Newsletter You can also look for information at: =over 4 =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * RT: CPAN's request tracker L =item * Search CPAN L =back =head1 ACKNOWLEDGEMENTS =head1 COPYRIGHT & LICENSE Copyright 2006 Dominik Hochreiter, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of Newsletter::Html::Templ