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