001    /**
002     *
003     *  Licensed to the Apache Software Foundation (ASF) under one or more
004     *  contributor license agreements.  See the NOTICE file distributed with
005     *  this work for additional information regarding copyright ownership.
006     *  The ASF licenses this file to You under the Apache License, Version 2.0
007     *  (the "License"); you may not use this file except in compliance with
008     *  the License.  You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     *  Unless required by applicable law or agreed to in writing, software
013     *  distributed under the License is distributed on an "AS IS" BASIS,
014     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     *  See the License for the specific language governing permissions and
016     *  limitations under the License.
017     */
018    package org.apache.geronimo.mail;
019    
020    import java.util.Properties;
021    
022    import org.apache.commons.logging.Log;
023    import org.apache.commons.logging.LogFactory;
024    
025    import org.apache.geronimo.gbean.GBeanInfo;
026    import org.apache.geronimo.gbean.GBeanInfoBuilder;
027    
028    /**
029     * A GBean that provides for the configuration of a JavaMail IMAP message store
030     * protocol.
031     * <p/>
032     * IMAP store properties that are common to all IMAP stores are
033     * provided via member variables of this class.  Values that are set in the
034     * individual member variables will override any of the corresponding values
035     * that have been set in the properties set.
036     *
037     * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $
038     * @see MailGBean
039     */
040    public class IMAPStoreGBean extends ProtocolGBean {
041    
042        // the IMAP configuration property names
043        static public final String IMAP_PORT = "mail.imap.port";
044        static public final String IMAP_CONNECTION_TIMEOUT = "mail.imap.connectiontimeout";
045        static public final String IMAP_TIMEOUT = "mail.imap.timeout";
046        static public final String IMAP_FACTORY_CLASS = "mail.imap.socketFactory.class";
047        static public final String IMAP_FACTORY_FALLBACK = "mail.imap.socketFactory.fallback";
048        static public final String IMAP_FACTORY_PORT = "mail.imap.socketFactory.port";
049        static public final String IMAP_LOCALHOST = "mail.imap.localhost";
050        static public final String IMAP_LOCALADDRESS = "mail.imap.localaddress";
051        static public final String IMAP_LOCALPORT = "mail.imap.localport";
052        static public final String IMAP_PARTIAL_FETCH = "mail.imap.partialfetch";
053        static public final String IMAP_FETCH_SIZE = "mail.imap.fetchsize";
054        static public final String IMAP_STATUS_TIMEOUT = "mail.imap.statuscachetimeout";
055        static public final String IMAP_APPEND_SIZE = "mail.imap.appendbuffersize";
056        static public final String IMAP_POOL_SIZE = "mail.imap.connectionpoolsize";
057        static public final String IMAP_POOL_TIMEOUT = "mail.imap.connectionpooltimeout";
058        static public final String IMAP_SEPARATE_STORE_CONNECTION = "mail.imap.separatestoreconnection";
059        static public final String IMAP_READONLY_SELECT = "mail.imap.alloreadonlyselect";
060        static public final String IMAP_LOGIN_DISABLE = "mail.imap.auth.login.disable";
061        static public final String IMAP_PLAIN_DISABLE = "mail.imap.auth.plain.disable";
062        static public final String IMAP_STARTTLS_ENABLE = "mail.imap.auth.starttls.enable";
063        static public final String IMAP_SASL_ENABLE = "mail.imap.sasl.enable";
064        static public final String IMAP_SASL_MECHANISMS = "mail.imap.sasl.mechanisms";
065        static public final String IMAP_SASL_AUTHORIZATIONID = "mail.imap.sasl.authorizationid";
066    
067    
068        // the GBEAN property names
069        static public final String GBEAN_PARTIAL_FETCH = "partialFetch";
070        static public final String GBEAN_FETCH_SIZE = "fetchSize";
071        static public final String GBEAN_STATUS_TIMEOUT = "statusCacheTimeout";
072        static public final String GBEAN_APPEND_SIZE = "appendBufferSize";
073        static public final String GBEAN_POOL_SIZE = "connectionPoolSize";
074        static public final String GBEAN_POOL_TIMEOUT = "connectionPoolTimeout";
075        static public final String GBEAN_SEPARATE_STORE_CONNECTION = "separateStoreConnection";
076        static public final String GBEAN_READONLY_SELECT = "allowReadOnlySelect";
077        static public final String GBEAN_LOGIN_DISABLE = "authLoginDisable";
078        static public final String GBEAN_PLAIN_DISABLE = "authPlainDisable";
079        static public final String GBEAN_STARTTLS_ENABLE = "startTLSEnable";
080        static public final String GBEAN_SASL_ENABLE = "saslEnable";
081        static public final String GBEAN_SASL_MECHANISMS = "saslMechanisms";
082        static public final String GBEAN_SASL_AUTHORIZATIONID = "saslAuthorizationId";
083    
084        private final Log log = LogFactory.getLog(IMAPStoreGBean.class);
085    
086        private Integer port;
087        private Boolean partialFetch;
088        private Integer fetchSize;
089        private Integer connectionTimeout;
090        private Integer timeout;
091        private Integer statusCacheTimeout;
092        private Integer appendBufferSize;
093        private Integer connectionPoolSize;
094        private Integer connectionPoolTimeout;
095        private Boolean separateStoreConnection;
096        private Boolean allowReadOnlySelect;
097        private Boolean authLoginDisable;
098        private Boolean authPlainDisable;
099        private Boolean startTLSEnable;
100        private String localaddress;
101        private Integer localport;
102        private Boolean saslEnable;
103        private String saslMechanisms;
104        private String saslAuthorizationId;
105        private String socketFactoryClass;
106        private Boolean socketFactoryFallback;
107        private Integer socketFactoryPort;
108    
109    
110        /**
111         * Construct an instance of IMAPStoreGBean
112         * <p/>
113         * Values that are set in the individual member variables will override any of
114         * the corresponding values that have been set in the properties set.
115         *
116         * @param objectName              the object name of the protocol
117         * @param properties              the set of default properties for the protocol
118         * @param host                    the host the protocol connects to
119         * @param user                    the default name for the protocol
120         * @param port                    the IMAP server port
121         * @param partialFetch            whether the IMAP partial-fetch capability should be used
122         * @param fetchSize               the partial fetch size in bytes
123         * @param connectionTimeout       the socket connection timeout value in milliseconds
124         * @param timeout                 the socket I/O timeout value in milliseconds
125         * @param statusCacheTimeout      the timeout value in milliseconds for cache of STATUS command response
126         * @param appendBufferSize        the maximum size of a message to buffer in memory when appending to an IMAP folder
127         * @param connectionPoolSize      the maximum number of available connections in the connection pool
128         * @param connectionPoolTimeout   the timeout value in milliseconds for connection pool connections
129         * @param separateStoreConnection the flag to indicate whether to use a dedicated store connection for store commands
130         * @param allowReadOnlySelect     the flag to indicate whether SELECT commands are read-only
131         * @param authLoginDisable        the flag that prevents use of the non-standard AUTHENTICATE LOGIN command, instead using the plain LOGIN command
132         * @param authPlainDisable        the flag that prevents use of the AUTHENTICATE PLAIN command
133         * @param startTLSEnable          the flag that enables the use of the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands
134         * @param localaddress            the local address (host name) to bind to when creating the IMAP socket
135         * @param localport               the local port number to bind to when creating the IMAP socket
136         * @param saslEnable              the flag that enables an attempt to use the javax.security.sasl package to choose an authentication mechanism for login
137         * @param saslMechanisms          a space or comma separated list of SASL mechanism names to try to use
138         * @param saslAuthorizationId     the authorization ID to use in the SASL authentication
139         * @param socketFactoryClass      the class that will be used to create IMAP sockets
140         * @param socketFactoryFallback   whether java.net.Socket class will be created if the specified
141         *                                socket factory class cannot be created
142         * @param socketFactoryPort       whether java.net.Socket class will be created if the specified
143         *                                socket factory class cannot be created
144         */
145        public IMAPStoreGBean(String objectName, Properties properties, String host, String user,
146                              Integer port,
147                              Boolean partialFetch,
148                              Integer fetchSize,
149                              Integer connectionTimeout,
150                              Integer timeout,
151                              Integer statusCacheTimeout,
152                              Integer appendBufferSize,
153                              Integer connectionPoolSize,
154                              Integer connectionPoolTimeout,
155                              Boolean separateStoreConnection,
156                              Boolean allowReadOnlySelect,
157                              Boolean authLoginDisable,
158                              Boolean authPlainDisable,
159                              Boolean startTLSEnable,
160                              String localaddress,
161                              Integer localport,
162                              Boolean saslEnable,
163                              String saslMechanisms,
164                              String saslAuthorizationId,
165                              String socketFactoryClass,
166                              Boolean socketFactoryFallback,
167                              Integer socketFactoryPort) {
168            super(objectName, "imap", properties, host, user);
169    
170            setPort(port);
171            setPartialFetch(partialFetch);
172            setFetchSize(fetchSize);
173            setConnectionTimeout(connectionTimeout);
174            setTimeout(timeout);
175            setStatusCacheTimeout(statusCacheTimeout);
176            setAppendBufferSize(appendBufferSize);
177            setConnectionPoolSize(connectionPoolSize);
178            setConnectionPoolTimeout(connectionPoolTimeout);
179            setSeparateStoreConnection(separateStoreConnection);
180            setAllowReadOnlySelect(allowReadOnlySelect);
181            setAuthLoginDisable(authLoginDisable);
182            setAuthPlainDisable(authPlainDisable);
183            setStartTLSEnable(startTLSEnable);
184            setLocaladdress(localaddress);
185            setLocalport(localport);
186            setSaslEnable(saslEnable);
187            setSaslMechanisms(saslMechanisms);
188            setSaslAuthorizationId(saslAuthorizationId);
189            setSocketFactoryClass(socketFactoryClass);
190            setSocketFactoryFallback(socketFactoryFallback);
191            setSocketFactoryPort(socketFactoryPort);
192        }
193    
194        /**
195         * Returns the IMAP server port to connect to, if the connect() method
196         * doesn't explicitly specify one.
197         */
198        public Integer getPort() {
199            return port;
200        }
201    
202        /**
203         * Sets the IMAP server port to connect to, if the connect() method
204         * doesn't explicitly specify one.
205         * <p/>
206         * Defaults to 143.
207         * <p/>
208         * Values that are set here will override any of the corresponding value
209         * that has been set in the properties.
210         *
211         * @param port the IMAP server port to connect to, if the connect() method
212         *             doesn't explicitly specify one
213         */
214        public void setPort(Integer port) {
215            this.port = port;
216        }
217    
218        /**
219         * Returns whether the IMAP partial-fetch capability should be used.
220         * <p/>
221         * Controls whether the IMAP partial-fetch capability should be used.
222         * Defaults to true.
223         */
224        public Boolean getPartialFetch() {
225            return partialFetch;
226        }
227    
228        /**
229         * Sets whether the IMAP partial-fetch capability should be used.
230         * <p/>
231         * Controls whether the IMAP partial-fetch capability should be used.
232         * Defaults to true.
233         * <p/>
234         * Values that are set here will override any of the corresponding value
235         * that has been set in the properties.
236         *
237         * @param partialFetch whether the IMAP partial-fetch capability should be used
238         */
239        public void setPartialFetch(Boolean partialFetch) {
240            this.partialFetch = partialFetch;
241        }
242    
243        /**
244         * Returns the partial fetch size in bytes.
245         * <p/>
246         * Defaults to 16K.
247         */
248        public Integer getFetchSize() {
249            return fetchSize;
250        }
251    
252        /**
253         * Sets the partial fetch size in bytes
254         * <p/>
255         * Defaults to 16K.
256         * <p/>
257         * Values that are set here will override any of the corresponding value
258         * that has been set in the properties.
259         *
260         * @param fetchSize the partial fetch size in bytes
261         */
262        public void setFetchSize(Integer fetchSize) {
263            this.fetchSize = fetchSize;
264        }
265    
266        /**
267         * Returns the socket connection timeout value in milliseconds.
268         */
269        public Integer getConnectionTimeout() {
270            return connectionTimeout;
271        }
272    
273        /**
274         * Sets the socket connection timeout value in milliseconds.
275         * <p/>
276         * Default is infinite timeout.
277         * <p/>
278         * Values that are set here will override any of the corresponding value
279         * that has been set in the properties.
280         *
281         * @param connectionTimeout the socket connection timeout value in milliseconds.
282         */
283        public void setConnectionTimeout(Integer connectionTimeout) {
284            this.connectionTimeout = connectionTimeout;
285        }
286    
287        /**
288         * Returns the socket I/O timeout value in milliseconds.
289         */
290        public Integer getTimeout() {
291            return timeout;
292        }
293    
294        /**
295         * Sets the socket I/O timeout value in milliseconds.
296         * <p/>
297         * Default is infinite timeout.
298         * <p/>
299         * Values that are set here will override any of the corresponding value
300         * that has been set in the properties.
301         *
302         * @param timeout the socket I/O timeout value in milliseconds
303         */
304        public void setTimeout(Integer timeout) {
305            this.timeout = timeout;
306        }
307    
308        /**
309         * Returns the timeout value in milliseconds for cache of STATUS command response.
310         * <p/>
311         * Timeout value in milliseconds for cache of STATUS command response.
312         * Default is 1000 (1 second). Zero disables cache.
313         */
314        public Integer getStatusCacheTimeout() {
315            return statusCacheTimeout;
316        }
317    
318        /**
319         * Sets the timeout value in milliseconds for cache of STATUS command response
320         * <p/>
321         * Timeout value in milliseconds for cache of STATUS command response.
322         * Default is 1000 (1 second). Zero disables cache.
323         * <p/>
324         * Values that are set here will override any of the corresponding value
325         * that has been set in the properties.
326         *
327         * @param statusCacheTimeout the timeout value in milliseconds for cache of STATUS command response
328         */
329        public void setStatusCacheTimeout(Integer statusCacheTimeout) {
330            this.statusCacheTimeout = statusCacheTimeout;
331        }
332    
333        /**
334         * Returns the maximum size of a message to buffer in memory when appending
335         * to an IMAP folder.
336         * <p/>
337         * Maximum size of a message to buffer in memory when appending to an IMAP
338         * folder. If not set, or set to -1, there is no maximum and all messages
339         * are buffered. If set to 0, no messages are buffered. If set to (e.g.)
340         * 8192, messages of 8K bytes or less are buffered, larger messages are not
341         * buffered. Buffering saves cpu time at the expense of short term memory
342         * usage. If you commonly append very large messages to IMAP mailboxes you
343         * might want to set this to a moderate value (1M or less).
344         */
345        public Integer getAppendBufferSize() {
346            return appendBufferSize;
347        }
348    
349        /**
350         * Sets the maximum size of a message to buffer in memory when appending
351         * to an IMAP folder.
352         * <p/>
353         * Maximum size of a message to buffer in memory when appending to an IMAP
354         * folder. If not set, or set to -1, there is no maximum and all messages
355         * are buffered. If set to 0, no messages are buffered. If set to (e.g.)
356         * 8192, messages of 8K bytes or less are buffered, larger messages are not
357         * buffered. Buffering saves cpu time at the expense of short term memory
358         * usage. If you commonly append very large messages to IMAP mailboxes you
359         * might want to set this to a moderate value (1M or less).
360         * <p/>
361         * Values that are set here will override any of the corresponding value
362         * that has been set in the properties.
363         *
364         * @param appendBufferSize the maximum size of a message to buffer in memory when appending
365         *                         to an IMAP folder
366         */
367        public void setAppendBufferSize(Integer appendBufferSize) {
368            this.appendBufferSize = appendBufferSize;
369        }
370    
371        /**
372         * Returns the maximum number of available connections in the connection pool.
373         * <p/>
374         * Default is 1.
375         */
376        public Integer getConnectionPoolSize() {
377            return connectionPoolSize;
378        }
379    
380        /**
381         * Sets the maximum number of available connections in the connection pool.
382         * <p/>
383         * Default is 1.
384         * <p/>
385         * Values that are set here will override any of the corresponding value
386         * that has been set in the properties.
387         *
388         * @param connectionPoolSize the maximum number of available connections in the connection pool
389         */
390        public void setConnectionPoolSize(Integer connectionPoolSize) {
391            this.connectionPoolSize = connectionPoolSize;
392        }
393    
394        /**
395         * Returns the timeout value in milliseconds for connection pool connections.
396         * <p/>
397         * Default is 45000 (45 seconds).
398         */
399        public Integer getConnectionPoolTimeout() {
400            return connectionPoolTimeout;
401        }
402    
403        /**
404         * Sets the timeout value in milliseconds for connection pool connections
405         * <p/>
406         * Default is 45000 (45 seconds).
407         * <p/>
408         * Values that are set here will override any of the corresponding value
409         * that has been set in the properties.
410         *
411         * @param connectionPoolTimeout the timeout value in milliseconds for connection pool connections
412         */
413        public void setConnectionPoolTimeout(Integer connectionPoolTimeout) {
414            this.connectionPoolTimeout = connectionPoolTimeout;
415        }
416    
417        /**
418         * Returns the flag to indicate whether to use a dedicated store
419         * connection for store commands.
420         * <p/>
421         * Flag to indicate whether to use a dedicated store connection
422         * for store commands. Default is false.
423         */
424        public Boolean getSeparateStoreConnection() {
425            return separateStoreConnection;
426        }
427    
428        /**
429         * Sets the flag to indicate whether to use a dedicated store
430         * connection for store commands
431         * <p/>
432         * Flag to indicate whether to use a dedicated store connection
433         * for store commands. Default is false.
434         * <p/>
435         * Values that are set here will override any of the corresponding value
436         * that has been set in the properties.
437         *
438         * @param separateStoreConnection the flag to indicate whether to use a dedicated store
439         *                                connection for store commands
440         */
441        public void setSeparateStoreConnection(Boolean separateStoreConnection) {
442            this.separateStoreConnection = separateStoreConnection;
443        }
444    
445        /**
446         * Returns the flag to indicate whether SELECT commands are read-only.
447         * <p/>
448         * If false, attempts to open a folder read/write will fail if the SELECT
449         * command succeeds but indicates that the folder is READ-ONLY. This
450         * sometimes indicates that the folder contents can'tbe changed, but the
451         * flags are per-user and can be changed, such as might be the case for
452         * public shared folders. If true, such open attempts will succeed, allowing
453         * the flags to be changed. The getMode method on the Folder object will
454         * return Folder.READ_ONLY in this case even though the open method specified
455         * Folder.READ_WRITE. Default is false.
456         */
457        public Boolean getAllowReadOnlySelect() {
458            return allowReadOnlySelect;
459        }
460    
461        /**
462         * Sets the flag to indicate whether SELECT commands are read-only.
463         * <p/>
464         * If false, attempts to open a folder read/write will fail if the SELECT
465         * command succeeds but indicates that the folder is READ-ONLY. This
466         * sometimes indicates that the folder contents can'tbe changed, but the
467         * flags are per-user and can be changed, such as might be the case for
468         * public shared folders. If true, such open attempts will succeed, allowing
469         * the flags to be changed. The getMode method on the Folder object will
470         * return Folder.READ_ONLY in this case even though the open method specified
471         * Folder.READ_WRITE. Default is false.
472         * <p/>
473         * Values that are set here will override any of the corresponding value
474         * that has been set in the properties.
475         *
476         * @param allowReadOnlySelect the flag to indicate whether SELECT commands are read-only
477         */
478        public void setAllowReadOnlySelect(Boolean allowReadOnlySelect) {
479            this.allowReadOnlySelect = allowReadOnlySelect;
480        }
481    
482        /**
483         * Returns the flag that prevents use of the non-standard AUTHENTICATE LOGIN
484         * command, instead using the plain LOGIN command.
485         * <p/>
486         * Default is false.
487         */
488        public Boolean getAuthLoginDisable() {
489            return authLoginDisable;
490        }
491    
492        /**
493         * Sets the flag that prevents use of the non-standard AUTHENTICATE LOGIN
494         * command, instead using the plain LOGIN command.
495         * <p/>
496         * Default is false.
497         * <p/>
498         * Values that are set here will override any of the corresponding value
499         * that has been set in the properties.
500         *
501         * @param authLoginDisable the flag that prevents use of the non-standard AUTHENTICATE LOGIN
502         *                         command, instead using the plain LOGIN command
503         */
504        public void setAuthLoginDisable(Boolean authLoginDisable) {
505            this.authLoginDisable = authLoginDisable;
506        }
507    
508        /**
509         * Returns the flag that prevents use of the AUTHENTICATE PLAIN command.
510         * <p/>
511         * Default is false.
512         */
513        public Boolean getAuthPlainDisable() {
514            return authPlainDisable;
515        }
516    
517        /**
518         * Sets the flag that prevents use of the AUTHENTICATE PLAIN command.
519         * <p/>
520         * Default is false.
521         * <p/>
522         * Values that are set here will override any of the corresponding value
523         * that has been set in the properties.
524         *
525         * @param authPlainDisable the flag that prevents use of the AUTHENTICATE PLAIN command
526         */
527        public void setAuthPlainDisable(Boolean authPlainDisable) {
528            this.authPlainDisable = authPlainDisable;
529        }
530    
531        /**
532         * Returns the flag that enables the use of the STARTTLS command (if
533         * supported by the server) to switch the connection to a TLS-protected
534         * connection before issuing any login commands.
535         * <p/>
536         * If true, enables the use of the STARTTLS command (if supported by the
537         * server) to switch the connection to a TLS-protected connection before
538         * issuing any login commands. Note that an appropriate trust store must
539         * configured so that the client will trust the server's certificate.
540         * This feature only works on J2SE 1.4 and newer systems. Default is false.
541         */
542        public Boolean getStartTLSEnable() {
543            return startTLSEnable;
544        }
545    
546        /**
547         * Sets the flag that enables the use of the STARTTLS command (if
548         * supported by the server) to switch the connection to a TLS-protected
549         * connection before issuing any login commands.
550         * <p/>
551         * If true, enables the use of the STARTTLS command (if supported by the
552         * server) to switch the connection to a TLS-protected connection before
553         * issuing any login commands. Note that an appropriate trust store must
554         * configured so that the client will trust the server's certificate.
555         * This feature only works on J2SE 1.4 and newer systems. Default is false.
556         * <p/>
557         * Values that are set here will override any of the corresponding value
558         * that has been set in the properties.
559         *
560         * @param startTLSEnable the flag that enables the use of the STARTTLS command (if
561         *                       supported by the server) to switch the connection to a TLS-protected
562         *                       connection before issuing any login commands
563         */
564        public void setStartTLSEnable(Boolean startTLSEnable) {
565            this.startTLSEnable = startTLSEnable;
566        }
567    
568        /**
569         * Returns the local address (host name) to bind to when creating the IMAP socket.
570         */
571        public String getLocaladdress() {
572            return localaddress;
573        }
574    
575        /**
576         * Sets the local address (host name) to bind to when creating the IMAP socket.
577         * <p/>
578         * Local address (host name) to bind to when creating the IMAP socket.
579         * Defaults to the address picked by the Socket class. Should not normally
580         * need to be set, but useful with multi-homed hosts where it's important
581         * to pick a particular local address to bind to.
582         * <p/>
583         * Values that are set here will override any of the corresponding value
584         * that has been set in the properties.
585         *
586         * @param localaddress the local address (host name) to bind to when creating the IMAP socket
587         */
588        public void setLocaladdress(String localaddress) {
589            this.localaddress = localaddress;
590        }
591    
592        /**
593         * Returns the local port number to bind to when creating the IMAP socket.
594         */
595        public Integer getLocalport() {
596            return localport;
597        }
598    
599        /**
600         * Sets the local port number to bind to when creating the IMAP socket.
601         * <p/>
602         * Local port number to bind to when creating the IMAP socket. Defaults to
603         * the port number picked by the Socket class.
604         * <p/>
605         * Values that are set here will override any of the corresponding value
606         * that has been set in the properties.
607         *
608         * @param localport the local port number to bind to when creating the IMAP socket
609         */
610        public void setLocalport(Integer localport) {
611            this.localport = localport;
612        }
613    
614        /**
615         * Returns the flag that enables an attempt to use the javax.security.sasl
616         * package to choose an authentication mechanism for login.
617         * <p/>
618         * Defaults to false.
619         */
620        public Boolean getSaslEnable() {
621            return saslEnable;
622        }
623    
624        /**
625         * Sets the flag that enables an attempt to use the javax.security.sasl
626         * package to choose an authentication mechanism for login.
627         * <p/>
628         * Defaults to false.
629         * <p/>
630         * Values that are set here will override any of the corresponding value
631         * that has been set in the properties.
632         *
633         * @param saslEnable the flag that enables an attempt to use the javax.security.sasl
634         *                   package to choose an authentication mechanism for login
635         */
636        public void setSaslEnable(Boolean saslEnable) {
637            this.saslEnable = saslEnable;
638        }
639    
640        /**
641         * Returns a space or comma separated list of SASL mechanism names to try to use.
642         */
643        public String getSaslMechanisms() {
644            return saslMechanisms;
645        }
646    
647        /**
648         * Sets a space or comma separated list of SASL mechanism names to try to use.
649         * <p/>
650         * Values that are set here will override any of the corresponding value
651         * that has been set in the properties.
652         *
653         * @param saslMechanisms a space or comma separated list of SASL mechanism names to try to use
654         */
655        public void setSaslMechanisms(String saslMechanisms) {
656            this.saslMechanisms = saslMechanisms;
657        }
658    
659        /**
660         * Returns the authorization ID to use in the SASL authentication.
661         * <p/>
662         * If not set, the authetication ID (user name) is used.
663         */
664        public String getSaslAuthorizationId() {
665            return saslAuthorizationId;
666        }
667    
668        /**
669         * Sets the authorization ID to use in the SASL authentication.
670         * <p/>
671         * If not set, the authetication ID (user name) is used.
672         * <p/>
673         * Values that are set here will override any of the corresponding value
674         * that has been set in the properties.
675         *
676         * @param saslAuthorizationId the authorization ID to use in the SASL authentication
677         */
678        public void setSaslAuthorizationId(String saslAuthorizationId) {
679            this.saslAuthorizationId = saslAuthorizationId;
680        }
681    
682        /**
683         * Returns the class that will be used to create IMAP sockets.
684         * <p/>
685         * If set, specifies the name of a class that implements the
686         * javax.net.SocketFactory interface. This class will be used to create IMAP
687         * sockets.
688         */
689        public String getSocketFactoryClass() {
690            return socketFactoryClass;
691        }
692    
693        /**
694         * Sets the class that will be used to create SMTP sockets.
695         * <p/>
696         * If set, specifies the name of a class that implements the
697         * javax.net.SocketFactory interface. This class will be used to create SMTP
698         * sockets.
699         * <p/>
700         * Values that are set here will override any of the corresponding value
701         * that has been set in the properties.
702         *
703         * @param socketFactoryClass the class that will be used to create SMTP sockets
704         */
705        public void setSocketFactoryClass(String socketFactoryClass) {
706            this.socketFactoryClass = socketFactoryClass;
707        }
708    
709        /**
710         * Returns whether java.net.Socket class will be created if the specified
711         * socket factory class cannot be created.
712         * <p/>
713         * If set to true, failure to create a socket using the specified socket
714         * factory class will cause the socket to be created using the
715         * java.net.Socket class. Defaults to true.
716         */
717        public Boolean getSocketFactoryFallback() {
718            return socketFactoryFallback;
719        }
720    
721        /**
722         * Sets whether java.net.Socket class will be created if the specified
723         * socket factory class cannot be created.
724         * <p/>
725         * If set to true, failure to create a socket using the specified socket
726         * factory class will cause the socket to be created using the
727         * java.net.Socket class. Defaults to true.
728         * <p/>
729         * Values that are set here will override any of the corresponding value
730         * that has been set in the properties.
731         *
732         * @param socketFactoryFallback whether java.net.Socket class will be created if the specified
733         *                              socket factory class cannot be created
734         */
735        public void setSocketFactoryFallback(Boolean socketFactoryFallback) {
736            this.socketFactoryFallback = socketFactoryFallback;
737        }
738    
739        /**
740         * Returns the port to connect to when using the specified socket factory.
741         * <p/>
742         * Specifies the port to connect to when using the specified socket
743         * factory. If not set, the default port will be used.
744         */
745        public Integer getSocketFactoryPort() {
746            return socketFactoryPort;
747        }
748    
749        /**
750         * Sets the port to connect to when using the specified socket factory.
751         * <p/>
752         * Specifies the port to connect to when using the specified socket
753         * factory. If not set, the default port will be used.
754         * <p/>
755         * Values that are set here will override any of the corresponding value
756         * that has been set in the properties.
757         *
758         * @param socketFactoryPort the port to connect to when using the specified socket factory
759         */
760        public void setSocketFactoryPort(Integer socketFactoryPort) {
761            this.socketFactoryPort = socketFactoryPort;
762        }
763    
764        /**
765         * Add the overrides from the member variables to the properties file.
766         */
767        public void addOverrides(Properties props) {
768            super.addOverrides(props);
769    
770            if (port != null) props.setProperty(IMAP_PORT, port.toString());
771            if (partialFetch != null) props.setProperty(IMAP_PARTIAL_FETCH, partialFetch.toString());
772            if (fetchSize != null) props.setProperty(IMAP_FETCH_SIZE, fetchSize.toString());
773            if (connectionTimeout != null) props.setProperty(IMAP_CONNECTION_TIMEOUT, connectionTimeout.toString());
774            if (timeout != null) props.setProperty(IMAP_TIMEOUT, timeout.toString());
775            if (statusCacheTimeout != null) props.setProperty(IMAP_STATUS_TIMEOUT, statusCacheTimeout.toString());
776            if (appendBufferSize != null) props.setProperty(IMAP_APPEND_SIZE, appendBufferSize.toString());
777            if (connectionPoolSize != null) props.setProperty(IMAP_POOL_SIZE, connectionPoolSize.toString());
778            if (connectionPoolTimeout != null) props.setProperty(IMAP_POOL_TIMEOUT, connectionPoolTimeout.toString());
779            if (separateStoreConnection != null) props.setProperty(IMAP_SEPARATE_STORE_CONNECTION, separateStoreConnection.toString());
780            if (allowReadOnlySelect != null) props.setProperty(IMAP_READONLY_SELECT, allowReadOnlySelect.toString());
781            if (authLoginDisable != null) props.setProperty(IMAP_LOGIN_DISABLE, authLoginDisable.toString());
782            if (authPlainDisable != null) props.setProperty(IMAP_PLAIN_DISABLE, authPlainDisable.toString());
783            if (startTLSEnable != null) props.setProperty(IMAP_STARTTLS_ENABLE, startTLSEnable.toString());
784            if (localaddress != null) props.setProperty(IMAP_LOCALADDRESS, localaddress);
785            if (localport != null) props.setProperty(IMAP_LOCALPORT, localport.toString());
786            if (saslEnable != null) props.setProperty(IMAP_SASL_ENABLE, saslEnable.toString());
787            if (saslMechanisms != null) props.setProperty(IMAP_SASL_MECHANISMS, saslMechanisms);
788            if (saslAuthorizationId != null) props.setProperty(IMAP_SASL_AUTHORIZATIONID, saslAuthorizationId);
789            if (socketFactoryClass != null) props.setProperty(IMAP_FACTORY_CLASS, socketFactoryClass);
790            if (socketFactoryFallback != null) props.setProperty(IMAP_FACTORY_FALLBACK, socketFactoryFallback.toString());
791            if (socketFactoryPort != null) props.setProperty(IMAP_FACTORY_PORT, socketFactoryPort.toString());
792        }
793    
794        public void doStart() throws Exception {
795            log.debug("Started " + getObjectName());
796        }
797    
798        public void doStop() throws Exception {
799            log.debug("Stopped " + getObjectName());
800        }
801    
802        public void doFail() {
803            log.warn("Failed " + getObjectName());
804        }
805    
806        public static final GBeanInfo GBEAN_INFO;
807    
808        static {
809            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(IMAPStoreGBean.class, ProtocolGBean.GBEAN_INFO);
810    
811            infoFactory.addAttribute(GBEAN_PORT, Integer.class, true);
812            infoFactory.addAttribute(GBEAN_CONNECTION_TIMEOUT, Integer.class, true);
813            infoFactory.addAttribute(GBEAN_TIMEOUT, Integer.class, true);
814            infoFactory.addAttribute(GBEAN_LOCALADDRESS, String.class, true);
815            infoFactory.addAttribute(GBEAN_LOCALPORT, Integer.class, true);
816            infoFactory.addAttribute(GBEAN_FACTORY_CLASS, String.class, true);
817            infoFactory.addAttribute(GBEAN_FACTORY_FALLBACK, Boolean.class, true);
818            infoFactory.addAttribute(GBEAN_FACTORY_PORT, Integer.class, true);
819            infoFactory.addAttribute(GBEAN_PARTIAL_FETCH, Boolean.class, true);
820            infoFactory.addAttribute(GBEAN_FETCH_SIZE, Integer.class, true);
821            infoFactory.addAttribute(GBEAN_STATUS_TIMEOUT, Integer.class, true);
822            infoFactory.addAttribute(GBEAN_APPEND_SIZE, Integer.class, true);
823            infoFactory.addAttribute(GBEAN_POOL_SIZE, Integer.class, true);
824            infoFactory.addAttribute(GBEAN_POOL_TIMEOUT, Integer.class, true);
825            infoFactory.addAttribute(GBEAN_SEPARATE_STORE_CONNECTION, Boolean.class, true);
826            infoFactory.addAttribute(GBEAN_READONLY_SELECT, Boolean.class, true);
827            infoFactory.addAttribute(GBEAN_LOGIN_DISABLE, Boolean.class, true);
828            infoFactory.addAttribute(GBEAN_PLAIN_DISABLE, Boolean.class, true);
829            infoFactory.addAttribute(GBEAN_STARTTLS_ENABLE, Boolean.class, true);
830            infoFactory.addAttribute(GBEAN_SASL_ENABLE, Boolean.class, true);
831            infoFactory.addAttribute(GBEAN_SASL_MECHANISMS, String.class, true);
832            infoFactory.addAttribute(GBEAN_SASL_AUTHORIZATIONID, String.class, true);
833    
834            infoFactory.addAttribute(GBEAN_OBJECTNAME, String.class, false);
835            infoFactory.addAttribute(GBEAN_PROTOCOL, String.class, true);
836            infoFactory.addAttribute(GBEAN_PROPERTIES, Properties.class, true);
837            infoFactory.addAttribute(GBEAN_HOST, String.class, true);
838            infoFactory.addAttribute(GBEAN_USER, String.class, true);
839            infoFactory.addOperation(GBEAN_ADD_OVERRIDES, new Class[]{Properties.class});
840    
841            infoFactory.setConstructor(new String[]{GBEAN_OBJECTNAME, GBEAN_PROPERTIES, GBEAN_HOST, GBEAN_USER,
842                                                    GBEAN_PORT,
843                                                    GBEAN_PARTIAL_FETCH,
844                                                    GBEAN_FETCH_SIZE,
845                                                    GBEAN_CONNECTION_TIMEOUT,
846                                                    GBEAN_TIMEOUT,
847                                                    GBEAN_STATUS_TIMEOUT,
848                                                    GBEAN_APPEND_SIZE,
849                                                    GBEAN_POOL_SIZE,
850                                                    GBEAN_POOL_TIMEOUT,
851                                                    GBEAN_SEPARATE_STORE_CONNECTION,
852                                                    GBEAN_READONLY_SELECT,
853                                                    GBEAN_LOGIN_DISABLE,
854                                                    GBEAN_PLAIN_DISABLE,
855                                                    GBEAN_STARTTLS_ENABLE,
856                                                    GBEAN_LOCALADDRESS,
857                                                    GBEAN_LOCALPORT,
858                                                    GBEAN_SASL_ENABLE,
859                                                    GBEAN_SASL_MECHANISMS,
860                                                    GBEAN_SASL_AUTHORIZATIONID,
861                                                    GBEAN_FACTORY_CLASS,
862                                                    GBEAN_FACTORY_FALLBACK,
863                                                    GBEAN_FACTORY_PORT});
864    
865            GBEAN_INFO = infoFactory.getBeanInfo();
866        }
867    
868        public static GBeanInfo getGBeanInfo() {
869            return GBEAN_INFO;
870        }
871    }