diff --git a/config.inc.php.dist b/config.inc.php.dist index 2cf06fc..40d1c09 100644 --- a/config.inc.php.dist +++ b/config.inc.php.dist @@ -164,6 +164,19 @@ $config['identity_from_directory_exclude_delete_unmanaged_regex'] = ''; $config['identity_from_directory_update_signatures'] = true; +// Switch for signature creation on missing signatures +// +// true: Create signatures only if the corresponding identity currently has no +// signature (empty). This allows users to customize their signature after the +// initial creation without it being overwritten on subsequent logins. +// +// false: Do not create signatures if signature updates are disabled. +// +// Note: If $config['identity_from_directory_update_signatures'] is true, then +// signatures are overwritten on each login regardless of this option. +$config['identity_from_directory_create_signatures'] = false; + + // Signature templates // // You can use each key from $config['identity_from_directory_ldap']['fieldmap'] diff --git a/identity_from_directory.php b/identity_from_directory.php index 3f42579..935a473 100644 --- a/identity_from_directory.php +++ b/identity_from_directory.php @@ -139,6 +139,7 @@ public function login_after($args) // get config and other data needed for further processing $ldap_config = (array) $this->rc->config->get('identity_from_directory_ldap'); $update_signatures = (bool) $this->rc->config->get('identity_from_directory_update_signatures'); + $create_signatures = (bool) $this->rc->config->get('identity_from_directory_create_signatures'); $use_html_signature = (bool) $this->rc->config->get('identity_from_directory_use_html_signature'); $wash_html_signature = (bool) $this->rc->config->get('identity_from_directory_wash_html_signature'); if ($use_html_signature) { @@ -178,7 +179,26 @@ public function login_after($args) 'organization' => (array_key_exists('organization', $user_data) ? $user_data['organization'] : ''), ]; + // Decide whether to set/overwrite the signature + // - update_signatures: always overwrite + // - create_signatures: set only if the current identity has an empty signature + $should_set_signature = false; if ($update_signatures) { + $should_set_signature = true; + } elseif ($create_signatures) { + if ($identity_id === 0) { + // New identity => signature is missing + $should_set_signature = true; + } elseif (method_exists($this->rc->user, 'get_identity')) { + $existing_identity = $this->rc->user->get_identity($identity_id); + if (is_array($existing_identity) && array_key_exists('signature', $existing_identity)) { + $existing_signature = (string) $existing_identity['signature']; + $should_set_signature = (trim($existing_signature) === ''); + } + } + } + + if ($should_set_signature) { // copy signature template $signature = $signature_template;