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