Skip to content

Commit

Permalink
lib-storage: add mail_user_plugin_getenv_bool
Browse files Browse the repository at this point in the history
New API will check boolean-like env setting OR its exsitence.

Function returns FALSE when:
* Read out a null string,
"Or" * String starts with any letter in set {'N', 'n', 'F','f','0'}

To keep downward compatibility, For other cases including an empty
string, function returns TRUE.
  • Loading branch information
Baofeng Wang authored and GitLab committed May 3, 2016
1 parent 88bcf81 commit 527c2b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lib-storage/mail-user.c
Expand Up @@ -417,6 +417,25 @@ bool mail_user_is_plugin_loaded(struct mail_user *user, struct module *module)
return ret;
}

bool mail_user_plugin_getenv_bool(struct mail_user *user, const char *name)
{
const char *env = mail_user_set_plugin_getenv(user->set, name);

if (env == NULL)
return FALSE;
switch (env[0]) {
case 'n':
case 'N':
case '0':
case 'f':
case 'F':
return FALSE;
}

//any other value including empty string will be treated as TRUE.
return TRUE;
}

const char *mail_user_plugin_getenv(struct mail_user *user, const char *name)
{
return mail_user_set_plugin_getenv(user->set, name);
Expand Down
1 change: 1 addition & 0 deletions src/lib-storage/mail-user.h
Expand Up @@ -146,6 +146,7 @@ void mail_user_set_get_temp_prefix(string_t *dest,
bool mail_user_is_plugin_loaded(struct mail_user *user, struct module *module);
/* If name exists in plugin_envs, return its value. */
const char *mail_user_plugin_getenv(struct mail_user *user, const char *name);
bool mail_user_plugin_getenv_bool(struct mail_user *user, const char *name);
const char *mail_user_set_plugin_getenv(const struct mail_user_settings *set,
const char *name);

Expand Down

0 comments on commit 527c2b0

Please sign in to comment.