KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > fetchmail > Account


1 /***********************************************************************
2  * Copyright (c) 2003-2004 The Apache Software Foundation. *
3  * All rights reserved. *
4  * ------------------------------------------------------------------- *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you *
6  * may not use this file except in compliance with the License. You *
7  * 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 *
14  * implied. See the License for the specific language governing *
15  * permissions and limitations under the License. *
16  ***********************************************************************/

17
18 package org.apache.james.fetchmail;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 import javax.mail.Session JavaDoc;
24 import javax.mail.internet.ParseException JavaDoc;
25
26 import org.apache.avalon.framework.configuration.ConfigurationException;
27 import org.apache.mailet.MailAddress;
28
29 /**
30  * <p>Class <code>Account</code> encapsulates the account details required to
31  * fetch mail from a message store.</p>
32  *
33  * <p>Instances are <code>Comparable</code> based on their sequence number.</p>
34  *
35  * <p>Creation Date: 05-Jun-03</p>
36  */

37 class Account implements Comparable JavaDoc
38 {
39     /**
40      * The user password for this account
41      */

42     private String JavaDoc fieldPassword;
43
44     /**
45      * The user to send the fetched mail to
46      */

47     private MailAddress fieldRecipient;
48
49     /**
50      * The user name for this account
51      */

52     private String JavaDoc fieldUser;
53
54     /**
55      * The ParsedConfiguration
56      */

57     private ParsedConfiguration fieldParsedConfiguration;
58     
59     /**
60      * List of MessageIDs for which processing has been deferred
61      * because the intended recipient could not be found.
62      */

63     private List JavaDoc fieldDeferredRecipientNotFoundMessageIDs;
64     
65     /**
66      * The sequence number for this account
67      */

68     private int fieldSequenceNumber;
69     
70     /**
71      * Ignore the recipient deduced from the header and use 'fieldRecipient'
72      */

73     private boolean fieldIgnoreRecipientHeader;
74
75     /**
76      * The JavaMail Session for this Account.
77      */

78     
79     private Session JavaDoc fieldSession;
80     /**
81      * Constructor for Account.
82      */

83     private Account()
84     {
85         super();
86     }
87     
88     /**
89      * Constructor for Account.
90      *
91      * @param sequenceNumber
92      * @param parsedConfiguration
93      * @param user
94      * @param password
95      * @param recipient
96      * @param ignoreRecipientHeader
97      * @param session
98      * @throws ConfigurationException
99      */

100     
101     public Account(
102         int sequenceNumber,
103         ParsedConfiguration parsedConfiguration,
104         String JavaDoc user,
105         String JavaDoc password,
106         String JavaDoc recipient,
107         boolean ignoreRecipientHeader,
108         Session JavaDoc session)
109         throws ConfigurationException
110     {
111         this();
112         setSequenceNumber(sequenceNumber);
113         setParsedConfiguration(parsedConfiguration);
114         setUser(user);
115         setPassword(password);
116         setRecipient(recipient);
117         setIgnoreRecipientHeader(ignoreRecipientHeader);
118         setSession(session);
119     }
120
121     /**
122      * Returns the password.
123      * @return String
124      */

125     public String JavaDoc getPassword()
126     {
127         return fieldPassword;
128     }
129
130     /**
131      * Returns the recipient.
132      * @return MailAddress
133      */

134     public MailAddress getRecipient()
135     {
136         return fieldRecipient;
137     }
138
139     /**
140      * Returns the user.
141      * @return String
142      */

143     public String JavaDoc getUser()
144     {
145         return fieldUser;
146     }
147
148     /**
149      * Sets the password.
150      * @param password The password to set
151      */

152     protected void setPassword(String JavaDoc password)
153     {
154         fieldPassword = password;
155     }
156
157     /**
158      * Sets the recipient.
159      * @param recipient The recipient to set
160      */

161     protected void setRecipient(MailAddress recipient)
162     {
163         fieldRecipient = recipient;
164     }
165     
166     /**
167      * Sets the recipient.
168      * @param recipient The recipient to set
169      */

170     protected void setRecipient(String JavaDoc recipient) throws ConfigurationException
171     {
172         if (null == recipient)
173         {
174             fieldRecipient = null;
175             return;
176         }
177             
178         try
179         {
180             setRecipient(new MailAddress(recipient));
181         }
182         catch (ParseException JavaDoc pe)
183         {
184             throw new ConfigurationException(
185                 "Invalid recipient address specified: " + recipient);
186         }
187     }
188
189
190     
191
192     /**
193      * Sets the user.
194      * @param user The user to set
195      */

196     protected void setUser(String JavaDoc user)
197     {
198         fieldUser = user;
199     }
200
201     /**
202      * Sets the ignoreRecipientHeader.
203      * @param ignoreRecipientHeader The ignoreRecipientHeader to set
204      */

205     protected void setIgnoreRecipientHeader(boolean ignoreRecipientHeader)
206     {
207         fieldIgnoreRecipientHeader = ignoreRecipientHeader;
208     }
209
210     /**
211      * Returns the ignoreRecipientHeader.
212      * @return boolean
213      */

214     public boolean isIgnoreRecipientHeader()
215     {
216         return fieldIgnoreRecipientHeader;
217     }
218
219     /**
220      * Returns the sequenceNumber.
221      * @return int
222      */

223     public int getSequenceNumber()
224     {
225         return fieldSequenceNumber;
226     }
227
228     /**
229      * Sets the sequenceNumber.
230      * @param sequenceNumber The sequenceNumber to set
231      */

232     protected void setSequenceNumber(int sequenceNumber)
233     {
234         fieldSequenceNumber = sequenceNumber;
235     }
236
237     /**
238      * Compares this object with the specified object for order. Returns a
239      * negative integer, zero, or a positive integer if this object is less
240      * than, equal to, or greater than the specified object.
241      *
242      * @see java.lang.Comparable#compareTo(Object)
243      */

244     public int compareTo(Object JavaDoc o)
245     {
246         return getSequenceNumber() - ((Account) o).getSequenceNumber();
247     }
248
249     /**
250      * Returns the deferredRecipientNotFoundMessageIDs. lazily initialised.
251      * @return List
252      */

253     public List JavaDoc getDeferredRecipientNotFoundMessageIDs()
254     {
255         List JavaDoc messageIDs = null;
256         if (null
257             == (messageIDs = getDeferredRecipientNotFoundMessageIDsBasic()))
258         {
259             updateDeferredRecipientNotFoundMessageIDs();
260             return getDeferredRecipientNotFoundMessageIDs();
261         }
262         return messageIDs;
263     }
264
265     /**
266      * Returns the deferredRecipientNotFoundMessageIDs.
267      * @return List
268      */

269     private List JavaDoc getDeferredRecipientNotFoundMessageIDsBasic()
270     {
271         return fieldDeferredRecipientNotFoundMessageIDs;
272     }
273     
274     /**
275      * Returns a new List of deferredRecipientNotFoundMessageIDs.
276      * @return List
277      */

278     protected List JavaDoc computeDeferredRecipientNotFoundMessageIDs()
279     {
280         return new ArrayList JavaDoc(16);
281     }
282     
283     /**
284      * Updates the deferredRecipientNotFoundMessageIDs.
285      */

286     protected void updateDeferredRecipientNotFoundMessageIDs()
287     {
288         setDeferredRecipientNotFoundMessageIDs(computeDeferredRecipientNotFoundMessageIDs());
289     }
290
291     /**
292      * Sets the defferedRecipientNotFoundMessageIDs.
293      * @param defferedRecipientNotFoundMessageIDs The defferedRecipientNotFoundMessageIDs to set
294      */

295     protected void setDeferredRecipientNotFoundMessageIDs(List JavaDoc defferedRecipientNotFoundMessageIDs)
296     {
297         fieldDeferredRecipientNotFoundMessageIDs =
298             defferedRecipientNotFoundMessageIDs;
299     }
300
301     /**
302      * Returns the parsedConfiguration.
303      * @return ParsedConfiguration
304      */

305     public ParsedConfiguration getParsedConfiguration()
306     {
307         return fieldParsedConfiguration;
308     }
309
310     /**
311      * Sets the parsedConfiguration.
312      * @param parsedConfiguration The parsedConfiguration to set
313      */

314     protected void setParsedConfiguration(ParsedConfiguration parsedConfiguration)
315     {
316         fieldParsedConfiguration = parsedConfiguration;
317     }
318
319     /**
320      * Returns the session.
321      * @return Session
322      */

323     public Session JavaDoc getSession()
324     {
325         return fieldSession;
326     }
327
328     /**
329      * Sets the session.
330      * @param session The session to set
331      */

332     protected void setSession(Session JavaDoc session)
333     {
334         fieldSession = session;
335     }
336
337 }
338
Popular Tags