-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.php
53 lines (53 loc) · 1.55 KB
/
sync.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
if (!@include_once(dirname(__FILE__) . '/data.php')) {
throw new Exception('No data.php exists. Please create a "data.php" file inside the "data" directory.');
}
if (empty($data)) {
throw new Exception("No data to sync.");
}
// Build the base command options.
$cmd_base = array();
if (isset($mode) && !empty($mode)) {
$cmd_base[$mode] = '';
}
$cmd_base['skipsize'] = '';
if (isset($debug) && $debug == TRUE) {
$cmd_base['debug'] = '';
}
$cmd_base['authmech1'] = 'PLAIN';
$cmd_base['port1'] = '143';
$cmd_base['port2'] = '993';
$cmd_base['authmech2'] = 'PLAIN';
$cmd_base['ssl2'] = '';
$cmd_base['noauthmd5'] = '';
print "--- START SYNC ---\r\n";
foreach ($data as $account) {
$cmd_account = array();
// Account options.
$cmd_account['host1'] = $account['host1'];
$cmd_account['user1'] = $account['user1'];
$cmd_account['password1'] = $account['password1'];
$cmd_account['host2'] = $account['host2'];
$cmd_account['user2'] = $account['user2'];
$cmd_account['password2'] = $account['password2'];
// Build the command string based on the options arrays.
$cmd = 'imapsync';
foreach (array_merge($cmd_base, $cmd_account) as $key => $value) {
if (empty($value)) {
$cmd .= ' --' . $key;
}
else {
$cmd .= ' --' . $key . ' ' . escapeshellarg($value);
}
}
// Print complete command if debug mode is enabled.
if (isset($debug) && $debug == TRUE) {
var_dump($cmd);
}
print ">> " . $account['user1'] . "\r\n";
// Run the command.
$result = shell_exec($cmd . ' >&1');
print $result;
}
print "\r\n--- END SYNC ---";
?>