bulkmail_sweep_bounce_queue

one of the documented procedures in this installation of the ACS
Usage:
bulkmail_sweep_bounce_queue
What it does:
Sweeps the bounce queue, handling bounced messages.
Defined in: /web/philip/tcl/bulkmail-utils.tcl

Source code:


    
    ns_log Notice "Sweeping bounce queue"

    set threshold [bulkmail_bounce_threshold]
    set bounce_dir [bulkmail_bounce_dir]
    set file_pattern "$bounce_dir/*"

    ns_log Notice "$bounce_dir\n$file_pattern"

    set db [ns_db gethandle]

    set n_bounces 0
    foreach file [glob -nocomplain $file_pattern] {
	ns_log Notice "Current file: $file"
	# file_name is file - bounce_dir + a slash (consumed by the zero-index)
	set file_name [string range $file [expr [string length $bounce_dir] + 1] end]
	set key_code [string toupper [lindex [split $file_name "@"] 0]]

	ns_log Notice "key_code: $key_code"
	set details [bulkmail_decode_key_code $key_code]

	ns_log Notice "file_name: $file_name\nDetails: $details"
	
	# See if we have garbage
	if { [llength $details] < 3 } {
	    # We can trash this file; it shouldn't be here
	    ns_unlink -nocomplain $file
	    continue
	}

	set bulkmail_id [lindex $details 0]
	set user_id [lindex $details 1]
	if {[catch {
	    ns_db dml $db "insert into bulkmail_bounces (bulkmail_id, user_id) values ($bulkmail_id, $user_id)"
	} errmsg] } {
	    ns_log Notice "Error on bulkmail_bounce insert.  key_code: $key_code\ndetails: $details\n$errmsg"
	} else {
	    ns_unlink -nocomplain "$file"
	    incr n_bounces

	}
    }

    if { $n_bounces > 0 } {
	set rows_affected [ns_ora exec_plsql $db "declare
	counter number;
	uid number;
	cursor BOUNCING_IDS is
	select user_id from bulkmail_bounces where active_p = 't' group by user_id having count(user_id) > 2 ;
	one_row BOUNCING_IDS%ROWTYPE;
	begin 
	--:counter := counter;
	counter := 0;
	for one_row in BOUNCING_IDS
	loop
	uid := one_row.user_id;
	update users set email_bouncing_p = 't' where user_id = uid;
	update bulkmail_bounces set active_p = 'f' where user_id = uid;
	commit;
	counter := counter + 1;
	end loop;
	:counter := counter;
	end;
	"]
	ns_log Notice "bulkmail bounce sweeper found $rows_affected bouncing ids."
    }

    ns_db releasehandle $db 
    ns_log Notice "Done sweeping bounce queue"


philg@mit.edu