?? messageforward.java
字號(hào):
package fengyun.Fastmail.beans;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.activation.*;
import fengyun.Fastmail.Maildir.MaildirStore;import fengyun.Fastmail.Maildir.MaildirFolder;import fengyun.Fastmail.Maildir.MaildirMessage;
public class MessageForward {
private static BeansConstants CONST = BeansConstants.getInstance();
private String MessageID = null;
private String Userid = null;
private Vector vAttach = null;
public MessageForward(HttpServletRequest request) throws MessagingException,IOException{
MessageID = request.getParameter(CONST.messageid);
String folderid = request.getParameter(CONST.folderid);
HttpSession httpsession = request.getSession(false);
if (folderid == null || MessageID == null || httpsession == null) {
throw new MessagingException("HTTPREQUEST ERROR");
}
Userid = (String)httpsession.getAttribute(CONST.FastmailUserid);
FolderView folderview = (FolderView)httpsession.getAttribute(CONST.FastmailFolderView);
if (folderview == null) {
throw new MessagingException("FOLDERVIEW ERROR");
}
int FolderIndex = Integer.parseInt(folderid);
folderid = folderview.folderlist.getFolderid(FolderIndex);
vAttach = (Vector)httpsession.getAttribute(CONST.FastmailAttach);
if (vAttach == null) { vAttach = new Vector();
httpsession.setAttribute(CONST.FastmailAttach,vAttach); } else { for(int i = 0; i < vAttach.size();i++) {
Attachment ai = (Attachment)vAttach.get(i);
ai.setAttached(false);
} } MaildirStore store = (MaildirStore)httpsession.getAttribute(CONST.FastmailStore);
MaildirFolder folder = (MaildirFolder)store.getFolder(folderid);
MaildirMessage mm = (MaildirMessage) folder.getMessage(MessageID);
if (mm.hasAttachment()) {
getAttachment(mm);
} } private void getAttachment(MaildirMessage mm) throws MessagingException,IOException { Object o = mm.getContent();
if (!(o instanceof Multipart)) { throw new MessagingException("NO ATTACHMENT IN THIS MESSAGE");
} Multipart mp = (Multipart)o; int count = mp.getCount();
BodyPart bp = null;
for(int i=0;i<count;i++) {
if (mp.getBodyPart(i)!=null) { dumpPart(mp.getBodyPart(i));
}
}
} /**
* DumpPart
* @param p Part
*/
private int level = 0;
private void dumpPart(Part p) throws MessagingException,IOException {
if(p==null) return;
if (p.isMimeType("multipart/*")) {
Multipart mp = null;
mp = (Multipart)p.getContent();
if (mp == null) return;
level++;
int count = mp.getCount();
for (int i = 0; i < count; i++) {
dumpPart((Part)mp.getBodyPart(i));
}
level--;
}
else if (p instanceof BodyPart && p!=null) {
if (p.getFileName() !=null && !p.getFileName().equals("")) {
Save((BodyPart)p);
}
}
}
private void Save(BodyPart bp) throws MessagingException,IOException{
String strFileName = bp.getFileName();
if (strFileName != null && strFileName.length() > 0) {
for(int i = 0; i < vAttach.size();i++) {
Attachment ai = (Attachment) vAttach.get(i);
if (ai.getFullName().equals(MessageID + "/" + strFileName)) {
ai.setAttached(true);
return;
}
}
Attachment cInfo = new Attachment();
cInfo.setUpload(false);
cInfo.setAttached(true);
cInfo.setContentType(bp.getContentType());
cInfo.setFileName(strFileName);
cInfo.setFullName(MessageID + "/" + strFileName);
String tmpFullFileName = CONST.attachmentpool + File.separator + System.currentTimeMillis()/1000 +
";" + Userid + ";" + strFileName;
File tmpFile = new File(tmpFullFileName);
if (!tmpFile.exists()) {
cInfo.setTempAbsolute(tmpFullFileName);
FileOutputStream fos = new FileOutputStream(tmpFile);
BufferedInputStream bis = new BufferedInputStream(bp.getInputStream());
byte[] cByte = new byte[1024];
int read = 0;
int size = 0;
while(true) {
read = bis.read(cByte);
if(read==-1) break;
size += read;
fos.write(cByte,0,read);
}
bis.close();
fos.close();
cInfo.setSize(size);
}
vAttach.addElement(cInfo);
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -