KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
21 import java.util.Set JavaDoc;
22
23 import javax.mail.MessagingException JavaDoc;
24 import javax.mail.Session JavaDoc;
25
26 import org.apache.avalon.framework.logger.Logger;
27 import org.apache.james.services.MailServer;
28 import org.apache.mailet.MailAddress;
29 import org.apache.james.services.UsersRepository;
30
31 /**
32  * <p>Class <code>ProcessorAbstract</code> is an abstract class that
33  * provides support for JavaMail processors. Concrete implementations are
34  * required to implement the abstract method <code>void process()</code> to
35  * process a JavaMail element.</p>
36  *
37  * <p>Typically, processors are chained. A Store processor delegates to a Folder
38  * processor that delegates to a Message processor.</p>
39  *
40  * <p><code>ProcessorAbstract</code> wraps an Account - see
41  * <code>org.apache.james.fetchmail.Account</code>
42  * - providing contextual information about the environment for the processor.</p>
43  *
44  * <p>Creation Date: 27-May-03</p>
45  *
46  */

47 abstract public class ProcessorAbstract
48 {
49     /**
50      * The prefix to place in front of any mail attributes used by this Processor.
51      */

52     private String JavaDoc fieldAttributePrefix;
53     
54     /**
55      * The Account for this task
56      */

57     private Account fieldAccount;
58
59     /**
60      * Constructor for ProcessorAbstract.
61      */

62     private ProcessorAbstract()
63     {
64         super();
65     }
66     
67     /**
68      * Constructor for ProcessorAbstract.
69      * @param account The <code>Account</code> to be processed
70      */

71     protected ProcessorAbstract(Account account)
72     {
73         this();
74         setAccount(account);
75     }
76     
77     /**
78      * Returns the defaultDomainName.
79      * @return String
80      */

81     protected String JavaDoc getDefaultDomainName()
82     {
83         return getConfiguration().getDefaultDomainName();
84     }
85     
86     /**
87      * Returns the message ids. of messages for which processing has been
88      * deferred as the recipient could not be found
89      * @return List
90      */

91     protected List JavaDoc getDeferredRecipientNotFoundMessageIDs()
92     {
93         return getAccount().getDeferredRecipientNotFoundMessageIDs();
94     }
95     
96     /**
97      * Returns the fetchTaskName.
98      * @return String
99      */

100     protected String JavaDoc getFetchTaskName()
101     {
102         return getConfiguration().getFetchTaskName();
103     }
104
105
106     /**
107      * Returns the host.
108      * @return String
109      */

110     protected String JavaDoc getHost()
111     {
112         return getConfiguration().getHost();
113     }
114
115
116     /**
117      * Returns the javaMailFolderName.
118      * @return String
119      */

120     protected String JavaDoc getJavaMailFolderName()
121     {
122         return getConfiguration().getJavaMailFolderName();
123     }
124
125
126
127     /**
128      * Returns the javaMailProviderName.
129      * @return String
130      */

131     protected String JavaDoc getJavaMailProviderName()
132     {
133         return getConfiguration().getJavaMailProviderName();
134     }
135
136
137
138     /**
139      * Returns the logger.
140      * @return Logger
141      */

142     protected Logger getLogger()
143     {
144         return getConfiguration().getLogger();
145     }
146
147
148     /**
149      * Returns the password.
150      * @return String
151      */

152     protected String JavaDoc getPassword()
153     {
154         return getAccount().getPassword();
155     }
156
157
158     /**
159      * Returns the recipient.
160      * @return MailAddress
161      */

162     protected MailAddress getRecipient()
163     {
164         return getAccount().getRecipient();
165     }
166     
167     /**
168      * Method getRemoteReceivedHeaderIndex.
169      * @return int
170      */

171     protected int getRemoteReceivedHeaderIndex()
172     {
173         return getConfiguration().getRemoteReceivedHeaderIndex();
174     }
175
176
177     /**
178      * Returns the server.
179      * @return MailServer
180      */

181     protected MailServer getServer()
182     {
183         return getConfiguration().getServer();
184     }
185     
186     /**
187      * Returns the session.
188      * @return Session
189      */

190     protected Session JavaDoc getSession()
191     {
192         return getAccount().getSession();
193     }
194     
195     /**
196      * Returns the repository of local users.
197      * @return UsersRepository
198      */

199     protected UsersRepository getLocalUsers()
200     {
201         return getConfiguration().getLocalUsers();
202     }
203
204
205     /**
206      * Returns the user.
207      * @return String
208      */

209     protected String JavaDoc getUser()
210     {
211         return getAccount().getUser();
212     }
213
214
215     /**
216      * Returns the fetchAll.
217      * @return boolean
218      */

219     protected boolean isFetchAll()
220     {
221         return getConfiguration().isFetchAll();
222     }
223
224
225     /**
226      * Returns the isDeferRecipientNotFound.
227      * @return boolean
228      */

229     protected boolean isDeferRecipientNotFound()
230     {
231         return getConfiguration().isDeferRecipientNotFound();
232     }
233     
234     /**
235      * Returns the ignoreOriginalRecipient.
236      * @return boolean
237      */

238     protected boolean isIgnoreRecipientHeader()
239     {
240         return getAccount().isIgnoreRecipientHeader();
241     }
242
243
244     /**
245      * Returns the leave.
246      * @return boolean
247      */

248     protected boolean isLeave()
249     {
250         return getConfiguration().isLeave();
251     }
252
253
254     /**
255      * Returns the markSeen.
256      * @return boolean
257      */

258     protected boolean isMarkSeen()
259     {
260         return getConfiguration().isMarkSeen();
261     }
262     
263     /**
264      * Returns the leaveBlacklisted.
265      * @return boolean
266      */

267     protected boolean isLeaveBlacklisted()
268     {
269         return getConfiguration().isLeaveBlacklisted();
270     }
271     
272     /**
273      * Returns the leaveRemoteRecipient.
274      * @return boolean
275      */

276     protected boolean isLeaveRemoteRecipient()
277     {
278         return getConfiguration().isLeaveRemoteRecipient();
279     }
280     
281     /**
282      * Returns the leaveUserUndefinded.
283      * @return boolean
284      */

285     protected boolean isLeaveUserUndefined()
286     {
287         return getConfiguration().isLeaveUserUndefined();
288     }
289     
290     /**
291      * Returns the leaveRemoteReceivedHeaderInvalid.
292      * @return boolean
293      */

294     protected boolean isLeaveRemoteReceivedHeaderInvalid()
295     {
296         return getConfiguration().isLeaveRemoteReceivedHeaderInvalid();
297     }
298     
299     /**
300      * Returns the LeaveMaxMessageSizeExceeded.
301      * @return boolean
302      */

303     protected boolean isLeaveMaxMessageSizeExceeded()
304     {
305         return getConfiguration().isLeaveMaxMessageSizeExceeded();
306     }
307     
308     /**
309      * Returns the leaveUndeliverable.
310      * @return boolean
311      */

312     protected boolean isLeaveUndeliverable()
313     {
314         return getConfiguration().isLeaveUndeliverable();
315     }
316
317     /**
318      * Returns the RejectUserUndefinded.
319      * @return boolean
320      */

321     protected boolean isRejectUserUndefined()
322     {
323         return getConfiguration().isRejectUserUndefined();
324     }
325     
326     /**
327      * Returns the RejectRemoteReceivedHeaderInvalid.
328      * @return boolean
329      */

330     protected boolean isRejectRemoteReceivedHeaderInvalid()
331     {
332         return getConfiguration().isRejectRemoteReceivedHeaderInvalid();
333     }
334     
335     /**
336      * Returns the RejectMaxMessageSizeExceeded.
337      * @return boolean
338      */

339     protected boolean isRejectMaxMessageSizeExceeded()
340     {
341         return getConfiguration().isRejectMaxMessageSizeExceeded();
342     }
343     
344     /**
345      * Returns the RejectUserBlacklisted.
346      * @return boolean
347      */

348     protected boolean isRejectBlacklisted()
349     {
350         return getConfiguration().isRejectBlacklisted();
351     }
352     
353     /**
354      * Returns the RejectRemoteRecipient.
355      * @return boolean
356      */

357     protected boolean isRejectRemoteRecipient()
358     {
359         return getConfiguration().isRejectRemoteRecipient();
360     }
361     
362     /**
363      * Returns the markBlacklistedSeen.
364      * @return boolean
365      */

366     protected boolean isMarkBlacklistedSeen()
367     {
368         return getConfiguration().isMarkBlacklistedSeen();
369     }
370     
371     /**
372      * Returns the markRecipientNotFoundSeen.
373      * @return boolean
374      */

375     protected boolean isMarkRecipientNotFoundSeen()
376     {
377         return getConfiguration().isMarkRecipientNotFoundSeen();
378     }
379     
380     /**
381      * Returns the leaveRecipientNotFound.
382      * @return boolean
383      */

384     protected boolean isLeaveRecipientNotFound()
385     {
386         return getConfiguration().isLeaveRecipientNotFound();
387     }
388     
389     /**
390      * Returns the rejectRecipientNotFound.
391      * @return boolean
392      */

393     protected boolean isRejectRecipientNotFound()
394     {
395         return getConfiguration().isRejectRecipientNotFound();
396     }
397
398     /**
399      * Returns the markRemoteRecipientSeen.
400      * @return boolean
401      */

402     protected boolean isMarkRemoteRecipientSeen()
403     {
404         return getConfiguration().isMarkRemoteRecipientSeen();
405     }
406     
407     /**
408      * Returns the markUserUndefindedSeen.
409      * @return boolean
410      */

411     protected boolean isMarkUserUndefinedSeen()
412     {
413         return getConfiguration().isMarkUserUndefinedSeen();
414     }
415     
416     /**
417      * Returns the markRemoteReceivedHeaderInvalidSeen.
418      * @return boolean
419      */

420     protected boolean isMarkRemoteReceivedHeaderInvalidSeen()
421     {
422         return getConfiguration().isMarkRemoteReceivedHeaderInvalidSeen();
423     }
424     
425     /**
426      * Returns the MarkMaxMessageSizeExceededSeen.
427      * @return boolean
428      */

429     protected boolean isMarkMaxMessageSizeExceededSeen()
430     {
431         return getConfiguration().isMarkMaxMessageSizeExceededSeen();
432     }
433     
434     /**
435      * Returns the markUndeliverableSeen.
436      * @return boolean
437      */

438     protected boolean isMarkUndeliverableSeen()
439     {
440         return getConfiguration().isMarkUndeliverableSeen();
441     }
442     
443     /**
444      * Answers true if the folder should be opened read only.
445      * For this to be true...
446      * - isKeep() must be true
447      * - isMarkSeen() must be false
448      * @return boolean
449      */

450     protected boolean isOpenReadOnly()
451     {
452         return getConfiguration().isOpenReadOnly();
453     }
454
455
456     /**
457      * Returns the recurse.
458      * @return boolean
459      */

460     protected boolean isRecurse()
461     {
462         return getConfiguration().isRecurse();
463     }
464
465
466     
467     
468     /**
469      * Process the mail elements of the receiver
470      */

471     abstract public void process() throws MessagingException JavaDoc;
472     
473     /**
474      * Returns the blacklist.
475      * @return Set
476      */

477     protected Set JavaDoc getBlacklist()
478     {
479         return getConfiguration().getBlacklist();
480     }
481     
482     /**
483      * Returns the <code>ParsedConfiguration</code> from the <code>Account</code>.
484      * @return ParsedConfiguration
485      */

486     protected ParsedConfiguration getConfiguration()
487     {
488         return getAccount().getParsedConfiguration();
489     }
490
491     /**
492      * Returns a lazy initialised attributePrefix.
493      * @return String
494      */

495     protected String JavaDoc getAttributePrefix()
496     {
497         String JavaDoc value = null;
498         if (null == (value = getAttributePrefixBasic()))
499         {
500             updateAttributePrefix();
501             return getAttributePrefix();
502         }
503         return value;
504     }
505     
506     /**
507      * Returns the attributePrefix.
508      * @return String
509      */

510     private String JavaDoc getAttributePrefixBasic()
511     {
512         return fieldAttributePrefix;
513     }
514     
515     /**
516      * Returns the computed attributePrefix.
517      * @return String
518      */

519     protected String JavaDoc computeAttributePrefix()
520     {
521         return getClass().getPackage().getName() + ".";
522     }
523
524     /**
525      * Sets the attributePrefix.
526      * @param attributePrefix The attributePrefix to set
527      */

528     protected void setAttributePrefix(String JavaDoc attributePrefix)
529     {
530         fieldAttributePrefix = attributePrefix;
531     }
532     
533     /**
534      * Updates the attributePrefix.
535      */

536     protected void updateAttributePrefix()
537     {
538         setAttributePrefix(computeAttributePrefix());
539     }
540
541     /**
542      * Returns the account.
543      * @return Account
544      */

545     public Account getAccount()
546     {
547         return fieldAccount;
548     }
549
550     /**
551      * Sets the account.
552      * @param account The account to set
553      */

554     protected void setAccount(Account account)
555     {
556         fieldAccount = account;
557     }
558     
559     /**
560      * Returns the getMaxMessageSizeLimit.
561      * @return int
562      */

563     protected int getMaxMessageSizeLimit()
564     {
565         return getConfiguration().getMaxMessageSizeLimit();
566     }
567
568 }
569
Popular Tags