From 316d2b9ed4390660d1a9a59da213a3c17840f3a9 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 24 Mar 2010 10:18:53 +0100 Subject: [PATCH 1/4] Add the "category by subject" management --- core/mail_api.php | 10 +++ lang/strings_english.txt | 1 + pages/maintainmailbox.php | 34 +++++++++++ pages/maintainmailbox_edit.php | 127 ++++++++++++++++++++++++---------------- 4 files changed, 122 insertions(+), 50 deletions(-) diff --git a/core/mail_api.php b/core/mail_api.php index cc76985..c36f8f8 100644 --- a/core/mail_api.php +++ b/core/mail_api.php @@ -724,6 +724,16 @@ $t_bug_data->view_state = gpc_get_int( 'view_state', config_get( 'default_bug_view_status' ) ); $t_bug_data->category_id = gpc_get_int( 'category_id', $p_mailbox[ 'mailbox_global_category' ] ); + + foreach ($p_mailbox[ 'mailbox_keyword_categories' ] as $expression_pair) + { + if (preg_match($expression_pair[ 'expression' ], $p_mail[ 'Subject' ]) == 1) + { + $t_bug_data->category_id = $expression_pair[ 'category' ]; + } + } + + $t_bug_data->reproducibility = config_get( 'default_bug_reproducibility', 10 ); $t_bug_data->severity = config_get( 'default_bug_severity', 50 ); $t_bug_data->priority = $p_mail[ 'Priority' ]; diff --git a/lang/strings_english.txt b/lang/strings_english.txt index f6a2809..7e60b90 100644 --- a/lang/strings_english.txt +++ b/lang/strings_english.txt @@ -61,6 +61,7 @@ $s_plugin_EmailReporting_mailbox_basefolder = 'Mailbox basefolder (IMAP)'; $s_plugin_EmailReporting_mailbox_createfolderstructure = 'Create project subfolder structure (IMAP)'; $s_plugin_EmailReporting_mailbox_project = 'Select a project (N/A if above is set to "yes")'; $s_plugin_EmailReporting_mailbox_global_category = 'Select a global category'; +$s_plugin_EmailReporting_mailbox_keyword_categories = 'Indicate your regular expression / category pairs (see preg_match for details)'; $s_plugin_EmailReporting_unknown_setting = 'Unknown setting encountered. Setting ignored'; $s_plugin_EmailReporting_missing_reporter = 'Please select a user account'; diff --git a/pages/maintainmailbox.php b/pages/maintainmailbox.php index 1b7ce01..076ce38 100644 --- a/pages/maintainmailbox.php +++ b/pages/maintainmailbox.php @@ -84,6 +84,11 @@ $t_config_array = array( 'type' => 'dropdown_global_categories', 'value' => '', ), + array( + 'name' => 'mailbox_keyword_categories', + 'type' => 'list_keywords_categories', + 'value' => '', + ) ); foreach( $t_config_array AS $t_config ) @@ -233,6 +238,35 @@ foreach( $t_config_array AS $t_config ) +> + + + + + "; + echo "\n"; + ++$i; + } + } + ?> + + + + +' . plugin_lang_get( 'unknown_setting' ) . ''; } } diff --git a/pages/maintainmailbox_edit.php b/pages/maintainmailbox_edit.php index 9f57174..94fa9f3 100644 --- a/pages/maintainmailbox_edit.php +++ b/pages/maintainmailbox_edit.php @@ -9,81 +9,108 @@ $t_mailboxes = plugin_config_get( 'mailboxes' ); if ( $f_mailbox_action === 'add' || ( ( $f_mailbox_action === 'edit' || $f_mailbox_action === 'test' ) && $f_select_mailbox >= 0 ) ) { - $t_mailbox = array( - 'mailbox_description' => gpc_get_string( 'mailbox_description' ), - 'mailbox_type' => gpc_get_string( 'mailbox_type', 'POP3' ), - 'mailbox_hostname' => gpc_get_string( 'mailbox_hostname' ), - 'mailbox_encryption' => gpc_get_string( 'mailbox_encryption', 'None' ), - 'mailbox_username' => gpc_get_string( 'mailbox_username' ), - 'mailbox_password' => base64_encode( gpc_get_string( 'mailbox_password' ) ), - 'mailbox_auth_method' => gpc_get_string( 'mailbox_auth_method', 'USER' ), - 'mailbox_basefolder' => trim( str_replace( '\\', '/', gpc_get_string( 'mailbox_basefolder', '' ) ), '/ ' ), - 'mailbox_createfolderstructure' => gpc_get_bool( 'mailbox_createfolderstructure', OFF ), - 'mailbox_project' => gpc_get_int( 'mailbox_project' ), - 'mailbox_global_category' => gpc_get_int( 'mailbox_global_category' ), - ); + $t_mailbox = array( + 'mailbox_description' => gpc_get_string( 'mailbox_description' ), + 'mailbox_type' => gpc_get_string( 'mailbox_type', 'POP3' ), + 'mailbox_hostname' => gpc_get_string( 'mailbox_hostname' ), + 'mailbox_encryption' => gpc_get_string( 'mailbox_encryption', 'None' ), + 'mailbox_username' => gpc_get_string( 'mailbox_username' ), + 'mailbox_password' => base64_encode( gpc_get_string( 'mailbox_password' ) ), + 'mailbox_auth_method' => gpc_get_string( 'mailbox_auth_method', 'USER' ), + 'mailbox_basefolder' => trim( str_replace( '\\', '/', gpc_get_string( 'mailbox_basefolder', '' ) ), '/ ' ), + 'mailbox_createfolderstructure' => gpc_get_bool( 'mailbox_createfolderstructure', OFF ), + 'mailbox_project' => gpc_get_int( 'mailbox_project' ), + 'mailbox_global_category' => gpc_get_int( 'mailbox_global_category' ), + 'mailbox_keyword_categories' => array(), + ); + + // Add existing pairs, only if they are filled in + $i = 0; + while (gpc_get_string('mailbox_keyword_categories_expression_'.$i, null) != null) + { + $expression = gpc_get_string('mailbox_keyword_categories_expression_'.$i); + if (!empty($expression)) + { + array_push($t_mailbox['mailbox_keyword_categories'], array('expression' => $expression, + 'category' => gpc_get_int('mailbox_keyword_categories_category_'.$i) + ) + ); + } + + ++$i; + } + + // Add a new pair, if filled in + $expression = gpc_get_string('mailbox_keyword_categories_expression_new'); + if (!empty($expression)) + { + array_push($t_mailbox['mailbox_keyword_categories'], array('expression' => $expression, + 'category' => gpc_get_int('mailbox_keyword_categories_category_new') + ) + ); + } } if ( $f_mailbox_action === 'add' ) { - array_push( $t_mailboxes, $t_mailbox ); + array_push( $t_mailboxes, $t_mailbox ); } elseif ( $f_mailbox_action === 'edit' && $f_select_mailbox >= 0 ) { - $t_mailboxes[ $f_select_mailbox ] = $t_mailbox; + $t_mailboxes[ $f_select_mailbox ] = $t_mailbox; } elseif ( $f_mailbox_action === 'delete' && $f_select_mailbox >= 0 ) { - unset( $t_mailboxes[ $f_select_mailbox ] ); + unset( $t_mailboxes[ $f_select_mailbox ] ); } elseif ( $f_mailbox_action === 'test' && $f_select_mailbox >= 0 ) { - # Verify mailbox - from Recmail by Cas Nuy - require_once( 'mail_api.php' ); + # Verify mailbox - from Recmail by Cas Nuy + require_once( 'mail_api.php' ); - $t_result = mail_process_all_mails( $t_mailbox, true ); + $t_result = mail_process_all_mails( $t_mailbox, true ); - if ( ( is_array( $t_result ) && $t_result[ 'ERROR_TYPE' ] === 'NON-PEAR-ERROR' ) || PEAR::isError( $t_result ) ) - { - $t_no_redirect = true; + if ( ( is_array( $t_result ) && $t_result[ 'ERROR_TYPE' ] === 'NON-PEAR-ERROR' ) || PEAR::isError( $t_result ) ) + { + $t_no_redirect = true; - html_page_top1(); - html_page_top2(); + html_page_top1(); + html_page_top2(); ?>
- -

- -
- -
- -
- -
- -
- -
- -
- -

- toString() ); ?> -

- + +

+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +

+ toString() ); ?> +

+
= 0 ) ) ) { - plugin_config_set( 'mailboxes', $t_mailboxes ); + plugin_config_set( 'mailboxes', $t_mailboxes ); } if ( !isset( $t_no_redirect ) ) { - print_successful_redirect( plugin_page( 'maintainmailbox', true ) ); -} + print_successful_redirect( plugin_page( 'maintainmailbox', true ) ); +} \ No newline at end of file -- 1.7.0.2.msysgit.0 From 4d401197225df12e5b64131c0a9b7bd5121de6d1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 29 Mar 2010 10:59:44 +0200 Subject: [PATCH 2/4] Better Regex for accented characters in project names --- core/mail_api.php | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/mail_api.php b/core/mail_api.php index c36f8f8..e29fcc0 100644 --- a/core/mail_api.php +++ b/core/mail_api.php @@ -454,7 +454,7 @@ # -------------------- # return true if there is a valid mantis bug refererence in subject or return false if not found function mail_is_a_bugnote ( $p_mail_subject ) { - if ( preg_match( "/\[([A-Za-z0-9-_\. ]*\s[0-9]{1,7})\]/", $p_mail_subject ) ){ + if ( preg_match( "/\[([[:alnum:]\p{L}-_\. ]*\s[0-9]{1,7})\]/iu", $p_mail_subject ) ){ $t_bug_id = mail_get_bug_id_from_subject( $p_mail_subject ); if ( bug_exists( $t_bug_id ) && !bug_is_readonly( $t_bug_id ) ){ return true; @@ -467,7 +467,7 @@ # -------------------- # return the bug's id from the subject function mail_get_bug_id_from_subject ( $p_mail_subject ) { - preg_match( "/\[([A-Za-z0-9-_\. ]*\s([0-9]{1,7}?))\]/", $p_mail_subject, $v_matches ); + preg_match( "/\[([[:alnum:]\p{L}-_\. ]*\s([0-9]{1,7}?))\]/iu", $p_mail_subject, $v_matches ); return $v_matches[ 2 ]; } -- 1.7.0.2.msysgit.0 From 3cc04e323a8a692d357d2a4bab4c776f7c0f79dc Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 6 Apr 2010 12:05:23 +0200 Subject: [PATCH 3/4] Can now use the email as the username (optionally stripping the domain name) and use the previous username as the realname. --- EmailReporting.php | 9 ++++++++- core/mail_api.php | 37 ++++++++++++++++++++++++++++++++----- lang/strings_english.txt | 2 ++ pages/config.php | 8 ++++++++ pages/config_edit.php | 10 ++++++++++ 5 files changed, 60 insertions(+), 6 deletions(-) diff --git a/EmailReporting.php b/EmailReporting.php index 604bd61..3c2bb5e 100644 --- a/EmailReporting.php +++ b/EmailReporting.php @@ -10,7 +10,7 @@ class EmailReportingPlugin extends MantisPlugin { $this->description = plugin_lang_get( 'description' ); $this->page = 'config'; - $this->version = '0.7.9'; + $this->version = '0.7.9-DEV'; $this->requires = array( 'MantisCore' => '1.2', ); @@ -50,6 +50,13 @@ class EmailReportingPlugin extends MantisPlugin { # Default is OFF, if mail_use_reporter is OFF and this is OFF then it will # fallback to the mail_reporter account above 'mail_auto_signup' => OFF, + + # Use the email as a username if auto signing up + 'mail_use_email_as_username' => OFF, + + # Strip the domain name (the part after the @) when using the email as a + # username and auto signing up + 'mail_strip_domain_from_username' => OFF, # How many mails should be fetched at the same time # If big mails with attachments should be received, specify only one diff --git a/core/mail_api.php b/core/mail_api.php index e29fcc0..3c7202a 100644 --- a/core/mail_api.php +++ b/core/mail_api.php @@ -286,7 +286,8 @@ if ( $t_mail_delete ) { - $p_mailbox_connection->deleteMsg( $p_i ); + if (!$p_mailbox_connection->deleteMsg( $p_i )) + echo 'deleteMsg failed'; } } @@ -423,17 +424,33 @@ { $v_mailaddress = array( 'username' => trim( $matches[ 1 ], '"\' ' ), + 'realname' => '', 'email' => trim( $matches[ 2 ] ), ); + + $t_mail_use_email_as_username = plugin_config_get( 'mail_use_email_as_username' ); + $t_mail_strip_domain_from_username = plugin_config_get( 'mail_strip_domain_from_username' ); + + if ($t_mail_use_email_as_username) + { + $v_mailaddress['realname'] = $v_mailaddress['username']; + $email = $v_mailaddress['email']; + + if ($t_mail_strip_domain_from_username) + $v_mailaddress['username'] = substr($email, 0, strpos($email, '@')); + else + $v_mailaddress['username'] = $email; + } } else { $v_mailaddress = array( - 'name' => '', + 'username' => '', + 'realname' => '', 'email' => $p_mailaddress, ); } - + return $v_mailaddress; } @@ -502,11 +519,15 @@ if ( user_is_name_valid( $t_reporter ) && user_is_name_unique( $t_reporter ) ) { - # notify the selected group a new user has signed-up + # notify the selected group a new user has signed-up and set realname if( user_signup( $t_reporter, $v_mailaddress[ 'email' ] ) ) { - email_notify_new_account( $t_reporter, $v_mailaddress[ 'email' ] ); + if (ON == config_get('enable_email_notification')) + email_notify_new_account( $t_reporter, $v_mailaddress[ 'email' ] ); + $t_reporter_id = user_get_id_by_name ( $t_reporter ); + if ($v_mailaddress['realname'] != '') + user_set_realname($t_reporter_id, $v_mailaddress['realname']); } } @@ -698,6 +719,7 @@ $t_resolved = config_get( 'bug_resolved_status_threshold' ); $t_status = bug_get_field( $t_bug_id, 'status' ); + config_set('email_receive_own', ON); if ( $t_resolved <= $t_status ) { # Reopen issue and add a bug note @@ -708,6 +730,8 @@ # Add a bug note bugnote_add( $t_bug_id, $t_description ); } + global $g_email_receive_own; + config_set('email_receive_own', $g_email_receive_own); } else { @@ -763,7 +787,10 @@ # Create the bug $t_bug_id = $t_bug_data->create(); + config_set('email_receive_own', ON); email_new_bug( $t_bug_id ); + global $g_email_receive_own; + config_set('email_receive_own', $g_email_receive_own); } # Add files diff --git a/lang/strings_english.txt b/lang/strings_english.txt index 7e60b90..2bfc623 100644 --- a/lang/strings_english.txt +++ b/lang/strings_english.txt @@ -25,6 +25,8 @@ $s_plugin_EmailReporting_mail_check_timer = 'How often should the mailboxes be c $s_plugin_EmailReporting_mail_use_reporter = 'Use one account for issues created by email'; $s_plugin_EmailReporting_mail_reporter = 'The account name for issues created by email'; $s_plugin_EmailReporting_mail_auto_signup = 'Signup new users automatically (possible security risk!, see documentation)'; +$s_plugin_EmailReporting_mail_use_email_as_username = 'Use email as username'; +$s_plugin_EmailReporting_mail_strip_domain_from_username = 'Strip domain name from username'; $s_plugin_EmailReporting_mail_fetch_max = 'How many emails per mailbox should be fetched every time this script is executed (see documentation)'; $s_plugin_EmailReporting_mail_add_complete_email = 'Add the complete email into the attachments'; $s_plugin_EmailReporting_mail_save_from = 'Write the sender of the message into the issue report'; diff --git a/pages/config.php b/pages/config.php index defac6d..b5fbe17 100644 --- a/pages/config.php +++ b/pages/config.php @@ -68,6 +68,14 @@ $t_config_array = array( 'type' => 'boolean', ), array( + 'name' => 'mail_use_email_as_username', + 'type' => 'boolean', + ), + array( + 'name' => 'mail_strip_domain_from_username', + 'type' => 'boolean', + ), + array( 'name' => 'mail_fetch_max', 'type' => 'integer', ), diff --git a/pages/config_edit.php b/pages/config_edit.php index b68e6a5..ceefe70 100644 --- a/pages/config_edit.php +++ b/pages/config_edit.php @@ -9,6 +9,8 @@ $f_mail_check_timer = gpc_get_int( 'mail_check_timer', 300 ); $f_mail_use_reporter = gpc_get_bool( 'mail_use_reporter', ON ); $f_mail_reporter = gpc_get_string( 'mail_reporter', 'Mail' ); $f_mail_auto_signup = gpc_get_bool( 'mail_auto_signup', OFF ); +$f_mail_use_email_as_username = gpc_get_bool('mail_use_email_as_username', OFF); +$f_mail_strip_domain_from_username = gpc_get_bool('mail_strip_domain_from_username', OFF); $f_mail_fetch_max = gpc_get_int( 'mail_fetch_max', 1 ); $f_mail_add_complete_email = gpc_get_bool( 'mail_add_complete_email', OFF ); $f_mail_save_from = gpc_get_bool( 'mail_save_from', OFF ); @@ -73,6 +75,14 @@ if( plugin_config_get( 'mail_auto_signup' ) != $f_mail_auto_signup ) { plugin_config_set( 'mail_auto_signup', $f_mail_auto_signup ); } +if( plugin_config_get( 'mail_use_email_as_username', false ) != $f_mail_use_email_as_username ) { + plugin_config_set( 'mail_use_email_as_username', $f_mail_use_email_as_username ); +} + +if( plugin_config_get( 'mail_strip_domain_from_username', false ) != $f_mail_strip_domain_from_username ) { + plugin_config_set( 'mail_strip_domain_from_username', $f_mail_strip_domain_from_username ); +} + if( plugin_config_get( 'mail_fetch_max' ) != $f_mail_fetch_max ) { plugin_config_set( 'mail_fetch_max', $f_mail_fetch_max ); } -- 1.7.0.2.msysgit.0 From 68bd57285282e4800e5b56b05fd7c2b93e597692 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 6 Apr 2010 14:24:08 +0200 Subject: [PATCH 4/4] Disable the signup email, it never finishes and prevents the rest of the code to work --- core/mail_api.php | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/mail_api.php b/core/mail_api.php index 3c7202a..407cca9 100644 --- a/core/mail_api.php +++ b/core/mail_api.php @@ -522,8 +522,8 @@ # notify the selected group a new user has signed-up and set realname if( user_signup( $t_reporter, $v_mailaddress[ 'email' ] ) ) { - if (ON == config_get('enable_email_notification')) - email_notify_new_account( $t_reporter, $v_mailaddress[ 'email' ] ); +// if (ON == config_get('enable_email_notification')) +// email_notify_new_account( $t_reporter, $v_mailaddress[ 'email' ] ); $t_reporter_id = user_get_id_by_name ( $t_reporter ); if ($v_mailaddress['realname'] != '') -- 1.7.0.2.msysgit.0