it is correct that the quota calculation is done by Dovecot.
I think the reason that Dovecot forbids userA to copy messages to a folder of userB is that Dovecot cannot know whom the messages in userBs mailbox “belong” to. Thus it calculates:
20085 + 39963 > 25600 → over quota.
When calculating a users quota Dovecot adds up all used storage that userA has access to - per namespace. It has two configuration entries for the private namespace:
/etc/dovecot/conf.d/90-quota.conf: quota_rule = *:storage=0 # no quota by default, will be overwritten per-user from LDAP
/etc/dovecot/conf.d/90-quota.conf: quota_rule2 = Trash:storage=+100M # for clients that do move-to-trash before deleting
You could add a dedicated rule for the shared mailbox to
/etc/dovecot/local.conf that should look like this:
quota_rule3 = INBOX/myshared:storage=+2000M
That should allow users to store 2GB more emails, when using a folder with that name. Completely untested btw.