View Javadoc

1   /*
2    * $Id: AbstractRetrieveMailConnector.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.email;
12  
13  import org.mule.umo.UMOComponent;
14  import org.mule.umo.endpoint.UMOEndpoint;
15  import org.mule.umo.provider.UMOMessageReceiver;
16  
17  /**
18   * Support for connecting to and receiving email from a mailbox (the exact protocol depends on
19   * the subclass).
20   */
21  public abstract class AbstractRetrieveMailConnector extends AbstractMailConnector
22  {
23      public static final int DEFAULT_CHECK_FREQUENCY = 60000;
24  
25      /**
26       * Holds the time in milliseconds that the endpoint should wait before checking a
27       * mailbox
28       */
29      private volatile long checkFrequency = DEFAULT_CHECK_FREQUENCY;
30  
31      /**
32       * Holds a path where messages should be backed up to (auto-generated if empty)
33       */
34      private volatile String backupFolder = null;
35  
36      /**
37       * Should we save backups to backupFolder?
38       */
39      private boolean backupEnabled = false;
40  
41      /**
42       * Once a message has been read, should it be deleted
43       */
44      private volatile boolean deleteReadMessages = true;
45  
46      
47      protected AbstractRetrieveMailConnector(int defaultPort)
48      {
49          super(defaultPort, MAILBOX);
50      }
51  
52      /**
53       * @return the milliseconds between checking the folder for messages
54       */
55      public long getCheckFrequency()
56      {
57          return checkFrequency;
58      }
59  
60      public void setCheckFrequency(long l)
61      {
62          if (l < 1)
63          {
64              l = DEFAULT_CHECK_FREQUENCY;
65          }
66          checkFrequency = l;
67      }
68  
69      /**
70       * @return a relative or absolute path to a directory on the file system
71       */
72      public String getBackupFolder()
73      {
74          return backupFolder;
75      }
76  
77      public void setBackupFolder(String string)
78      {
79          backupFolder = string;
80      }
81  
82      /*
83       * (non-Javadoc)
84       * 
85       * @see org.mule.providers.UMOConnector#registerListener(javax.jms.MessageListener,
86       *      java.lang.String)
87       */
88      public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception
89      {
90          Object[] args = {new Long(checkFrequency), Boolean.valueOf(isBackupEnabled()), backupFolder};
91          return serviceDescriptor.createMessageReceiver(this, component, endpoint, args);
92      }
93  
94      public boolean isDeleteReadMessages()
95      {
96          return deleteReadMessages;
97      }
98  
99      public void setDeleteReadMessages(boolean deleteReadMessages)
100     {
101         this.deleteReadMessages = deleteReadMessages;
102     }
103 
104     public boolean isBackupEnabled()
105     {
106         return backupEnabled;
107     }
108 
109     public void setBackupEnabled(boolean backupEnabled)
110     {
111         this.backupEnabled = backupEnabled;
112     }
113 
114 }