<?php

auth_reauthenticate();
access_ensure_global_level(config_get('manage_plugin_threshold'));
plugin_require_api('core/config_api.php');
$f_mailbox_action = gpc_get_string('mailbox_action');
$f_select_mailbox = gpc_get_int('select_mailbox');
$t_mailboxes = plugin_config_get('mailboxes');
if ($f_mailbox_action === 'add' || $f_mailbox_action === 'copy' || ($f_mailbox_action === 'edit' || $f_mailbox_action === 'test' || $f_mailbox_action === 'complete_test') && $f_select_mailbox >= 0) {
    $t_mailbox = array('enabled' => gpc_get_int('enabled', ON), 'description' => gpc_get_string('description', ''), 'mailbox_type' => gpc_get_string('mailbox_type'), 'hostname' => gpc_get_string('hostname', ''), 'port' => gpc_get_string('port', ''), 'encryption' => gpc_get_string('encryption'), 'ssl_cert_verify' => gpc_get_int('ssl_cert_verify', ON), 'erp_username' => gpc_get_string('erp_username', ''), 'erp_password' => base64_encode(gpc_get_string('erp_password', '')), 'auth_method' => gpc_get_string('auth_method'), 'project_id' => gpc_get_int('project_id'), 'global_category_id' => gpc_get_int('global_category_id'));
    if ($t_mailbox['mailbox_type'] === 'IMAP') {
        $t_mailbox_imap = array('imap_basefolder' => ERP_prepare_directory_string(gpc_get_string('imap_basefolder', ''), TRUE), 'imap_createfolderstructure' => gpc_get_int('imap_createfolderstructure'));
        $t_mailbox += $t_mailbox_imap;
    }
    $t_plugin_content = gpc_get_string_array('plugin_content', NULL);
    if (is_array($t_plugin_content)) {
        $t_mailbox += array('plugin_content' => $t_plugin_content);
    }
}
if ($f_mailbox_action === 'add' || $f_mailbox_action === 'copy') {
    $t_mailboxes[] = $t_mailbox;
} elseif ($f_mailbox_action === 'edit' && $f_select_mailbox >= 0) {
    $t_mailboxes[$f_select_mailbox] = $t_mailbox;
} elseif ($f_mailbox_action === 'delete' && $f_select_mailbox >= 0) {
    unset($t_mailboxes[$f_select_mailbox]);
} elseif (($f_mailbox_action === 'test' || $f_mailbox_action === 'complete_test') && $f_select_mailbox >= 0) {
    # Verify mailbox - from Recmail by Cas Nuy
    plugin_require_api('core/mail_api.php');
    echo '<pre>';
    $t_mailbox_api = new ERP_mailbox_api($f_mailbox_action === 'complete_test' ? FALSE : TRUE);
    $t_result = $t_mailbox_api->process_mailbox($t_mailbox);
Example #2
0
 public function process_mailbox($p_mailbox)
 {
     $this->_mailbox = $p_mailbox + ERP_get_default_mailbox();
     if ($this->_functionality_enabled) {
         if ($this->_mailbox['enabled']) {
             // Check whether EmailReporting supports the mailbox type. The check is based on available default ports
             if (isset($this->_default_ports[$this->_mailbox['mailbox_type']])) {
                 if (project_exists($this->_mailbox['project_id'])) {
                     if (category_exists($this->_mailbox['global_category_id'])) {
                         $t_upload_folder_passed = TRUE;
                         if ($this->_allow_file_upload && $this->_file_upload_method == DISK) {
                             $t_upload_folder_passed = FALSE;
                             $t_file_path = project_get_field($this->_mailbox['project_id'], 'file_path');
                             if ($t_file_path == '') {
                                 $t_file_path = config_get('absolute_path_default_upload_folder');
                             }
                             $t_file_path = ERP_prepare_directory_string($t_file_path, TRUE);
                             $t_real_file_path = ERP_prepare_directory_string($t_file_path);
                             if (!file_exists($t_file_path) || !is_dir($t_file_path) || !is_writable($t_file_path) || !is_readable($t_file_path)) {
                                 $this->custom_error('Upload folder is not writable: ' . $t_file_path . "\n");
                             } elseif (strcasecmp($t_real_file_path, $t_file_path) !== 0) {
                                 $this->custom_error('Upload folder is not an absolute path' . "\n" . 'Upload folder: ' . $t_file_path . "\n" . 'Absolute path: ' . $t_real_file_path . "\n");
                             } else {
                                 $t_upload_folder_passed = TRUE;
                             }
                         }
                         if ($t_upload_folder_passed) {
                             $this->prepare_mailbox_hostname();
                             if (!$this->_test_only && $this->_mail_debug) {
                                 var_dump($this->_mailbox);
                             }
                             $this->show_memory_usage('Start process mailbox');
                             $t_process_mailbox_function = 'process_' . strtolower($this->_mailbox['mailbox_type']) . '_mailbox';
                             $this->{$t_process_mailbox_function}();
                             $this->show_memory_usage('Finished process mailbox');
                         }
                     } else {
                         $this->custom_error('Category does not exist');
                     }
                 } else {
                     $this->custom_error('Project does not exist');
                 }
             } else {
                 $this->custom_error('Unknown mailbox type');
             }
         } else {
             $this->custom_error('Mailbox disabled');
         }
     }
     return $this->_result;
 }
<?php

auth_reauthenticate();
access_ensure_global_level(config_get('manage_plugin_threshold'));
plugin_require_api('core/config_api.php');
$f_gpc = array('mail_add_bug_reports' => gpc_get_int('mail_add_bug_reports'), 'mail_add_bugnotes' => gpc_get_int('mail_add_bugnotes'), 'mail_add_complete_email' => gpc_get_int('mail_add_complete_email'), 'mail_add_users_from_cc_to' => gpc_get_int('mail_add_users_from_cc_to'), 'mail_auto_signup' => gpc_get_int('mail_auto_signup'), 'mail_block_attachments_md5' => array_map('strtolower', array_filter(array_map('trim', explode("\n", str_replace(array("\r\n", "\r"), "\n", gpc_get_string('mail_block_attachments_md5')))))), 'mail_block_attachments_logging' => gpc_get_int('mail_block_attachments_logging'), 'mail_debug' => gpc_get_int('mail_debug'), 'mail_debug_directory' => ERP_prepare_directory_string(gpc_get_string('mail_debug_directory')), 'mail_debug_show_memory_usage' => gpc_get_int('mail_debug_show_memory_usage'), 'mail_delete' => gpc_get_int('mail_delete'), 'mail_disposable_email_checker' => gpc_get_int('mail_disposable_email_checker'), 'mail_email_receive_own' => gpc_get_int('mail_email_receive_own'), 'mail_fallback_mail_reporter' => gpc_get_int('mail_fallback_mail_reporter'), 'mail_nodescription' => gpc_get_string('mail_nodescription'), 'mail_nosubject' => gpc_get_string('mail_nosubject'), 'mail_parse_html' => gpc_get_int('mail_parse_html'), 'mail_preferred_username' => gpc_get_string('mail_preferred_username'), 'mail_preferred_realname' => gpc_get_string('mail_preferred_realname'), 'mail_remove_mantis_email' => gpc_get_int('mail_remove_mantis_email'), 'mail_remove_replies' => gpc_get_int('mail_remove_replies'), 'mail_strip_gmail_style_replies' => gpc_get_int('mail_strip_gmail_style_replies'), 'mail_remove_replies_after' => gpc_get_string('mail_remove_replies_after'), 'mail_removed_reply_text' => gpc_get_string('mail_removed_reply_text'), 'mail_reporter_id' => gpc_get_int('mail_reporter_id'), 'mail_rule_system' => gpc_get_int('mail_rule_system'), 'mail_save_from' => gpc_get_int('mail_save_from'), 'mail_save_subject_in_note' => gpc_get_int('mail_save_subject_in_note'), 'mail_secured_script' => gpc_get_int('mail_secured_script'), 'mail_strip_signature' => gpc_get_int('mail_strip_signature'), 'mail_strip_signature_delim' => gpc_get_string('mail_strip_signature_delim'), 'mail_subject_id_regex' => gpc_get_string('mail_subject_id_regex'), 'mail_use_bug_priority' => gpc_get_int('mail_use_bug_priority'), 'mail_use_message_id' => gpc_get_int('mail_use_message_id'), 'mail_use_reporter' => gpc_get_int('mail_use_reporter'));
$f_mail_bug_priority = 'array (' . "\n" . gpc_get_string('mail_bug_priority') . "\n" . ')';
foreach ($f_gpc as $t_key => $t_value) {
    if (plugin_config_get($t_key) !== $t_value) {
        plugin_config_set($t_key, $t_value);
    }
}
$t_mail_bug_priority = process_complex_value($f_mail_bug_priority);
if (is_array($t_mail_bug_priority)) {
    if (plugin_config_get('mail_bug_priority') !== $t_mail_bug_priority) {
        plugin_config_set('mail_bug_priority', $t_mail_bug_priority);
    }
} else {
    html_page_top(plugin_lang_get('plugin_title'));
    echo '<br /><div class="center">';
    echo plugin_lang_get('mail_bug_priority_array_failure') . ' ';
    print_bracket_link(plugin_page('manage_config', TRUE), lang_get('proceed'));
    echo '</div>';
    $t_notsuccesfull = TRUE;
    html_page_bottom(__FILE__);
}
if (!isset($t_notsuccesfull)) {
    print_successful_redirect(plugin_page('manage_config', TRUE));
}