Commit 67a35bd0 authored by Frank Bergmann's avatar Frank Bergmann

- modified member-notify to handle attachments

parent ba836940
Pipeline #77 failed with stages
......@@ -164,7 +164,7 @@ create table acs_mail_gc_objects (
-- Mail bodies
create table acs_mail_bodies (
body_id integer
body_id integer
constraint acs_mail_bodies_body_id_pk
primary key
constraint acs_mail_bodies_body_id_fk
......@@ -177,7 +177,7 @@ create table acs_mail_bodies (
constraint acs_mail_bodies_body_from_fk
references parties on delete set null,
body_date timestamptz,
header_message_id varchar(1000)
header_message_id varchar(1000)
constraint acs_mail_bodies_h_m_id_un
unique
constraint acs_mail_bodies_h_m_id_nn
......@@ -233,7 +233,7 @@ create table acs_mail_multipart_parts (
constraint acs_mail_mp_parts_mp_id_fk
references acs_mail_multiparts on delete cascade,
mime_filename varchar(1000),
mime_disposition varchar(1000),
mime_disposition varchar(1000),
sequence_number integer,
content_item_id integer
constraint acs_mail_mp_parts_c_itm_id_fk
......@@ -248,12 +248,12 @@ create index acs_mail_mpp_cr_item_id_idx ON acs_mail_multipart_parts(content_ite
-- Mail Links
create table acs_mail_links (
mail_link_id integer
mail_link_id integer
constraint acs_mail_links_ml_id_pk
primary key
constraint acs_mail_links_ml_id_fk
references acs_objects on delete cascade,
body_id integer
body_id integer
constraint acs_mail_links_body_id_nn
not null
constraint acs_mail_links_body_id_fk
......
......@@ -140,12 +140,12 @@ where r.revision_id = $revision_id and
<querytext>
select acs_mail_gc_object__new (
:object_id, -- gc_object_id
:object_id, -- gc_object_id
'acs_mail_gc_object', -- object_type
now(), -- creation_date
:creation_user, -- creation_user
:creation_ip, -- creation_ip
null -- context_id
now(), -- creation_date
:creation_user, -- creation_user
:creation_ip, -- creation_ip
null -- context_id
);
</querytext>
......@@ -156,21 +156,21 @@ select acs_mail_gc_object__new (
<querytext>
select acs_mail_body__new (
:body_id, -- body_id
:body_id, -- body_id
:body_reply_to, -- body_reply_to
:body_from, -- body_from
:body_date, -- body_date
:header_message_id, -- header_message_id
:header_message_id, -- header_message_id
:header_reply_to, -- header_reply_to
:header_subject, -- header_subject
:header_subject, -- header_subject
:header_from, -- header_from
:header_to, -- header_to
:content_item_id, -- content_item_id
'acs_mail_body', -- object_type
now(), -- creation_date
now() ::date, -- creation_date
:creation_user, -- creation_user
:creation_ip, -- creation_ip
null -- context_id
null -- context_id
);
</querytext>
......
......@@ -198,147 +198,142 @@ ad_proc -private acs_mail_encode_content {
ns_log Debug "acs-mail: encode: starting $content_item_id"
# What sort of content do we have?
if ![acs_mail_multipart_p $content_item_id] {
ns_log Debug "acs-mail: encode: one part $content_item_id"
ns_log Debug "acs-mail: encode: one part $content_item_id"
# Easy as pie.
# Let's get the data.
# vinodk: first get the latest revision
set revision_id [db_exec_plsql get_latest_revision "
# vinodk: first get the latest revision
set revision_id [db_exec_plsql get_latest_revision "
begin
return content_item__get_latest_revision ( :content_item_id );
end;"
]
set storage_type [db_string get_storage_type "
select storage_type from cr_items
where item_id = :content_item_id
"]
if [db_0or1row acs_mail_body_to_mime_get_content_simple {
select content, mime_type as v_content_type
from cr_revisions
where revision_id = :revision_id
}] {
if [string equal $storage_type text] {
ns_log Debug "acs-mail: encode: one part hit $content_item_id"
# vinodk: no need for this, since we're checking
# storage_type
#
# We win! Hopefully. Check if there are 8bit characters/data.
# HT NL CR SP-~ The full range of ASCII with spaces but no
# control characters.
#if ![regexp "\[^\u0009\u000A\u000D\u0020-\u007E\]" $content] {
# ns_log Debug "acs-mail: encode: good code $content_item_id"
# # We're still okay. Use it!
return [list $v_content_type $content]
#}
#ns_log "Notice" "acs-mail: encode: bad code $content_item_id"
} else {
# this content is in the file system or a blob
ns_log Debug "acs-mail: encode: binary content $content_item_id"
if [string equal $storage_type file] {
ns_log Debug "acs-mail: encode: file $content_item_id"
set encoded_content [acs_mail_uuencode_file [cr_fs_path]$content]
} else {
ns_log Debug "acs-mail: encode: lob $content_item_id"
# Blob. Now we need to decide if this is binary
# so we can uuencode it if necessary.
# We'll use the mime type to decide
if { [string first "text" $v_content_type] == 0 } {
ns_log Debug "acs-mail: encode: plain content"
set encoded_content "$content"
} else {
# binary content - copy the blob to temp file
# that we will then uuencode
set file [ns_tmpnam]
db_blob_get_file copy_blob_to_file "
select r.content, i.storage_type
from cr_revisions r, cr_items i
where r.revision_id = $revision_id and
r.item_id = i.item_id " -file $file
ns_log Debug "acs-mail: encode: binary content"
set encoded_content [acs_mail_uuencode_file $file]
}
}
return [list $v_content_type $encoded_content]
}
}
} else {
# Harder. Oops.
ns_log Debug "acs-mail: encode: multipart $content_item_id"
set boundary "=-=-="
set contents {}
# Get the component pieces
set multipart_list [db_list_of_lists acs_mail_body_to_mime_get_contents {
select mime_filename, mime_disposition, content_item_id as ci_id
from acs_mail_multipart_parts
where multipart_id = :content_item_id
order by sequence_number
}
]
]
set storage_type [db_string get_storage_type "
select storage_type
from cr_items
where item_id = :content_item_id
"]
if ![empty_string_p $multipart_list] {
foreach multipart_item $multipart_list {
set mime_filename [lindex $multipart_item 0]
set mime_disposition [lindex $multipart_item 1]
set ci_id [lindex $multipart_item 2]
if {[string equal "" $mime_disposition]} {
if {![string equal "" $mime_filename]} {
set mime_disposition "attachment; filename=$mime_filename"
} else {
set mime_disposition "inline"
}
} else {
if {![string equal "" $mime_filename]} {
set mime_disposition \
"$mime_disposition; filename=$mime_filename"
}
}
set content [acs_mail_encode_content $ci_id]
while {[regexp -- "--$boundary--" $content]} {
set boundary "=$boundary"
}
lappend contents [list $mime_disposition $content]
}
if [db_0or1row acs_mail_body_to_mime_get_content_simple {
select content, mime_type as v_content_type
from cr_revisions
where revision_id = :revision_id
}] {
if [string equal $storage_type text] {
ns_log Debug "acs-mail: encode: one part hit $content_item_id"
return [list $v_content_type $content]
} else {
# this content is in the file system or a blob
ns_log Debug "acs-mail: encode: binary content $content_item_id"
if [string equal $storage_type file] {
ns_log Debug "acs-mail: encode: file $content_item_id"
set encoded_content [acs_mail_uuencode_file [cr_fs_path]$content]
} else {
# Defaults
return {
"text/plain; charset=us-ascii"
"An OpenACS object was unable to be encoded here.\n"
}
ns_log Debug "acs-mail: encode: lob $content_item_id"
# Blob. Now we need to decide if this is binary
# so we can uuencode it if necessary.
# We'll use the mime type to decide
if { [string first "text" $v_content_type] == 0 } {
ns_log Debug "acs-mail: encode: plain content"
set encoded_content "$content"
} else {
# binary content - copy the blob to temp file
# that we will then uuencode
set file [ns_tmpnam]
db_blob_get_file copy_blob_to_file "
select r.content, i.storage_type
from cr_revisions r, cr_items i
where r.revision_id = $revision_id and
r.item_id = i.item_id " -file $file
ns_log Debug "acs-mail: encode: binary content"
set encoded_content [acs_mail_uuencode_file $file]
}
}
set content_type \
"multipart/[acs_mail_multipart_type $content_item_id]; boundary=\"$boundary\""
set content ""
foreach {cont} $contents {
set c_disp [lindex $cont 0]
set c_type [lindex [lindex $cont 1] 0]
set c_cont [lindex [lindex $cont 1] 1]
append content "--$boundary\n"
append content "Content-Type: $c_type\n"
if { [string first "text" $c_type] != 0 } {
# not a text item: therefore base64
append content "Content-Transfer-Encoding: base64\n"
}
append content "Content-Disposition: $c_disp\n"
append content "\n"
append content $c_cont
append content "\n\n"
}
append content "--$boundary--\n"
return [list $content_type $content]
return [list $v_content_type $encoded_content]
}
}
} else {
# This is a multipart item.
# Harder. Oops.
ns_log Debug "acs-mail: encode: multipart $content_item_id"
set boundary "=-=-="
set contents {}
# Get the component pieces
set multipart_list [db_list_of_lists acs_mail_body_to_mime_get_contents {
select mime_filename, mime_disposition, content_item_id as ci_id
from acs_mail_multipart_parts
where multipart_id = :content_item_id
order by sequence_number
}]
# Defaults
return {
if ![empty_string_p $multipart_list] {
foreach multipart_item $multipart_list {
set mime_filename [lindex $multipart_item 0]
set mime_disposition [lindex $multipart_item 1]
set ci_id [lindex $multipart_item 2]
if {[string equal "" $mime_disposition]} {
if {![string equal "" $mime_filename]} {
set mime_disposition "attachment; filename=$mime_filename"
} else {
set mime_disposition "inline"
}
} else {
if {![string equal "" $mime_filename]} {
set mime_disposition \
"$mime_disposition; filename=$mime_filename"
}
}
set content [acs_mail_encode_content $ci_id]
while {[regexp -- "--$boundary--" $content]} {
set boundary "=$boundary"
}
lappend contents [list $mime_disposition $content]
}
} else {
# Defaults
return {
"text/plain; charset=us-ascii"
"An OpenACS object was unable to be encoded here.\n"
}
}
set content_type \
"multipart/[acs_mail_multipart_type $content_item_id]; boundary=\"$boundary\""
set content ""
foreach {cont} $contents {
set c_disp [lindex $cont 0]
set c_type [lindex [lindex $cont 1] 0]
set c_cont [lindex [lindex $cont 1] 1]
append content "--$boundary\n"
append content "Content-Type: $c_type\n"
if { [string first "text" $c_type] != 0 } {
# not a text item: therefore base64
append content "Content-Transfer-Encoding: base64\n"
}
append content "Content-Disposition: $c_disp\n"
append content "\n"
append content $c_cont
append content "\n\n"
}
append content "--$boundary--\n"
return [list $content_type $content]
}
# Defaults
return {
"text/plain; charset=us-ascii"
"An OpenACS object was unable to be encoded here.\n"
}
}
ad_proc -private acs_mail_body_to_output_format {
......@@ -404,7 +399,8 @@ ad_proc -private acs_mail_process_queue {
from acs_mail_queue_outgoing
} {
set to_send [acs_mail_body_to_output_format -link_id $message_id]
set to_send_2 [list $envelope_to $envelope_from [lindex $to_send 2] [lindex $to_send 3] [lindex $to_send 4]]
set to_send_2 [list $envelope_to $envelope_from [lindex $to_send 2] [lindex $to_send 3] [lindex $to_send 4]]
ns_log notice "acs_mail_process_queue: to_send_2=$to_send_2"
if [catch {
eval ns_sendmail $to_send_2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment