First cut at digests

[prev] [thread] [next] [lurker] [Date index for 2004/04/05]

From: Simon Wistow
Subject: First cut at digests
Date: 18:54 on 05 Apr 2004
--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Bit icky but it's a stab

Simon

--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="siesta-digest.patch"

Index: Config.pm.in
===================================================================
--- Config.pm.in	(revision 1496)
+++ Config.pm.in	(working copy)
@@ -1,7 +1,7 @@
 # $Id$
 package Siesta::Config;
 use strict;
-use vars qw( $CONFIG_FILE $ROOT $MESSAGES @STORAGE $ARCHIVE $LOG_PATH $LOG_LEVEL $config );
+use vars qw( $CONFIG_FILE $ROOT $MESSAGES @STORAGE $ARCHIVE $DIGESTS $LOG_PATH $LOG_LEVEL $config );
 use AppConfig qw(:expand :argcount);
 use base 'Exporter';
 our @EXPORT_OK = qw( $config );
@@ -16,18 +16,18 @@
 
 Where to install everything to. Currently this is set to 
 
-	@@ROOT@@
+    @@ROOT@@
 
 =head2 C<$CONFIG_FILE>
 
 Where the config file is currently 
 
-	@@ROOT@@/siesta.conf
+    @@ROOT@@/siesta.conf
 
 This can be overridden when using the command line tools by 
 using 
 
-	-f <new config file>
+    -f <new config file>
 
 
 =head3 CONFIG OPTIONS
@@ -52,6 +52,12 @@
 
 By default - @@ROOT@@/archive/<list name>/
 
+=item digests
+
+Where we save our digest spools
+
+By default = @@ROOT@@/digests/
+
 =item log_path
 
 Where we log things
@@ -104,6 +110,7 @@
                   $config->get('storage_pass')),
     $MESSAGES  = $config->get('messages');
     $ARCHIVE   = $config->get('archive');
+    $DIGESTS   = $config->get('digests');
     $LOG_PATH  = $config->get('log_path');
     $LOG_LEVEL = $config->get('log_level');
 }
@@ -128,6 +135,9 @@
         archive => {
             DEFAULT => '@@ROOT@@/archive',
         },
+        digests => {
+            DEFAULT => '@@ROOT@@/digests',
+        }
         log_path => {
             DEFAULT => '@@ROOT@@/error',
         },
Index: lib/Siesta/Plugin/Digest.pm
===================================================================
--- lib/Siesta/Plugin/Digest.pm	(working copy)
+++ lib/Siesta/Plugin/Digest.pm	(working copy)
@@ -0,0 +1,89 @@
+package Siesta::Plugin::Digest;
+use strict;
+use base 'Siesta::Plugin';
+__PACKAGE__->columns( TEMP => qw( send_this ));
+
+use Email::LocalDelivery;
+use Email::Folder;
+
+sub description { "handle the digest collating and sending" }
+sub personal { 1 }
+
+
+# TODO do this on a time basis?
+
+sub process {
+    my $self = shift;
+    my $mail = shift;
+
+    my $path = $self->pref('path');
+
+    unless ($self->user) {  # first pass                                                         
+        $self->add_to_digest( $mail );
+        my ($count, $digest) = $self->get_digest();
+
+        if ($count >  $self->pref('messages')) { # spool is big enough                                                         
+            $self->send_this($digest);
+
+            # we should probably lock this
+            if (-f $path) {
+                unlink($path) || die "Couldn't unlink '$path'\n";
+            } else { 
+                chdir($path)  || die "Couldn't chdir to '$path'\n";
+                unlink(<*>)   || die "Couldn't unlink '$path/*'\n";
+            }
+        }
+        return; # carry on                                                                       
+    }
+
+    # okay, this user isn't interested in digests, continue with the                             
+    # regular mail                                                                               
+    return unless $self->pref( 'digest' );
+
+    return 1 unless $self->send_this; # the digest isn't ready yet, stop.                        
+    $mail = $self->send_this;
+    return;
+}
+
+# get the number of digests and the body of the digest
+sub get_digest {
+    my $self     = shift;
+    my $count    = 0;
+
+    my $path     = $self->pref('path');
+    my $folder   = Email::Folder->new($self->pref('path')) 
+                    || die "Couldn't open email folder '$path'\n";
+    my @messages = $folder->messages;
+    my $digest   = Siesta->bake('digest', list => $self->list, messages => @messages);
+
+    return ($#messages, $digest);
+}
+
+# spool to disk
+sub add_to_digest {
+    my ($self, $mail) = @_;
+
+    my $path = $self->pref('path');
+    Email::LocalDelivery->deliver( $mail->as_string, $path )
+        or die "storage of digets mail into '$path' failed";
+}
+
+
+sub options {
+    my $self = shift;
+    my $name = $self->list->name;
+    +{
+        path => {
+            description => "where to spool the digest",
+            type        => "string",
+            default     => "$Siesta::Config::DIGEST/$name/",
+        },
+        messages => {
+            description => "how many messages to spool before sending the digest",
+            type        => "number",
+            default     => "20",
+        }        
+    };
+}
+
+
Index: messages/digest
===================================================================
--- messages/digest	(working copy)
+++ messages/digest	(working copy)
@@ -0,0 +1,44 @@
+Send [% list.name %] mailing list submissions to                               
+        [% list.post_address -%]
+
+[%# TODO                                                                                   
+To subscribe or unsubscribe via the World Wide Web, visit                          
+        WEBADDRESS
+or, via email, send a message with subject or body 'help' to                       
+        LISTHELP
+-%] 
+
+You can reach the person managing the list at                                      
+        [% list.owner %]
+                                                                                  
+When replying, please edit your Subject line so it is more specific                
+than "Re: Contents of [% list.name %] digest..."                               
+                                                                                   
+                                                                                   
+Today's Topics:                                                                    
+
+[%- SET count = 0 -%]
+[%- FOREACH message = messages +%]    
+    [%- count = count + 1 -%]
+    [%- count %]. [%- message.header('subject') %] ([% message.header('from') %])
+
+[%- END -%]                                                   
+                                   
+[%- SET count = 1 -%]
+
+[% FOREACH message = messages %]
+
+
+--__--__--                   
+                                                      
+
+Message: [% count %]
+Date: [% message.header('date') %]
+To: [% message.header('to') %]
+Subject: [% message.header('subject') %]
+From: [% message.header('from') %]
+[% IF  message.header('cc') %]Cc: [% message.header('cc') %][% END %]
+
+[% message.body() %]
+[% count = count + 1 %]
+[% END %]

--fUYQa+Pmc3FrFX/N--

Generated at 13:56 on 01 Jul 2004 by mariachi 0.52