#requires -Version 5.1 <# .SYNOPSIS Runs imapsync (via the upstream gilleslamiral/imapsync image) for every account in a migration accounts.csv, copying mail from docker-mailserver to Stalwart. #> param( [Parameter(Mandatory = $true)][string]$CsvPath, [Parameter(Mandatory = $true)][string]$SourceHost, [Parameter(Mandatory = $true)][string]$DestHost, [int]$SourcePort = 993, [int]$DestPort = 993, [switch]$DryRun ) $rows = Import-Csv -Path $CsvPath $missing = $rows | Where-Object { -not $_.old_password -or -not $_.new_password } if ($missing) { throw "accounts.csv has $($missing.Count) row(s) missing old_password or new_password. Fill them in before syncing." } foreach ($row in $rows) { Write-Host "==> Syncing $($row.email)" $dockerArgs = @( "run", "--rm", "gilleslamiral/imapsync", "imapsync", "--host1", $SourceHost, "--port1", $SourcePort, "--ssl1", "--user1", $row.email, "--password1", $row.old_password, "--host2", $DestHost, "--port2", $DestPort, "--ssl2", "--user2", $row.email, "--password2", $row.new_password, "--automap", "--syncinternaldates", "--skipcrossduplicates", "--no-modulesversion" ) if ($DryRun) { $dockerArgs += "--dry" } docker @dockerArgs if ($LASTEXITCODE -ne 0) { Write-Warning "imapsync exited with code $LASTEXITCODE for $($row.email)" } }