|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package javax.mail.internet; |
|
19 |
| |
|
20 |
| import java.io.IOException; |
|
21 |
| import java.io.InputStream; |
|
22 |
| import java.io.OutputStream; |
|
23 |
| import java.net.UnknownServiceException; |
|
24 |
| import javax.activation.DataSource; |
|
25 |
| import javax.mail.MessageAware; |
|
26 |
| import javax.mail.MessageContext; |
|
27 |
| import javax.mail.MessagingException; |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| public class MimePartDataSource implements DataSource, MessageAware { |
|
33 |
| private final MimePart part; |
|
34 |
| |
|
35 |
3
| public MimePartDataSource(MimePart part) {
|
|
36 |
3
| this.part = part;
|
|
37 |
| } |
|
38 |
| |
|
39 |
3
| public InputStream getInputStream() throws IOException {
|
|
40 |
3
| try {
|
|
41 |
3
| InputStream stream;
|
|
42 |
3
| if (part instanceof MimeMessage) {
|
|
43 |
1
| stream = ((MimeMessage) part).getContentStream();
|
|
44 |
2
| } else if (part instanceof MimeBodyPart) {
|
|
45 |
2
| stream = ((MimeBodyPart) part).getContentStream();
|
|
46 |
| } else { |
|
47 |
0
| throw new MessagingException("Unknown part");
|
|
48 |
| } |
|
49 |
3
| String encoding = part.getEncoding();
|
|
50 |
3
| return encoding == null ? stream : MimeUtility.decode(stream, encoding);
|
|
51 |
| } catch (MessagingException e) { |
|
52 |
0
| throw (IOException) new IOException(e.getMessage()).initCause(e);
|
|
53 |
| } |
|
54 |
| } |
|
55 |
| |
|
56 |
0
| public OutputStream getOutputStream() throws IOException {
|
|
57 |
0
| throw new UnknownServiceException();
|
|
58 |
| } |
|
59 |
| |
|
60 |
6
| public String getContentType() {
|
|
61 |
6
| try {
|
|
62 |
6
| return part.getContentType();
|
|
63 |
| } catch (MessagingException e) { |
|
64 |
0
| return null;
|
|
65 |
| } |
|
66 |
| } |
|
67 |
| |
|
68 |
0
| public String getName() {
|
|
69 |
0
| return "";
|
|
70 |
| } |
|
71 |
| |
|
72 |
0
| public synchronized MessageContext getMessageContext() {
|
|
73 |
0
| return new MessageContext(part);
|
|
74 |
| } |
|
75 |
| } |