KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > utils > HeaderUtils


1 package SnowMailClient.utils;
2
3 import SnowMailClient.model.*;
4 import java.util.*;
5 import java.text.*;
6 import java.io.*;
7
8 public final class HeaderUtils
9 {
10
11   private HeaderUtils()
12   {
13   }
14
15   /** gets the charset from the header.
16       It is dissimulated in the content-type entry, within some other datas
17   */

18   public static String JavaDoc getHeader_Charset_entry(Header header) throws Exception JavaDoc
19   {
20     String JavaDoc ct = header.getEntryValue("Content-Type", "").toUpperCase();
21     int pos = ct.indexOf("CHARSET=");
22     if(pos>=0)
23     {
24       String JavaDoc cs = ct.substring(pos+8).trim();
25
26       // maybe starts with quotes
27
if(cs.startsWith("\"")) cs = cs.substring(1);
28
29       // maybe utf-8;***
30
pos = cs.indexOf(";");
31       if(pos>0) cs = cs.substring(0,pos);
32
33       // maybe ends with quotes
34
if(cs.endsWith("\"")) cs = cs.substring(0,cs.length()-1);
35       return cs;
36     }
37     return "iso-8859-1";
38   }
39
40
41 }
Popular Tags