# SLA: Just get the first open SLA for the customer as an example.
# Customers may want to use more complex logic and assign the
# ticket to different SLAs depending on the sender domain etc.
$sth=$dbh->prepare("SELECT min(project_id) as sla_id from im_projects where company_id = '$ticket_customer_id' and project_type_id = 2502 and project_status_id in (select im_sub_categories(76))");
my$rv=$sth->execute()||die"import-pop3: Unable to execute SQL statement.\n";
# SLA: Check for the regex_selector or ticket containers and
# match them agains the header.
my$ticket_sla_id="NULL";
if($rv>=0){
$row=$sth->fetchrow_hashref;
my$ticket_sla_id=$row->{sla_id};
}
if("NULL"eq$ticket_sla_id){
# Didn't find an open SLA, so let's just take the first one in any state
$sth=$dbh->prepare("SELECT min(project_id) as sla_id from im_projects where project_type_id = 2502");
my$rv=$sth->execute()||die"import-pop3: Unable to execute SQL statement.\n";
# Check for ticket containers with email selectors
$sth=$dbh->prepare("SELECT project_id, project_name, ticket_container_email_selector from im_projects where ticket_container_email_selector is not null and project_type_id = 2502 and project_status_id in (select im_sub_categories(76)) order by project_id");
my$rv=$sth->execute()||die"import-pop3: Unable to execute SQL statement.\n";
while(my$row=$sth->fetchrow_hashref){
my$project_id=$row->{project_id};
my$project_name=$row->{project_name};
my$regex=$row->{ticket_container_email_selector};
print"import-pop3: regexp in row=",$i++,": $project_name (#$project_id): regex=$regex\n"if($debug>=7);
if($header_string=~/$regex/im){
print"import-pop3: process_message: found regex=$regex in header=$header_string\n"if($debug>3);
$ticket_sla_id=$project_id;
last;
}
}
if($i>0&&"NULL"eq$ticket_sla_id){
print"import-pop3: process_message: did not find regex=$regex in header=$header_string\n"if($debug>3);