001: /*
002: * MailboxURL.java
003: *
004: * Copyright (C) 2002 Peter Graves
005: * $Id: MailboxURL.java,v 1.1.1.1 2002/09/24 16:09:53 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j.mail;
023:
024: import java.net.MalformedURLException;
025: import org.armedbear.j.Log;
026:
027: public abstract class MailboxURL {
028: private String baseName;
029: private String limitPattern;
030:
031: protected String user;
032: protected String host;
033: protected int port;
034:
035: public final String getBaseName() {
036: return baseName;
037: }
038:
039: public final void setBaseName(String baseName) {
040: this .baseName = baseName;
041: }
042:
043: public final String getLimitPattern() {
044: return limitPattern;
045: }
046:
047: public final void setLimitPattern(String limitPattern) {
048: this .limitPattern = limitPattern;
049: }
050:
051: public final String getUser() {
052: return user;
053: }
054:
055: public final void setUser(String user) {
056: this .user = user;
057: }
058:
059: public final String getHost() {
060: return host;
061: }
062:
063: public final int getPort() {
064: return port;
065: }
066:
067: public static MailboxURL parse(String input) {
068: if (input == null)
069: return null;
070: input = input.trim();
071: if (input.length() == 0)
072: return null;
073: String baseName;
074: String limitPattern = null;
075: if (input.charAt(0) == '"') {
076: int index = input.indexOf('"', 1);
077: if (index < 0)
078: return null;
079: baseName = input.substring(1, index);
080: if (index < input.length() - 1)
081: limitPattern = input.substring(index + 1).trim();
082: } else {
083: int index = input.indexOf(' ');
084: if (index >= 0) {
085: baseName = input.substring(0, index);
086: limitPattern = input.substring(index).trim();
087: } else
088: baseName = input;
089: }
090: if (baseName.length() == 0)
091: return null;
092: MailboxURL url = null;
093: try {
094: if (baseName.charAt(0) == '{') {
095: // IMAP.
096: url = new ImapURL(baseName);
097: } else if (baseName.startsWith("pop://")) {
098: // POP.
099: url = new PopURL(baseName);
100: } else {
101: // Local.
102: url = new LocalMailboxURL(baseName);
103: }
104: } catch (MalformedURLException e) {
105: Log.error(e);
106: }
107: if (url != null) {
108: url.setBaseName(baseName);
109: url.setLimitPattern(limitPattern);
110: }
111: return url;
112: }
113:
114: public abstract String getCanonicalName();
115: }
|