private function add_bug(&$p_email, $p_overwrite_project_id = FALSE) { $this->show_memory_usage('Start add bug'); //Merge References and In-Reply-To headers into one array $t_references = $p_email['References']; $t_references[] = $p_email['In-Reply-To']; if ($this->_mail_add_bugnotes) { $t_bug_id = $this->mail_is_a_bugnote($p_email['Subject'], $t_references); } else { $t_bug_id = FALSE; } if ($t_bug_id !== FALSE && !bug_is_readonly($t_bug_id)) { // @TODO@ Disabled for now until we find a good solution on how to handle the reporters possible lack of access permissions // access_ensure_bug_level( config_get( 'add_bugnote_threshold' ), $f_bug_id ); $t_description = $p_email['X-Mantis-Body']; $t_description = $this->identify_replies($t_description); $t_description = $this->strip_signature($t_description); $t_description = $this->add_additional_info('note', $p_email, $t_description); $t_project_id = bug_get_field($t_bug_id, 'project_id'); ERP_set_temporary_overwrite('project_override', $t_project_id); # Event integration # Core mantis event already exists within bugnote_add function $t_description = event_signal('EVENT_ERP_BUGNOTE_DATA', $t_description, $t_bug_id); if (bug_is_resolved($t_bug_id)) { # Reopen issue and add a bug note bug_reopen($t_bug_id, $t_description); } elseif (!is_blank($t_description)) { # Add a bug note bugnote_add($t_bug_id, $t_description); } } elseif ($this->_mail_add_bug_reports) { // @TODO@ Disabled for now until we find a good solution on how to handle the reporters possible lack of access permissions // access_ensure_project_level( config_get('report_bug_threshold' ) ); $f_master_bug_id = $t_bug_id !== FALSE && bug_is_readonly($t_bug_id) ? $t_bug_id : 0; $this->fix_empty_fields($p_email); $t_project_id = $p_overwrite_project_id === FALSE ? $this->_mailbox['project_id'] : $p_overwrite_project_id; ERP_set_temporary_overwrite('project_override', $t_project_id); $t_bug_data = new BugData(); $t_bug_data->build = ''; $t_bug_data->platform = ''; $t_bug_data->os = ''; $t_bug_data->os_build = ''; $t_bug_data->version = ''; $t_bug_data->profile_id = 0; $t_bug_data->handler_id = 0; $t_bug_data->view_state = (int) config_get('default_bug_view_status'); $t_bug_data->category_id = (int) $this->_mailbox['global_category_id']; $t_bug_data->reproducibility = (int) config_get('default_bug_reproducibility'); $t_bug_data->severity = (int) config_get('default_bug_severity'); $t_bug_data->priority = (int) ($this->_mail_use_bug_priority ? $p_email['Priority'] : config_get('default_bug_priority')); $t_bug_data->projection = (int) config_get('default_bug_projection'); $t_bug_data->eta = (int) config_get('default_bug_eta'); $t_bug_data->resolution = config_get('default_bug_resolution'); $t_bug_data->status = config_get('bug_submit_status'); $t_bug_data->summary = $p_email['Subject']; $t_description = $p_email['X-Mantis-Body']; $t_description = $this->strip_signature($t_description); $t_description = $this->add_additional_info('issue', $p_email, $t_description); $t_bug_data->description = $t_description; $t_bug_data->steps_to_reproduce = config_get('default_bug_steps_to_reproduce'); $t_bug_data->additional_information = config_get('default_bug_additional_info'); $t_bug_data->due_date = date_get_null(); $t_bug_data->project_id = $t_project_id; $t_bug_data->reporter_id = $p_email['Reporter_id']; // This function might do stuff that EmailReporting cannot handle. Disabled //helper_call_custom_function( 'issue_create_validate', array( $t_bug_data ) ); // @TODO@ Disabled for now but possibly needed for other future features # Validate the custom fields before adding the bug. /* $t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug_data->project_id ); foreach( $t_related_custom_field_ids as $t_id ) { $t_def = custom_field_get_definition( $t_id ); # Produce an error if the field is required but wasn't posted if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) && ( $t_def['require_report'] || $t_def['type'] == CUSTOM_FIELD_TYPE_ENUM || $t_def['type'] == CUSTOM_FIELD_TYPE_LIST || $t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST || $t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); trigger_error( ERROR_EMPTY_FIELD, ERROR ); } if ( !custom_field_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ) ) ) { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR ); } }*/ # Allow plugins to pre-process bug data $t_bug_data = event_signal('EVENT_REPORT_BUG_DATA', $t_bug_data); $t_bug_data = event_signal('EVENT_ERP_REPORT_BUG_DATA', $t_bug_data); # Create the bug $t_bug_id = $t_bug_data->create(); // @TODO@ Disabled for now but possibly needed for other future features # Handle custom field submission /* foreach( $t_related_custom_field_ids as $t_id ) { # Do not set custom field value if user has no write access. if( !custom_field_has_write_access( $t_id, $t_bug_id ) ) { continue; } $t_def = custom_field_get_definition( $t_id ); if( !custom_field_set_value( $t_id, $t_bug_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' ), false ) ) { { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR ); } }*/ // Lets link a readonly already existing bug to the newly created one if ($f_master_bug_id > 0) { $f_rel_type = BUG_RELATED; # update master bug last updated bug_update_date($f_master_bug_id); # Add the relationship relationship_add($t_bug_id, $f_master_bug_id, $f_rel_type); # Add log line to the history (both issues) history_log_event_special($f_master_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $t_bug_id); history_log_event_special($t_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_master_bug_id); # Send the email notification email_relationship_added($f_master_bug_id, $t_bug_id, relationship_get_complementary_type($f_rel_type)); } helper_call_custom_function('issue_create_notify', array($t_bug_id)); # Allow plugins to post-process bug data with the new bug ID event_signal('EVENT_REPORT_BUG', array($t_bug_data, $t_bug_id)); email_new_bug($t_bug_id); } else { // Not allowed to add issues and not allowed / able to add notes. Need to stop processing $this->custom_error('Not allowed to create a new issue. Email ignored'); return; } $this->custom_error('Reporter: ' . $p_email['Reporter_id'] . ' - ' . $p_email['From_parsed']['email'] . ' --> Issue ID: #' . $t_bug_id, FALSE); $this->show_memory_usage('Finished add bug'); $this->show_memory_usage('Start processing attachments'); # Add files if ($this->_allow_file_upload) { if (count($p_email['X-Mantis-Parts']) > 0) { $t_rejected_files = NULL; while ($t_part = array_shift($p_email['X-Mantis-Parts'])) { $t_file_rejected = $this->add_file($t_bug_id, $t_part); if ($t_file_rejected !== TRUE) { $t_rejected_files .= $t_file_rejected; } } if ($t_rejected_files !== NULL) { $t_part = array('name' => 'Rejected files.txt', 'ctype' => 'text/plain', 'body' => 'List of rejected files' . "\n\n" . $t_rejected_files); $t_reject_rejected_files = $this->add_file($t_bug_id, $t_part); if ($t_reject_rejected_files !== TRUE) { $t_part['body'] .= $t_reject_rejected_files; $this->custom_error('Failed to add "' . $t_part['name'] . '" to the issue. See below for all errors.' . "\n" . $t_part['body']); } } } } //Add the users in Cc and To list in mail header $this->add_monitors($t_bug_id, $p_email); //Add the message-id to the database $this->add_msg_id($t_bug_id, $p_email['Message-ID']); ERP_set_temporary_overwrite('project_override', NULL); $this->show_memory_usage('Finished processing attachments'); }
function ERP_custom_function_print_global_category_option_list($p_sel_value) { // Need to disable allow_no_category for a moment ERP_set_temporary_overwrite('allow_no_category', OFF); // Need to disable inherit projects for one moment. ERP_set_temporary_overwrite('subprojects_inherit_categories', OFF); $t_sel_value = (array) $p_sel_value; print_category_option_list($t_sel_value, ALL_PROJECTS); $t_all_projects = project_get_all_rows(); $t_projects_info = array(); foreach ($t_all_projects as $t_project) { $t_projects_info[$t_project['id']] = $t_project['name']; } natcasesort($t_projects_info); foreach ($t_projects_info as $t_project_id => $t_project_name) { echo '<optgroup label="' . string_attribute($t_project_name) . '">'; print_category_option_list($t_sel_value, (int) $t_project_id); echo '</optgroup>'; } }
echo "bug_report_mail.php is not allowed to run through the webserver.\n"; exit(1); } ini_set('memory_limit', -1); if (ini_get('safe_mode') == 0) { set_time_limit(0); } if (php_sapi_name() !== 'cli') { echo '<pre>'; } plugin_require_api('core/mail_api.php'); plugin_require_api('core/config_api.php'); $GLOBALS['t_mailboxes'] = plugin_config_get('mailboxes'); $t_mail_mantisbt_url_fix = plugin_config_get('mail_mantisbt_url_fix', ''); if (isset($GLOBALS['t_dir_emailreporting_adjust']) && !is_blank($t_mail_mantisbt_url_fix)) { ERP_set_temporary_overwrite('path', $t_mail_mantisbt_url_fix); } // Register the user that is currently running this script $t_job_users = plugin_config_get('job_users'); $t_username = ERP_get_current_os_user(); if (!isset($t_job_users[php_sapi_name()]) || $t_job_users[php_sapi_name()] !== $t_username) { $t_job_users[php_sapi_name()] = (string) $t_username; plugin_config_set('job_users', $t_job_users); } echo 'Start checking all mailboxes: ' . date('l jS \\of F Y H:i:s') . "\n\n"; $t_mailbox_api_index = ERP_get_mailbox_api_name(); $GLOBALS[$t_mailbox_api_index] = new ERP_mailbox_api(); foreach ($GLOBALS['t_mailboxes'] as $t_mailbox) { $GLOBALS[$t_mailbox_api_index]->process_mailbox($t_mailbox); } echo "\n\n" . 'Done checking all mailboxes' . "\n";
function ERP_update_check() { $t_config_version = plugin_config_get('config_version'); if ($t_config_version === 0) { $t_username = plugin_config_get('mail_reporter', ''); if (strlen($t_username) > 0) { $t_user_id = user_get_id_by_name($t_username); if ($t_user_id !== FALSE) { $t_user_email = user_get_email($t_user_id); if ($t_user_email === 'nomail') { plugin_require_api('core/config_api.php'); # We need to allow blank emails for a sec ERP_set_temporary_overwrite('allow_blank_email', ON); user_set_email($t_user_id, ''); } } } $t_schema = plugin_config_get('schema'); $t_reset_schema = plugin_config_get('reset_schema'); if ($t_schema !== -1 && $t_reset_schema === 0) { plugin_config_set('schema', -1); plugin_config_set('reset_schema', 1); } plugin_config_set('config_version', 1); } if ($t_config_version <= 1) { $t_mail_reporter = plugin_config_get('mail_reporter', ''); if (strlen($t_mail_reporter) > 0) { $t_mail_reporter_id = user_get_id_by_name($t_mail_reporter); plugin_config_set('mail_reporter_id', $t_mail_reporter_id); } plugin_config_delete('mail_directory'); plugin_config_delete('mail_reporter'); plugin_config_delete('mail_additional'); plugin_config_delete('random_user_number'); plugin_config_delete('mail_bug_priority_default'); plugin_config_set('config_version', 2); } if ($t_config_version <= 2) { plugin_config_delete('mail_cronjob_present'); plugin_config_delete('mail_check_timer'); plugin_config_delete('mail_last_check'); plugin_config_set('config_version', 3); } if ($t_config_version <= 3) { $t_mailboxes = plugin_config_get('mailboxes', array()); $t_indexes = array('mailbox_project' => 'mailbox_project_id', 'mailbox_global_category' => 'mailbox_global_category_id'); foreach ($t_mailboxes as $t_key => $t_array) { if (isset($t_array['mailbox_hostname'])) { # Correct the hostname if it is stored in an older format $t_hostname = $t_array['mailbox_hostname']; if (!is_array($t_hostname)) { // ipv6 also uses : so we need to work around that if (substr_count($t_hostname, ':') === 1) { $t_hostname = explode(':', $t_hostname, 2); } else { $t_hostname = array($t_hostname); } $t_hostname = array('hostname' => $t_hostname[0], 'port' => isset($t_hostname[1]) ? $t_hostname[1] : ''); $t_array['mailbox_hostname'] = $t_hostname; } } $t_mailboxes[$t_key] = $this->ERP_update_indexes($t_array, $t_indexes); } plugin_config_set('mailboxes', $t_mailboxes); plugin_config_set('config_version', 4); } if ($t_config_version <= 4) { $t_mail_remove_mantis_email = plugin_config_get('mail_remove_mantis_email', -1); $t_mail_identify_reply = plugin_config_get('mail_identify_reply', $t_mail_remove_mantis_email); if ($t_mail_remove_mantis_email !== -1 && $t_mail_identify_reply !== $t_mail_remove_mantis_email) { plugin_config_set('mail_remove_mantis_email', $t_mail_identify_reply); } plugin_config_delete('mail_identify_reply'); plugin_config_set('config_version', 5); } if ($t_config_version <= 5) { plugin_config_delete('mail_parse_mime'); plugin_config_set('config_version', 6); } if ($t_config_version <= 6) { $t_mailboxes = plugin_config_get('mailboxes', array()); $t_indexes = array('mailbox_enabled' => 'enabled', 'mailbox_description' => 'description', 'mailbox_type' => 'type', 'mailbox_hostname' => 'hostname', 'mailbox_encryption' => 'encryption', 'mailbox_username' => 'username', 'mailbox_password' => 'password', 'mailbox_auth_method' => 'auth_method', 'mailbox_project_id' => 'project_id', 'mailbox_global_category_id' => 'global_category_id', 'mailbox_basefolder' => 'basefolder', 'mailbox_createfolderstructure' => 'createfolderstructure'); foreach ($t_mailboxes as $t_key => $t_array) { $t_mailboxes[$t_key] = $this->ERP_update_indexes($t_array, $t_indexes); } plugin_config_set('mailboxes', $t_mailboxes); plugin_config_set('config_version', 7); } if ($t_config_version <= 7) { $t_mailboxes = plugin_config_get('mailboxes', array()); foreach ($t_mailboxes as $t_key => $t_array) { if (isset($t_array['hostname'])) { $t_hostname = $t_array['hostname']; if (is_array($t_hostname)) { $t_array['hostname'] = $t_hostname['hostname']; $t_array['port'] = $t_hostname['port']; } $t_mailboxes[$t_key] = $t_array; } } plugin_config_set('mailboxes', $t_mailboxes); plugin_config_set('config_version', 8); } if ($t_config_version <= 8) { plugin_config_delete('mail_tmp_directory'); plugin_config_set('config_version', 9); } if ($t_config_version <= 9) { $t_mailboxes = plugin_config_get('mailboxes', array()); $t_indexes = array('type' => 'mailbox_type', 'basefolder' => 'imap_basefolder', 'createfolderstructure' => 'imap_createfolderstructure'); foreach ($t_mailboxes as $t_key => $t_array) { $t_mailboxes[$t_key] = $this->ERP_update_indexes($t_array, $t_indexes); } plugin_config_set('mailboxes', $t_mailboxes); plugin_config_set('config_version', 10); } if ($t_config_version <= 10) { plugin_config_delete('mail_rule_system'); plugin_config_set('config_version', 11); } if ($t_config_version <= 11) { $t_mailboxes = plugin_config_get('mailboxes', array()); $t_indexes = array('username' => 'erp_username', 'password' => 'erp_password'); foreach ($t_mailboxes as $t_key => $t_array) { $t_mailboxes[$t_key] = $this->ERP_update_indexes($t_array, $t_indexes); } plugin_config_set('mailboxes', $t_mailboxes); plugin_config_delete('rules'); plugin_config_delete('mail_encoding'); plugin_config_set('config_version', 12); } if ($t_config_version <= 12) { plugin_config_set('reset_schema', 1); plugin_config_set('config_version', 13); } if ($t_config_version <= 13) { plugin_config_delete('mail_fetch_max'); plugin_config_set('config_version', 14); } if ($t_config_version <= 14) { $t_mail_reporter_id = plugin_config_get('mail_reporter_id', 'Mail'); $t_report_bug_threshold = config_get_global('report_bug_threshold'); if ($t_mail_reporter_id !== 'Mail' && user_exists($t_mail_reporter_id)) { if (!access_has_global_level($t_report_bug_threshold, $t_mail_reporter_id)) { user_set_field($t_mail_reporter_id, 'access_level', $t_report_bug_threshold); } } plugin_config_set('config_version', 15); } }