/** * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ /******************************************************************************\ * * This product was developed by * * SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), * * a government company established under Brazilian law (5.615/70), * at Department of Development of Porto Alegre. * \******************************************************************************/ package serpro.mailarchiver.domain.metaarchive; import javax.jdo.annotations.NotPersistent; import javax.jdo.annotations.PersistenceCapable; import org.apache.james.mime4j.codec.EncoderUtil; import serpro.mailarchiver.domain.BaseObject; import serpro.mailarchiver.util.Logger; @PersistenceCapable public abstract class Address extends BaseObject { @NotPersistent private static final Logger log = Logger.getLocalLogger(); //**** P E R S I S T E N T **** private String oid; private String name; //mailbox protected String localPart; protected String domain; protected String route; //***************************** public abstract Message getRootMessage(); public final String getOid() { return oid; } public final void setOid(String oid) { this.oid = oid; } public final String getName() { return name; } public final void setName(String name) { this.name = name; } //-------------------------------------------------------------------------- public String dumpPath() { StringBuilder sb = new StringBuilder(); dumpPath(sb, true); return sb.toString(); } abstract int dumpPath(StringBuilder sb, boolean quit); public String dumpTree() { StringBuilder sb = new StringBuilder(); dumpTree(sb, ""); return sb.toString(); } abstract void dumpTree(StringBuilder sb, String pad); @Override public final String toString() { return toString(" "); } abstract String toString(String pad); //-------------------------------------------------------------------------- public final String toDisplayString() { return toDisplayString(false); } public String toDisplayString(boolean includeRoute) { includeRoute &= (route != null); boolean includeAngleBrackets = (name != null) || includeRoute; StringBuilder sb = new StringBuilder(); if(name != null) { sb.append(name); sb.append(" "); } if(includeAngleBrackets) { sb.append("<"); } if(includeRoute) { sb.append(route); sb.append(":"); } sb.append(localPart); if(domain != null) { sb.append("@"); sb.append(domain); } if(includeAngleBrackets) { sb.append(">"); } return sb.toString(); } public String toEncodedString() { StringBuilder sb = new StringBuilder(); if(name != null) { sb.append(EncoderUtil.encodeAddressDisplayName(name)); sb.append(" <"); } sb.append(EncoderUtil.encodeAddressLocalPart(localPart)); // domain = dot-atom / domain-literal // domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS] // dtext = %d33-90 / %d94-126 if(domain != null) { sb.append("@"); sb.append(domain); } if(name != null) { sb.append(">"); } return sb.toString(); } }