Index: openacs-4/packages/mail-tracking/mail-tracking.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/mail-tracking/mail-tracking.info,v diff -u -r1.5 -r1.6 --- openacs-4/packages/mail-tracking/mail-tracking.info 17 Mar 2006 10:06:45 -0000 1.5 +++ openacs-4/packages/mail-tracking/mail-tracking.info 14 May 2006 16:11:18 -0000 1.6 @@ -8,7 +8,7 @@ t tracking - + Nima Mazloumi Mail tracking package. Records all messages send out by acs-mail-lite. 2005-10-24 @@ -18,8 +18,8 @@ 0 - - + + Index: openacs-4/packages/mail-tracking/lib/messages.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/mail-tracking/lib/messages.tcl,v diff -u -r1.27 -r1.28 --- openacs-4/packages/mail-tracking/lib/messages.tcl 5 May 2006 04:50:39 -0000 1.27 +++ openacs-4/packages/mail-tracking/lib/messages.tcl 14 May 2006 16:11:19 -0000 1.28 @@ -107,11 +107,8 @@ pkg_id { label "[_ mail-tracking.Package]" where_clause "package_id = :pkg_id" - } \ - recipient { - label "[_ mail-tracking.Sender]" - } - ] + } + ] if { [apm_package_installed_p organizations] && [exists_and_not_null recipient]} { set org_p [organization::organization_p -party_id $recipient] @@ -125,12 +122,12 @@ if { $org_p && [string equal $emp_mail_f 2] } { set emp_list [contact::util::get_employees -organization_id $recipient] lappend emp_list $recipient - set recipient_where_clause " and recipient_id in ([template::util::tcl_to_sql_list $emp_list])" + set recipient_where_clause " and mlrm.recipient_id in ([template::util::tcl_to_sql_list $emp_list])" } else { - set recipient_where_clause " and recipient_id = :recipient" + set recipient_where_clause " and mlrm.recipient_id = :recipient" } } elseif { [exists_and_not_null recipient] } { - set recipient_where_clause " and recipient_id = :recipient" + set recipient_where_clause " and mlrm.recipient_id = :recipient" } else { set recipient_where_clause "" } @@ -142,7 +139,7 @@ -multirow messages \ -key acs_mail_log.log_id \ -page_size $page_size \ - -page_flush_p 0 \ + -page_flush_p 1 \ -page_query_name "messages_pagination" \ -row_pretty_plural "[_ mail-tracking.messages]" \ -elements { @@ -155,7 +152,7 @@ recipient { label "[_ mail-tracking.Recipient]" display_template { - @messages.receiver_name@ + @messages.recipient;noquote@ } } pkg_id { @@ -187,10 +184,6 @@ label "[_ mail-tracking.Sent_Date]" } } -orderby { - recipient { - orderby recipient_id - label "[_ mail-tracking.Recipient]" - } sender { orderby sender_id label "[_ mail-tracking.Sender]" @@ -216,25 +209,14 @@ } -filters $filters \ -db_multirow -extend { file_ids object_url sender_name receiver_name package_name package_url url_message_id download_files} messages select_messages { } { - set sender_name "" - set receiver_name "" - if { [catch { set sender_name [person::name -person_id $sender_id] } errMsg] } { - # We will try to see if it's a contact and has an email. This will break - # if the contacts package is not installed so this is why we need to put - # it inside a catch - if { [catch { set sender_name [contact::email -party_id $sender_id] } errorMsg] } { - set sender_name "" - } +db_multirow -extend { file_ids object_url sender_name recipient package_name package_url url_message_id download_files} messages select_messages { } { + + set sender_name [party::name -party_id $sender_id] + set reciever_list [list] + db_foreach reciever_id {select recipient_id from acs_mail_log_recipient_map where type ='to' and log_id = :log_id and recipient_id is not null} { + lappend reciever_list [party::name -party_id $recipient_id] } - if { [catch { set receiver_name [person::name -person_id $recipient_id]} errMsg] } { - # We will try to see if it's a contact and has an email. This will break - # if the contacts package is not installed so this is why we need to put - # it inside a catch - if { [catch { set receiver_name [contact::email -party_id $recipient_id] } errorMsg] } { - set receiver_name "" - } - } + set recipient [join $reciever_list "
"] if {[exists_and_not_null package_id]} { set package_name [apm_instance_name_from_id $package_id] Index: openacs-4/packages/mail-tracking/lib/messages.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/mail-tracking/lib/messages.xql,v diff -u -r1.7 -r1.8 --- openacs-4/packages/mail-tracking/lib/messages.xql 17 Mar 2006 10:06:45 -0000 1.7 +++ openacs-4/packages/mail-tracking/lib/messages.xql 14 May 2006 16:11:19 -0000 1.8 @@ -8,7 +8,6 @@ select message_id, sender_id, - recipient_id, package_id, sent_date, body, @@ -17,19 +16,17 @@ log_id from acs_mail_log - where 1=1 - $recipient_where_clause - [template::list::page_where_clause -and -name messages] + where [template::list::page_where_clause -name messages] [template::list::filter_where_clauses -and -name messages] [template::list::orderby_clause -orderby -name messages] - select log_id - from acs_mail_log - where 1=1 + select distinct ml.log_id, sent_date + from acs_mail_log ml, acs_mail_log_recipient_map mlrm + where ml.log_id=mlrm.log_id $recipient_where_clause [template::list::filter_where_clauses -and -name messages] [template::list::orderby_clause -orderby -name messages] Index: openacs-4/packages/mail-tracking/sql/postgresql/mail-tracking-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/mail-tracking/sql/postgresql/mail-tracking-create.sql,v diff -u -r1.6 -r1.7 --- openacs-4/packages/mail-tracking/sql/postgresql/mail-tracking-create.sql 17 Mar 2006 10:06:45 -0000 1.6 +++ openacs-4/packages/mail-tracking/sql/postgresql/mail-tracking-create.sql 14 May 2006 16:11:19 -0000 1.7 @@ -17,32 +17,43 @@ create table acs_mail_log ( - log_id integer + log_id integer primary key constraint acs_mail_log_object_id_fk references acs_objects(object_id), message_id varchar(300), -- object_id of the object that triggered the sending of the email object_id integer constraint acs_mail_log_owner_id_fk references acs_objects(object_id), - recipient_id integer - constraint acs_mail_log_recipient_id_fk - references parties(party_id), sender_id integer constraint acs_mail_log_sender_id_fk references parties(party_id), package_id integer, subject varchar(1024), body text, - -- List of CC E-Mail addresses, seperated by "," as passed in from acs-mail-lite::send prozedures + -- List of CC/BCC E-Mail addresses, seperated by "," as passed in from acs-mail-lite::send prozedures + -- Only used for those emails that do not have a party_id in openacs. cc varchar(4000), + bcc varchar(4000), sent_date timestamp); create index acs_mail_log_object_idx on acs_mail_log(object_id); -create index acs_mail_log_recipient_idx on acs_mail_log(recipient_id); create index acs_mail_log_sender_idx on acs_mail_log(sender_id); +create table acs_mail_log_recipient_map ( + recipient_id integer constraint + acs_mail_log_recipient_id_fk + references parties(party_id), + log_id integer + constraint acs_mail_log_log_id_fk + references acs_mail_log(log_id), + type varchar(30) +); +create index acs_mail_log_recipient_map_log_idx on acs_mail_log_recipient_map(log_id); +create index acs_mail_log_recipient_map_recipient_idx on acs_mail_log_recipient_map(recipient_id); +create index acs_mail_log_um_log_rec_idx on acs_mail_log_recipient_map(log_id,recipient_id,type); + -- create the content type select acs_object_type__create_type ( 'mail_log', -- content_type @@ -57,21 +68,22 @@ NULL -- name_method ); -create or replace function acs_mail_log__new (integer,varchar, integer, integer, integer, varchar, varchar,integer,varchar,integer,integer,varchar) +create or replace function acs_mail_log__new (integer,varchar, integer, integer, varchar, varchar,integer,varchar,integer,integer,varchar,varchar,varchar) returns integer as ' declare p_log_id alias for $1; p_message_id alias for $2; - p_recipient_id alias for $3; - p_sender_id alias for $4; - p_package_id alias for $5; - p_subject alias for $6; - p_body alias for $7; - p_creation_user alias for $8; - p_creation_ip alias for $9; - p_context_id alias for $10; - p_object_id alias for $11; + p_sender_id alias for $3; + p_package_id alias for $4; + p_subject alias for $5; + p_body alias for $6; + p_creation_user alias for $7; + p_creation_ip alias for $8; + p_context_id alias for $9; + p_object_id alias for $10; p_cc alias for $11; + p_bcc alias for $12; + p_to_addr alias for $13; v_log_id acs_mail_log.log_id%TYPE; begin v_log_id := acs_object__new ( @@ -80,9 +92,9 @@ ); insert into acs_mail_log - (log_id, message_id, recipient_id, sender_id, package_id, subject, body, sent_date, object_id, cc) + (log_id, message_id, sender_id, package_id, subject, body, sent_date, object_id, cc, bcc, to_addr) values - (v_log_id, p_message_id, p_recipient_id, p_sender_id, p_package_id, p_subject, p_body, now(), p_object_id, p_cc); + (v_log_id, p_message_id, p_sender_id, p_package_id, p_subject, p_body, now(), p_object_id, p_cc, p_bcc, p_to_addr); return v_log_id; Index: openacs-4/packages/mail-tracking/tcl/mail-tracking-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/mail-tracking/tcl/mail-tracking-callback-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/mail-tracking/tcl/mail-tracking-callback-procs.tcl 17 Mar 2006 10:06:46 -0000 1.4 +++ openacs-4/packages/mail-tracking/tcl/mail-tracking-callback-procs.tcl 14 May 2006 16:11:19 -0000 1.5 @@ -13,32 +13,36 @@ ad_proc -public -callback acs_mail_lite::complex_send -impl mail_tracking { {-package_id:required} {-from_party_id:required} - {-to_party_id:required} + {-to_party_ids ""} + {-cc_party_ids ""} + {-bcc_party_ids ""} + {-to_addr ""} + {-cc_addr ""} + {-bcc_addr ""} {-body ""} {-message_id:required} {-subject ""} {-object_id ""} {-file_ids ""} - {-cc ""} } { create a new entry in the mail tracking table } { - - if {![exists_and_not_null cc]} { - set cc "" - } # We need to put lindex here since the value from # the swithc converts this "element element" to this # "{element element}" - # set file_ids [lindex $file_ids 0] set file_ids [string trim $file_ids "{}"] + set log_id [mail_tracking::new -package_id $package_id \ -sender_id $from_party_id \ - -recipient_id $to_party_id \ + -recipient_ids $to_party_ids \ + -cc_ids $cc_party_ids \ + -bcc_ids $bcc_party_ids \ + -to_addr $to_addr \ + -cc_addr $cc_addr \ + -bcc_addr $bcc_addr \ -body $body \ -message_id $message_id \ -subject $subject \ - -cc $cc \ -object_id $object_id] foreach file_id $file_ids { Index: openacs-4/packages/mail-tracking/tcl/mail-tracking-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/mail-tracking/tcl/mail-tracking-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/mail-tracking/tcl/mail-tracking-procs.tcl 17 Mar 2006 10:06:46 -0000 1.3 +++ openacs-4/packages/mail-tracking/tcl/mail-tracking-procs.tcl 14 May 2006 16:11:19 -0000 1.4 @@ -27,22 +27,39 @@ {-log_id ""} {-package_id:required} {-sender_id:required} - {-recipient_id:required} + {-recipient_ids:required} + {-cc_ids ""} + {-bcc_ids ""} + {-to_addr ""} + {-cc_addr ""} + {-bcc_addr ""} {-body ""} {-message_id:required} {-subject ""} {-object_id ""} {-context_id ""} - {-cc ""} } { Insert new log entry - @param cc CC E-Mail Address as recieved from the send procedures + + @param sender_id party_id of the sender + @param recipient_ids List of party_ids of recipients + @param cc_ids List of party_ids for recipients in the "CC" field + @param bcc_ids List of party_ids for recipients in the "BCC" field + @param to_addr List of email addresses seperated by "," who recieved the email in the "to" field but got no party_id + @param cc_addr List of email addresses seperated by "," who recieved the email in the "cc" field but got no party_id + @param bcc_addr List of email addresses seperated by "," who recieved the email in the "bcc" field but got no party_id + @param body Text of the message + @param message_id Message_id of the email + @param subject Subject of the email + @param object_id Object for which this message was sent + @param context_id Context in which this message was send. } { set creation_ip "127.0.0.1" - return [db_exec_plsql insert_log_entry {select acs_mail_log__new ( + + # First create the message entry + set log_id [db_exec_plsql insert_log_entry {select acs_mail_log__new ( :log_id, :message_id, - :recipient_id, :sender_id, :package_id, :subject, @@ -51,7 +68,24 @@ :creation_ip, :context_id, :object_id, - :cc + :cc_addr, + :bcc_addr, + :to_addr )}] + + # Now add the recipients to the log_id + foreach recipient_id $recipient_ids { + db_dml insert_recipient {insert into acs_mail_log_recipient_map (recipient_id,log_id,type) values (:recipient_id,:log_id,'to')} + } + + foreach recipient_id $cc_ids { + db_dml insert_recipient {insert into acs_mail_log_recipient_map (recipient_id,log_id,type) values (:recipient_id,:log_id,'cc')} + } + + foreach recipient_id $bcc_ids { + db_dml insert_recipient {insert into acs_mail_log_recipient_map (recipient_id,log_id,type) values (:recipient_id,:log_id,'bcc')} + } + + return $log_id } Index: openacs-4/packages/mail-tracking/www/one-message.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/mail-tracking/www/one-message.adp,v diff -u -r1.4 -r1.5 --- openacs-4/packages/mail-tracking/www/one-message.adp 17 Mar 2006 10:06:46 -0000 1.4 +++ openacs-4/packages/mail-tracking/www/one-message.adp 14 May 2006 16:11:19 -0000 1.5 @@ -9,7 +9,8 @@ #mail-tracking.Sender#:@sender;noquote@ #mail-tracking.Recipient#:@recipient;noquote@ -#mail-tracking.CC#:@cc;noquote@ +#mail-tracking.CC#:@cc_string;noquote@ +#mail-tracking.BCC#:@bcc_string;noquote@ #mail-tracking.Subject#:@subject;noquote@ #mail-tracking.Attachments#:@download_files;noquote@ #mail-tracking.MessageID#:@message_id;noquote@ Index: openacs-4/packages/mail-tracking/www/one-message.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/mail-tracking/www/one-message.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/packages/mail-tracking/www/one-message.tcl 17 Mar 2006 10:06:46 -0000 1.7 +++ openacs-4/packages/mail-tracking/www/one-message.tcl 14 May 2006 16:11:19 -0000 1.8 @@ -16,6 +16,8 @@ } } +# We need to figure out a way to detect which contacts package a party_id belongs to +set contacts_package_id [apm_package_id_from_key contacts] set page_title "[_ mail-tracking.One_message]" set context [list] @@ -33,25 +35,53 @@ set cc "" } -if { [catch { set sender [person::name -person_id $sender_id] } errorMsg] } { - # We will try to see if it's a contact and has an email. This will break - # if the contacts package is not installed so this is why we need to put - # it inside a catch - if { [catch { set sender [contact::email -party_id $sender_id] } errorMsg] } { - set sender "" +if {$contacts_package_id} { + set sender "[party::name -party_id $sender_id]" +} else { + set sender [party::name -party_id $sender_id] +} + +set reciever_list [list] +db_foreach reciever_id {select recipient_id from acs_mail_log_recipient_map where type ='to' and log_id = :log_id and recipient_id is not null} { + if {$contacts_package_id} { + lappend reciever_list "[party::name -party_id $recipient_id]" + } else { + lappend reciever_list "[party::name -party_id $recipient_id]" } } +if {![string eq "" $to_addr]} { + lappend reciever_list $to_addr +} +set recipient [join $reciever_list ","] -if { [catch { set recipient [person::name -person_id $recipient_id] } errMsg] } { - # We will try to see if it's a contact and has an email. This will break - # if the contacts package is not installed so this is why we need to put - # it inside a catch - set recipient "" - if { [catch { set recipient [contact::email -party_id $recipient_id] } errorMsg] } { - set recipient "" +# Now the CC users +set reciever_list [list] +db_foreach reciever_id {select recipient_id from acs_mail_log_recipient_map where type ='cc' and log_id = :log_id and recipient_id is not null} { + if {$contacts_package_id} { + lappend reciever_list "[party::name -party_id $recipient_id]" + } else { + lappend reciever_list "[party::name -party_id $recipient_id]" } } +if {![string eq "" $cc]} { + lappend reciever_list $cc +} +set cc_string [join $reciever_list ","] +# And the BCC ones +set reciever_list [list] +db_foreach reciever_id {select recipient_id from acs_mail_log_recipient_map where type ='bcc' and log_id = :log_id and recipient_id is not null} { + if {$contacts_package_id} { + lappend reciever_list "[party::name -party_id $recipient_id]" + } else { + lappend reciever_list "[party::name -party_id $recipient_id]" + } +} +if {![string eq "" $bcc]} { + lappend reciever_list $bcc +} +set bcc_string [join $reciever_list ","] + # We get the related files set files [list]