View Javadoc

1   /*
2    * $Id: AbstractRetrieveMailConnector.java 20813 2010-12-21 11:37:48Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport.email;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.construct.FlowConstruct;
15  import org.mule.api.endpoint.InboundEndpoint;
16  import org.mule.api.transport.MessageReceiver;
17  
18  import javax.mail.Flags;
19  
20  /**
21   * Support for connecting to and receiving email from a mailbox (the exact protocol depends on
22   * the subclass).
23   */
24  public abstract class AbstractRetrieveMailConnector extends AbstractMailConnector
25  {
26      public static final int DEFAULT_CHECK_FREQUENCY = 60000;
27  
28      /**
29       * Holds the time in milliseconds that the endpoint should wait before checking a
30       * mailbox
31       */
32      private volatile long checkFrequency = DEFAULT_CHECK_FREQUENCY;
33  
34      /**
35       * Holds a path where messages should be backed up to (auto-generated if empty)
36       */
37      private volatile String backupFolder = null;
38  
39      /**
40       * Holds a remote folder name where messages should be moved to after being read
41       */
42      private volatile String moveToFolder = null;
43  
44      /**
45       * Should we save backups to backupFolder?
46       */
47      private boolean backupEnabled = false;
48  
49      /**
50       * Once a message has been read, should it be deleted
51       */
52      private volatile boolean deleteReadMessages = true;
53  
54      /**
55       * The action performed if the deleteReadMessages actions is set to false
56       */
57      private Flags.Flag defaultProcessMessageAction = Flags.Flag.SEEN;
58  
59  
60      protected AbstractRetrieveMailConnector(int defaultPort, MuleContext context)
61      {
62          super(defaultPort, MAILBOX, context);
63      }
64  
65      /**
66       * @return the milliseconds between checking the folder for messages
67       */
68      public long getCheckFrequency()
69      {
70          return checkFrequency;
71      }
72  
73      public void setCheckFrequency(long l)
74      {
75          if (l < 1)
76          {
77              l = DEFAULT_CHECK_FREQUENCY;
78          }
79          checkFrequency = l;
80      }
81  
82      /**
83       * @return a relative or absolute path to a directory on the file system
84       */
85      public String getBackupFolder()
86      {
87          return backupFolder;
88      }
89  
90      public void setBackupFolder(String string)
91      {
92          backupFolder = string;
93      }
94  
95      @Override
96      public MessageReceiver createReceiver(FlowConstruct flowConstruct, InboundEndpoint endpoint) throws Exception
97      {
98          Object[] args = {checkFrequency, isBackupEnabled(), backupFolder};
99          return serviceDescriptor.createMessageReceiver(this, flowConstruct, endpoint, args);
100     }
101 
102     public boolean isDeleteReadMessages()
103     {
104         return deleteReadMessages;
105     }
106 
107     public void setDeleteReadMessages(boolean deleteReadMessages)
108     {
109         this.deleteReadMessages = deleteReadMessages;
110     }
111 
112     public boolean isBackupEnabled()
113     {
114         return backupEnabled;
115     }
116 
117     public void setBackupEnabled(boolean backupEnabled)
118     {
119         this.backupEnabled = backupEnabled;
120     }
121 
122     public String getMoveToFolder()
123     {
124         return moveToFolder;
125     }
126 
127     public void setMoveToFolder(String moveToFolder)
128     {
129         this.moveToFolder = moveToFolder;
130     }
131 
132     public Flags.Flag getDefaultProcessMessageAction()
133     {
134         return defaultProcessMessageAction;
135     }
136 
137     public void setDefaultProcessMessageAction(Flags.Flag defaultProcessMessageAction)
138     {
139         this.defaultProcessMessageAction = defaultProcessMessageAction;
140     }
141 }