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.util.ArrayList; |
21 |
| import java.util.List; |
22 |
| import java.util.StringTokenizer; |
23 |
| |
24 |
| import javax.mail.Address; |
25 |
| |
26 |
| import sun.security.provider.Sun; |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public class NewsAddress extends Address { |
34 |
| |
35 |
| |
36 |
| |
37 |
| protected String host; |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| protected String newsgroup; |
43 |
| |
44 |
0
| public NewsAddress() {
|
45 |
| } |
46 |
| |
47 |
13
| public NewsAddress(String newsgroup) {
|
48 |
13
| this.newsgroup = newsgroup;
|
49 |
| } |
50 |
| |
51 |
3
| public NewsAddress(String newsgroup, String host) {
|
52 |
3
| this.newsgroup = newsgroup;
|
53 |
3
| this.host = host;
|
54 |
| } |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
2
| public String getType() {
|
61 |
2
| return "news";
|
62 |
| } |
63 |
| |
64 |
0
| public void setNewsgroup(String newsgroup) {
|
65 |
0
| this.newsgroup = newsgroup;
|
66 |
| } |
67 |
| |
68 |
3
| public String getNewsgroup() {
|
69 |
3
| return newsgroup;
|
70 |
| } |
71 |
| |
72 |
0
| public void setHost(String host) {
|
73 |
0
| this.host = host;
|
74 |
| } |
75 |
| |
76 |
3
| public String getHost() {
|
77 |
3
| return host;
|
78 |
| } |
79 |
| |
80 |
7
| public String toString() {
|
81 |
| |
82 |
7
| return newsgroup;
|
83 |
| } |
84 |
| |
85 |
10
| public boolean equals(Object o) {
|
86 |
0
| if (this == o) return true;
|
87 |
0
| if (!(o instanceof NewsAddress)) return false;
|
88 |
| |
89 |
10
| final NewsAddress newsAddress = (NewsAddress) o;
|
90 |
| |
91 |
0
| if (host != null ? !host.equals(newsAddress.host) : newsAddress.host != null) return false;
|
92 |
0
| if (newsgroup != null ? !newsgroup.equals(newsAddress.newsgroup) : newsAddress.newsgroup != null) return false;
|
93 |
| |
94 |
10
| return true;
|
95 |
| } |
96 |
| |
97 |
0
| public int hashCode() {
|
98 |
0
| int result;
|
99 |
0
| result = (host != null ? host.toLowerCase().hashCode() : 0);
|
100 |
0
| result = 29 * result + (newsgroup != null ? newsgroup.hashCode() : 0);
|
101 |
0
| return result;
|
102 |
| } |
103 |
| |
104 |
| |
105 |
| |
106 |
| |
107 |
| |
108 |
| |
109 |
| |
110 |
| |
111 |
10
| public static NewsAddress[] parse(String addresses) throws AddressException {
|
112 |
10
| List result = new ArrayList();
|
113 |
10
| StringTokenizer tokenizer = new StringTokenizer(addresses, ",");
|
114 |
10
| while (tokenizer.hasMoreTokens()) {
|
115 |
12
| String address = tokenizer.nextToken().trim();
|
116 |
12
| int index = address.indexOf('@');
|
117 |
12
| if (index == -1) {
|
118 |
10
| result.add(new NewsAddress(address));
|
119 |
| } else { |
120 |
2
| String newsgroup = address.substring(0, index).trim();
|
121 |
2
| String host = address.substring(index+1).trim();
|
122 |
2
| result.add(new NewsAddress(newsgroup, host));
|
123 |
| } |
124 |
| } |
125 |
10
| return (NewsAddress[]) result.toArray(new NewsAddress[result.size()]);
|
126 |
| } |
127 |
| |
128 |
| |
129 |
| |
130 |
| |
131 |
| |
132 |
| |
133 |
| |
134 |
| |
135 |
0
| public static String toString(Address[] addresses) {
|
136 |
0
| if (addresses == null) {
|
137 |
0
| return null;
|
138 |
| } |
139 |
0
| if (addresses.length == 0) {
|
140 |
0
| return "";
|
141 |
| } |
142 |
| |
143 |
0
| StringBuffer result = new StringBuffer(addresses.length * 32);
|
144 |
0
| result.append(addresses[0]);
|
145 |
0
| for (int i = 1; i < addresses.length; i++) {
|
146 |
0
| result.append(',').append(addresses[i].toString());
|
147 |
| } |
148 |
0
| return result.toString();
|
149 |
| } |
150 |
| } |