Forum OpenACS Development: exec tcl proc

Collapse
Posted by Iuri Sampaio on
Hi all,

I have tried to exec procs manually to test email features in the system (openacs-5-4).
But i am lost at how to pull the trigger to start the whole sequences of tcl code from the first ad_proc.

I will try to explain a scenario:
the whole (end-to-end) process, in a few words,
stands for:
send email from client -> server maildir -> tcl procs -> new bug-tracker ticket created

The process is automatic. It is scheduled in the acs-mail-lite parameters to exec in 2 minutes. (If you know acs-mail-lite package you will clearly understand)

So, i debugged tcl procs related and i verified that:

1. everything starts at file: acs-mail-lite-init.tcl line 12
ad_schedule_proc runs every two minutes and calls acs_mail_lite::load_mails

I wonder if the lines commented out do not affect the process.

#############################
set queue_dir [parameter::get_from_package_key -parameter
"BounceMailDir" -package_key "acs-mail-lite"]

if {$queue_dir ne ""} {
# if BounceMailDir is set then handle incoming mail
ad_schedule_proc -thread t 120 acs_mail_lite::load_mails -queue_dir
$queue_dir
}

# check every few minutes for bounces
#ad_schedule_proc -thread t [acs_mail_lite::get_parameter -name BounceScanQueue -default 120] acs_mail_lite::scan_replies

nsv_set acs_mail_lite send_mails_p 0
nsv_set acs_mail_lite check_bounce_p 0

#ad_schedule_proc -thread t -schedule_proc ns_schedule_daily [list 0 25] acs_mail_lite::check_bounces

#############################

2. Then we have the file:
packages/acs-mail-lite/tcl/incoming-mail-procs.tcl line 29

This proc will prepare the var $email to be used at callbacks later at line 107

ad_proc -private load_mails {
.
.
.
#line 107
if {!$callback_executed_p} {
# We execute all callbacks now
callback acs_mail_lite::incoming_email -array email
}

...}

3. line 107 takes to file
acs-mail-lite-callback-procs.tcl line 127

ad_proc -public -callback acs_mail_lite::incoming_email -impl acs-mail-lite {
-array:required
-package_id:required
} {

upvar $array email



set to [acs_mail_lite::parse_email_address -email $email(to)]

ns_log Debug "acs_mail_lite::incoming_email -impl acs-mail-lite called. Recepient $to"



util_unlist [acs_mail_lite::parse_bounce_address -bounce_address $to] user_id package_id signature



# If no user_id found or signature invalid, ignore message

if {$user_id eq ""} {

ns_log Debug "acs_mail_lite::incoming_email impl acs-mail-lite: No equivalent user found for $to"

} else {

ns_log Debug "acs_mail_lite::incoming_email impl acs-mail-lite: Bounce checking $to, $user_id"

acs_mail_lite::record_bounce -user_id $user_id

}

}
#####################################

This proc alerts if there's a message bounced to a user.
I believe inside the else block, it would be the place to call the bugtracker procedure to create new tickets on bug-tracker aplication.
However i am blind how to call the bugtracker callback to create the tickets, because it doesn't have a name such as in ad_proc ... ::load_mail or ... ::incoming_email

The header of the proc is:

packages/bug-tracker/tcl/bug-tracker-callback-procs.tcl line 11

ad_proc -public -callback acs_mail_lite::incoming_email -impl
bug-tracker { ... }

Everything seems to be correct in place. Parameters and variables properly set, however the tickets has not been created.
I put some ns_log in the procs to try to debug it and nothing was wrong.

How do I exec bugtracker proc?

Collapse
2: Re: exec tcl proc (response to 1)
Posted by Dave Bauer on
One way to test this is to write a test script, and call that.

You can do that with acs-automated-testing, or just write a tcl script that calls the procedures you need.

In your case you need to

1) Make sure the email ends up in the correct Maildir
2) Make sure acs-mail-lite reads the maildir and finds the email
3) amke sure acs-mail-lite decodes the email prefix and calls the bugtracker incoming email handler.

You should be able to do all that by putting ns_logs in the procedures that handle the mail.

NOTE: if you change a tcl procedure called by a scheduled procedure you need to restart aolserver for it to be reloaded. Using the APM reload feature will not work.

Collapse
3: Re: exec tcl proc (response to 2)
Posted by Iuri Sampaio on
I wrote the tcl script

One thing i noticed from
set queue_dir [parameter::get_from_package_key -parameter "BounceMailDir" -package_key "acs-mail-lite"]

$queue_dir holds 1 as its value

however looking at procedure acs_mail_litle::load_mails $queue_dir is treated as a string.

why is that? is that an error?

Collapse
4: Re: exec tcl proc (response to 1)
Posted by Dave Bauer on
Well :)

You'll need to debug that. What is the parameter value. Why is parameter::get returning that value etc.

Collapse
5: Re: exec tcl proc (response to 4)
Posted by Iuri Sampaio on
I debugged and i don't understand why is that. Since in the file "packages/acs-mail-lite/tcl/incoming-mail-procs.tcl"

we have the proc at line 29

ad_proc -private load_mails { ...

line 59
the var $queue_dir is used as the path of maildir.

# get list of all incoming mail
if {[catch {
set messages [glob "$queue_dir/new/*"]
} errmsg]} {

So i wonder why in the file

"packages/acs-mail-lite/tcl/acs-mail-lite-init.tcl" line 14

we have this proc that returns 1 and assign into $queue_dir

set queue_dir [parameter::get_from_package_key -parameter "BounceMailDir" -package_key "acs-mail-lite"]

I

Collapse
6: Re: exec tcl proc (response to 5)
Posted by Brian Fenton on
Hi Iuri,

I can't tell you how to create the bugtracker entry, but Malte has documented how to set up the ACS mail lite here: http://www.cognovis.de/developer/en/incoming_email_install

hope this helps
Brian

Collapse
7: Re: exec tcl proc (response to 6)
Posted by Iuri Sampaio on
Hi Brian,

I figured that out.
Now i am stuck at adding email attachments as uploaded files on bugtracker.

I need help! :)
I am at #openacs