35 --dry-run dry run ($opt_dry) |
35 --dry-run dry run ($opt_dry) |
36 --skip skipp missing mailboxes ($opt_skip) |
36 --skip skipp missing mailboxes ($opt_skip) |
37 --logdir=s directory where logfiles will go to ($opt_logdir) |
37 --logdir=s directory where logfiles will go to ($opt_logdir) |
38 --maxage=i synchronize only mails younger than $(opt_maxage) |
38 --maxage=i synchronize only mails younger than $(opt_maxage) |
39 --help this help text |
39 --help this help text |
|
40 --folders only sync folders |
|
41 --acls fix ACLs |
40 # |
42 # |
41 |
43 |
42 use strict; |
44 use strict; |
43 use warnings; |
45 use warnings; |
44 use Smart::Comments; |
46 use Smart::Comments; |
60 |
62 |
61 my $opt_dry = 0; |
63 my $opt_dry = 0; |
62 my $opt_skip = 0; |
64 my $opt_skip = 0; |
63 my $opt_logdir = "./imapsync-log/"; |
65 my $opt_logdir = "./imapsync-log/"; |
64 my $opt_maxage = 0; |
66 my $opt_maxage = 0; |
|
67 my $opt_folders = 0; |
|
68 my $opt_acls = 0; |
65 |
69 |
66 GetOptions( |
70 GetOptions( |
67 "dry-ryn" => \$opt_dry, |
71 "dry-ryn" => \$opt_dry, |
68 "skip" => \$opt_skip, |
72 "skip" => \$opt_skip, |
|
73 "folders" => \$opt_folders, |
|
74 "acls" => \$opt_acls, |
69 "logdir=s" => \$opt_logdir, |
75 "logdir=s" => \$opt_logdir, |
70 "maxage=i" => \$opt_maxage, |
76 "maxage=i" => \$opt_maxage, |
71 ) or die eval "\"$usage\""; |
77 ) or die eval "\"$usage\""; |
72 |
78 |
|
79 if ($opt_acls) { |
|
80 system("su - cyrus -c '/usr/sbin/ctl_mboxlist -d' > cyrus_mbox_acls.txt"); |
|
81 #system('cat cyrus_mbox_acls.txt | sed s/root@[^\t]*/root/ | su - cyrus -c "/usr/sbin/ctl_mboxlist -u"'); |
|
82 system('cat cyrus_mbox_acls.txt | sed \'s/root@[^\t]*/root/\' | su - cyrus -c "/usr/sbin/ctl_mboxlist -u"'); |
|
83 |
|
84 exit 0; |
|
85 } |
73 |
86 |
74 ### connection to mysql account database |
87 ### connection to mysql account database |
75 my $dbh = DBI->connect($dsn, $db_user, $db_pass, { RaiseError => 1} ) or |
88 my $dbh = DBI->connect($dsn, $db_user, $db_pass, { RaiseError => 1} ) or |
76 die "$ME: cannot conncet to mysql: $!\n"; |
89 die "$ME: cannot conncet to mysql: $!\n"; |
77 |
90 |
105 ### processing mailbox: $mailbox |
118 ### processing mailbox: $mailbox |
106 my $imapsync_options = ""; |
119 my $imapsync_options = ""; |
107 $imapsync_options .= " --dry" if $opt_dry; |
120 $imapsync_options .= " --dry" if $opt_dry; |
108 $imapsync_options .= " --maxage=$opt_maxage" if $opt_maxage > 0; |
121 $imapsync_options .= " --maxage=$opt_maxage" if $opt_maxage > 0; |
109 |
122 |
110 my $logfile = "$opt_logdir/$mailbox.log"; |
123 my $logfile = ">> $opt_logdir/$mailbox.log"; |
|
124 unlink("opt_logdir/$mailbox.log"); |
111 |
125 |
112 my $cmd = sprintf( "imapsync %s --ssl1 --ssl2 --subscribe" |
126 my $cmd = <<EOF; |
113 . " --host1 %s --host2 %s" |
127 ./imapsync --ssl1 --ssl2 --prefix2 '' --sep2 / --host1 $imap_from_host --host2 $imap_to_host |
114 . " --user1 %s --user2 %s --password1 %s --password2 %s > %s", |
128 --subscribe --user1 $mailbox --user2 $mailbox --authuser1 root --authuser2 root |
115 $imapsync_options, $imap_from_host, $imap_to_host, |
129 --password1 x --password2 x |
116 $mailbox, $mailbox, $password_of_account_{$mailbox}, |
130 --exclude 'Shared Folders' --exclude 'Other Users' |
117 $password_of_account_{$mailbox}, |
131 EOF |
118 $logfile); |
132 $cmd =~ s/\n/ /g; |
119 |
133 |
120 system($cmd); |
134 if ($opt_folders) { |
121 warn "$ME: migration of mailbox $mailbox failed, see $logfile\n" if ($? != 0); |
135 # only INBOX |
|
136 system("$cmd --syncacls --justfolders --folderrec INBOX $logfile"); |
|
137 warn "$ME: migration of mailbox $mailbox failed, see $logfile\n" if ($? != 0); |
|
138 |
|
139 # now the remaining mailboxes |
|
140 system("$cmd --syncacls --justfolders $logfile"); |
|
141 warn "$ME: migration of mailbox $mailbox failed, see $logfile\n" if ($? != 0); |
|
142 } else { |
|
143 system("$cmd $logfile"); |
|
144 warn "$ME: migration of mailbox $mailbox failed, see $logfile\n" if ($? != 0); |
|
145 } |
122 } |
146 } |
123 |
147 |
124 # vim: sw=4 sts=4 aw |
148 # vim: sw=4 sts=4 aw |