| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.commons.net.smtp.RelayPath |
|
|
| 1 | /* |
|
| 2 | * Copyright 2001-2005 The Apache Software Foundation |
|
| 3 | * |
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 5 | * you may not use this file except in compliance with the License. |
|
| 6 | * You may obtain a copy of the License at |
|
| 7 | * |
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 9 | * |
|
| 10 | * Unless required by applicable law or agreed to in writing, software |
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 13 | * See the License for the specific language governing permissions and |
|
| 14 | * limitations under the License. |
|
| 15 | */ |
|
| 16 | package org.apache.commons.net.smtp; |
|
| 17 | ||
| 18 | import java.util.Enumeration; |
|
| 19 | import java.util.Vector; |
|
| 20 | ||
| 21 | /*** |
|
| 22 | * A class used to represent forward and reverse relay paths. The |
|
| 23 | * SMTP MAIL command requires a reverse relay path while the SMTP RCPT |
|
| 24 | * command requires a forward relay path. See RFC 821 for more details. |
|
| 25 | * In general, you will not have to deal with relay paths. |
|
| 26 | * <p> |
|
| 27 | * <p> |
|
| 28 | * @author Daniel F. Savarese |
|
| 29 | * @see SMTPClient |
|
| 30 | ***/ |
|
| 31 | ||
| 32 | public final class RelayPath |
|
| 33 | { |
|
| 34 | Vector _path; |
|
| 35 | String _emailAddress; |
|
| 36 | ||
| 37 | /*** |
|
| 38 | * Create a relay path with the specified email address as the ultimate |
|
| 39 | * destination. |
|
| 40 | * <p> |
|
| 41 | * @param emailAddress The destination email address. |
|
| 42 | ***/ |
|
| 43 | public RelayPath(String emailAddress) |
|
| 44 | 0 | { |
| 45 | 0 | _path = new Vector(); |
| 46 | 0 | _emailAddress = emailAddress; |
| 47 | 0 | } |
| 48 | ||
| 49 | /*** |
|
| 50 | * Add a mail relay host to the relay path. Hosts are added left to |
|
| 51 | * right. For example, the following will create the path |
|
| 52 | * <code><b> < @bar.com,@foo.com:foobar@foo.com > </b></code> |
|
| 53 | * <pre> |
|
| 54 | * path = new RelayPath("foobar@foo.com"); |
|
| 55 | * path.addRelay("bar.com"); |
|
| 56 | * path.addRelay("foo.com"); |
|
| 57 | * </pre> |
|
| 58 | * <p> |
|
| 59 | * @param hostname The host to add to the relay path. |
|
| 60 | ***/ |
|
| 61 | public void addRelay(String hostname) |
|
| 62 | { |
|
| 63 | 0 | _path.addElement(hostname); |
| 64 | 0 | } |
| 65 | ||
| 66 | /*** |
|
| 67 | * Return the properly formatted string representation of the relay path. |
|
| 68 | * <p> |
|
| 69 | * @return The properly formatted string representation of the relay path. |
|
| 70 | ***/ |
|
| 71 | public String toString() |
|
| 72 | { |
|
| 73 | 0 | StringBuffer buffer = new StringBuffer(); |
| 74 | Enumeration hosts; |
|
| 75 | ||
| 76 | 0 | buffer.append('<'); |
| 77 | ||
| 78 | 0 | hosts = _path.elements(); |
| 79 | ||
| 80 | 0 | if (hosts.hasMoreElements()) |
| 81 | { |
|
| 82 | 0 | buffer.append('@'); |
| 83 | 0 | buffer.append((String)hosts.nextElement()); |
| 84 | ||
| 85 | 0 | while (hosts.hasMoreElements()) |
| 86 | { |
|
| 87 | 0 | buffer.append(",@"); |
| 88 | 0 | buffer.append((String)hosts.nextElement()); |
| 89 | } |
|
| 90 | 0 | buffer.append(':'); |
| 91 | } |
|
| 92 | ||
| 93 | 0 | buffer.append(_emailAddress); |
| 94 | 0 | buffer.append('>'); |
| 95 | ||
| 96 | 0 | return buffer.toString(); |
| 97 | } |
|
| 98 | ||
| 99 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |