#!/bin/sh
# ====================[ imapsync.sh                        ]====================
# Migrate from a local IMAP server (Dovecot) to a remote IMAP server (Gmail).
#
# Note that, for Gmail, Gmail-internal folders (e.g., "All Mail", "Sent Mail")
# are "[Gmail]/"-prefixed when exposed to IMAP (e.g., "[Gmail]/All Mail",
# "[Gmail]/Sent Mail"), while all other user-created labels are not, except for
# the Gmail-internal "INBOX" folder, which has no such "[Gmail]/"-prefix.
imapsync \
  --host1 localhost      --user1 'leycec'           --passfile1 ~/bin/imapsync/local.pass \
  --host2 imap.gmail.com --user2 'leycec@gmail.com' --passfile2 ~/bin/imapsync/gmail.pass \
  --authmech1 PLAIN \
  --ssl2 --split2 256 --syncinternaldates \
  --exclude 'INBOX|Drafts|Sent|Trash|dead' \
  --sep1 '.' --sep2 '/' \
  --regextrans2 's~^\.~~' \
  --regextrans2 's~^read$~hole~' \
  --regextrans2 's~^read.not$~INBOX~' \
  --regextrans2 's~^sent$~[Gmail]/Sent Mail~' \
  --regextrans2 's~^sent.not$~[Gmail]/Drafts~'
#   --dry --justfolders
#   --debug --debugimap \
#   --include 'sent|read' \
#   --prefix2 '[Gmail]/' --exclude 'dead|hole' \
