+++ This bug was initially created as a clone of Bug #1580480 +++
In Bug 1580480 comment 25 I list some issues with the current dynamic chunk size adjustment method. The attached diff shows the suggested improvements to address them that I have tested.
This enables dynamic adjustment for all possible chunking conditions. It also converges faster on the optimal chunk size by doubling or halving the current chunks size instead of just adding or subtracting 8192.
Note: To slow down the network interface so that decrease in chunk size occurs dynamically, a script such as this is helpful: https://github.com/ModusCreateOrg/slow. Also, the primary slowdown needs to occur at the server (in my case Dovecot) so that fetched data is slowed down.