Moving to Kantoor
How to bring an existing mailbox, calendar and address book over to Kantoor.
Mail goes in over Kantoor's IMAP server with imapsync;
calendars and contacts go in over CalDAV and CardDAV with any DAV client or
with vdirsyncer. The examples use
example.com for your domain, old.example.net for the old provider and
mail.example.com for Kantoor.
Read What was and was not tested at the end before you rely on a command.
Before you start
- The mailbox must exist in Kantoor: the domain is attached on the admin Domains page and the user has a mailbox.
- IMAP must be switched on and reachable
(Installing Kantoor,
Mail clients). Check it first with
openssl s_client -connect mail.example.com:993. - In Settings, App passwords make two app passwords, one with the
imapscope and one with thedavscope, and give both an expiry date a few days away. They are shown once. Revoke them when the move is done. - If the mailbox has a quota, make it big enough for the whole old mailbox first (see Quota).
- Do not change the MX records yet. Mail keeps arriving at the old provider while you copy, and you copy once more at the end.
Mail with imapsync
imapsync copies one account at a time, one way, and does not make duplicates: it recognises a message it has copied before, so it can be run again and again.
Put each password in a file that only you can read, so it is not on the command line or in the shell history:
mkdir -p ~/move && cd ~/move
umask 077
printf '%s\n' 'the-old-password' > old.pass
printf '%s\n' 'the-kantoor-app-password' > new.pass
The examples run imapsync in Docker. The image is the author's own
(gilleslamiral/imapsync). --user makes the container read the password files
as you: its default user (nobody) cannot read a file that only you may read.
If you have imapsync installed, drop the first line of the command and use the
paths of your own password files in place of /secrets/.
1. Look at the folders first (changes nothing)
docker run --rm --user "$(id -u):$(id -g)" -v "$PWD:/secrets:ro" gilleslamiral/imapsync imapsync \
--host1 old.example.net --user1 ann@example.com --passfile1 /secrets/old.pass --ssl1 \
--host2 mail.example.com --user2 ann@example.com --passfile2 /secrets/new.pass --ssl2 \
--dry --justfolders --nofoldersizes
--dry makes imapsync do nothing for real, --justfolders leaves the
messages out, and --nofoldersizes skips the size count at the start. The
output lists each folder of the old account and the folder it would be copied
to in Kantoor.
--ssl1 and --ssl2 use implicit TLS, port 993 unless you add --port1 or
--port2 (use --port2 1993 if you reach Kantoor's own listener without a port
mapping). For STARTTLS on port 143 use --tls1 or --tls2 instead.
2. Fix the folder names
Kantoor has five fixed folders: INBOX, Sent, Drafts, Trash and Junk;
the four last are announced to clients with their special-use attribute, are
found by those names, and cannot be renamed or deleted. Any other folder is an
ordinary folder; the hierarchy delimiter is /. imapsync turns the old
server's delimiter into the new one by itself.
imapsync's --automap (on by default since its release 2.321) guesses a match
for the folders it knows as "Sent", "Junk", "Drafts", "All", "Archive" and
"Flagged". It does not list Trash, and a provider may call these folders
anything, so check the output of step 1 and force the ones that are wrong with
--f1f2 old=new (one-to-one, full folder names), added to the command:
--f1f2 'Deleted Items=Trash' --f1f2 'Sent Items=Sent' --f1f2 'Spam=Junk'
Leave out what you do not want with --exclude (a regular expression,
several alternatives with |):
--exclude '^\[Gmail\]/All Mail$|^Notes$'
Run step 1 again until the list is right.
3. Copy
Without --dry and --justfolders:
docker run --rm --user "$(id -u):$(id -g)" -v "$PWD:/secrets:ro" gilleslamiral/imapsync imapsync \
--host1 old.example.net --user1 ann@example.com --passfile1 /secrets/old.pass --ssl1 \
--host2 mail.example.com --user2 ann@example.com --passfile2 /secrets/new.pass --ssl2 \
--f1f2 'Deleted Items=Trash' --f1f2 'Sent Items=Sent' --f1f2 'Spam=Junk' \
--maxsize 26214400 --addheader --subscribed
--maxsize 26214400skips messages of 25 MiB or more (imapsync skips messages larger than or equal to the number). That is Kantoor's default limit for oneAPPEND; if you raisedKANTOOR_IMAP_MAX_MESSAGE_BYTES, use that number.--addheadergives a message without identifying headers aMessage-Id, so that a second run does not copy it again. It is mostly the Sent and Drafts folders that need it.--subscribedcopies the subscribed folders only. Leave it out to copy all of them. Subscription is carried over by default.- imapsync keeps the flags and the internal dates (it sets the internal date on the target the same as on the source by default).
Never add --delete2 or --delete2folders: they delete what is in Kantoor and
not in the old account.
If the old server is slow or you share its line, --maxbytespersecond 1000000
limits the average rate.
4. Copy again, switch, copy once more
Run the same command again: it copies only what is new and updates flags. When it runs cleanly, point the MX records of the domain at Karta (that part is Karta's, see Karta), wait until the old account stops receiving mail, and run the command a last time. Then check a few folders in the webmail and in a mail client, and revoke the app password.
Calendars and contacts
CalDAV and CardDAV are served at https://mail.example.com/dav/
(Calendar, contacts and tasks). The login
is the email address and the password the dav app password. Each user starts
with a calendar default (called "Calendar"), a task list tasks and an address
book default (called "Contacts").
With vdirsyncer
vdirsyncer reads from the old server and writes to Kantoor. A file
~/move/vdirsyncer.conf:
[general]
status_path = "~/move/status/"
[pair calendar]
a = "calendar_old"
b = "calendar_kantoor"
collections = [["calendar", "personal", "default"]]
conflict_resolution = "a wins"
[storage calendar_old]
type = "caldav"
url = "https://old.example.net/dav/"
username = "ann@example.com"
password.fetch = ["command", "cat", "/home/ann/move/old.pass"]
[storage calendar_kantoor]
type = "caldav"
url = "https://mail.example.com/dav/"
username = "ann@example.com"
password.fetch = ["command", "cat", "/home/ann/move/dav.pass"]
[pair contacts]
a = "contacts_old"
b = "contacts_kantoor"
collections = [["contacts", "default", "default"]]
conflict_resolution = "a wins"
[storage contacts_old]
type = "carddav"
url = "https://old.example.net/dav/"
username = "ann@example.com"
password.fetch = ["command", "cat", "/home/ann/move/old.pass"]
[storage contacts_kantoor]
type = "carddav"
url = "https://mail.example.com/dav/"
username = "ann@example.com"
password.fetch = ["command", "cat", "/home/ann/move/dav.pass"]Each entry of collections is [name, id on a, id on b]: the first of the old
account's calendars (its id is the last part of its URL; vdirsyncer discover
shows it) goes into Kantoor's default calendar. Write one line per calendar,
and use "tasks" as the id on b for a task list.
printf '%s\n' 'the-kantoor-dav-app-password' > ~/move/dav.pass
vdirsyncer --config ~/move/vdirsyncer.conf discover calendar
vdirsyncer --config ~/move/vdirsyncer.conf discover contacts
vdirsyncer --config ~/move/vdirsyncer.conf sync
vdirsyncer synchronises both ways: what you later delete in Kantoor is
deleted at the old server too on the next run, and the other way round. Run it
only for the move, and delete ~/move/status/ and the config when you are
done. conflict_resolution = "a wins" makes the old server win when both sides
changed the same item.
With a DAV client
Any client that talks to two accounts will do: add the old calendar and
Kantoor (https://mail.example.com, the discovery address that DAVx5, iOS,
macOS and Thunderbird use), and copy or drag the events and contacts from the
old into the new. Thunderbird can also import an exported .ics or .vcf file
into a Kantoor calendar or address book. Or let the old service export a file and
import it in the client of your choice. Check the counts afterwards.
Events with guests: read this first
Kantoor is a scheduling server. When an event is written in which you are the
ORGANIZER and there are ATTENDEEs elsewhere, Kantoor mails those guests an
invitation, just as if you had made the event today. Writing the old events in
bulk can therefore send a wave of invitations. (SCHEDULE-AGENT=CLIENT does not
stop this; the DAV library says it does not implement it.) Before you import,
strip the guest lines from the files you are going to write, for example from an
exported calendar.ics:
awk '/^(ORGANIZER|ATTENDEE)[;:]/ {skip=1; next} /^[ \t]/ && skip {next} {skip=0; print}' \
calendar.ics > calendar-no-guests.ics
The events keep their title, time, place and repeat rule; they lose the guest list. With vdirsyncer there is no such step: strip the guests at the source (export, strip and import the file) or move events that have guests by hand.
Limits
Folder names. Only INBOX, Sent, Drafts, Trash and Junk are
special; a differently named special folder arrives as an ordinary folder unless
you map it with --f1f2. The hierarchy delimiter is /. Gmail's virtual
folders ([Gmail]/All Mail, labels) show the same mail more than once; copy the
real folders and exclude All Mail.
Flags. The system flags \Seen, \Answered, \Flagged, \Deleted and
\Draft are kept, as are keywords of letters, digits and the characters
!#$&'+-._^`|~ up to 64 bytes. \Recent is dropped. A message with another
flag (a keyword with a space or a slash, an unknown \Flag) is refused with a
BAD or NO answer; imapsync's --regexflag can rewrite the flag list, and
--filterbuggyflags drops flags known to cause trouble. A copied \Deleted
flag stays: expunge in the old account first if you do not want those mail.
Message size. 25 MiB per message by default (see step 3). Larger messages
are skipped by --maxsize and have to be moved another way or left behind.
Large mailboxes. Mail written over IMAP lives only in Kantoor's database (Karta never sees it, and Karta's retention does not apply). A 20 GB mailbox is up to 20 GB more in Postgres (bodies are stored compressed) and in its backups. Plan the disk and the backups before you start. A first run on a big account takes hours. Kantoor allows 20 connections per client address, a login must finish within 60 seconds and an idle connection is closed after 30 minutes. If a run is cut off, run the same command again: messages already copied are recognised and skipped. Do not run several imapsync processes against the same mailbox at once.
Quota. A mailbox over its quota refuses an APPEND with
NO [OVERQUOTA]; imapsync reports each message it could not place. This is different from mail that arrives over quota, which is
accepted and held out of sight (not visible over IMAP, POP3 or the webmail)
until space is freed. Held mail also blocks further APPENDs until it has been
released, so a quota that was too small shows up twice. Raise the quota
(admin Domains page, per domain or per mailbox) before you start, run imapsync
again afterwards, and lower it later if you want.
DAV. One resource holds one event or contact (one UID): a .ics file with
many events has to be split before a plain PUT, which is what the clients and
vdirsyncer do. The body of a DAV request is limited to 6 MiB. Tasks go in a
task list (VTODO only), not into a calendar of events. There are no DAV quotas.
What was and was not tested
Tested while writing this page:
- The imapsync options used above (
--host1,--user1,--passfile1,--ssl1,--tls1,--port1and the same for host 2,--dry,--justfolders,--nofoldersizes,--f1f2,--exclude,--maxsize,--addheader,--subscribed,--maxbytespersecond,--regexflag,--filterbuggyflags,--delete2,--delete2folders) against the documentation of imapsync 2.326 (imapsync --help, from thegilleslamiral/imapsyncimage). The step 1 command and a command with the step 3 options were run in that image against a server that does not exist: imapsync accepted every option and got as far as connecting, and read the password files (with--user; asnobodyit could not). An option it does not know is reported (Found 1 supplementary arguments), which is how a wrong spelling shows. imapsync's spelling for subscribing everything is--subscribeall, not--subscribe_all. - The vdirsyncer configuration with vdirsyncer 0.21.0: the file is read, the
password.fetchcommand runs anddiscovertries to connect. - The
awkcommand on a file with foldedATTENDEElines. - From Kantoor's code and tests: the folder rules, the flag rules, the
APPENDsize,OVERQUOTAonAPPENDand held mail on delivery, that anAPPENDed message is stored only in Kantoor, and that writing an event with outside guests over DAV sends them an invitation (also withSCHEDULE-AGENT=CLIENT).
Tested since, against the authors' live Kantoor (13 November 2026, once):
vdirsyncer 0.21.0 ran discover and a two-way sync of every calendar, the
task list and the address book between a local store and Kantoor. A local
event, task and card were uploaded, a server edit came down, and local deletes
were carried over. The other side was a local store, not another provider's
server.
Not tested: a complete imapsync run against a Kantoor server, a vdirsyncer run from another provider's server into Kantoor, the import of a file by a particular DAV client, and the behaviour of any particular old provider.