Two scripts I have used in the past.

  1. http://edoceo.com/creo/imap-move
  2. https://github.com/edoceo/imap-move