Index: openacs-4/packages/acs-tcl/tcl/html-email-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/html-email-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-tcl/tcl/html-email-procs.tcl 23 Jun 2003 19:44:31 -0000 1.1.2.1 @@ -0,0 +1,159 @@ +ad_library { + Contains procs to send HTML email outside of the context of + ACS Mail package. + + @author Doug Harris (dharris@worldbank.org) + @author Janine Sisk (jsisk@mit.edu) + @creation-date 25 Feb 2002 + @cvs-id $Id: html-email-procs.tcl,v 1.1.2.1 2003/06/23 19:44:31 janines Exp $ +} + +ad_proc build_mime_message { + text_body + html_body + {charset "iso-8859-1"} +} { + Composes multipart/alternative email containing plain text + and html versions of the message, parses out the headers we need, + constructs an array and returns it to the caller. + + This proc is based on ad_html_sendmail, written by Doug Harris at + the World Bank. + + Comment from the original code: The message + is encoded with iso-8859-x charset (all mail readers I've tested seem + to be unable to handle utf-8 encoding). A future version of this proc + should probably support an alternative charset argument or switch. +} { + + # this is always called from a scheduled proc + set r_dir [acs_root_dir]/packages/acs-tcl/tcl + source $r_dir/base64.tcl + source $r_dir/md5.tcl + source $r_dir/mime.tcl + + package require mime + + # since mime tries to treat =xx as a hex ascii code, replace any + # equals signs with "=3d" (mime encoding of equals sign) + regsub -all "=" $text_body "=3d" text_body + regsub -all "=" $html_body "=3d" html_body_for_non_base64 + + # convert text to charset + set encoding [ns_encodingforcharset $charset] + if {[lsearch [encoding names] $encoding] != -1} { + set html_body [encoding convertto $encoding $html_body] + set text_body [encoding convertto $encoding $text_body] + } else { + ns_log error "ad_html_sendmail: unknown charset passed in ($charset)" + } + + # build body + set base64_html_part [mime::initialize -canonical text/html \ + -param [list charset $charset] \ + -encoding base64 \ + -string $html_body] + set html_part [mime::initialize -canonical text/html \ + -param [list charset $charset] \ + -encoding quoted-printable \ + -string $html_body_for_non_base64] + set text_part [mime::initialize -canonical text/plain \ + -param [list charset $charset] \ + -encoding quoted-printable \ + -string $text_body] + #It works better without 'charset'! + # set multi_part [mime::initialize -canonical multipart/alternative \ + # -param [list charset $charset] \ + # -parts [list $text_part $html_part]] + set multi_part [mime::initialize -canonical multipart/alternative \ + -parts [list $text_part $base64_html_part $html_part]] + + # this gives us a complete mime message, minus the headers because + # we don't pass any in. This code is designed to send a fully-formed + # message out through an SMTP socket, but we're not doing that so we + # have to hijack the process a bit. + set mime_body [mime::buildmessage $multi_part] + + # the first three lines of the message are special; we need to grab + # the info, add it to the message headers, and discard the lines + set lines [split $mime_body \n] + set message_data [ns_set new] + + # get mime version + regexp {MIME-Version: (.*)} [lindex $lines 0] junk mime_version + ns_set put $message_data MIME-Version $mime_version + # the content id + regexp {Content-ID: (.*)} [lindex $lines 1] junk content_id + ns_set put $message_data Content-ID $content_id + # and the content type and boundary + regexp {Content-Type: (.*)} [lindex $lines 2] junk content_type + set content_type "$content_type\n[lindex $lines 3]" + ns_set put $message_data Content-Type $content_type + + # the rest of the lines form the message body. We strip off the last + # line, which is the last boundary, because ns_sendmail seems to be + # adding another one on for us. + ns_set put $message_data body [join [lrange $lines 4 [expr [llength $lines] - 3]] \n] + + return $message_data +} + + +ad_proc parse_incoming_email { + message +} { + Takes an incoming message and splits it into parts. The main goal + of this proc is to return something that can be stuffed into the + database somewhere, such as a forum message. Since we aggressively + filter HTML, the HTML tags are stripped out of the returned content. + + The message may have only plain text, plain text and HTML, or plain + text and something else (Apple Mail uses text/enhanced, for example). + To make our lives simpler we support only text/html as a special case; + in all other cases the plain text is returned. +} { + # look for the files we need. If they aren't there, we can't do anything + # and will just return the message as-is (cringe) + set source_dir [acs_root_dir]/packages/acs-tcl/tcl + if { ![file exists $source_dir/base64.tcl] || + ![file exists $source_dir/md5.tcl] || + ![file exists $source_dir/mime.tcl] } { + return $message + } + + source $source_dir/base64.tcl + source $source_dir/md5.tcl + source $source_dir/mime.tcl + package require mime + + set mime [mime::initialize -string $message] + set content [mime::getproperty $mime content] + + if { [string first "multipart" $content] != -1 } { + set parts [mime::getproperty $mime parts] + } else { + set parts [list $mime] + } + + foreach part $parts { + switch [mime::getproperty $part content] { + "text/plain" { + set plain [mime::getbody $part] + } + "text/html" { + set html [mime::getbody $part] + } + } + } + + if { [info exists html] } { + set body [ad_html_to_text $html] + } elseif { [info exists plain] } { + set body $plain + } else { + set body $message + } + + mime::finalize $mime -subordinates all + return $body +} Index: openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-create.sql,v diff -u -N -r1.1.1.1.2.1 -r1.1.1.1.2.2 --- openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-create.sql 11 Jun 2003 10:36:28 -0000 1.1.1.1.2.1 +++ openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-create.sql 23 Jun 2003 19:44:30 -0000 1.1.1.1.2.2 @@ -18,12 +18,6 @@ default sysdate constraint bm_messages_send_date_nn not null, - sent_p char(1) - default 'f' - constraint bm_messages_sent_p_ck - check (sent_p in ('t', 'f')) - constraint bm_messages_sent_p_nn - not null, from_addr varchar(4000) constraint bm_messages_from_addr_nn not null, @@ -35,6 +29,12 @@ not null, query clob constraint bm_messages_query_nn + not null, + status varchar2(100) + default 'pending' + constraint bm_messages_status_ck + check (status in ('pending', 'sent')) + constraint bm_messages_status_nn not null ); Index: openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-package-create.sql,v diff -u -N -r1.1.1.1 -r1.1.1.1.2.1 --- openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-package-create.sql 15 May 2002 22:07:52 -0000 1.1.1.1 +++ openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-package-create.sql 23 Jun 2003 19:44:30 -0000 1.1.1.1.2.1 @@ -13,7 +13,7 @@ package_id in bulk_mail_messages.package_id%TYPE, send_date in varchar default null, date_format in varchar default 'YYYY MM DD HH24 MI SS', - sent_p in bulk_mail_messages.sent_p%TYPE default 'f', + status in bulk_mail_messages.status%TYPE default 'pending', from_addr in bulk_mail_messages.from_addr%TYPE, subject in bulk_mail_messages.subject%TYPE default null, reply_to in bulk_mail_messages.reply_to%TYPE default null, @@ -42,7 +42,7 @@ package_id in bulk_mail_messages.package_id%TYPE, send_date in varchar default null, date_format in varchar default 'YYYY MM DD HH24 MI SS', - sent_p in bulk_mail_messages.sent_p%TYPE default 'f', + status in bulk_mail_messages.status%TYPE default 'pending', from_addr in bulk_mail_messages.from_addr%TYPE, subject in bulk_mail_messages.subject%TYPE default null, reply_to in bulk_mail_messages.reply_to%TYPE default null, @@ -78,12 +78,12 @@ insert into bulk_mail_messages (bulk_mail_id, package_id, - send_date, sent_p, + send_date, status, from_addr, subject, reply_to, extra_headers, message, query) values (v_bulk_mail_id, bulk_mail.new.package_id, - to_date(bulk_mail.new.send_date, bulk_mail.new.date_format), bulk_mail.new.sent_p, + to_date(bulk_mail.new.send_date, bulk_mail.new.date_format), bulk_mail.new.status, bulk_mail.new.from_addr, bulk_mail.new.subject, bulk_mail.new.reply_to, bulk_mail.new.extra_headers, bulk_mail.new.message, bulk_mail.new.query); Index: openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-views-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-views-create.sql,v diff -u -N -r1.1.1.1 -r1.1.1.1.2.1 --- openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-views-create.sql 15 May 2002 22:07:52 -0000 1.1.1.1 +++ openacs-4/packages/bulk-mail/sql/oracle/bulk-mail-views-create.sql 23 Jun 2003 19:44:30 -0000 1.1.1.1.2.1 @@ -9,10 +9,11 @@ as select bulk_mail_messages.* from bulk_mail_messages - where sent_p = 'f'; + where status = 'pending'; create or replace view bulk_mail_messages_sent as select bulk_mail_messages.* from bulk_mail_messages - where sent_p = 't'; + where status = 'sent'; + Index: openacs-4/packages/bulk-mail/sql/oracle/upgrade/upgrade-0.3-0.4.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/sql/oracle/upgrade/upgrade-0.3-0.4.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/bulk-mail/sql/oracle/upgrade/upgrade-0.3-0.4.sql 23 Jun 2003 19:44:30 -0000 1.1.2.1 @@ -0,0 +1,42 @@ +-- Changes to support HTML in bulk mail (work originally done by Mohan for +-- Sloanspace). + +-- this should be a 'not null' column, but you can't do that when the +-- table's not empty +alter table bulk_mail_messages +add status varchar2(100); + +-- mark all the messages that are already sent as such +update bulk_mail_messages +set status = 'sent' +where sent_p = 't'; + +alter table bulk_mail_messages +drop column sent_p; + +-- now we can do this without having all the previously sent messages get +-- suddenly marked as pending and sent again (don't ask me how I know this :) +alter table bulk_mail_messages +modify status default 'pending'; + +alter table bulk_mail_messages +add constraint bm_messages_status_ck +check (status in ('pending', 'sent')); + +-- recreate the views +create or replace view bulk_mail_messages_unsent +as + select bulk_mail_messages.* + from bulk_mail_messages + where status = 'pending'; + +create or replace view bulk_mail_messages_sent +as + select bulk_mail_messages.* + from bulk_mail_messages + where status = 'sent'; + + +-- lastly, we seem to have to do this because the package is invalidated by +-- the above steps +@@bulk-mail-package-create Index: openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-create.sql,v diff -u -N -r1.2.2.2 -r1.2.2.3 --- openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-create.sql 12 Jun 2003 15:37:41 -0000 1.2.2.2 +++ openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-create.sql 23 Jun 2003 19:44:31 -0000 1.2.2.3 @@ -35,7 +35,12 @@ not null, query text constraint bm_messages_query_nn + not null, + status varchar(100) + default 'pending' + constraint bm_messages_status_nn not null + ); -- create a new object type Index: openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-package-create.sql,v diff -u -N -r1.2.2.3 -r1.2.2.4 --- openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-package-create.sql 2 Mar 2003 22:40:01 -0000 1.2.2.3 +++ openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-package-create.sql 23 Jun 2003 19:44:31 -0000 1.2.2.4 @@ -5,7 +5,7 @@ -- @version $Id$ -- -select define_function_args('bulk_mail__new','bulk_mail_id,package_id,send_date,date_format,sent_p;f,from_addr,subject,reply_to,extra_headers,message,query,creation_date;now(),creation_user,creation_ip,context_id'); +select define_function_args('bulk_mail__new','bulk_mail_id,package_id,send_date,date_format,status;pending,from_addr,subject,reply_to,extra_headers,message,query,creation_date;now(),creation_user,creation_ip,context_id'); create function bulk_mail__new (integer, integer, varchar, varchar, varchar, varchar, varchar, varchar, varchar, text, varchar, timestamptz, integer, varchar, integer) returns integer as ' @@ -14,7 +14,7 @@ bulk_mail__new__package_id alias for $2; bulk_mail__new__send_date alias for $3; -- default to null bulk_mail__new__date_format alias for $4; -- default to "YYYY MM DD HH24 MI SS" - bulk_mail__new__sent_p alias for $5; -- default to "f" + bulk_mail__new__status alias for $5; -- default to "pending" bulk_mail__new__from_addr alias for $6; bulk_mail__new__subject alias for $7; -- default to null bulk_mail__new__reply_to alias for $8; -- default to null @@ -28,7 +28,7 @@ v_bulk_mail_id integer; v_send_date varchar(4000); v_date_format varchar(4000); - v_sent_p boolean; + v_status varchar(100); begin v_bulk_mail_id := acs_object__new( @@ -51,20 +51,20 @@ into v_send_date; end if; - v_sent_p := bulk_mail__new__sent_p; - if v_sent_p is null then - v_sent_p := ''f''; + v_status := bulk_mail__new__status; + if v_status is null then + v_status := ''pending''; end if; insert into bulk_mail_messages (bulk_mail_id, package_id, - send_date, sent_p, + send_date, status, from_addr, subject, reply_to, extra_headers, message, query) values (v_bulk_mail_id, bulk_mail__new__package_id, - to_date(v_send_date, v_date_format), v_sent_p, + to_date(v_send_date, v_date_format), v_status, bulk_mail__new__from_addr, bulk_mail__new__subject, bulk_mail__new__reply_to, bulk_mail__new__extra_headers, bulk_mail__new__message, bulk_mail__new__query); Index: openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-views-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-views-create.sql,v diff -u -N -r1.1.1.1 -r1.1.1.1.2.1 --- openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-views-create.sql 15 May 2002 22:07:52 -0000 1.1.1.1 +++ openacs-4/packages/bulk-mail/sql/postgresql/bulk-mail-views-create.sql 23 Jun 2003 19:44:31 -0000 1.1.1.1.2.1 @@ -9,10 +9,10 @@ as select bulk_mail_messages.* from bulk_mail_messages - where sent_p = 'f'; + where status = 'pending'; create view bulk_mail_messages_sent as select bulk_mail_messages.* from bulk_mail_messages - where sent_p = 't'; + where status = 'sent'; Index: openacs-4/packages/bulk-mail/sql/postgresql/upgrade/upgrade-0.3-0.4.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/sql/postgresql/upgrade/Attic/upgrade-0.3-0.4.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/bulk-mail/sql/postgresql/upgrade/upgrade-0.3-0.4.sql 23 Jun 2003 19:44:31 -0000 1.1.2.1 @@ -0,0 +1,38 @@ +-- Changes to support HTML in bulk mail (work originally done by Mohan for +-- Sloanspace). + +-- this should be a 'not null' column, but you can't do that when the +-- table's not empty +alter table bulk_mail_messages +add status varchar(100); + +-- mark all the messages that are already sent as such +update bulk_mail_messages +set status = 'sent' +where sent_p = 't'; + +alter table bulk_mail_messages +drop column sent_p; + +-- now we can do this without having all the previously sent messages get +-- suddenly marked as pending and sent again (don't ask me how I know this :) +alter table bulk_mail_messages +modify status default 'pending'; + +-- recreate the views +create or replace view bulk_mail_messages_unsent +as + select bulk_mail_messages.* + from bulk_mail_messages + where status = 'pending'; + +create or replace view bulk_mail_messages_sent +as + select bulk_mail_messages.* + from bulk_mail_messages + where status = 'sent'; + + +-- lastly, we seem to have to do this because the package is invalidated by +-- the above steps +@@bulk-mail-package-create Index: openacs-4/packages/bulk-mail/tcl/bulk-mail-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/tcl/bulk-mail-procs-oracle.xql,v diff -u -N -r1.1.1.1.2.1 -r1.1.1.1.2.2 --- openacs-4/packages/bulk-mail/tcl/bulk-mail-procs-oracle.xql 18 Dec 2002 20:06:39 -0000 1.1.1.1.2.1 +++ openacs-4/packages/bulk-mail/tcl/bulk-mail-procs-oracle.xql 23 Jun 2003 19:44:30 -0000 1.1.1.1.2.2 @@ -22,8 +22,9 @@ select bulk_mail_messages.* from bulk_mail_messages - where bulk_mail_messages.sent_p = 'f' + where bulk_mail_messages.status = 'pending' and bulk_mail_messages.send_date <= sysdate + for update Index: openacs-4/packages/bulk-mail/tcl/bulk-mail-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/tcl/bulk-mail-procs-postgresql.xql,v diff -u -N -r1.1.1.1.2.1 -r1.1.1.1.2.2 --- openacs-4/packages/bulk-mail/tcl/bulk-mail-procs-postgresql.xql 18 Dec 2002 20:06:39 -0000 1.1.1.1.2.1 +++ openacs-4/packages/bulk-mail/tcl/bulk-mail-procs-postgresql.xql 23 Jun 2003 19:44:30 -0000 1.1.1.1.2.2 @@ -21,8 +21,9 @@ select bulk_mail_messages.* from bulk_mail_messages - where bulk_mail_messages.sent_p = 'f' + where bulk_mail_messages.status = 'pending' and bulk_mail_messages.send_date <= now() + for update Index: openacs-4/packages/bulk-mail/tcl/bulk-mail-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/tcl/bulk-mail-procs.tcl,v diff -u -N -r1.3.2.1 -r1.3.2.2 --- openacs-4/packages/bulk-mail/tcl/bulk-mail-procs.tcl 17 Dec 2002 18:03:23 -0000 1.3.2.1 +++ openacs-4/packages/bulk-mail/tcl/bulk-mail-procs.tcl 23 Jun 2003 19:44:30 -0000 1.3.2.2 @@ -1,10 +1,10 @@ ad_library { - bulk mail procedure library + bulk_mail procedure library @author yon (yon@openforce.net) @creation-date 2002-05-07 - @cvs-id $Id$ + @version $Id$ } @@ -83,6 +83,7 @@ {-reply_to ""} {-extra_headers ""} {-message:required} + {-message_type ""} {-query:required} } { create a new bulk_mail message @@ -106,6 +107,7 @@ @param message the body of the email, can be overridden by a value selected in the query. will be interpolated with values from the query. + @param message_type - "text" or "html" (added by mohan) @param query a query that must select the email address to send to as 'email' and can select any other values that will be interpolated into the subject and message of the bulk_mail for @@ -154,8 +156,9 @@ ns_set put $extra_vars from_addr $from_addr ns_set put $extra_vars subject $subject ns_set put $extra_vars reply_to $reply_to - ns_set put $extra_vars extra_headers $extra_headers + ns_set put $extra_vars extra_headers "$extra_headers bulk-mail-type $message_type" ns_set put $extra_vars message $message + ns_set put $extra_vars message_type $message_type ns_set put $extra_vars query $query ns_set put $extra_vars context_id $package_id @@ -170,15 +173,17 @@ ns_log notice "bulk_mail::sweep starting" ## JCD: this transaction is misguided since any code - ## errors in any procs below would cause the messages + ## errors in any procs below would cause the messages ## already sent to be marked unsent. Also, it seems to - ## cause locking problems on oracle + ## cause locking problems on oracle ## (per Caroline Meeks ## http://openacs.org/bugtracker/openacs/bug?bug_number=93 #db_transaction { - foreach bulk_mail [db_list_of_ns_sets select_bulk_mails_to_send {}] { + #Although the message may change for each recipiant, it usually doesn't. We check by looking to see if message_old = the current messag. This is inicialized here for each bulk_mail. + set message_old "" + foreach recipient [db_list_of_ns_sets select_bulk_mail_recipients [ns_set get $bulk_mail query]] { # create a list of key, value pairs that will be used to @@ -224,18 +229,52 @@ set message [ns_set get $recipient message] } + # mohan's hack to fix the passing of message type for the + # mail. + # Comment: I have to ask Caroline or Andrew if itis ok to + # change bulk-mail datamodel to accomodate message_type. + + set extra_headers [util_list_to_ns_set [ns_set get $bulk_mail extra_headers]] + set message_type [ns_set get $extra_headers bulk-mail-type] + + # don't need this anymore and don't want to send it along + ns_set delkey $extra_headers bulk-mail-type + # interpolate the key, value pairs (as described above) # into the message body set message [interpolate -values $pairs -text $message] - # send the message reliably - acs_mail_lite::send \ - -to_addr [ns_set get $recipient email] \ - -from_addr $from_addr \ - -subject $subject \ - -body $message \ - -extraheaders [util_list_to_ns_set [ns_set get $bulk_mail extra_headers]] + if {$message_type == "html"} { + if {[string compare $message_old $message] != 0} { + # If this message is different then the last loop + # we set up the html and text messages. Note that + # ad_html_text_convert can get quite expensive, + # if you start sending different long html + # messages created by microsoft word to each of + # over 100 users, expect performance problems. + # the from to html closes any open tags. + set message_html [ad_html_text_convert -from html -to html $message] + # some mailers are chopping off the last few characters. + append message_html " " + set message_text [ad_html_text_convert -from html -to text $message] + set message_old $message + } + + set message_data [build_mime_message $message_text $message_html] + ns_set put $extra_headers MIME-Version [ns_set get $message_data MIME-Version] + ns_set put $extra_headers Content-ID [ns_set get $message_data Content-ID] + ns_set put $extra_headers Content-Type [ns_set get $message_data Content-Type] + set message [ns_set get $message_data body] + } + + # both html and plain messages can now be sent the same way + acs_mail_lite::send \ + -to_addr [ns_set get $recipient email] \ + -from_addr $from_addr \ + -subject $subject \ + -body $message \ + -extraheaders $extra_headers } # mark the bulk_mail as sent so that we don't process it again Index: openacs-4/packages/bulk-mail/tcl/bulk-mail-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/tcl/bulk-mail-procs.xql,v diff -u -N -r1.1.1.1 -r1.1.1.1.2.1 --- openacs-4/packages/bulk-mail/tcl/bulk-mail-procs.xql 15 May 2002 22:07:52 -0000 1.1.1.1 +++ openacs-4/packages/bulk-mail/tcl/bulk-mail-procs.xql 23 Jun 2003 19:44:30 -0000 1.1.1.1.2.1 @@ -12,7 +12,7 @@ update bulk_mail_messages - set sent_p = 't' + set status = 'sent' where bulk_mail_id = :bulk_mail_id Index: openacs-4/packages/bulk-mail/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/www/index.tcl,v diff -u -N -r1.7 -r1.7.2.1 --- openacs-4/packages/bulk-mail/www/index.tcl 10 Sep 2002 22:22:30 -0000 1.7 +++ openacs-4/packages/bulk-mail/www/index.tcl 23 Jun 2003 19:44:30 -0000 1.7.2.1 @@ -23,7 +23,7 @@ {send_date {Send Date} {bulk_mail_messages.send_date $order} {[util_AnsiDatetoPrettyDate $send_date]}} {from_addr From {bulk_mail_messages.from_addr $order} {$from_addr}} {subject Subject {bulk_mail_messages.subject $order} {$subject}} - {sent_p {Sent?} {bulk_mail_messages.sent_p $order} {[ad_decode $sent_p t Yes No]}} + {status {Sent?} {bulk_mail_messages.status $order} {[ad_decode $status sent Yes No]}} } set sql " Index: openacs-4/packages/bulk-mail/www/one.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/www/one.adp,v diff -u -N -r1.6 -r1.6.2.1 --- openacs-4/packages/bulk-mail/www/one.adp 6 Sep 2002 21:50:25 -0000 1.6 +++ openacs-4/packages/bulk-mail/www/one.adp 23 Jun 2003 19:44:30 -0000 1.6.2.1 @@ -33,6 +33,6 @@ Sent? - YesNo + YesNo Index: openacs-4/packages/bulk-mail/www/one.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bulk-mail/www/one.xql,v diff -u -N -r1.1.1.1 -r1.1.1.1.2.1 --- openacs-4/packages/bulk-mail/www/one.xql 15 May 2002 22:07:52 -0000 1.1.1.1 +++ openacs-4/packages/bulk-mail/www/one.xql 23 Jun 2003 19:44:30 -0000 1.1.1.1.2.1 @@ -6,7 +6,7 @@ select bulk_mail_messages.bulk_mail_id, to_char(bulk_mail_messages.send_date, 'Mon DD YYYY HH24:MI') as send_date, - bulk_mail_messages.sent_p, + bulk_mail_messages.status, bulk_mail_messages.from_addr, bulk_mail_messages.subject, bulk_mail_messages.reply_to, Index: openacs-4/packages/notifications/tcl/notification-email-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-email-procs.tcl,v diff -u -N -r1.9.2.5 -r1.9.2.6 --- openacs-4/packages/notifications/tcl/notification-email-procs.tcl 12 Jun 2003 13:34:52 -0000 1.9.2.5 +++ openacs-4/packages/notifications/tcl/notification-email-procs.tcl 23 Jun 2003 19:46:42 -0000 1.9.2.6 @@ -81,44 +81,28 @@ } ad_proc -public send { - from_user_id to_user_id reply_object_id notification_type_id subject content } { - Send the actual email. - - @param from_user_id The user_id of the user that the email should be sent as. Leave empty for the standard mailer from address. + Send the actual email } { # Get email set email [cc_email_from_party $to_user_id] - append content "\nGetting too much email? Manage your notifications at: [manage_notifications_url]" - + # This should disable most auto-replies. set extra_headers [ns_set new] - - if { ![empty_string_p $from_user_id] && [db_0or1row get_person {}]} { - set from_email "\"$first_names $last_name\" <[cc_email_from_party $from_user_id]>" - - # Set the Reply-To and Mail-Followup-To addresses to the - # address of the notifications handler. - set reply_to [reply_address -object_id $reply_object_id -type_id $notification_type_id] - ns_set put $extra_headers Reply-To $reply_to - ns_set put $extra_headers Mail-Followup-To $reply_to - } else { - set from_email [reply_address -object_id $reply_object_id -type_id $notification_type_id] - } - ns_set put $extra_headers Precedence list + append content "\nGetting too much email? Manage your notifications at: [manage_notifications_url]" + acs_mail_lite::send \ -to_addr $email \ - -from_addr $from_email \ + -from_addr [reply_address -object_id $reply_object_id -type_id $notification_type_id] \ -subject $subject \ - -body $content \ - -extraheaders $extra_headers + -body $content } ad_proc -private load_qmail_mail_queue { @@ -149,9 +133,9 @@ if [catch {set f [open $msg r]}] { continue } - set file [read $f] + set orig_file [read $f] close $f - set file [split $file "\n"] + set file [split $orig_file "\n"] set new_messages 1 set end_of_headers_p 0 @@ -160,35 +144,58 @@ set headers [list] # walk through the headers and extract each one + set is_auto_reply_p 0 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 } + set multiline_header_p 0 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 + set multiline_header_p 1 + } else { + # we only want messages a person typed in themselves - nothing + # from any sort of auto-responder. + if { [string compare -nocase $name "Auto-Submitted"] == 0 } { set is_auto_reply_p 1 + break + } else { + lappend headers [string tolower $name] $value } - lappend headers [string tolower $name] $value + } if {$end_of_headers_p} { - incr i - break + 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 + break } } incr i - set line [lindex $file $i] + if { $multiline_header_p } { + append line [lindex $file $i] + } else { + set line [lindex $file $i] + } } - set body "\n[join [lrange $file $i end] "\n"]" + # a break above just exited the while loop; now we need to skip + # the rest of the foreach as well + if { $is_auto_reply_p } { + ns_log Notice "NOTIF-INCOMING-EMAIL: message contains Auto-Submitted header, skipping" + if {[catch {ns_unlink $msg} errmsg]} { + ns_log Notice "NOTIF-INCOMING-EMAIL: couldn't remove message $msg: $errmsg" + } + continue + } + + set body [parse_incoming_email $orig_file] + # okay now we have a list of headers and the body, let's # put it into notifications stuff array set email_headers $headers @@ -210,7 +217,7 @@ if {[empty_string_p $from_user]} { ns_log Notice "NOTIF-INCOMING-EMAIL: no user $from" if {[catch {ns_unlink $msg} errmsg]} { - ns_log Notice "NOTIF-INCOMING-EMAIL: couldn't remove message" + ns_log Notice "NOTIF-INCOMING-EMAIL: couldn't remove message $msg: $errmsg" } continue } @@ -221,7 +228,7 @@ if {[empty_string_p $to_stuff]} { ns_log Notice "NOTIF-INCOMING-EMAIL: bad to address $to" if {[catch {ns_unlink $msg} errmsg]} { - ns_log Notice "NOTIF-INCOMING-EMAIL: couldn't remove message" + ns_log Notice "NOTIF-INCOMING-EMAIL: couldn't remove message $msg: $errmsg" } continue }