Move single email message from inbox to another folder

E

Edwinah63

Hi everyone,

I would like some code to move a SINGLE email message from the inbox
to another one.

I have code to move a group of them:

folder.copyMessage(messages, SomeOtherFolder);

but what I would like to do is:

folder.copyMessage(messages, SomeOtherFolder);

the idea being that as I iterate through each message, I can file them
away in the appropriate folder.

code snippet:

//logon to pop3 server
//connect to store
//open inbox folder

Message messages[] = inboxFolder.getMessages();
for (int i=0, n=messages.length; i<n; i++)
{
//do some code to process subject line, body, sender etc
//save message body and any attachments to database
//then move it to the correct folder

if (SaveFlag)
//move this message to the SaveSuccessful folder
else
//move it to SaveFailed folder

}

//close everything and clean up

Any and all help appreciated.

Edwinah63

(BTW searching google for this info yesterday returned an error that I
was trying to hack the system!)
 
J

Joshua Cranmer

Edwinah63 said:
Hi everyone,

I would like some code to move a SINGLE email message from the inbox
to another one.

I have code to move a group of them:

folder.copyMessage(messages, SomeOtherFolder);

copyMessage implies that the function copies *a* message, not *many*
messages.
but what I would like to do is:

folder.copyMessage(messages, SomeOtherFolder);


One message can be trivially converted into an array:
Message uniMessage[] = new Messages[] {messages};
Message messages[] = inboxFolder.getMessages();
for (int i=0, n=messages.length; i<n; i++)
{
//do some code to process subject line, body, sender etc
//save message body and any attachments to database
//then move it to the correct folder

if (SaveFlag)
//move this message to the SaveSuccessful folder
else
//move it to SaveFailed folder

}

A better tactic would be to keep two lists:
LinkedList<Message> successful = new LinkedList<Message>();
LinkedList<Message> failed = new LinkedList<Message>();
for (Message m : messages) {
if (saveFlag)
successful.add(m);
else
failed.add(m);
}
folder.copyMessages(successful.toArray(new Message[0]));
folder.copyMessages(failed.toArray(new Message[0]));
(BTW searching google for this info yesterday returned an error that I
was trying to hack the system!)

ERROR: Does not compute.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top