source: contrib/MailArchiver/sources/src/serpro/mailarchiver/domain/metaarchive/Address.java @ 6785

Revision 6785, 4.4 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado codigo do MailArchiver?. Documentação na subpasta DOCS.

Line 
1/**
2 * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface.
3 * Copyright (C) 2012  Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/******************************************************************************\
20*
21*  This product was developed by
22*
23*        SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
24*
25*  a government company established under Brazilian law (5.615/70),
26*  at Department of Development of Porto Alegre.
27*
28\******************************************************************************/
29
30package serpro.mailarchiver.domain.metaarchive;
31
32import javax.jdo.annotations.NotPersistent;
33import javax.jdo.annotations.PersistenceCapable;
34
35import org.apache.james.mime4j.codec.EncoderUtil;
36
37import serpro.mailarchiver.domain.BaseObject;
38import serpro.mailarchiver.util.Logger;
39
40@PersistenceCapable
41public abstract class Address
42    extends BaseObject
43{
44    @NotPersistent
45    private static final Logger log = Logger.getLocalLogger();
46
47    //**** P E R S I S T E N T ****
48    private String oid;
49    private String name;
50
51    //mailbox
52    protected String localPart;
53    protected String domain;
54    protected String route;
55    //*****************************
56
57    public abstract Message getRootMessage();
58
59    public final String getOid() {
60        return oid;
61    }
62
63    public final void setOid(String oid) {
64        this.oid = oid;
65    }
66
67    public final String getName() {
68        return name;
69    }
70
71    public final void setName(String name) {
72        this.name = name;
73    }
74
75    //--------------------------------------------------------------------------
76    public String dumpPath() {
77        StringBuilder sb = new StringBuilder();
78        dumpPath(sb, true);
79        return sb.toString();
80    }
81
82    abstract int dumpPath(StringBuilder sb, boolean quit);
83
84    public String dumpTree() {
85        StringBuilder sb = new StringBuilder();
86        dumpTree(sb, "");
87        return sb.toString();
88    }
89
90    abstract void dumpTree(StringBuilder sb, String pad);
91
92    @Override
93    public final String toString() {
94        return toString("    ");
95    }
96
97    abstract String toString(String pad);
98
99    //--------------------------------------------------------------------------
100    public final String toDisplayString() {
101        return toDisplayString(false);
102    }
103
104    public String toDisplayString(boolean includeRoute) {
105
106        includeRoute &= (route != null);
107        boolean includeAngleBrackets = (name != null) || includeRoute;
108
109        StringBuilder sb = new StringBuilder();
110
111        if(name != null) {
112            sb.append(name);
113            sb.append(" ");
114        }
115
116        if(includeAngleBrackets) {
117            sb.append("<");
118        }
119
120        if(includeRoute) {
121            sb.append(route);
122            sb.append(":");
123        }
124
125        sb.append(localPart);
126
127        if(domain != null) {
128            sb.append("@");
129            sb.append(domain);
130        }
131
132        if(includeAngleBrackets) {
133            sb.append(">");
134        }
135
136        return sb.toString();
137    }
138
139    public String toEncodedString() {
140        StringBuilder sb = new StringBuilder();
141
142        if(name != null) {
143            sb.append(EncoderUtil.encodeAddressDisplayName(name));
144            sb.append(" <");
145        }
146
147        sb.append(EncoderUtil.encodeAddressLocalPart(localPart));
148
149        // domain = dot-atom / domain-literal
150        // domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]
151        // dtext = %d33-90 / %d94-126
152        if(domain != null) {
153            sb.append("@");
154            sb.append(domain);
155        }
156
157        if(name != null) {
158            sb.append(">");
159        }
160
161        return sb.toString();
162    }
163}
Note: See TracBrowser for help on using the repository browser.