1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.mercury.smtp.util;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import javax.mail.Folder;
19
20
21
22
23
24
25
26 public class Path {
27
28
29 private String mailbox;
30
31
32 private String domain;
33
34
35 private List<String> returnPath;
36
37
38 private boolean localDomain = false;
39
40
41 private Folder folder;
42
43
44
45
46 public Path() {
47 }
48
49
50
51
52
53
54 public Path(String mailbox, String domain) {
55 this.mailbox = mailbox;
56 this.domain = domain;
57 }
58
59
60
61
62
63 public String getMailbox() {
64 return mailbox;
65 }
66
67
68
69
70
71 public void setMailbox(String mailbox) {
72 this.mailbox = mailbox;
73 }
74
75
76
77
78
79 public String getDomain() {
80 return domain;
81 }
82
83
84
85
86
87 public void setDomain(String domain) {
88 this.domain = domain;
89 }
90
91
92
93
94
95 public String[] getReturnPath() {
96 if (returnPath == null) { return new String[0]; }
97 String[] res = new String[returnPath.size()];
98 res = (String[]) returnPath.toArray(res);
99 return res;
100 }
101
102
103
104
105
106 public void addReturnPath(String returnPath) {
107 if (this.returnPath == null) {
108 this.returnPath = new ArrayList<String>();
109 }
110 this.returnPath.add(returnPath);
111 }
112
113
114
115
116
117 public void setLocalDomain(boolean localDomain) {
118 this.localDomain = localDomain;
119 }
120
121
122
123
124
125 public boolean isLocalDomain() {
126 return localDomain;
127 }
128
129
130
131
132
133 public boolean isLocalMailbox() {
134 return folder != null;
135 }
136
137
138
139
140
141 public void setFolder(Folder folder) {
142 this.folder = folder;
143 }
144
145
146
147
148
149 public Folder getFolder() {
150 return folder;
151 }
152
153
154
155
156
157 public String toMailboxString() {
158 StringBuffer buf = new StringBuffer();
159 buf.append(mailbox).append('@').append(domain);
160 return buf.toString();
161 }
162
163
164
165
166
167 public String toString() {
168 StringBuffer buf = new StringBuffer();
169 buf.append(mailbox).append('@').append(domain);
170 if (localDomain) {
171 if (folder != null) {
172 buf.append(" (").append(folder.getStore().getURLName()).append('#').append(folder.getName()).append(')');
173 } else {
174 buf.append(" (storage error)");
175 }
176 } else {
177 buf.append(" (foreign mailbox)");
178 }
179 return buf.toString();
180 }
181
182
183
184
185
186
187 public int hashCode() {
188 return mailbox.hashCode()+domain.hashCode();
189 }
190
191
192
193
194
195
196 public boolean equals(Object o) {
197 if (o instanceof Path) {
198 Path p = (Path)o;
199 if (((p.domain == domain) || ((domain != null) && domain.equals(p.domain)))
200 && ((p.mailbox == mailbox) || ((mailbox != null) && mailbox.equals(p.mailbox)))) {
201 return true;
202 }
203 }
204 return false;
205 }
206
207 }