1 package SnowMailClient.model.multipart; 2 3 import SnowMailClient.model.MailMessage; 4 import java.text.DecimalFormat ; 5 6 public final class MimeUtils 7 { 8 private MimeUtils() 9 { 10 } 11 12 14 public static String createUniqueBoundary(int n, int rand1, int rand2) 15 { 16 return "----=_NextPart_"+format000.format(n)+"_0005_" +format00000000.format(rand1)+"." 18 +format00000000.format(rand2); 19 } 20 21 public static final DecimalFormat format000 = new DecimalFormat ("000"); 22 public static final DecimalFormat format00000000 = new DecimalFormat ("00000000"); 23 24 25 public static boolean isMultipart(MailMessage mess) 26 { 27 String ct = mess.getContentType().trim(); 28 String ctU = ct.toUpperCase(); 29 if(ctU.indexOf("MULTIPART")!=-1) return true; 30 31 if(ctU.indexOf("APPLICATION")!=-1) return true; 33 34 return false; 35 } 36 37 public static MimePart.ContentType guessContentType(String fileName) 38 { 39 return MimePart.ContentType.APPLICATION; 40 } 41 42 public static String guessContentSubType(String fileName) 43 { 44 String fnu = fileName.toUpperCase(); 45 if(fnu.endsWith(".JPEG") || fnu.endsWith(".JPG")) return "JPEG"; 46 47 int posPt = fnu.indexOf("."); 48 if(posPt>=0) return fnu.substring(posPt+1); 49 50 return fnu; 51 } 52 53 54 68 } | Popular Tags |