84 lignes
2.6 KiB
Bash
Executable File
84 lignes
2.6 KiB
Bash
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
/**
|
|
+-----------------------------------------------------------------------+
|
|
| export-contacts.sh |
|
|
| |
|
|
| This script permit to export Roundcube user's address book in vCard |
|
|
| format. |
|
|
| |
|
|
| Copyright (C) 2018, Cliss XXI |
|
|
| Copyright (C) 2017, Easter-eggs |
|
|
| |
|
|
| Licensed under the GNU General Public License version 3 or |
|
|
| any later version with exceptions for skins & plugins. |
|
|
| See the LICENSE file for a full license statement. |
|
|
| |
|
|
+-----------------------------------------------------------------------+
|
|
| Author: Benjamin Renard <brenard@easter-eggs.com> |
|
|
| Author: Jerome Lebleu <contact@cliss21.com> |
|
|
+-----------------------------------------------------------------------+
|
|
*/
|
|
|
|
// Unset memory limit during the export
|
|
ini_set('memory_limit', -1);
|
|
|
|
require_once 'common.php';
|
|
|
|
function print_usage()
|
|
{
|
|
echo "Usage: export-contact.sh [options] username\n\n";
|
|
echo "Options:\n";
|
|
echo " -h, --host=domain Mail host (optional, e.g. example.org)\n";
|
|
echo " -o, --output=path Path to the output file\n";
|
|
echo " -v, --verbose Enable verbose mode\n";
|
|
echo " -d, --debug Enable debug mode\n";
|
|
}
|
|
|
|
// get arguments
|
|
$args = rcube_utils::get_opt(array(
|
|
'h' => 'host',
|
|
'o' => 'output',
|
|
'd' => 'debug:bool',
|
|
'v' => 'verbose:bool',
|
|
'h' => 'help:bool',
|
|
));
|
|
|
|
if ('help' == $_SERVER['argv'][1] || $args['help']) {
|
|
print_usage();
|
|
exit(0);
|
|
} elseif (empty($args[0])) {
|
|
echo "Missing required parameter.\n\n";
|
|
print_usage();
|
|
exit(1);
|
|
}
|
|
|
|
$username = trim($args[0]);
|
|
|
|
// define logging level
|
|
if ($args['debug']) {
|
|
set_log_level('DEBUG');
|
|
} elseif ($args['verbose']) {
|
|
set_log_level('INFO');
|
|
}
|
|
|
|
// check output file
|
|
$out = null;
|
|
if (!empty($args['output'])) {
|
|
$out = fopen($args['output'], 'w');
|
|
if (false === $out) {
|
|
raise_err("Fail to open output file!");
|
|
}
|
|
} else {
|
|
$out = $GLOBALS['args']['file'] ? STDOUT : STDERR;
|
|
}
|
|
|
|
$contacts = new rcmail_contacts_utils($username, $args['host']);
|
|
$contacts->export($out);
|
|
|
|
if (!empty($args['output'])) {
|
|
fclose($out);
|
|
}
|
|
|
|
?>
|