/* * Copyright 2006 Under Dusken * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.pegadi.server.mail; import java.util.ArrayList; /** * Created by IntelliJ IDEA. * Date: 1/09/2006 * Time: 17:33:01 * To change this template use File | Settings | File Templates. * * @author Erlend Hamnaberg<erlenha@underdusken.no> */ public class InternetAddress { private String name; private String email; public InternetAddress(String name, String email) { this.name = name; this.email = email; } public static InternetAddress[] parse(String string) { ArrayList list = new ArrayList(); if (string.indexOf(",") != -1) { String[] array = string.split(","); for (String s : array) { s = s.trim(); int i = s.indexOf("<"); if (i != -1) { list.add(new InternetAddress(s.substring(0, i), s.substring(i + 1, s.length() - 1))); } } } else { int i = string.indexOf("<"); if (i != -1) { list.add(new InternetAddress(string.substring(0, i), string.substring(i + 1, string.length() - 1))); } else list.add(new InternetAddress(null,string)); } return (InternetAddress[]) list.toArray(new InternetAddress[list.size()]); } public static InternetAddress[] parse(String[] array) { ArrayList list = new ArrayList(); for (String s : array) { s = s.trim(); int i = s.indexOf("<"); if (i != -1) { list.add(new InternetAddress(s.substring(0, i), s.substring(i + 1, s.length() - 1))); } else list.add(new InternetAddress(null, s)); } return (InternetAddress[]) list.toArray(new InternetAddress[list.size()]); } public String getName() { return name; } public String getEmail() { return email; } public String toString() { return "name: " + name + "\nemail: " + email; } }