How to copy messages between mailboxes?

Bron Gondwana brong at fastmail.fm
Wed Feb 25 18:16:40 EST 2009


On Wed, Feb 25, 2009 at 05:45:25PM -0500, Jason Voorhees wrote:
> Hi people:
> 
> I'm trying to create a script to copy "certain" messages from a
> mailbox of user A to mailbox of user B. These are the steps I have in
> mind:
 
Wrong steps.  That's not a good way to do it.

> # mkdir /var/spool/imap/a/user/B/Recent
> # cd /var/spool/imap/a/user/A
> # cp 234. 235. 236. Drafts/12* /var/spool/imap/a/user/B/Recent
> # chown -R cyrus:mail /var/spool/imap/a/user/B/Recent
> # su cyrus -c '/usr/lib/cyrus-imapd/reconstruct -r user/B'

Use IMAP.

a) Connect as an admin (with permissions on both user.A and user.B)

b) CREATE user.B.Recent

c) SELECT user.A
d) UID COPY 234,235,236 user.B.Recent

e) SELECT user.A.Drafts
f) UID COPY 12:* user.B.Recent

------------

Much cleaner, and you get all the locking goodness of doing it the
RIGHT way.

An alternative to being admin is just adding read ACLs for user
B on user A's folders (as user A), then logging in as user B and
doing these steps.

You can use any IMAP client library.  We use Perl Mail::ImapTalk,
but whatever language you're familiar with is fine.

Bron.


More information about the Info-cyrus mailing list