|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
在ruby里才是一切皆对象。当然我不并不是很了解ruby,但是ruby确实是将语法简化得很好。server
QuestionHowdoyoudeleteamessagefromthemailserver?
DerivedfromAnunansweredquestionoriginallyposedbyBenjaminAlejandroRodriguezRengifo
TopicsJava:API:JavaMail:IMAP4,Java:API:JavaMail:POP3
AuthorJohnZukowski
Created23-Feb-00Modified25-Jul-00
Answer
ThebasicprocessofdeletingamessageistocallsetFlag()onthemessageandsettheFlags.Flag.DELETEDflagtotrue.
message.setFlag(Flags.Flag.DELETED,true);
Then,whenyouclosethefolder,deletedmessageswillberemoved.
Besuretoopenthefolderforread/writeaccess:
folder.open(Folder.READ_WRITE);
Thefollowingprogramdemonstrateslistingeachmessageinthefolderandpromptingfordeletion:
importjava.io.*;
importjavax.mail.*;
importjavax.mail.internet.*;
publicclassDeleteMessageExample{
publicstaticvoidmain(Stringargs[])throwsException{
Stringhost=args[0];
Stringusername=args[1];
Stringpassword=args[2];
//Getsession
Sessionsession=Session.getInstance(
System.getProperties(),null);
//Getthestore
Storestore=session.getStore("pop3");
store.connect(host,username,password);
//Getfolder
Folderfolder=store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
BufferedReaderreader=newBufferedReader(
newInputStreamReader(System.in));
//Getdirectory
Messagemessage[]=folder.getMessages();
for(inti=0,n=message.length;i<n;i++){
System.out.println(i+":"+message[i].getFrom()[0]
+" "+message[i].getSubject());
System.out.println("Doyouwanttodeletemessage?[YEStodelete]");
Stringline=reader.readLine();
//Markasdeletedifappropriate
if("YES".equals(line)){
message[i].setFlag(Flags.Flag.DELETED,true);
}
}
//Closeconnection
folder.close(true);
store.close();
}
}
Youcanalsoexpunge()theFolder.However,thePOP3serverfromSundoesnotsupportthisoperation.
关于第二点:俺问问你,如果是企业级项目的话,诸如RMI,EJB,等一些关键技术,这些难道都不需要学么?如果光是使用jsp,servlet,javabean的话。 |
|