1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package javax.mail.internet;
19
20 import java.io.InputStream;
21 import java.io.OutputStream;
22 import java.io.UnsupportedEncodingException;
23 import javax.activation.DataHandler;
24 import javax.activation.DataSource;
25 import javax.mail.MessagingException;
26
27 // encodings include "base64", "quoted-printable", "7bit", "8bit" and "binary".
28 // In addition, "uuencode" is also supported. The
29
30 /**
31 * @version $Rev: 149170 $ $Date: 2005-01-30 14:21:08 -0800 (Sun, 30 Jan 2005) $
32 */
33 public class MimeUtility {
34 private MimeUtility() {
35 }
36
37 public static final int ALL = -1;
38
39 private static String defaultJavaCharset;
40
41 public static InputStream decode(InputStream in, String encoding) throws MessagingException {
42 // TODO - take account of encoding
43 return in;
44 }
45
46 public static String decodeText(String word) throws UnsupportedEncodingException {
47 // TODO - take account of encoding
48 return word;
49 }
50
51 public static String decodeWord(String word) throws ParseException, UnsupportedEncodingException {
52 // TODO - take account of encoding
53 return word;
54 }
55
56 public static OutputStream encode(OutputStream out, String encoding) throws MessagingException {
57 // TODO - take account of encoding
58 return out;
59 }
60
61 public static OutputStream encode(OutputStream out, String encoding, String filename) throws MessagingException {
62 // TODO - take account of encoding
63 return out;
64 }
65
66 public static String encodeText(String word) throws UnsupportedEncodingException {
67 // TODO - take account of encoding
68 return word;
69 }
70
71 public static String encodeText(String word, String characterset, String encoding) throws UnsupportedEncodingException {
72 // TODO - take account of encoding
73 return word;
74 }
75
76 public static String encodeWord(String word) throws UnsupportedEncodingException {
77 // TODO - take account of encoding
78 return word;
79 }
80
81 public static String encodeWord(String word, String characteset, String encoding) throws UnsupportedEncodingException {
82 // TODO - take account of encoding
83 return word;
84 }
85
86 public static String getEncoding(DataHandler handler) {
87 // TODO figure what type of data it is
88 return "binary";
89 }
90
91 public static String getEncoding(DataSource source) {
92 // TODO figure what type of data it is
93 return "binary";
94 }
95
96 public static String quote(String word, String specials) {
97 // TODO Check for specials
98 return word;
99 }
100
101 public static String javaCharset(String charset) {
102 // TODO Perform translations as appropriate
103 return charset;
104 }
105
106 public static String mimeCharset(String charset) {
107 // TODO Perform translations as appropriate
108 return charset;
109 }
110
111 public static String getDefaultJavaCharset() {
112 try {
113 String charset = System.getProperty("mail.mime.charset");
114 if (charset != null) {
115 return javaCharset(charset);
116 }
117 charset = System.getProperty("file.encoding");
118 if (charset != null) {
119 return charset;
120 }
121 } catch (SecurityException e) {
122 // ignore
123 }
124 return "utf-8";
125 }
126 }