Index: openacs-4/packages/acs-mail-lite/tcl/acs-mail-lite-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-mail-lite/tcl/acs-mail-lite-procs.tcl,v diff -u -r1.39 -r1.40 --- openacs-4/packages/acs-mail-lite/tcl/acs-mail-lite-procs.tcl 4 Jan 2006 09:50:19 -0000 1.39 +++ openacs-4/packages/acs-mail-lite/tcl/acs-mail-lite-procs.tcl 12 Mar 2006 14:33:22 -0000 1.40 @@ -244,13 +244,16 @@ @see acs_mail_lite::incoming_email @see acs_mail_lite::parse_email } { + + # FIXME + set queue_dir "/home/malte/mail/" # get list of all incoming mail if {[catch { set messages [glob "$queue_dir/new/*"] } errmsg]} { if {[string match "no files matched glob pattern*" $errmsg ]} { - ns_log Notice "load_mails: queue dir = $queue_dir/new/*, no messages" + ns_log Debug "load_mails: queue dir = $queue_dir/new/*, no messages" } else { ns_log Error "load_mails: queue dir = $queue_dir/new/ error $errmsg" } @@ -259,13 +262,13 @@ # loop over every incoming mail foreach msg $messages { - ns_log Notice "load_mails: opening $msg" + ns_log Debug "load_mails: opening $msg" array set email {} parse_email -file $msg -array email set email(to) [parse_email_address -email $email(to)] set email(from) [parse_email_address -email $email(from)] - ns_log Notice "load_mails: message from $email(from) to $email(to)" + ns_log Debug "load_mails: message from $email(from) to $email(to)" set process_p 1 @@ -290,7 +293,11 @@ if {$process_p} { #check if an implementation exists for the package_prefix and call the callback - if {[db_0or1row select_impl {}]} { +### FIXME!!!!! +### + + +# if {[db_0or1row select_impl {}]} { # ns_log Notice "load_mails: Prefix $prefix found. Calling callback implmentation $impl_name for package_id $package_id" # callback -impl $impl_name acs_mail_lite::incoming_email -array email -package_id $package_id @@ -299,19 +306,19 @@ # We execute all callbacks now # callback acs_mail_lite::incoming_email -array email - } else { - ns_log Notice "load_mails: prefix not found. Doing nothing." - } +# } else { +# ns_log Notice "load_mails: prefix not found. Doing nothing." +# } } else { - ns_log Notice "load_mails: Either the SitePrefix setting was incorrect or not registered package prefix '$package_prefix'." + ns_log Error "load_mails: Either the SitePrefix setting was incorrect or not registered package prefix '$package_prefix'." } #let's delete the file now if {[catch {ns_unlink $msg} errmsg]} { ns_log Error "load_mails: unable to delete queued message $msg: $errmsg" } else { - ns_log Notice "load_mails: deleted $msg" + ns_log Debug "load_mails: deleted $msg" } } } @@ -366,7 +373,15 @@ upvar $array email #prepare the message - set mime [mime::initialize -file $file] + if {[catch {set mime [mime::initialize -file $file]} errormsg]} { + ns_log error "Email could not be delivered for file $file" + set stream [open $file] + set content [read $stream] + close $stream + ns_log error "$content" + ns_unlink $file + return + } #get the content type set content [mime::getproperty $mime content] @@ -520,7 +535,7 @@ } set to [parse_email_address -email $to] - ns_log Notice "acs-mail-lite: To: $to" + ns_log Debug "acs-mail-lite: To: $to" util_unlist [parse_bounce_address -bounce_address $to] user_id package_id signature # If no user_id found or signature invalid, ignore message @@ -571,7 +586,7 @@ } with_finally -code { - ns_log Debug "acs-mail-lite: about to load qmail queue" + ns_log Debug "acs-mail-lite: about to load qmail queue for [mail_dir]" load_mails -queue_dir [mail_dir] } -finally { nsv_incr acs_mail_lite check_bounce_p -1 @@ -897,7 +912,7 @@ {-extraheaders ""} {-bcc ""} {-package_id ""} - -no_callback_p:boolean + -no_callback:boolean } { Reliably send an email message. @@ -969,7 +984,7 @@ db_dml create_queue_entry {} } - if { ![exists_and_not_null no_callback_p] } { + if { !$no_callback_p } { callback acs_mail_lite::send \ -package_id $package_id \ -from_party_id $from_party_id \ @@ -995,7 +1010,8 @@ {-folder_id ""} {-mime_type "text/plain"} {-object_id ""} - -no_callback_p:boolean + -no_callback:boolean + -use_sender:boolean } { Prepare an email to be send with the option to pass in a list @@ -1015,21 +1031,22 @@ @param package_id Package ID of the sending package - @param file_ids List of file ids to be send as attachments. This will only work with files stored in the file system. + @param file_ids List of file ids (ITEMS, not revisions) to be send as attachments. This will only work with files stored in the file system. @param mime_type MIME Type of the mail to send out. Can be "text/plain", "text/html". @param object_id The ID of the object that is responsible for sending the mail in the first place - @param no_callback_p Boolean that indicates if callback should be executed or not. If you don't provide it it will execute callbacks - + @param no_callback Boolean that indicates if callback should be executed or not. If you don't provide it it will execute callbacks + + @param use_sender Boolean indicating that from_addr should be used regardless of fixed-sender parameter } { # We check if the parameter set fixed_sender [parameter::get -parameter "FixedSenderEmail" \ -package_id [apm_package_id_from_key "acs-mail-lite"]] - if { ![empty_string_p $fixed_sender] } { + if { ![empty_string_p $fixed_sender] && !$use_sender_p} { set sender_addr $fixed_sender } else { set sender_addr $from_addr @@ -1051,29 +1068,66 @@ } } elseif {[exists_and_not_null file_ids]} { + set item_p 1 db_foreach get_file_info "select r.mime_type,r.title, r.content as filename from cr_revisions r where r.revision_id in ([join $file_ids ","])" { lappend tokens [mime::initialize -param [list name "[ad_quotehtml $title]"] -canonical $mime_type -file "[cr_fs_path]$filename"] + set item_p 0 } + + if {$item_p} { + db_foreach get_file_info "select r.mime_type,r.title, r.content as filename + from cr_revisions r, cr_items i + where r.revision_id = i.latest_revision + and i.item_id in ([join $file_ids ","])" { + ns_log Debug "Files: $file_ids ::: $filename" + lappend tokens [mime::initialize -param [list name "[ad_quotehtml $title]"] -canonical $mime_type -file "[cr_fs_path]$filename"] + } + } } set multi_token [mime::initialize -canonical multipart/mixed -parts "$tokens"] mime::setheader $multi_token Subject "$subject" set packaged [mime::buildmessage $multi_token] - + #Close all mime tokens mime::finalize $multi_token -subordinates all set message_id [generate_message_id] + + # Rollout support (see above for details) - acs_mail_lite::sendmail -from_addr $sender_addr -sendlist [get_address_array -addresses $to_addr] -msg $packaged -valid_email_p t -message_id $message_id -package_id $package_id + set delivery_mode [ns_config ns/server/[ns_info server]/acs/acs-rollout-support EmailDeliveryMode] + if {![empty_string_p $delivery_mode] + && ![string equal $delivery_mode default] + } { + # The to_addr has been put in an array, and returned. Now + # it is of the form: email email_address name namefromdb + # user_id user_id_if_present_or_empty_string + # ---------------------------------------------------- + # Rollout support + # ---------------------------------------------------- + # if set in etc/config.tcl, then + # packages/acs-tcl/tcl/rollout-email-procs.tcl will rename a + # proc to ns_sendmail. So we simply call ns_sendmail instead + # of the sendmail bin if the EmailDeliveryMode parameter is + # set to anything other than default - JFR + #----------------------------------------------------- + + set to_address "[lindex $to_addr 1] ([lindex $to_addr 3])" + set eh [util_list_to_ns_set $extraheaders] + ns_sendmail $to_address $from_addr $subject $body $eh $bcc + } else { + acs_mail_lite::sendmail -from_addr $sender_addr -sendlist [get_address_array -addresses $to_addr] -msg $packaged -valid_email_p t -message_id $message_id -package_id $package_id + } + if {[empty_string_p $package_id]} { set package_id [apm_package_id_from_key "acs-mail-lite"] } - if { ![exists_and_not_null no_callback_p] } { + if { !$no_callback_p } { callback acs_mail_lite::complex_send \ -package_id $package_id \ -from_party_id [party::get_by_email -email $from_addr] \ @@ -1140,7 +1194,7 @@ ns_log "Notice" "Mail info will be written in the db" db_dml create_queue_entry {} } else { - ns_log "Notice" "acs_mail_lite::deliver_mail successful" + ns_log "Debug" "acs_mail_lite::deliver_mail successful" } }