diff --git a/plugins/libkolab/bin/modcache.sh b/plugins/libkolab/bin/modcache.sh index 869edf09..cac2bf09 100755 --- a/plugins/libkolab/bin/modcache.sh +++ b/plugins/libkolab/bin/modcache.sh @@ -55,6 +55,11 @@ $action = $opts[0]; $rcmail = rcube::get_instance(rcube::INIT_WITH_DB | rcube::INIT_WITH_PLUGINS); +// Make --host argument optional where the default_host is a simple string +if (empty($opts['host'])) { + $opts['host'] = imap_host(); +} + // connect to database $db = $rcmail->get_dbh(); $db->db_connect('w'); @@ -232,3 +237,23 @@ function authenticate(&$opts) return $auth['valid']; } +function imap_host() +{ + global $rcmail; + + $default_host = $rcmail->config->get('default_host'); + + if (is_array($default_host)) { + $key = key($default_host); + $imap_host = is_numeric($key) ? $default_host[$key] : $key; + } + else { + $imap_host = $default_host; + } + + // strip protocol prefix + $uri = parse_url($imap_host); + if (!empty($uri['host'])) { + return $uri['host']; + } +} diff --git a/plugins/libkolab/bin/randomcontacts.sh b/plugins/libkolab/bin/randomcontacts.sh index 3fb496d7..dc2bbb52 100755 --- a/plugins/libkolab/bin/randomcontacts.sh +++ b/plugins/libkolab/bin/randomcontacts.sh @@ -31,7 +31,7 @@ require_once INSTALL_PATH . 'program/include/clisetup.php'; function print_usage() { print "Usage: randomcontacts.sh [OPTIONS] USERNAME FOLDER\n"; - print "Create random contact that for then given user in the specified folder.\n"; + print "Create random contact for a given user in a specified folder.\n"; print "-n, --num Number of contacts to be created, defaults to 50\n"; print "-h, --host IMAP host name\n"; print "-p, --password IMAP user password\n"; @@ -53,11 +53,8 @@ $rcmail = rcube::get_instance(rcube::INIT_WITH_DB | rcube::INIT_WITH_PLUGINS); $rcmail->plugins->load_plugins(array('libkolab')); ini_set('display_errors', 1); - if (empty($opts['host'])) { - $opts['host'] = $rcmail->config->get('default_host'); - if (is_array($opts['host'])) // not unique - $opts['host'] = null; + $opts['host'] = imap_host(); } if (empty($opts['username']) || empty($opts['folder']) || empty($opts['host'])) { @@ -176,3 +173,24 @@ function random_string($len) return rtrim($str); } + +function imap_host() +{ + global $rcmail; + + $default_host = $rcmail->config->get('default_host'); + + if (is_array($default_host)) { + $key = key($default_host); + $imap_host = is_numeric($key) ? $default_host[$key] : $key; + } + else { + $imap_host = $default_host; + } + + // strip protocol prefix + $uri = parse_url($imap_host); + if (!empty($uri['host'])) { + return $uri['host']; + } +} diff --git a/plugins/libkolab/bin/readcache.sh b/plugins/libkolab/bin/readcache.sh index ddc30e7f..56de7aea 100755 --- a/plugins/libkolab/bin/readcache.sh +++ b/plugins/libkolab/bin/readcache.sh @@ -48,17 +48,7 @@ $imap_host = $opts['host']; $rcmail = rcube::get_instance(rcube::INIT_WITH_DB | rcube::INIT_WITH_PLUGINS); if (empty($imap_host)) { - $default_host = $rcmail->config->get('default_host'); - if (is_array($default_host)) { - list($k,$v) = each($default_host); - $imap_host = is_numeric($k) ? $v : $k; - } - else { - $imap_host = $default_host; - } - - // strip protocol prefix - $imap_host = preg_replace('!^[a-z]+://!', '', $imap_host); + $imap_host = imap_host(); } if (empty($folder) || empty($imap_host)) { @@ -145,3 +135,25 @@ while ($result && ($sql_arr = $db->fetch_assoc($result))) { print "----------------------------------------------------------------------------------\n"; echo "Done.\n"; + + +function imap_host() +{ + global $rcmail; + + $default_host = $rcmail->config->get('default_host'); + + if (is_array($default_host)) { + $key = key($default_host); + $imap_host = is_numeric($key) ? $default_host[$key] : $key; + } + else { + $imap_host = $default_host; + } + + // strip protocol prefix + $uri = parse_url($imap_host); + if (!empty($uri['host'])) { + return $uri['host']; + } +}