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 @@