source: contrib/MailArchiver/sources/src/serpro/mailarchiver/service/dto/TMessage.java @ 6785

Revision 6785, 10.0 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.service.dto;
31
32import java.util.Date;
33import java.util.regex.Pattern;
34
35import javax.xml.bind.annotation.XmlRootElement;
36
37import serpro.mailarchiver.domain.metaarchive.AddressListField;
38import serpro.mailarchiver.domain.metaarchive.ContentTypeField;
39import serpro.mailarchiver.domain.metaarchive.DateTimeField;
40import serpro.mailarchiver.domain.metaarchive.Folder;
41import serpro.mailarchiver.domain.metaarchive.MailboxField;
42import serpro.mailarchiver.domain.metaarchive.MailboxListField;
43import serpro.mailarchiver.domain.metaarchive.Message;
44import serpro.mailarchiver.domain.metaarchive.TextBody;
45import serpro.mailarchiver.domain.metaarchive.UnstructuredField;
46import serpro.mailarchiver.util.BodyVisitor;
47import serpro.mailarchiver.util.Logger;
48
49@XmlRootElement(name="Message")
50public class TMessage implements Identifiable {
51
52    private static final Logger log = Logger.getLocalLogger();
53
54    private String id;
55    @Override
56    public String getId() { return id; }
57    @Override
58    public void setId(String id) { this.id = id; }
59
60    //--------------------------------------------------------------------------
61    private String subject;
62    public String getSubject() { return subject; }
63    public void setSubject(String subject) { this.subject = subject; }
64
65    //--------------------------------------------------------------------------
66    private String preview;
67    public String getPreview() { return preview; }
68    public void setPreview(String preview) { this.preview = preview; }
69
70    //--------------------------------------------------------------------------
71    private long size;
72    public long getSize() { return size; }
73    public void setSize(long size) { this.size = size; }
74
75    //--------------------------------------------------------------------------
76    private String sender;
77    public String getSender() { return sender; }
78    public void setSender(String sender) { this.sender = sender; }
79
80    //--------------------------------------------------------------------------
81    private String from;
82    public String getFrom() { return from; }
83    public void setFrom(String from) { this.from = from; }
84
85    //--------------------------------------------------------------------------
86    private String to;
87    public String getTo() { return to; }
88    public void setTo(String to) { this.to = to; }
89
90    //--------------------------------------------------------------------------
91    private String cc;
92    public String getCc() { return cc; }
93    public void setCc(String cc) { this.cc = cc; }
94
95    //--------------------------------------------------------------------------
96    private String bcc;
97    public String getBcc() { return bcc; }
98    public void setBcc(String bcc) { this.bcc = bcc; }
99
100    //--------------------------------------------------------------------------
101    private String replyTo;
102    public String getReplyTo() { return replyTo; }
103    public void setReplyTo(String replyTo) { this.replyTo = replyTo; }
104
105    //--------------------------------------------------------------------------
106    private String dispositionNotificationTo;
107    public String getDispositionNotificationTo() { return dispositionNotificationTo; }
108    public void setDispositionNotificationTo(String dispositionNotificationTo) { this.dispositionNotificationTo = dispositionNotificationTo; }
109
110    //--------------------------------------------------------------------------
111    private long date;
112    public long getDate() { return date; }
113    public void setDate(long date) { this.date = date; }
114
115    //--------------------------------------------------------------------------
116    private long receivedDate;
117    public long getReceivedDate() { return receivedDate; }
118    public void setReceivedDate(long receivedDate) { this.receivedDate = receivedDate; }
119
120    //--------------------------------------------------------------------------
121    private String folderId;
122    public String getFolderId() { return folderId; }
123    public void setFolderId(String folderId) { this.folderId = folderId; }
124
125    //--------------------------------------------------------------------------
126    private String folderPath;
127    public String getFolderPath() { return folderPath; }
128    public void setFolderPath(String folderPath) { this.folderPath = folderPath; }
129
130    //--------------------------------------------------------------------------
131    private String tags;
132    public String getTags() { return tags; }
133    public void setTags(String tags) { this.tags = tags; }
134
135    //--------------------------------------------------------------------------
136    private String contentType;
137    public String getContentType() { return contentType; }
138    public void setContentType(String contentType) { this.contentType = contentType; }
139
140    //--------------------------------------------------------------------------
141    private String attachments;
142    public String getAttachments() { return attachments; }
143    public void setAttachments(String attachments) { this.attachments = attachments; }
144
145    //==========================================================================
146    private static final Pattern controlCharactersPattern = Pattern.compile("[\\x00-\\x1F]");
147
148    public TMessage() {}
149
150    public TMessage(Message message) {
151
152        id = message.getOid();
153
154        Folder folder = message.getFolder();
155        folderId = folder.getExternalOid();
156        folderPath = folder.getRelativePath().toString().replace('\\', '/');
157
158        UnstructuredField subjectField = message.getSubjectField();
159        subject = (subjectField != null) ? subjectField.getText() : "";
160
161        message.visitBodies(new BodyVisitor() {
162            @Override
163            public void visitTextBody(TextBody textBody) {
164                preview = controlCharactersPattern.matcher(textBody.getPreview()).replaceAll("");
165                quit();
166            }
167        });
168
169        DateTimeField dateField = message.getDateField();
170        date = (dateField != null && dateField.getDate() != null) ? dateField.getDate().getTime() : 0;
171
172        Date recDate = message.getLastReceivedDate();
173        receivedDate = (recDate != null) ? recDate.getTime() : 0;
174
175        size = message.getSize();
176
177        tags = message.getTagsJSONString();
178
179        ContentTypeField contentTypeField = message.getContentTypeField();
180        contentType = (contentTypeField != null) ? contentTypeField.getMediaType() + "/" + contentTypeField.getSubType() : "";
181
182        MailboxField senderField = message.getSenderField();
183        sender = (senderField != null) ? senderField.toJSONString() : "";
184
185        MailboxListField fromField = message.getFromField();
186        from = (fromField != null) ? fromField.toJSONString() : "";
187
188        AddressListField toField = message.getToField();
189        to = (toField != null) ? toField.toJSONString() : "";
190
191        AddressListField ccField = message.getCcField();
192        cc = (ccField != null) ? ccField.toJSONString() : "";
193
194        AddressListField bccField = message.getBccField();
195        bcc = (bccField != null) ? bccField.toJSONString() : "";
196
197        AddressListField replyToField = message.getReplyToField();
198        replyTo = (replyToField != null) ? replyToField.toJSONString() : "";
199
200        MailboxListField dispositionNotificationToField = message.getDispositionNotificationToField();
201        dispositionNotificationTo = (dispositionNotificationToField != null) ? dispositionNotificationToField.toJSONString() : "";
202
203        attachments = message.getAttachmentsJSONString();
204
205
206        //DEBUG
207        //System.out.println(toString());
208
209    }
210
211    @Override
212    public String toString() {
213        return String.format(
214                "TMessage%n"
215              + "%1$sid: %2$s%n"
216              + "%1$ssubject: %3$s%n"
217              + "%1$spreview: %4$s%n"
218              + "%1$ssize: %5$d%n"
219              + "%1$ssender: %6$s%n"
220              + "%1$sfrom: %7$s%n"
221              + "%1$sto: %8$s%n"
222              + "%1$scc: %9$s%n"
223              + "%1$sbcc: %10$s%n"
224              + "%1$sreplyTo: %11$s%n"
225              + "%1$sdispositionNotificationTo: %12$s%n"
226              + "%1$sdate: %13$d%n"
227              + "%1$sreceivedDate: %14$d%n"
228              + "%1$sfolderId: %15$s%n"
229              + "%1$sfolderPath: %16$s%n"
230              + "%1$stags: %17$s%n"
231              + "%1$scontentType: %18$s%n"
232              + "%1$sattachments: %19$s"
233              , "    "
234              , id
235              , subject
236              , preview
237              , size
238              , sender
239              , from
240              , to
241              , cc
242              , bcc
243              , replyTo
244              , dispositionNotificationTo
245              , date
246              , receivedDate
247              , folderId
248              , folderPath
249              , tags
250              , contentType
251              , attachments);
252    }
253}
Note: See TracBrowser for help on using the repository browser.