Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Move single email message from inbox to another folder

Thread view: 
Edwinah63 - 13 Sep 2007 23:47 GMT
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[i], 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!)
Joshua Cranmer - 14 Sep 2007 01:25 GMT
> Hi everyone,
>
[quoted text clipped - 4 lines]
>
> 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[i], SomeOtherFolder);

One message can be trivially converted into an array:
Message uniMessage[] = new Messages[] {messages[i]};

> Message messages[] = inboxFolder.getMessages();
> for (int i=0, n=messages.length; i<n; i++)
[quoted text clipped - 9 lines]
>
> }

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.

Signature

Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.