Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.

1 /***********************************************************************2 * Copyright (c) 2000-2004 The Apache Software Foundation. *3 * All rights reserved. *4 * ------------------------------------------------------------------- *5 * Licensed under the Apache License, Version 2.0 (the "License"); you *6 * may not use this file except in compliance with the License. You *7 * may obtain a copy of the License at: *8 * *9 * http://www.apache.org/licenses/LICENSE-2.0 *10 * *11 * Unless required by applicable law or agreed to in writing, software *12 * distributed under the License is distributed on an "AS IS" BASIS, *13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *14 * implied. See the License for the specific language governing *15 * permissions and limitations under the License. *16 ***********************************************************************/17 18 package org.apache.james.transport.mailets;19 20 importjava.net.InetAddress;21 importjava.net.Socket;22 importjava.net.UnknownHostException;23 importjava.io.IOException;24 25 /**26 * It is used by RemoteDelivery in order to make possible to bind the client27 * socket to a specific ip address.28 *29 * This is not a nice solution because the ip address must be shared by all 30 * RemoteDelivery instances. It would be better to modify JavaMail 31 * (current version 1.3) to support a corresonding property, e.g.32 * mail.smtp.bindAdress.33 * 34 * It should be a javax.net.SocketFactory descendant, but 35 * 1. it is not necessary because JavaMail 1.2 uses reflection when accessing36 * this class;37 * 2. it is not desirable because it would require java 1.4.38 */39 publicclass RemoteDeliverySocketFactory {40 41 /**42 * @param addr the ip address or host name the delivery socket will bind to43 */44 staticvoid setBindAdress(String addr) throwsUnknownHostException {45 if (addr == null) bindAddress = null;46 else bindAddress = InetAddress.getByName(addr);47 }48 49 /**50 * the same as the similarly named javax.net.SocketFactory operation.51 */52 publicstaticRemoteDeliverySocketFactory getDefault() {53 returnnewRemoteDeliverySocketFactory();54 }55 56 /**57 * the same as the similarly named javax.net.SocketFactory operation.58 * Just to be safe, it is not used by JavaMail 1.3.59 */60 publicSocket createSocket() throwsIOException {61 thrownewIOException("Incompatible JavaMail version, " +62 "cannot bound socket");63 }64 65 /**66 * the same as the similarly named javax.net.SocketFactory operation.67 * This is the one which is used by JavaMail 1.3.68 */69 publicSocket createSocket(String host, int port)70 throwsIOException, UnknownHostException {71 returnnewSocket(host, port, bindAddress, 0);72 }73 74 /**75 * the same as the similarly named javax.net.SocketFactory operation.76 * Just to be safe, it is not used by JavaMail 1.3.77 */78 publicSocket createSocket(String host,79 int port,80 InetAddress clientHost,81 int clientPort)82 throwsIOException,83 UnknownHostException {84 returnnewSocket(host, port, 85 clientHost == null ? bindAddress : clientHost, clientPort);86 }87 88 /**89 * the same as the similarly named javax.net.SocketFactory operation.90 * Just to be safe, it is not used by JavaMail 1.3.91 */92 publicSocket createSocket(InetAddress host, int port) throwsIOException {93 returnnewSocket(host, port, bindAddress, 0);94 }95 96 /**97 * the same as the similarly named javax.net.SocketFactory operation.98 * Just to be safe, it is not used by JavaMail 1.3.99 */100 publicSocket createSocket(InetAddress address,101 int port,102 InetAddress clientAddress,103 int clientPort)104 throwsIOException {105 returnnewSocket(address, port, 106 clientAddress == null ? bindAddress : clientAddress, 107 clientPort);108 }109 110 /**111 * it should be set by setBindAdress(). Null means the socket is bind to 112 * the default address.113 */114 privatestaticInetAddress bindAddress;115 }116