diff --git a/docs/mail_commands_setup.pod b/docs/mail_commands_setup.pod new file mode 100644 index 0000000..10e0e1f --- /dev/null +++ b/docs/mail_commands_setup.pod @@ -0,0 +1,101 @@ +=head1 Configuring WebGUI mail commands + +This document discusses the steps required to tie WebGUI mal command into +postfix. + +=head2 Setting up WebGUI + +The mappings between To adress in the incoming emails and WebGUI instances is +defined in /data/WebGUI/etc/mailing_dispatch.config. This is a JSON file +containing a hash with domain to instance config file mappings: + + { + "mailing.domain1.com" : "www_domain1_com.conf", + "newsletter.foo.com" : "www_foo_com.conf" + } + +Note that any domain can be tied to any config file: domains don't have to +match. The only requirement is that the server can receive mail on the given +domain. Eg. the following is a valid mapping + + { + "newsletter.bar.com" : "www_xyzzy_com.conf" + } + +It is also possible to map multiple domains to a single config file, eg. + + { + "mailing.example.com" : "example_com.conf", + "mailing.foobar.org" : "example_com.conf" + } + +However it is not allowed to map a single domain to multiple config files. If +you do the instance that is used, is not defined. Eg. the following is NOT +allowed. + + { + "mailing.example.com" : "example_com.conf", + "mailing.example.com" : "foobar_org.conf" + } + + +=head2 Setting up Postfix + +The newsletter-transport.pl script in the webgui_newsletter sbin directory +acts as a bridge between postfix and WebGUI. It is intended to be invoked +by postfix's pipe command. + +=head3 Configuring master.cf + +We need a queue that processes mail intended for WebGUI. To do so add the +following to /etc/postfix/master.cf: + + wgml unix - n n - - pipe + flags=FR user=webgui argv=/data/custom/webgui_newsletter/sbin/newsletter-transport.pl \ + --domain=${domain} --user=${user} --sender=${sender} --senderIp=${client_address} + +This creates a queue called wgml that pipes all mail in it through the +newsletter-transport.pl script. Make sure that the user parameter is set correctly and argv +contains the full path to the newsletter-transport.pl script. + + +=head3 Setup a transport map + +In order to determine which emails should go to the wgml queue, create a +mapping in /etc/postfix/wg_mailer_transport. There are more ways to do this. + +If you use a dedicated maildomain used solely for receiving WebGUI mail +commands add a line like the following for each mail domain in your +/date/WebGUI/etc/mailing_dispatch.config: + + /@mailing.foo.com$/ wgml: + /@newsletter.example.com$/ wgml: + +If you use a domain that is not solely dedicated to receiving WebGUI mail +commands, you can match on individual commands: + + /^[a-zA-Z0-9_-]+-bounce@/ wgml: + /^[a-zA-Z0-9_-]+-subscribe@/ wgml: + + +Afterwards complile the mapping into a postfix lookup table + + postmap /etc/postfix/wg_mailer_transport + +You have to do this everytime you change the mapping. + +=head3 Configuring main.cf + +Now we need to tell postfix to use the mapping, and how to use the wgml +queue. To do this add the following to /etc/postfix/main.cf: + + smtpd_reject_unlisted_recipient = no + transport_maps = regexp:/etc/postfix/wg_mailer_transport + wgml_destination_recipient_limit = 1 + +Make sure you add the domains in your mailing_dispatch.config to the +mydestination directlive in main.cf: + + mydestination = mailing.foo.com, newsletter.example.org, some.other.domain + +Finally restart postfix. diff --git a/docs/postfix_configuration b/docs/postfix_configuration deleted file mode 100644 index b6ee775..0000000 --- a/docs/postfix_configuration +++ /dev/null @@ -1,17 +0,0 @@ -Add to /etc/postfix/main.cf: - smtpd_reject_unlisted_recipient = no - transport_maps = regexp:/etc/postfix/wg_mailer_transport - wgml_destination_recipient_limit = 1 - -Add to /etc/postfix/master.cf: - wgml unix - n n - - pipe - flags=FR user=martin argv=/data/custom/webgui_newsletter/sbin/newsletter-transport.pl ${domain} ${user} - - -Create /etc/postfix/wg_mailer_transport: - /^[a-zA-Z0-9]+-bounce@/ wgml: - -And run: - postmap /etc/postfix/wg_mailer_transport - -Finally restart postfix. diff --git a/docs/required_modules b/docs/required_modules index f1d1dac..b8200dc 100644 --- a/docs/required_modules +++ b/docs/required_modules @@ -1,3 +1,3 @@ -Mail::DeliveryStatus::BounceParser -Class::InsideOut +Mail::DeliveryStatus::BounceParser (v 1.525) +Class::InsideOut (v 1.10) diff --git a/lib/WebGUI/Asset/Wobject/NewsletterCollection.pm b/lib/WebGUI/Asset/Wobject/NewsletterCollection.pm index d35d745..d0a234a 100644 --- a/lib/WebGUI/Asset/Wobject/NewsletterCollection.pm +++ b/lib/WebGUI/Asset/Wobject/NewsletterCollection.pm @@ -8,7 +8,7 @@ use Class::C3; use WebGUI::User::SpecialState; use base qw{ - WebGUI::AssetAspect::Mailable + WebGUI::AssetAspect::Mailable WebGUI::AssetAspect::Subscriber WebGUI::Asset::Wobject }; @@ -34,8 +34,15 @@ sub definition { tab => 'display', defaultValue => 1, }, + useHoneypot => { + fieldType => 'yesNo', + label => $i18n->get('useHoneypot label'), + hoverHelp => $i18n->get('useHoneypot description'), + tab => 'security', + defaultValue => 1, + }, ); - + push @{ $definition }, { assetName => $i18n->get('assetName'), icon => 'newsletter_collection.gif', @@ -52,12 +59,16 @@ sub definition { sub getIssues { my $self = shift; - my $issues = $self->getLineage( [ 'children' ], { - returnObjects => 1, - orderByClause => 'lineage desc', - } ); - - return $issues; + # Caching of instanciated assets is not for speed, but is requied since prepareView is called on them, and we + # need them again in that state in getViewVars. + unless ( $self->{ _issues } ) { + $self->{ _issues } = $self->getLineage( [ 'children' ], { + returnObjects => 1, + orderByClause => 'lineage desc', + } ); + } + + return $self->{ _issues }; } #---------------------------------------------------------------------------- @@ -88,7 +99,8 @@ sub getAssetContent { my $self = shift; my $asset = shift; - $asset->prepareView; + # Do not call prepareView on $asset here but rather do this in our own prepareView to prevent head tags being + # written to body. my $content = $asset->view; return $content; @@ -106,6 +118,11 @@ sub prepareView { $self->{ _viewTemplate } = $template; + # Call prepareview on issues here, to prevent head tags ending up in the body. + foreach my $issue ( @{ $self->getIssues } ) { + $issue->prepareView; + } + return; } @@ -126,11 +143,11 @@ sub getViewVars { foreach my $issue ( @{ $issues } ) { my $issueVar = $issue->get; $issueVar->{ url } = $issue->getUrl; - - my $isRecent = - ( !$displayIssueId && $recentCount < $maxRecent ) - || ( $issue->getId eq $displayIssueId ) - ; + + my $isRecent = defined $displayIssueId + ? $issue->getId eq $displayIssueId + : $recentCount < $maxRecent + ; if ( $isRecent ) { $issueVar->{ content } = $self->getAssetContent( $issue ); @@ -157,7 +174,7 @@ sub view { my $self = shift; my $form = $self->session->form; - my $var = $self->getViewVars( { + my $var = $self->getViewVars( { displayIssue => $form->guid('displayIssue'), } ); @@ -165,4 +182,3 @@ sub view { } 1; - diff --git a/lib/WebGUI/AssetAspect/Mailable.pm b/lib/WebGUI/AssetAspect/Mailable.pm index 90bc717..5efa6c7 100644 --- a/lib/WebGUI/AssetAspect/Mailable.pm +++ b/lib/WebGUI/AssetAspect/Mailable.pm @@ -2,7 +2,7 @@ package WebGUI::AssetAspect::Mailable; use strict; use warnings; -use Class::C3; +use Class::C3; use WebGUI::Macro; use Tie::IxHash; @@ -115,13 +115,15 @@ sub processContentAsUser { $session->user( { userId => $userId } ); $session->log->preventDebugOutput; - my $styleTemplateId = - $configuration->{ styleTemplateId } - || $self->get('mailStyleTemplateId') + my $styleTemplateId = + $configuration->{ styleTemplateId } + || $self->get('mailStyleTemplateId') || $self->get('styleTemplateId'); + $session->stow->set( 'mailing_rendering' => 1 ); + # Generate email body for this user - my $content = $session->style->process( + my $content = $session->style->process( $self->generateEmailContent( $issueId, $configuration ), $styleTemplateId, ); @@ -129,10 +131,13 @@ sub processContentAsUser { # Process macros WebGUI::Macro::process( $session, \$content ); + $session->stow->delete( 'mailing_rendering' ); + # Become ourselves again. $session->user( { userId => $currentUser->getId } ); $var->switchAdminOn if $adminOn; + return $content; } diff --git a/lib/WebGUI/AssetAspect/Subscriber.pm b/lib/WebGUI/AssetAspect/Subscriber.pm index 272e14a..fed9da6 100644 --- a/lib/WebGUI/AssetAspect/Subscriber.pm +++ b/lib/WebGUI/AssetAspect/Subscriber.pm @@ -2,11 +2,19 @@ package WebGUI::AssetAspect::Subscriber; use strict; use warnings; -use Class::C3; +use 5.010; +use Class::C3; use Carp; use WebGUI::Asset::Template; use WebGUI::Macro; +use WebGUI::Mail::Send; +use WebGUI::Group; +use WebGUI::Asset; +use WebGUI::Form; +use WebGUI::Form::Honeypot; +use WebGUI::User::SpecialState; +use WebGUI::International; use Tie::IxHash; use URI; @@ -18,6 +26,11 @@ sub definition { my $i18n = WebGUI::International->new( $session,'AssetAspect_Subscriber' ); tie my %properties, 'Tie::IxHash', ( + listName => { + fieldType => 'text', + label => $i18n->echo("List name"), + tab => 'subscription', + }, subscriptionGroupId => { fieldType => 'subscriptionGroup', label => $i18n->get( 'Subscription group' ), @@ -33,7 +46,7 @@ sub definition { alwaysConfirmSubscription => { fieldType => 'yesNo', defaultValue => 0, - label => $i18n->get( 'require confirmation' ), + label => $i18n->get( 'require confirmation' ), tab => 'subscription', }, allowAnonymousSubscription => { @@ -75,6 +88,13 @@ sub definition { namespace => 'Subscriber/NoMutationEmail', tab => 'subscription', }, + confirmMutationTemplateId => { + fieldType => 'template', + defaultValue => 'WUk-wEhGiF8dcEogrJfrfg', + label => $i18n->get( 'confirm mutation template' ), + namespace => 'Subscriber/MutationConfirmation', + tab => 'subscription', + } ); push( @{ $definition }, { @@ -116,7 +136,7 @@ sub getListHeaders { my $site = $self->session->url->getSiteURL; my $headers = { - 'List-Unsubscribe' => + 'List-Unsubscribe' => '<' . $site . $self->getUrl( "func=processSubscription&action=unsubscribe&email=$email" ) . '>', 'List-Subscribe' => '<' . $site . $self->getUrl( "func=processSubscription&action=subscribe&email=$email" ) . '>', @@ -173,6 +193,44 @@ sub isSubscribed { } #---------------------------------------------------------------------------- +=head2 appendSubscriptionFormVars + +=head3 honeyPot +Part of the form vars are the honeyPot variables. This is a form plugin that +is used in NewsletterCollection.pm to activate the use of a honeypot or not, +in this module, AssetAspect/Subscriber.pm, to check the honeypot and to +display the form values and in i18n. + +There are the following form vars: + +=head4 subscriptionForm_emailBox +This renders both the emailbox, subscribe/unsubscribe radio buttons and the +honeypot form inputs: + +
+ + + +You can easily make the honeypot input field invisible with some css for +class honeypot. + +=head4 form_honeypot +Renders these fields: + + + +=head4 form_honeypot_id +Gives you the id for the honeypot input. This makes it easy to create a label: + + +=cut sub appendSubscriptionFormVars { my $self = shift; my $var = shift || {}; @@ -180,16 +238,41 @@ sub appendSubscriptionFormVars { my $i18n = WebGUI::International->new( $session, 'AssetAspect_Subscriber' ); # Setup form controls - my $formHeader = + my $formHeader = WebGUI::Form::formHeader( $session, { action => $self->getUrl } ) . WebGUI::Form::hidden( $session, { name => 'func', value => 'processSubscription' } ) ; - my $subscribeButton = - sprintf '', $i18n->get('subscribe'); - my $unsubscribeButton = - sprintf '', $i18n->get('unsubscribe'); - my $emailBox = WebGUI::Form::email( $session, { name => 'email', value => '' } ); my $formFooter = WebGUI::Form::formFooter( $session ); + my $subscribeButton = + $formHeader + . WebGUI::Form::hidden( $session, { name => 'action', value => 'subscribe' } ) + . WebGUI::Form::submit( $session, { value => $i18n->get('subscribe') } ) + . $formFooter + ; + my $unsubscribeButton = + $formHeader + . WebGUI::Form::hidden( $session, { name => 'action', value => 'unsubscribe' } ) + . WebGUI::Form::submit( $session, { value => $i18n->get('unsubscribe') } ) + . $formFooter + ; + # honeypot is connected to the emailbox, that is displayed on anonymous subscription + # and only if set to useHoneyPot in definition/display + my $honeypot = WebGUI::Form::Honeypot->new( $self->session, { name => 'hp' } ); + my $honeypot_form = $self->get('useHoneypot') ? $honeypot->toHtml : ''; + my $emailBox = + $formHeader + . WebGUI::Form::email( $session, { name => 'email', value => '' } ) + . WebGUI::Form::radioList( $session, { + name => 'action', + options => { + subscribe => $i18n->get('subscribe'), + unsubscribe => $i18n->get('unsubscribe'), + } + } ) + . $honeypot_form + . WebGUI::Form::submit( $session ) + . $formFooter + ; # Compose default subscription form for current user my $form = ''; @@ -198,19 +281,21 @@ sub appendSubscriptionFormVars { $form .= $unsubscribeButton if $self->canUnsubscribe; } elsif ( $self->get('allowAnonymousSubscription') ) { - $form = $emailBox . $subscribeButton . $unsubscribeButton; + $form = $emailBox; } # Setup tmpl_vars - $var->{ subscriptionForm_form } = "$formHeader $form $formFooter" if $form; + $var->{ subscriptionForm_form } = $form if $form; $var->{ subscriptionForm_header } = $formHeader; $var->{ subscriptionForm_footer } = $formFooter; $var->{ subscriptionForm_subscribeButton } = $subscribeButton; $var->{ subscriptionForm_unsubscribeButton } = $unsubscribeButton; - $var->{ subscrittionForm_emailBox } = $emailBox; + $var->{ subscriptionForm_emailBox } = $emailBox; $var->{ user_canSubscribe } = $self->canSubscribe; $var->{ user_canUnsubscribe } = $self->canUnsubscribe; $var->{ user_isRegistered } = $session->user->isRegistered; + $var->{ form_honeypot } = $honeypot->toHtml; + $var->{ form_honeypot_id } = $honeypot->get('id'); return $var; } @@ -219,8 +304,8 @@ sub appendSubscriptionFormVars { sub getSubscriptionGroup { my $self = shift; my $groupId = $self->get( "subscriptionGroupId" ); - my $group = $groupId - ? WebGUI::Group->new( $self->session, $groupId ) + my $group = $groupId + ? WebGUI::Group->new( $self->session, $groupId ) : $self->createSubscriptionGroup ; @@ -231,7 +316,7 @@ sub getSubscriptionGroup { sub getReturnUrl { my $self = shift; my $referer = $self->session->env->get('HTTP_REFERER'); - + return unless $referer; # Get path and strip leading and trailing slash if it exists. @@ -263,6 +348,45 @@ sub getEmailVars { return $var; } +#---------------------------------------------------------------------------- +sub getAssetByListName { + my $class = shift; + my $session = shift; + my $listName = shift || return; + my $db = $session->db; + + my $assetId = $db->quickScalar( 'select assetId from assetAspectSubscriber where listName=? limit 1', [ + $listName + ] ); + + return unless $assetId; + + my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId ); + + return $asset; +} + +#---------------------------------------------------------------------------- +sub processPropertiesFromFormPost { + my $self = shift; + my $session = $self->session; + my $form = $session->form; + + my $listName = $form->get('listName'); + my $asset = WebGUI::AssetAspect::Subscriber->getAssetByListName( $session, $listName ); + + my $errors = $self->next::method; + + if ( $asset && $asset->getId ne $self->getId ) { + return [ + @{ $errors || [] }, + "List name $listName is already taken." + ]; + } + + return $errors; +} + #---------------------------------------------------------------------------- sub sendSubscriptionConfirmation { my $self = shift; @@ -271,7 +395,13 @@ sub sendSubscriptionConfirmation { my $action = shift || 'subscribe'; my $session = $self->session; my $i18n = WebGUI::International->new( $session, 'AssetAspect_Subscriber' ); - +=pod + my $honeypot = $session->form->honeypot( 'hp' ); + if ( $self->get('useHoneypot') && $honeypot ) { + $session->log->warn( "Honeypot triggered: $honeypot" ); + return; + } +=cut my $var = $self->getEmailVars( $user ); my $url = $session->url->getSiteURL . $self->getUrl( "func=confirmMutation;code=$code" ); @@ -280,14 +410,18 @@ sub sendSubscriptionConfirmation { $var->{ actionIsSubscribe } = $action eq 'subscribe'; my $mail = WebGUI::Mail::Send->create( $self->session, { - to => $user->get('email'), - subject => $self->get('confirmationEmailSubject'), + to => $user->get('email'), + subject => $self->get('confirmationEmailSubject'), + contentType => 'multipart/alternative', } ); my $templateId = $self->get('confirmationEmailTemplateId'); my $template = WebGUI::Asset::Template->new( $session, $templateId ); if ( $template ) { - $mail->addHtml( $template->process( $var ) ); + my $content = $template->process( $var ); + + $mail->addHtml( $content ); + $mail->addText( $self->transformToText( $content ) ); } else { $session->log->error( "Cannot instanciate confirmation email template with id [$templateId]" ); @@ -306,19 +440,29 @@ sub sendNoMutationEmail { my $action = shift || 'subscribe'; my $session = $self->session; my $i18n = WebGUI::International->new( $session, 'AssetAspect_Subscriber' ); - +=pod + my $honeypot = $session->form->honeypot( 'hp' ); + if ( $self->get('useHoneypot') && $honeypot ) { + $session->log->warn( "Honeypot triggered: $honeypot" ); + return; + } +=cut my $var = $self->getEmailVars( $user ); $var->{ actionIsSubscribe } = $action eq 'subscribe'; my $mail = WebGUI::Mail::Send->create( $self->session, { - to => $user->get('email'), - subject => $self->get('noMutationEmailSubject'), + to => $user->get('email'), + subject => $self->get('noMutationEmailSubject'), + contentType => 'multipart/alternative', } ); my $templateId = $self->get('noMutationEmailTemplateId'); my $template = WebGUI::Asset::Template->new( $session, $templateId ); if ( $template ) { - $mail->addHtml( $template->process( $var ) ); + my $content = $template->process( $var ); + + $mail->addHtml( $content ); + $mail->addText( $self->transformToText( $content ) ); } else { $session->log->error( "Cannot instanciate no mutation email template with id [$templateId]" ); @@ -332,6 +476,18 @@ sub sendNoMutationEmail { return; } +sub transformToText { + my $self = shift; + my $html = shift; + + my $text = $html; + #HTML::Entities::decode($text); + $text =~ s/Terug naar de mailing manager.
@@ -516,11 +526,11 @@ sub www_previewEmail { } - - - - - + + + + + +EOJS + + $style->setLink( $url->extras('yui/build/datatable/assets/skins/sam/datatable.css'), { type => 'text/css', rel => 'stylesheet' } ); + $style->setScript( $url->extras('yui/build/yahoo-dom-event/yahoo-dom-event.js'), { type => 'text/javascript' } ); + $style->setScript( $url->extras('yui/build/element/element-min.js'), { type => 'text/javascript' } ); + $style->setScript( $url->extras('yui/build/datasource/datasource-min.js'), { type => 'text/javascript' } ); + $style->setScript( $url->extras('yui/build/datatable/datatable-min.js'), { type => 'text/javascript' } ); + $style->setRawHeadTags( $js ); + + return; +} + + 1; diff --git a/lib/WebGUI/Mailing/Email.pm b/lib/WebGUI/Mailing/Email.pm index 7598656..9445285 100644 --- a/lib/WebGUI/Mailing/Email.pm +++ b/lib/WebGUI/Mailing/Email.pm @@ -54,7 +54,7 @@ sub crud_definition { }, ); - $definition->{ properties } = { + $definition->{ properties } = { %{ $definition->{ properties } || {} }, %properties, }; @@ -128,20 +128,19 @@ sub absolutifyURIs { my $tb = HTML::TreeBuilder->new; my $root = $tb->parse( $content ); - foreach my $link ( @{ $root->extract_links } ) { + foreach my $link ( @{ $root->extract_links } ) { my ($uri, $element, $attr, $tag) = @{ $link }; - - if ( $uri !~ m{ ^ [a-z]+:// }xmsi ) { - my $new = + if ( $uri !~ m{ ^ (?: [a-z]+:// | \# | mailto: ) }xmsi ) { + my $new = ( $uri =~ m{ ^ / }xmsi ) # Is url absolute? ? $siteUrl . $uri : $siteUrl . $pageUrl . '/' . $uri ; - + # replace attribute $element->attr( $attr, $new ); } - } + } return $tb->as_HTML; } @@ -167,7 +166,7 @@ sub send { #### TODO: Error checking my $mailing = $self->getMailing; unless ( $mailing ) { - $session->log->error( 'Cannot send because getMailing doesn\'t return one.' ); + $session->log->error( 'Cannot send because getMailing doesn\'t return one.' ); return; } @@ -193,7 +192,7 @@ sub send { # Check bounce score my $bounceScoreOk = WebGUI::Mailing::Bounce->new( $session )->bounceScoreOk( $to ); if ( !$self->get( 'isTest' ) && !$bounceScoreOk ) { - $self->update( { + $self->update( { status => 'skipped', sendDate => time, errorMessage => "Bounce score for $to too high", @@ -228,14 +227,14 @@ sub send { } } - # And send it. + # And send it. my $success = $mail->send; if ( $success ne '1' ) { $self->error( "Mail couldn't be sent by WebGUI::Mail::Send" ); } else { - $self->update( { + $self->update( { status => 'sent', sendDate => time, sentTo => $to, diff --git a/lib/WebGUI/Registration/Step/MailingSubscribe.pm b/lib/WebGUI/Registration/Step/MailingSubscribe.pm index deff855..997d8b8 100644 --- a/lib/WebGUI/Registration/Step/MailingSubscribe.pm +++ b/lib/WebGUI/Registration/Step/MailingSubscribe.pm @@ -15,12 +15,15 @@ sub getAvailableMailings { my $self = shift; my $session = $self->session; - my $availableMailings = WebGUI::Asset->getRoot( $session )->getLineage( ['descendants'], { - returnObjects => 1, - isa => 'WebGUI::Asset::Wobject::NewsletterCollection', - } ); + my $mailingIds = $self->get( 'includeMailings' ); - return $availableMailings; + my @mailings = + grep { defined $_ } + map { WebGUI::Asset->newByDynamicClass( $session, $_ ) } + ref $mailingIds eq 'ARRAY' ? @{ $mailingIds } : $mailingIds + ; + + return \@mailings; } #------------------------------------------------------------------- @@ -31,7 +34,7 @@ sub apply { my $subscribeTo = { map { $_ => 1 } @{ $self->getConfigurationData->{ subscribeMailings } || [] } }; - + my $availableMailings = $self->getAvailableMailings; my $sendNotification = 0; @@ -49,22 +52,32 @@ sub apply { return; } -##------------------------------------------------------------------- -#sub crud_definition { -# my $class = shift; -# my $session = shift; -# my $definition = $class->SUPER::crud_definition( $session ); -# my $i18n = WebGUI::International->new( $session, 'Registration_Step_Homepage' ); -# -# -# $definition->{ dynamic }->{ urlStorageField } = { -# fieldType => 'selectBox', -# label => 'Store homepage url in field', -# options => \%profileFields, -# }; -# -# return $definition; -#} +#------------------------------------------------------------------- +sub crud_definition { + my $class = shift; + my $session = shift; + my $definition = $class->SUPER::crud_definition( $session ); + my $i18n = WebGUI::International->new( $session, 'RegistrationStep_MailingSubscribe' ); + + tie my %mailings, 'Tie::IxHash', ( + map { $_->getId => $_->getTitle } + @{ + WebGUI::Asset->getRoot( $session )->getLineage( ['descendants'], { + returnObjects => 1, + isa => 'WebGUI::Asset::Wobject::NewsletterCollection', + } ) + } + ); + + $definition->{ dynamic }->{ includeMailings } = { + fieldType => 'checkList', + label => $i18n->get('Include newsletters'), + options => \%mailings, + vertical => 1, + }; + + return $definition; +} #------------------------------------------------------------------- sub getSummaryTemplateVars { @@ -77,7 +90,7 @@ sub getSummaryTemplateVars { # Fetch preferred homepage url my $mailings = $self->getConfigurationData->{ subscribeMailings }; - my @assets = + my @assets = grep { defined $_ } map { WebGUI::Asset->newByDynamicClass( $session, $_ ) } @{ $mailings }; @@ -89,12 +102,12 @@ sub getSummaryTemplateVars { # Setup tmpl_var my $var = { - field_loop => \@fields, + field_loop => \@fields, category_label => $self->get('title'), category_edit_url => $self->changeStepDataUrl, }; - return ( $var ); + return ( $var ); } #------------------------------------------------------------------- @@ -119,7 +132,7 @@ sub getViewVars { } else { # The step hasn't been done yet. - @subscribeMailings = grep { $_->isSubscribed( $user ) } @{ $availableMailings }; + @subscribeMailings = map { $_->getId } grep { $_->isSubscribed( $user ) } @{ $availableMailings }; } # Create lookup table @@ -171,10 +184,7 @@ sub updateFromFormPost { my $self = shift; my $session = $self->session; - $self->SUPER::updateFromFormPost; - -# $self->update( { -# } ); + return $self->SUPER::updateFromFormPost; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/i18n/Dutch/AssetAspect_Subscriber.pm b/lib/WebGUI/i18n/Dutch/AssetAspect_Subscriber.pm index ee759a2..e6e8995 100644 --- a/lib/WebGUI/i18n/Dutch/AssetAspect_Subscriber.pm +++ b/lib/WebGUI/i18n/Dutch/AssetAspect_Subscriber.pm @@ -3,7 +3,7 @@ package WebGUI::i18n::Dutch::AssetAspect_Subscriber; use strict; our $I18N = { - 'Subscription group' => { + 'Subscription group' => { message => 'Abonnee groep', }, 'Enable subscription' => { @@ -24,7 +24,7 @@ our $I18N = { 'confirmation email template' => { message => 'Verificatie email: sjabloon', }, - 'no mutation subject' => { + 'no mutation subject' => { message => 'Geen wijziging email: onderwerp', }, 'no mutation template' => { @@ -52,16 +52,19 @@ our $I18N = { 'anonnymous not allowed' => { message => 'Anonieme inschrijvingen zijn niet toegestaan. Log in om in- of uit te schrijven.', }, - + 'subscription successful' => { - message => 'Uw inschrijving is geslaagd. Terug naar de site', + message => 'Uw inschrijving is geslaagd.', }, 'unsubscription successful' => { - message => 'Uw uitschrijving is geslaagd. Terug naar de site', + message => 'Uw uitschrijving is geslaagd.', }, 'wrong code' => { message => 'De verificatiecode in de link is onbekend, al gebruikt of verlopen. Als u zich wilt in- of uitschrijven probeer dit dan opnieuw of neem contact op met de websitebeheerders.', }, + 'confirm mutation template' => { + message => 'Mutatie bevestigings template', + }, }; 1; diff --git a/lib/WebGUI/i18n/Dutch/Asset_NewsletterCollection.pm b/lib/WebGUI/i18n/Dutch/Asset_NewsletterCollection.pm index 3fd5aa0..e4b8137 100644 --- a/lib/WebGUI/i18n/Dutch/Asset_NewsletterCollection.pm +++ b/lib/WebGUI/i18n/Dutch/Asset_NewsletterCollection.pm @@ -6,14 +6,26 @@ our $I18N = { assetName => { message => 'Nieuwsbrief collectie', }, + 'subscribe' => { + message => 'inschrijven', + }, + 'unsubscribe' => { + message => 'uitschrijven', + }, 'template' => { message => 'Sjabloon', }, 'number of recent issues' => { - message => 'Aantal recente uitgaven', + message => 'Aantal recente nieuwsbrieven', }, - + 'useHoneypot label' => { + message => q|Gebruik honeypot|, + lastUpdated => 0, + }, + 'useHoneypot description' => { + message => q|Gebruik honeypot om spam te voorkomen.|, + lastUpdated => 0, + }, }; 1; - diff --git a/lib/WebGUI/i18n/Dutch/MailingManager.pm b/lib/WebGUI/i18n/Dutch/MailingManager.pm index 4dc165b..31892b7 100644 --- a/lib/WebGUI/i18n/Dutch/MailingManager.pm +++ b/lib/WebGUI/i18n/Dutch/MailingManager.pm @@ -26,7 +26,7 @@ our $I18N = { 'bounce score' => { message => 'Bounce score', }, - + 'cannot cancel' => { message => 'Mailing \'%s\' kan niet worden afgebroken.', }, @@ -100,6 +100,14 @@ our $I18N = { 'generate mailing' => { message => 'Genereer mailing', }, + + 'bounce reason' => { + message => 'Laatste bounce oorzaak', + }, + + 'bounce message' => { + message => 'Laatste bounce omschrijving', + }, }; 1; diff --git a/lib/WebGUI/i18n/Dutch/RegistrationStep_MailingSubscribe.pm b/lib/WebGUI/i18n/Dutch/RegistrationStep_MailingSubscribe.pm index 957d7f1..05a0d19 100644 --- a/lib/WebGUI/i18n/Dutch/RegistrationStep_MailingSubscribe.pm +++ b/lib/WebGUI/i18n/Dutch/RegistrationStep_MailingSubscribe.pm @@ -4,10 +4,13 @@ use strict; our $I18N = { 'Subscribe to mailings' => { - message => 'Abonneren op nieuwsbrieven', + message => 'Ontvang deze nieuwsbrief', }, 'Subscribe to this mailing' => { - message => 'Abonneer op deze nieuwsbrief', + message => 'Ontvang deze nieuwsbrief', + }, + 'Include newsletters' => { + message => 'Selecteerbare nieuwsbrieven', }, }; diff --git a/lib/WebGUI/i18n/English/AssetAspect_Subscriber.pm b/lib/WebGUI/i18n/English/AssetAspect_Subscriber.pm index f330260..cc5b9e5 100644 --- a/lib/WebGUI/i18n/English/AssetAspect_Subscriber.pm +++ b/lib/WebGUI/i18n/English/AssetAspect_Subscriber.pm @@ -3,7 +3,7 @@ package WebGUI::i18n::English::AssetAspect_Subscriber; use strict; our $I18N = { - 'Subscription group' => { + 'Subscription group' => { message => 'Subscription group', }, 'Enable subscription' => { @@ -24,7 +24,7 @@ our $I18N = { 'confirmation email template' => { message => 'Confirmation email template', }, - 'no mutation subject' => { + 'no mutation subject' => { message => 'No mutation email subject', }, 'no mutation template' => { @@ -34,7 +34,6 @@ our $I18N = { message => 'Subscription', }, - 'subscribe' => { message => 'Subscribe', }, @@ -52,17 +51,20 @@ our $I18N = { 'anonnymous not allowed' => { message => 'Anonymous subscription is not allowed. Please log in to (un)subscribe', }, - + 'subscription successful' => { - message => 'You are succesfully subscribed. Back to site', + message => 'You are succesfully subscribed.', }, 'unsubscription successful' => { - message => 'You are succesfully unsubscribed. Back to site', + message => 'You are succesfully unsubscribed.', }, 'wrong code' => { message => 'The verification code you supplied is either unknown, already used or expired. Please try again to (un)subscribe or contact the site administrators.', }, + 'confirm mutation template' => { + message => 'Mutation confirmation template', + }, }; 1; diff --git a/lib/WebGUI/i18n/English/Asset_NewsletterCollection.pm b/lib/WebGUI/i18n/English/Asset_NewsletterCollection.pm index 45d9bcb..ad946b2 100644 --- a/lib/WebGUI/i18n/English/Asset_NewsletterCollection.pm +++ b/lib/WebGUI/i18n/English/Asset_NewsletterCollection.pm @@ -18,7 +18,14 @@ our $I18N = { 'number of recent issues' => { message => 'Number of recent issues', }, - + 'useHoneypot label' => { + message => q|Use honeypot|, + lastUpdated => 0, + }, + 'useHoneypot description' => { + message => q|Use honeypot to verify humanity.|, + lastUpdated => 0, + }, }; 1; diff --git a/lib/WebGUI/i18n/English/MailingManager.pm b/lib/WebGUI/i18n/English/MailingManager.pm index 51798f1..e8aebca 100644 --- a/lib/WebGUI/i18n/English/MailingManager.pm +++ b/lib/WebGUI/i18n/English/MailingManager.pm @@ -26,7 +26,7 @@ our $I18N = { 'bounce score' => { message => 'Bounce score', }, - + 'error' => { message => 'An error occurred', }, @@ -100,6 +100,14 @@ our $I18N = { 'generate mailing' => { message => 'Generate mailing', }, + + 'bounce reason' => { + message => 'Latest bounce reason', + }, + + 'bounce message' => { + message => 'Latest bounce message', + }, }; 1; diff --git a/lib/WebGUI/i18n/English/RegistrationStep_MailingSubscribe.pm b/lib/WebGUI/i18n/English/RegistrationStep_MailingSubscribe.pm index 9b6df53..71534e4 100644 --- a/lib/WebGUI/i18n/English/RegistrationStep_MailingSubscribe.pm +++ b/lib/WebGUI/i18n/English/RegistrationStep_MailingSubscribe.pm @@ -9,6 +9,9 @@ our $I18N = { 'Subscribe to this mailing' => { message => 'Subscribe to this mailing', }, + 'Include newsletters' => { + message => 'Include newsletters', + }, }; 1; diff --git a/sbin/importSpecialState.pl b/sbin/importSpecialState.pl index 91a0158..ff20fb1 100644 --- a/sbin/importSpecialState.pl +++ b/sbin/importSpecialState.pl @@ -1,7 +1,7 @@ #!/usr/bin/env perl $|++; # disable output buffering -our ($webguiRoot, $configFile, $state, $emailFile, $groupId ); +our ($webguiRoot, $configFile, $state, $emailFile, $groupId, $existingUsersGroupId ); BEGIN { $webguiRoot = ".."; @@ -15,12 +15,16 @@ use WebGUI::Session; use WebGUI::User; use WebGUI::User::SpecialState; +# Set default value +$existingUsersGroupId = ''; + # Get parameters here, including $help GetOptions( - 'configFile=s' => \$configFile, - 'groupId=s' => \$groupId, - 'state=s' => \$state, - 'emailFile=s' => \$emailFile, + 'configFile=s' => \$configFile, + 'groupId=s' => \$groupId, + 'existingUsersGroupId=s' => \$existingUsersGroupId, + 'state=s' => \$state, + 'emailFile=s' => \$emailFile, ); my $session = start( $webguiRoot, $configFile ); @@ -40,18 +44,24 @@ while ( my $email = <$fh> ) { my $user = WebGUI::User->newByEmail( $session, $email ); if ( $user ) { print "\tEmail already has account. Skipping.\n"; + if ( $existingUsersGroupId ) { + print "\tAdding user to group $existingUsersGroupId\n"; + $user->addToGroups( [ $existingUsersGroupId ] ); + } + else { + print "\tAdding user to group $groupId\n"; + $user->addToGroups( [ $groupId ] ); + } } else { print "\tEmail has no account, creating special state $state.\n"; $user = WebGUI::User::SpecialState->create( $session ); $user->update( { email => $email } ); $user->addSpecialState( $state ); + print "\tAdding user to group $groupId\n"; + $user->addToGroups( [ $groupId ] ); } - print "\tAdding user to group $groupId\n"; - - $user->addToGroups( [ $groupId ] ); - } print "Done\n\n"; @@ -120,6 +130,22 @@ The WebGUI config file to use. Only the file name needs to be specified, since it will be looked up inside WebGUI's configuration directory. This parameter is required. +=item B<--groupId> + +Add users to this group. If no existingUsersGroupId is given, all users, both new and existing users, are added to this group. If the --existingUsersGroupId is given, new users are added to this group, existing users are added to the existingUsersGroupId. + +=item B<--existingUsersGroupId> + +Add existing users to this group. + +=item B<--state> + +Set the so called specialState for this user. For all users disabeled accounts are created. SpecialState accounts can be transformed into regular accounts using the webgui_registration content handler. The special states are crm or Subscriber, for a user added via the crm or a newsletter subscription respectively. + +=item B<--emailFile> + +A text file with an emailadress on every line. + =item B<--help> Shows a short summary and usage @@ -132,7 +158,7 @@ Shows this document =head1 AUTHOR -Copyright 2001-2009 Plain Black Corporation. +Copyright 2010-2011 United Knowledge B.V. =cut diff --git a/sbin/install_newsletter.pl b/sbin/install_newsletter.pl index 89aa378..0d782bb 100644 --- a/sbin/install_newsletter.pl +++ b/sbin/install_newsletter.pl @@ -12,7 +12,7 @@ use strict; use Pod::Usage; use Getopt::Long; use WebGUI::Session; -use List::MoreUtils qw{ insert_after_string }; +use List::MoreUtils qw{ insert_after_string none }; # Get parameters here, including $help GetOptions( @@ -32,10 +32,75 @@ addTemplateColumnToNewsletterCollection( $session ); addRecentColumnToNewsletterCollection( $session ); renamespaceTemplates( $session ); addSpecialStateTable( $session ); +addListNameColumn( $session ); addRegistrationSteps( $session ); +addConfirmationTemplateColumn( $session ); +addSentToIndex( $session ); +addUseHoneypotColumn( $session ); finish($session); +#------------------------------------------------------------------------------- +sub addConfirmationTemplateColumn { + my $session = shift; + my $db = $session->db; + + print "\tAdding column for mutation confirmation template..."; + + my $hasColumn = $db->quickScalar( 'show columns from assetAspectSubscriber where Field = ?', [ + 'confirmMutationTemplateId', + ] ); + + unless ( $hasColumn ) { + $db->write( + 'alter table assetAspectSubscriber add column confirmMutationTemplateId char(22) binary not null default ?', + [ + 'WUk-wEhGiF8dcEogrJfrfg', + ] + ); + + $db->write( + 'update assetAspectSubscriber set confirmMutationTemplateId=? where confirmMutationTemplateId is null', + [ + 'WUk-wEhGiF8dcEogrJfrfg', + ] + ); + } + + print "Done.\n"; +} + +#---------------------------------------------------------------------------- +sub addSentToIndex { + my $session = shift; + my $db = $session->db; + + print "\tAdding index to column Mailing_email.sentTo..."; + + my @indexes = $db->buildArray('show indexes from Mailing_email where Column_name=?',['sentTo']); + + if ( @indexes == 0 ) { + $db->write('alter table Mailing_email add index(sentTo)'); + } + + print "Done.\n"; +} + +#---------------------------------------------------------------------------- +sub addListNameColumn { + my $session = shift; + my $db = $session->db; + print "\tAdding list name column for subscribers..."; + + my @columns = $db->buildArray( 'desc assetAspectSubscriber' ); + + if ( none { $_ eq 'listName' } @columns ) { + $db->write( 'alter table assetAspectSubscriber add column listName varchar(255)' ); + } + + print "Done.\n"; +} + #---------------------------------------------------------------------------- sub installMailableAspectTable { my $session = shift; @@ -60,21 +125,21 @@ sub installSubscriberAspectTable { $session->db->write(<