1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.mailrepository.javamail;
21
22 import java.lang.reflect.InvocationTargetException;
23 import java.lang.reflect.Method;
24
25 import javax.mail.Folder;
26 import javax.mail.Message;
27 import javax.mail.MessagingException;
28 import javax.mail.UIDFolder;
29
30
31
32
33
34 public class UIDPlusFolderAdapter extends FolderAdapter implements UIDPlusFolder {
35
36 private Method addUIDMessagesMethod;
37 private Method addMessagesMethod;
38
39 public UIDPlusFolderAdapter(Folder folder) {
40 super(folder);
41 try {
42 addUIDMessagesMethod=folder.getClass().getMethod("addUIDMessages",
43 new Class[] { Message[].class });
44 addMessagesMethod=folder.getClass().getMethod("addMessages",
45 new Class[] { Message[].class });
46 } catch (SecurityException e) {
47 throw new RuntimeException(e);
48 } catch (NoSuchMethodException e) {
49 throw new RuntimeException(e);
50 }
51 }
52
53
54
55
56 public long[] addUIDMessages(Message[] msgs) throws MessagingException {
57 try {
58 return (long[]) addUIDMessagesMethod.invoke(folder, new Object[] { msgs });
59 } catch (IllegalArgumentException e) {
60 throw new RuntimeException(e);
61 } catch (IllegalAccessException e) {
62 throw new RuntimeException(e);
63 } catch (InvocationTargetException e) {
64 Throwable cause=e.getCause();
65 if (cause instanceof RuntimeException) {
66 throw (RuntimeException)cause;
67 }
68 throw new RuntimeException(e);
69 }
70 }
71
72
73
74
75 public Message[] addMessages(Message[] msgs) throws MessagingException {
76 try {
77 return (Message[]) addMessagesMethod.invoke(folder, new Object[] { msgs });
78 } catch (IllegalArgumentException e) {
79 throw new RuntimeException(e);
80 } catch (IllegalAccessException e) {
81 throw new RuntimeException(e);
82 } catch (InvocationTargetException e) {
83 Throwable cause=e.getCause();
84 if (cause instanceof RuntimeException) {
85 throw (RuntimeException)cause;
86 }
87 throw new RuntimeException(e);
88 }
89 }
90
91
92
93
94 public long getUIDValidity() throws MessagingException {
95 return ((UIDFolder)folder).getUIDValidity();
96 }
97
98
99
100
101 public Message getMessageByUID(long uid) throws MessagingException {
102 return ((UIDFolder)folder).getMessageByUID(uid);
103 }
104
105
106
107
108 public Message[] getMessagesByUID(long start, long end) throws MessagingException {
109 return ((UIDFolder)folder).getMessagesByUID(start, end);
110 }
111
112
113
114
115 public Message[] getMessagesByUID(long[] uids) throws MessagingException {
116 return ((UIDFolder)folder).getMessagesByUID(uids);
117 }
118
119
120
121
122 public long getUID(Message message) throws MessagingException {
123 return ((UIDFolder)folder).getUID(message);
124 }
125 }