1 package SnowMailClient.view.html; 2 3 import SnowMailClient.model.multipart.*; 4 import snow.utils.storage.*; 5 import SnowMailClient.*; 6 import SnowMailClient.html.*; 7 8 import java.util.*; 9 import java.io.*; 10 11 20 public class HTMLFromMIME 21 { 22 MimeTreeModel mimeTree; 23 String htmlContent; 24 25 public HTMLFromMIME(MimeTreeModel mimeTree) throws Exception 26 { 27 this.mimeTree = mimeTree; 28 29 MimePart part = mimeTree.getFirstHTMLTextPart(); 30 if(part==null) throw new Exception ("No HTML part !"); 31 htmlContent = part.getBodyAsText(); 32 33 String cont = htmlContent; 34 36 37 resolveLinks(); 38 39 } 41 42 public String getHTMLCodeWithLocalizedLinks() 43 { 44 return htmlContent; 45 } 46 47 48 53 private void resolveLinks() throws Exception 54 { 55 Vector<CIDLink> cids = new Vector<CIDLink>(); 56 String contUP = this.htmlContent.toUpperCase(); 57 int pos = -5; 58 while(true) 59 { 60 pos = contUP.indexOf("\"CID:", pos+5); 61 if(pos==-1) break; 63 int posEnd = contUP.indexOf("\"", pos+4); 64 if(posEnd==-1) 65 { 66 throw new Exception ("Bad content-id syntax, no closing \" found."); 67 } 68 69 String cid = contUP.substring(pos+5, posEnd); 70 MimePart mp = mimeTree.getPartWithID("<"+cid+">"); 71 if(mp!=null) 72 { 73 CIDLink cl = new CIDLink(cid, pos, mp); 74 cids.add(cl); 75 } 77 else 78 { 79 System.out.println("Part not found, CID= "+cid); 81 } 82 } 83 84 for(int i=cids.size()-1; i>=0; i--) 86 { 87 CIDLink cl = cids.elementAt(i); 88 int start = cl.getPosInSource()+1; 89 int end = start+cl.CID.length()+4; 90 htmlContent = 91 htmlContent.substring(0,start) 92 + "file:"+cl.getAbsolutePath() 93 + htmlContent.substring(end); 94 } 95 96 98 } 99 100 101 104 106 } | Popular Tags |