Index: openacs-4/packages/notifications/sql/oracle/notifications-core-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/sql/oracle/notifications-core-create.sql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/notifications/sql/oracle/notifications-core-create.sql 4 Jun 2002 22:53:50 -0000 1.4 +++ openacs-4/packages/notifications/sql/oracle/notifications-core-create.sql 25 Jun 2002 18:58:06 -0000 1.5 @@ -33,6 +33,9 @@ references acs_objects (object_id) constraint notif_deliv_meth_pk primary key, + sc_impl_id integer not null + constraint notif_deliv_meth_impl_id_fk + references acs_sc_impls(impl_id), short_name varchar(100) constraint notif_deliv_short_name_nn not null @@ -43,10 +46,13 @@ ); create table notification_types ( - type_id constraint notif_type_type_id_fk + type_id constraint notif_type_type_id_fk references acs_objects (object_id) constraint notif_type_type_id_pk primary key, + sc_impl_id integer not null + constraint notif_deliv_meth_impl_id_fk + references acs_sc_impls(impl_id), short_name varchar(100) constraint notif_type_short_name_nn not null Index: openacs-4/packages/notifications/sql/oracle/notifications-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/sql/oracle/notifications-create.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/notifications/sql/oracle/notifications-create.sql 4 Jun 2002 22:53:50 -0000 1.3 +++ openacs-4/packages/notifications/sql/oracle/notifications-create.sql 25 Jun 2002 18:58:06 -0000 1.4 @@ -17,3 +17,4 @@ -- @ notifications-delivery-sc-create.sql @ notifications-init.sql +@ email-sc-impl-create.sql Index: openacs-4/packages/notifications/sql/oracle/notifications-init.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/sql/oracle/notifications-init.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/notifications/sql/oracle/notifications-init.sql 4 Jun 2002 22:53:50 -0000 1.2 +++ openacs-4/packages/notifications/sql/oracle/notifications-init.sql 25 Jun 2002 18:58:06 -0000 1.3 @@ -35,12 +35,14 @@ creation_ip => null ); - v_foo:= notification_delivery_method.new( - short_name => 'email', - pretty_name => 'Email', - creation_user => null, - creation_ip => null - ); +-- This now done by email-sc-impl-create.sql +-- +-- v_foo:= notification_delivery_method.new( +-- short_name => 'email', +-- pretty_name => 'Email', +-- creation_user => null, +-- creation_ip => null +-- ); end; / Index: openacs-4/packages/notifications/sql/oracle/notifications-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/sql/oracle/notifications-package-create.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/notifications/sql/oracle/notifications-package-create.sql 29 May 2002 21:47:18 -0000 1.3 +++ openacs-4/packages/notifications/sql/oracle/notifications-package-create.sql 25 Jun 2002 18:58:06 -0000 1.4 @@ -82,6 +82,7 @@ as function new ( delivery_method_id in notification_delivery_methods.delivery_method_id%TYPE default null, + sc_impl_id in notification_delivery_methods.sc_impl_id%TYPE, short_name in notification_delivery_methods.short_name%TYPE, pretty_name in notification_delivery_methods.pretty_name%TYPE, creation_date in acs_objects.creation_date%TYPE default sysdate, @@ -104,6 +105,7 @@ as function new ( delivery_method_id in notification_delivery_methods.delivery_method_id%TYPE default null, + sc_impl_id in notification_delivery_methods.sc_impl_id%TYPE, short_name in notification_delivery_methods.short_name%TYPE, pretty_name in notification_delivery_methods.pretty_name%TYPE, creation_date in acs_objects.creation_date%TYPE default sysdate, @@ -124,8 +126,8 @@ ); insert into notification_delivery_methods - (delivery_method_id, short_name, pretty_name) values - (v_delivery_method_id, short_name, pretty_name); + (delivery_method_id, sc_impl_id, short_name, pretty_name) values + (v_delivery_method_id, sc_impl_id, short_name, pretty_name); return v_delivery_method_id; end new; @@ -149,6 +151,7 @@ as function new ( type_id in notification_types.type_id%TYPE default null, + sc_impl_id in notification_types.sc_impl_id%TYPE, short_name in notification_types.short_name%TYPE, pretty_name in notification_types.pretty_name%TYPE, description in notification_types.description%TYPE, @@ -172,6 +175,7 @@ as function new ( type_id in notification_types.type_id%TYPE default null, + sc_impl_id in notification_types.sc_impl_id%TYPE, short_name in notification_types.short_name%TYPE, pretty_name in notification_types.pretty_name%TYPE, description in notification_types.description%TYPE, @@ -193,8 +197,8 @@ ); insert into notification_types - (type_id, short_name, pretty_name, description) values - (v_type_id, short_name, pretty_name, description); + (type_id, sc_impl_id, short_name, pretty_name, description) values + (v_type_id, sc_impl_id, short_name, pretty_name, description); return v_type_id; end new; Index: openacs-4/packages/notifications/sql/postgresql/notifications-core-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/sql/postgresql/notifications-core-create.sql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/notifications/sql/postgresql/notifications-core-create.sql 24 Jun 2002 22:12:54 -0000 1.4 +++ openacs-4/packages/notifications/sql/postgresql/notifications-core-create.sql 25 Jun 2002 18:58:06 -0000 1.5 @@ -35,6 +35,9 @@ references acs_objects (object_id) constraint notif_deliv_meth_pk primary key, + sc_impl_id integer not null + constraint notif_deliv_meth_impl_id_fk + references acs_sc_impls(impl_id), short_name varchar(100) constraint notif_deliv_short_name_nn not null @@ -50,7 +53,10 @@ references acs_objects (object_id) constraint notif_type_type_id_pk primary key, - short_name varchar(100) + sc_impl_id integer not null + constraint notif_deliv_meth_impl_id_fk + references acs_sc_impls(impl_id), + short_name varchar(100) constraint notif_type_short_name_nn not null constraint notif_type_short_name_un Index: openacs-4/packages/notifications/sql/postgresql/notifications-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/sql/postgresql/notifications-package-create.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/notifications/sql/postgresql/notifications-package-create.sql 24 Jun 2002 22:12:54 -0000 1.2 +++ openacs-4/packages/notifications/sql/postgresql/notifications-package-create.sql 25 Jun 2002 18:58:06 -0000 1.3 @@ -85,50 +85,83 @@ end; ' language 'plpgsql'; -select define_function_args ('notification_delivery_method__delete','delivery_method_id'); +create function notification_delivery_method__new (integer, integer, varchar, varchar, timestamp, integer, varchar, integer) +returns integer as ' +DECLARE + p_delivery_method_id alias for $1; + p_sc_impl_id alias for $2; + p_short_name alias for $3; + p_pretty_name alias for $4; + p_creation_date alias for $5; + p_creation_user alias for $6; + p_creation_ip alias for $7; + p_context_id alias for $8; + v_delivery_method_id integer; +BEGIN + v_delivery_method_id:= acs_object__new ( + p_delivery_method_id, + ''notification_delivery_method'', + p_creation_date, + p_creation_user, + p_creation_ip, + p_context_id); + + insert into notification_delivery_methods + (delivery_method_id, sc_impl_id, short_name, pretty_name) values + (v_delivery_method_id, p_sc_impl_id, p_short_name, p_pretty_name); + + return v_delivery_method_id; +END; +' language 'plpgsql'; + create function notification_delivery_method__delete(integer) returns integer as ' -declare - p_delivery_method_id alias for $1; -begin - perform acs_object__delete(p_delivery_method_id); - return 0; -end; +DECLARE + p_delivery_method_id alias for $1; +BEGIN + perform acs_object__delete(p_delivery_method_id); + return 0; +END; ' language 'plpgsql'; -select define_function_args ('notification_type__new','type_id,short_name,pretty_name,description,creation_date,creation_user,creation_ip,context_id'); -create function notification_type__new (integer,varchar,varchar,varchar,timestamp,integer,varchar,integer) -returns integer as ' -declare - p_type_id alias for $1; - p_short_name alias for $2; - p_pretty_name alias for $3; - p_description alias for $4; - p_creation_date alias for $5; - p_creation_user alias for $6; - p_creation_ip alias for $7; - p_context_id alias for $8; - v_type_id integer; -begin - v_type_id := acs_object__new( - p_type_id, - ''notification_type'', - p_creation_date, - p_creation_user, - p_creation_ip, - p_context_id - ); +-- Notification Types Package +select define_function_args ('notification_type__new','type_id,sc_impl_id,short_name,pretty_name,description,creation_date,creation_user,creation_ip,context_id'); - insert - into notification_types - (type_id, short_name, pretty_name, description) - values - (v_type_id, p_short_name, p_pretty_name, p_description); +select define_function_args ('notification_type__delete','type_id'); - return v_type_id; -end; + +-- implementation + +create function notification_type__new (integer,integer,varchar,varchar,varchar,timestamp,integer,varchar,integer) +returns integer as ' +DECLARE + p_type_id alias for $1; + p_sc_impl_id alias for $2; + p_short_name alias for $3; + p_pretty_name alias for $4; + p_description alias for $5; + p_creation_date alias for $6; + p_creation_user alias for $7; + p_creation_ip alias for $8; + p_context_id alias for $9; + v_type_id integer; +BEGIN + v_type_id:= acs_object__new ( + p_type_id, + ''notification_type'', + p_creation_date, + p_creation_user, + p_creation_ip, + p_context_id); + + insert into notification_types + (type_id, sc_impl_id, short_name, pretty_name, description) values + (v_type_id, p_sc_impl_id, p_short_name, p_pretty_name, p_description); + + return v_type_id; +END; ' language 'plpgsql'; select define_function_args ('notification_type__delete','type_id'); @@ -147,38 +180,36 @@ create function notification_request__new (integer,varchar,integer,integer,integer,integer,varchar,timestamp,integer,varchar,integer) returns integer as ' -declare - p_request_id alias for $1; - p_object_type alias for $2; - p_type_id alias for $3; - p_user_id alias for $4; - p_object_id alias for $5; - p_interval_id alias for $6; - p_delivery_method_id alias for $7; - p_format alias for $8; - p_creation_date alias for $9; - p_creation_user alias for $10; - p_creation_ip alias for $11; - p_context_id alias for $12; - v_request_id integer; -begin - v_request_id := acs_object__new( - p_request_id, - p_object_type, - p_creation_date, - p_creation_user, - p_creation_ip, - p_context_id - ); +DECLARE + p_request_id alias for $1; + p_object_type alias for $2; + p_type_id alias for $3; + p_user_id alias for $4; + p_object_id alias for $5; + p_interval_id alias for $6; + p_delivery_method_id alias for $7; + p_format alias for $8; + p_creation_date alias for $9; + p_creation_user alias for $10; + p_creation_ip alias for $11; + p_context_id alias for $12; + v_request_id integer; +BEGIN + v_request_id:= acs_object__new ( + p_request_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + p_context_id); - insert - into notification_requests - (request_id, type_id, user_id, object_id, interval_id, delivery_method_id, format) - values - (v_request_id, p_type_id, p_user_id, p_object_id, p_interval_id, p_delivery_method_id, p_format); + insert into notification_requests + (request_id, type_id, user_id, object_id, interval_id, delivery_method_id, format) values + (v_request_id, p_type_id, p_user_id, p_object_id, p_interval_id, p_delivery_method_id, p_format); - return v_request_id; -end; + return v_request_id; + +END; ' language 'plpgsql'; select define_function_args ('notification_request__delete','request_id'); Index: openacs-4/packages/notifications/tcl/delivery-method-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/delivery-method-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/notifications/tcl/delivery-method-procs.tcl 24 May 2002 20:42:42 -0000 1.1 +++ openacs-4/packages/notifications/tcl/delivery-method-procs.tcl 25 Jun 2002 18:58:06 -0000 1.2 @@ -10,14 +10,47 @@ namespace eval notification::delivery { - ad_proc -public deliver { + ad_proc -private get_impl_key { {-delivery_method_id:required} - {-to:required} + } { + return [db_string select_impl_key {}] + } + + ad_proc -public send { + {-delivery_method_id:required} + {-reply_object_id ""} + {-notification_type_id:required} + {-to_user_id:required} + {-subject:required} {-content:required} } { do the delivery of certain content to a particular user } { - # FIXME: implement + # Get the implementation key + set impl_key [get_impl_key -delivery_method_id $delivery_method_id] + + # Prepare the arguments + set args [list $to_user_id $reply_object_id $notification_type_id $subject $content] + + # Make the generic call + return [acs_sc_call NotificationDeliveryMethod Send $args $impl_key] } + ad_proc -public scan_replies { + {-delivery_method_id:required} + } { + scan for replies + } { + # Get the implementation key + set impl_key [get_impl_key -delivery_method_id $delivery_method_id] + + # Prepare the arguments + set args [list $to_user_id $reply_object_id $subject $content] + + ns_log Notice "NOTIF-DELIV-METHOD: about to call acs_sc on $impl_key" + + # Make the generic call + return [acs_sc_call NotificationDeliveryMethod ScanReplies $args $impl_key] + } + } Index: openacs-4/packages/notifications/tcl/notification-reply-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-reply-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/notifications/tcl/notification-reply-procs.tcl 3 Jun 2002 08:13:18 -0000 1.1 +++ openacs-4/packages/notifications/tcl/notification-reply-procs.tcl 25 Jun 2002 18:58:06 -0000 1.2 @@ -10,30 +10,6 @@ namespace eval notification::reply { - ad_proc -public reply_address_domain {} { - return "openforce.net" - } - - ad_proc -public reply_address { - {-object_id:required} - {-type_id:required} - } { - return "notification-$object_id-$type_id@[reply_address_domain]" - } - - ad_proc -public parse_reply_address { - {-reply_address:required} - } { - This takes a reply address, checks it for consistency, and returns a list of object_id and type_id - } { - # Check the format and extract type_id and object_id at the same time - if {![regexp {^notification-([0-9]*)-([0-9]*)@} $reply_address all object_id type_id]} { - return "" - } - - return [list $object_id $type_id] - } - ad_proc -public new { {-reply_id ""} {-object_id:required} Index: openacs-4/packages/notifications/tcl/notification-type-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-type-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/notifications/tcl/notification-type-procs.tcl 24 May 2002 20:42:42 -0000 1.1 +++ openacs-4/packages/notifications/tcl/notification-type-procs.tcl 25 Jun 2002 18:58:06 -0000 1.2 @@ -12,14 +12,15 @@ ad_proc -public new { {-type_id ""} + {-sc_impl_id:required} {-short_name:required} {-pretty_name:required} {-description ""} } { create a new notification type } { set extra_vars [ns_set create] - oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list {type_id short_name pretty_name description} + oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list {type_id sc_impl_id short_name pretty_name description} set type_id [package_instantiate_object -extra_vars $extra_vars notification_type] @@ -81,5 +82,16 @@ # perform the delete if necessary db_dml delete_delivery_method_map {} } + + ad_proc -public process_reply { + {-type_id:required} + {-reply_id:required} + } { + # Get the impl key + set impl_key [get_impl_key -type_id $type_id] + + # Dispatch to the notification type specific reply processing + acs_sc_call NotificationType ProcessReply [list $reply_id] $impl_key + } } Index: openacs-4/packages/notifications/tcl/reply-sweep-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/reply-sweep-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/notifications/tcl/reply-sweep-procs.tcl 3 Jun 2002 08:13:18 -0000 1.1 +++ openacs-4/packages/notifications/tcl/reply-sweep-procs.tcl 25 Jun 2002 18:58:06 -0000 1.2 @@ -9,130 +9,39 @@ } namespace eval notification::reply::sweep { - - ad_proc -public qmail_mail_queue_dir {} { - return "" - } - ad_proc -public load_mail_queue {} { - return [load_qmail_mail_queue -queue_dir [qmail_mail_queue_dir]] - } - - ad_proc -public load_qmail_mail_queue { - {-queue_dir:required} + ad_proc -public scan_all_replies {} { + # Go through all the delivery methods and do the right thing } { - Scans qmail incoming email queue and queues up messages - using acs-mail. + ns_log Notice "NOTIF- scan_all_replies starting" - @Author dan.wickstrom@openforce.net, ben@openforce - @creation-date 22 Sept, 2001 - - @param queue_dir The location of the qmail mail queue in - the file-system. - } { - if [catch {set messages [glob "$queue_dir/new/*"]} ] { - ns_log Notice "queue dir = [glob $queue_dir/new/*]" - return [list] + # Load up the delivery methods + set delivery_method_ids [db_list select_deliv_methods {}] + + # Loop and scan replies on each one + foreach delivery_method_id $delivery_method_ids { + ns_log Notice "NOTIF- scan_all_replies deliv method $delivery_method_id" + notification::delivery::scan_replies -delivery_method_id $delivery_method_id } + } - set mail_link_ids [list] - set new_messages_p 0 - - foreach msg $messages { - ns_log Notice "opening file: $msg" - if [catch {set f [open $msg r]}] { - continue - } - set file [read $f] - close $f - set file [split $file "\n"] - - set new_messages 1 - set end_of_headers_p 0 - set i 0 - set line [lindex $file $i] - set headers [list] - - # walk through the headers and extract each one - while ![empty_string_p $line] { - set next_line [lindex $file [expr $i + 1]] - if {[regexp {^[ ]*$} $next_line match] && $i > 0} { - set end_of_headers_p 1 - } - if {[regexp {^([^:]+):[ ]+(.+)$} $line match name value]} { - # join headers that span more than one line (e.g. Received) - if { ![regexp {^([^:]+):[ ]+(.+)$} $next_line match] && !$end_of_headers_p} { - append line $next_line - incr i - } - lappend headers [string tolower $name] $value - - if {$end_of_headers_p} { - incr i - break - } - } else { - # The headers and the body are delimited by a null line as specified by RFC822 - if {[regexp {^[ ]*$} $line match]} { - incr i - break - } - } - incr i - set line [lindex $file $i] - } - set body "\n[join [lrange $file $i end] "\n"]" - - # okay now we have a list of headers and the body, let's - # put it into notifications stuff - array set email_headers $headers - - if [catch {set from $email_headers(from)}] { - set from "" - } - if [catch {set to $email_headers(to)}] { - set to "" - } - - # Find the from user - set from_user [cc_lookup_email_user $from] + ad_proc -public process_all_replies {} { + # Go through the replies in the DB and dispatch correctly + } { + ns_log Notice "NOTIF- process_all_replies starting" - # We don't accept empty users for now - if {[empty_string_p $from_user]} { - ns_log Notice "NOTIF-INCOMING-EMAIL: no user $from" - continue - } - - set to_stuff [notification::reply::parse_reply_address -reply_address $to] + # Load up the replies + set replies [db_list_of_lists select_replies {}] - # We don't accept a bad incoming email address - if {[empty_string_p $to_stuff]} { - ns_log Notice "NOTIF-INCOMING-EMAIL: bad to address $to" - continue - } + # Loop through and transactionally process each one + foreach reply $replies { + ns_log Notice "NOTIF- one reply $reply_id of type $type_id" - set object_id [lindex $to_stuff 0] - set type_id [lindex $to_stuff 1] + set reply_id [lindex $reply 0] + set type_id [lindex $reply 1] - db_transaction { - set reply_id [notification::reply::new \ - -object_id $object_id \ - -type_id $type_id \ - -from_user $from_user \ - -subject $email_headers(subject) \ - -content $body] - - catch {ns_unlink $msg} - } on_error { - ns_log Error "Error inserting incoming email into the queue" - } + notification::type::process_reply -type_id $type_id -reply_id $reply_id } - - return $list_of_reply_ids } - ad_proc -public process_db_queue {} { - - } - } Index: openacs-4/packages/notifications/tcl/sweep-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/Attic/sweep-procs-oracle.xql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/notifications/tcl/sweep-procs-oracle.xql 25 Jun 2002 16:27:03 -0000 1.4 +++ openacs-4/packages/notifications/tcl/sweep-procs-oracle.xql 25 Jun 2002 18:58:06 -0000 1.5 @@ -25,6 +25,7 @@ notif_text, notif_html, notification_requests.user_id, + type_id, acs_object.name(notifications.object_id) as object_name from notifications, notification_requests, Index: openacs-4/packages/notifications/tcl/sweep-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/sweep-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/notifications/tcl/sweep-procs.tcl 3 Jun 2002 22:27:00 -0000 1.5 +++ openacs-4/packages/notifications/tcl/sweep-procs.tcl 25 Jun 2002 18:58:06 -0000 1.6 @@ -15,26 +15,6 @@ } { } - ad_proc -public send_one { - {-user_id:required} - {-subject:required} - {-content:required} - {-response_id:required} - {-delivery_method_id:required} - } { - hack currently send only by email - # FIXME - } { - # Get email - set email [cc_email_from_party $user_id] - - acs_mail_lite::send \ - -to_addr $email \ - -from_addr "notifications@openforce.biz" \ - -subject $subject \ - -body $content - } - ad_proc -public cleanup_notifications {} { Clean up the notifications that are done } { @@ -64,10 +44,11 @@ if {!$batched_p} { db_transaction { # Send it - send_one -user_id [ns_set get $notif user_id] \ + notification::delivery::send -to_user_id [ns_set get $notif user_id] \ + -notification_type_id [ns_set get $notif type_id] \ -subject "\[[ad_system_name] - [ns_set get $notif object_name]\] [ns_set get $notif notif_subject]" \ -content [ns_set get $notif notif_text] \ - -response_id [ns_set get $notif response_id] \ + -reply_object_id [ns_set get $notif response_id] \ -delivery_method_id [ns_set get $notif delivery_method_id] # Markt it as sent @@ -77,7 +58,7 @@ } } else { # It's batched, we're not handling this one yet - ns_log Notice "Notifcations: Batched Request not handled" + ns_log Notice "Notifications: Batched Request not handled" } } }