Index: openacs-4/packages/notifications/sql/oracle/notifications-replies-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/sql/oracle/notifications-replies-create.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/notifications/sql/oracle/notifications-replies-create.sql 3 Jun 2002 08:13:18 -0000 1.1
@@ -0,0 +1,44 @@
+
+--
+-- The Notifications Package
+--
+-- ben@openforce.net
+-- Copyright OpenForce, 2002.
+--
+-- GNU GPL v2
+--
+
+--
+-- The queue of messages coming back
+--
+
+create table notification_replies (
+ reply_id integer not null
+ constraint notif_repl_repl_id_fk references acs_objects(object_id)
+ constraint notif_repl_repl_id_pk primary key,
+ object_id integer not null
+ constraint notif_repl_obj_id_fk references acs_objects(object_id),
+ type_id integer not null
+ constraint notif_repl_type_id_fk references notification_types(type_id),
+ from_user integer not null
+ constraint notif_repl_from_fk references users(user_id),
+ subject varchar(100),
+ content clob,
+ reply_date date
+);
+
+
+declare
+begin
+ acs_object_type.create_type (
+ supertype => 'acs_object',
+ object_type => 'notification_reply',
+ pretty_name => 'Notification Reply',
+ pretty_plural => 'Notification Replies',
+ table_name => 'notification_replies',
+ id_column => 'reply_id',
+ package_name => 'notification_reply'
+ );
+end;
+/
+show errors
Index: openacs-4/packages/notifications/sql/oracle/notifications-replies-package-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/sql/oracle/notifications-replies-package-create.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/notifications/sql/oracle/notifications-replies-package-create.sql 3 Jun 2002 08:13:18 -0000 1.1
@@ -0,0 +1,83 @@
+
+--
+-- The Notifications Package
+--
+-- ben@openforce.net
+-- Copyright OpenForce, 2002.
+--
+-- GNU GPL v2
+--
+
+
+-- The Notification Replies Package
+
+create or replace package notification_reply
+as
+ function new (
+ reply_id in notification_replies.reply_id%TYPE default null,
+ object_id in notification_replies.object_id%TYPE,
+ type_id in notification_replies.type_id%TYPE,
+ from_user in notification_replies.from_user%TYPE,
+ subject in notification_replies.subject%TYPE,
+ content in varchar,
+ reply_date in notification_replies.reply_date%TYPE default sysdate,
+ creation_date in acs_objects.creation_date%TYPE default sysdate,
+ creation_user in acs_objects.creation_user%TYPE default null,
+ creation_ip in acs_objects.creation_ip%TYPE default null,
+ context_id in acs_objects.context_id%TYPE default null
+ ) return notification_replies.reply_id%TYPE;
+
+ procedure delete (
+ reply_id in notification_replies.reply_id%TYPE
+ );
+end notification_reply;
+/
+show errors
+
+
+create or replace package body notification_reply
+as
+ function new (
+ reply_id in notification_replies.reply_id%TYPE default null,
+ object_id in notification_replies.object_id%TYPE,
+ type_id in notification_replies.type_id%TYPE,
+ from_user in notification_replies.from_user%TYPE,
+ subject in notification_replies.subject%TYPE,
+ content in varchar,
+ reply_date in notification_replies.reply_date%TYPE default sysdate,
+ creation_date in acs_objects.creation_date%TYPE default sysdate,
+ creation_user in acs_objects.creation_user%TYPE default null,
+ creation_ip in acs_objects.creation_ip%TYPE default null,
+ context_id in acs_objects.context_id%TYPE default null
+ ) return notification_replies.reply_id%TYPE
+ is
+ v_reply_id acs_objects.object_id%TYPE;
+ begin
+ v_reply_id:= acs_object.new (
+ object_id => reply_id,
+ object_type => 'notification_reply',
+ creation_date => creation_date,
+ creation_user => creation_user,
+ creation_ip => creation_ip,
+ context_id => context_id
+ );
+
+ insert into notification_replies
+ (reply_id, object_id, type_id, from_user, subject, content, reply_date)
+ values
+ (v_reply_id, object_id, type_id, from_user, subject, content, reply_date);
+
+ return v_reply_id;
+ end new;
+
+ procedure delete (
+ reply_id in notification_replies.reply_id%TYPE
+ )
+ is
+ begin
+ acs_object.delete(object_id => reply_id);
+ end delete;
+
+end notification_reply;
+/
+show errors
Index: openacs-4/packages/notifications/tcl/notification-reply-procs-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-reply-procs-oracle.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/notifications/tcl/notification-reply-procs-oracle.xql 3 Jun 2002 08:13:18 -0000 1.1
@@ -0,0 +1,13 @@
+
+
+ oracle8.1.6
+
+
+
+declare begin
+ notification_reply.delete(reply_id => :reply_id);
+end;
+
+
+
+
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
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/notifications/tcl/notification-reply-procs.tcl 3 Jun 2002 08:13:18 -0000 1.1
@@ -0,0 +1,64 @@
+ad_library {
+
+ Notification Replies
+
+ @creation-date 2002-06-02
+ @author Ben Adida
+ @cvs-id $Id: notification-reply-procs.tcl,v 1.1 2002/06/03 08:13:18 ben Exp $
+
+}
+
+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}
+ {-type_id:required}
+ {-from_user:required}
+ {-subject:required}
+ {-content:required}
+ {-reply_date ""}
+ } {
+ create a new reply
+ } {
+ set extra_vars [ns_set create]
+ oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list {reply_id object_id type_id from_user subject content reply_date}
+
+ set reply_id [package_instantiate_object -extra_vars $extra_vars notification_reply]
+
+ return $reply_id
+ }
+
+ ad_proc -public delete {
+ {-reply_id:required}
+ } {
+ delete a reply
+ } {
+ db_exec_plsql delete_reply {}
+ }
+
+}
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
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/notifications/tcl/reply-sweep-procs.tcl 3 Jun 2002 08:13:18 -0000 1.1
@@ -0,0 +1,138 @@
+ad_library {
+
+ Notification Reply Sweeps
+
+ @creation-date 2002-06-02
+ @author Ben Adida
+ @cvs-id $Id: reply-sweep-procs.tcl,v 1.1 2002/06/03 08:13:18 ben Exp $
+
+}
+
+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}
+ } {
+ Scans qmail incoming email queue and queues up messages
+ using acs-mail.
+
+ @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]
+ }
+
+ 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]
+
+ # 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]
+
+ # 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
+ }
+
+ set object_id [lindex $to_stuff 0]
+ set type_id [lindex $to_stuff 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"
+ }
+ }
+
+ 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.1 -r1.2
--- openacs-4/packages/notifications/tcl/sweep-procs-oracle.xql 29 May 2002 05:12:01 -0000 1.1
+++ openacs-4/packages/notifications/tcl/sweep-procs-oracle.xql 3 Jun 2002 08:13:18 -0000 1.2
@@ -17,7 +17,7 @@
-select notifications.notification_id, notif_subject, notif_text, notif_html, notification_requests.user_id
+select notifications.notification_id, notif_subject, notif_text, notif_html, notification_requests.user_id, acs_object.name(object_id) as object_name
from notifications, notification_requests, notification_user_map
where notifications.type_id = notification_requests.type_id
and interval_id = :interval_id
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.3 -r1.4
--- openacs-4/packages/notifications/tcl/sweep-procs.tcl 3 Jun 2002 05:55:01 -0000 1.3
+++ openacs-4/packages/notifications/tcl/sweep-procs.tcl 3 Jun 2002 08:13:18 -0000 1.4
@@ -63,7 +63,7 @@
db_transaction {
# Send it
send_one -user_id [ns_set get $notif user_id] \
- -subject "\[Notification\] [ns_set get $notif notif_subject]" \
+ -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] \
-delivery_method_id [ns_set get $notif delivery_method_id]