Reputation: 21
I need to move messsage from an IMAP folder to another IMAP folder (of the same account) via Java.
I work on Gmail and the oauth login.
I use the java imap mail client: i fetch the message with sourceFolder.getMessages() and then I call the
method destFolder.appendMessages(sourceFolder.getMessages())
or addMessages
: the problem born when the number of the messages to move is too big. I had the to move 8000 mail and the login session expire after several minutes that the procedure has started to add but has not yet finished.
It process about 1 message for second.I use the oauth login
Upvotes: 2
Views: 2868
Reputation: 9377
The IMAP MOVE
Extension, specified in RFC 6851 from January 2013, introduced:
two new commands, MOVE and UID MOVE, that are used to move messages from one mailbox to another.
It is supported by JavaEE's package com.sun.mail.imap
:
MOVE Support
The IMAP MOVE extension (RFC 6851) is supported via the
IMAPFolder
methodsmoveMessages
andmoveUIDMessages
.
See also:
IMAPFolder.moveMessages
MOVE
commandUpvotes: 0
Reputation: 10985
The normal way to do this is to use server copy and delete. In IMAP syntax, the copy command is tag COPY sequence mailboxname
. Like: a000 COPY 1:* INBOX.Saved
, would copy all messages to my Saved subfolder.
The method you're doing requires each message to be downloaded then to reupload it.
Upvotes: 1