Resolving Imapsync issues with Zimbra shared folders

While migrating mailboxes away from a Zimbra server using imapsync, I ran into several accounts which consistently failed with errors like:

Host1 folder 45/55 [INBOX/Some_Folder] Host1 Folder INBOX/Some_Folder: Could not select: * BYE zcs1.brewerscience.com Zimbra IMAP4rev1 server closing connection (4x)

I found the following in the Zimbra log around the same time:

2017-05-06 18:15:34,903 WARN [ImapServer-13] [name=username@domain.com;mid=285; ip=192.168.253.100;oip=10.0.50.6;via=192.168.253.100 (nginx/1.2.0-zimbra);ua=Zimbra/8.6.0_GA_1200;] imap – target account missing or not active; dropping connection

The accounts were active and otherwise appeared to be working properly. A Google search revealed nothing. The issue turned out to be that these users had mail folders shared to them from other accounts, and those accounts were either closed or had revoked the share. I had excluded these folders since they were shared and I didn’t want to copy them, but imapsync apparently still tried to access them. This issue seemed to happen the first time imapsync tried to access a revoked/closed shared folder and to every request that followed, even for normal folders.

The solution is to remove the shared folders from the account, after which imapsync works properly. You can do this by clicking on the folder name. Zimbra will prompt you to remove the folder.