KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > model > multipart > MimeUtils


1 package SnowMailClient.model.multipart;
2
3 import SnowMailClient.model.MailMessage;
4 import java.text.DecimalFormat JavaDoc;
5
6 public final class MimeUtils
7 {
8   private MimeUtils()
9   {
10   }
11
12   /** Creates a valid boundary name for the given level and random numbers.
13   */

14   public static String JavaDoc createUniqueBoundary(int n, int rand1, int rand2)
15   {
16      return "----=_NextPart_"+format000.format(n)+"_0005_" // "_" are good because they cannot be generated by accident as part of quoted printable !
17
+format00000000.format(rand1)+"."
18        +format00000000.format(rand2);
19   }
20
21   public static final DecimalFormat JavaDoc format000 = new DecimalFormat JavaDoc("000");
22   public static final DecimalFormat JavaDoc format00000000 = new DecimalFormat JavaDoc("00000000");
23
24
25   public static boolean isMultipart(MailMessage mess)
26   {
27      String JavaDoc ct = mess.getContentType().trim();
28      String JavaDoc ctU = ct.toUpperCase();
29      if(ctU.indexOf("MULTIPART")!=-1) return true;
30
31      // [Jan2006] when an attachment is send without text
32
if(ctU.indexOf("APPLICATION")!=-1) return true;
33
34      return false;
35   }
36
37   public static MimePart.ContentType guessContentType(String JavaDoc fileName)
38   {
39      return MimePart.ContentType.APPLICATION;
40   }
41
42   public static String JavaDoc guessContentSubType(String JavaDoc fileName)
43   {
44      String JavaDoc 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 /* test
55   public static void main(String[] aaa)
56   {
57     String hello = "Hello à tous, çeci l'est";
58     try
59     {
60       byte[] cont = hello.getBytes("iso-latin-1");
61       System.out.println(""+cont.length);
62     }
63     catch(Exception e)
64     {
65       e.printStackTrace();
66     }
67   }*/

68 }
Popular Tags