Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : : #ifndef _TOOLS_INETMSG_HXX
20 : : #define _TOOLS_INETMSG_HXX
21 : :
22 : : #include "tools/toolsdllapi.h"
23 : : #include <sal/types.h>
24 : : #include <rtl/textenc.h>
25 : : #include <tools/inetmime.hxx>
26 : : #include <tools/stream.hxx>
27 : : #include <tools/string.hxx>
28 : :
29 : : #include <vector>
30 : :
31 : : class DateTime;
32 : :
33 : : class INetMessageHeader
34 : : {
35 : : rtl::OString m_aName;
36 : : rtl::OString m_aValue;
37 : :
38 : : public:
39 : : INetMessageHeader()
40 : : {}
41 : :
42 : : INetMessageHeader (
43 : : const rtl::OString& rName, const rtl::OString& rValue)
44 : : : m_aName (rName), m_aValue (rValue)
45 : : {}
46 : :
47 : : INetMessageHeader (
48 : : const INetMessageHeader& rHdr)
49 : : : m_aName (rHdr.m_aName), m_aValue (rHdr.m_aValue)
50 : : {}
51 : :
52 : : ~INetMessageHeader()
53 : : {}
54 : :
55 : : INetMessageHeader& operator= (const INetMessageHeader& rHdr)
56 : : {
57 : : m_aName = rHdr.m_aName;
58 : : m_aValue = rHdr.m_aValue;
59 : : return *this;
60 : : }
61 : :
62 : : const rtl::OString& GetName() const { return m_aName; }
63 : 0 : const rtl::OString& GetValue() const { return m_aValue; }
64 : :
65 : : friend SvStream& operator<< (
66 : : SvStream& rStrm, const INetMessageHeader& rHdr)
67 : : {
68 : : write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rStrm, rHdr.m_aName);
69 : : write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rStrm, rHdr.m_aValue);
70 : : return rStrm;
71 : : }
72 : :
73 : : friend SvStream& operator>> (
74 : : SvStream& rStrm, INetMessageHeader& rHdr)
75 : : {
76 : : rHdr.m_aName = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rStrm);
77 : : rHdr.m_aValue = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rStrm);
78 : : return rStrm;
79 : : }
80 : : };
81 : :
82 : : typedef ::std::vector< INetMessageHeader* > HeaderList_impl;
83 : :
84 : : class INetMessage
85 : : {
86 : : HeaderList_impl m_aHeaderList;
87 : :
88 : : sal_uIntPtr m_nDocSize;
89 : : rtl::OUString m_aDocName;
90 : : SvLockBytesRef m_xDocLB;
91 : :
92 : : void ListCleanup_Impl();
93 : : void ListCopy (const INetMessage& rMsg);
94 : :
95 : : protected:
96 : : rtl::OUString GetHeaderName_Impl (
97 : : sal_uIntPtr nIndex, rtl_TextEncoding eEncoding) const
98 : : {
99 : : if ( nIndex < m_aHeaderList.size() ) {
100 : : return rtl::OStringToOUString(m_aHeaderList[ nIndex ]->GetName(), eEncoding);
101 : : } else {
102 : : return rtl::OUString();
103 : : }
104 : : }
105 : :
106 : 0 : rtl::OUString GetHeaderValue_Impl (
107 : : sal_uIntPtr nIndex, INetMIME::HeaderFieldType eType) const
108 : : {
109 [ # # ]: 0 : if ( nIndex < m_aHeaderList.size() ) {
110 : 0 : return INetMIME::decodeHeaderFieldBody(eType, m_aHeaderList[ nIndex ]->GetValue());
111 : : } else {
112 : 0 : return rtl::OUString();
113 : : }
114 : : }
115 : :
116 : : void SetHeaderField_Impl (
117 : : const INetMessageHeader &rHeader, sal_uIntPtr &rnIndex)
118 : : {
119 : : INetMessageHeader *p = new INetMessageHeader (rHeader);
120 : : if (m_aHeaderList.size() <= rnIndex)
121 : : {
122 : : rnIndex = m_aHeaderList.size();
123 : : m_aHeaderList.push_back( p );
124 : : }
125 : : else
126 : : {
127 : : delete m_aHeaderList[ rnIndex ];
128 : : m_aHeaderList[ rnIndex ] = p;
129 : : }
130 : : }
131 : :
132 : : void SetHeaderField_Impl (
133 : : INetMIME::HeaderFieldType eType,
134 : : const rtl::OString &rName,
135 : : const rtl::OUString &rValue,
136 : : sal_uIntPtr &rnIndex);
137 : :
138 : : virtual SvStream& operator<< (SvStream& rStrm) const;
139 : : virtual SvStream& operator>> (SvStream& rStrm);
140 : :
141 : : public:
142 : : INetMessage() : m_nDocSize(0) {}
143 : : virtual ~INetMessage();
144 : :
145 : : INetMessage (const INetMessage& rMsg)
146 : : : m_nDocSize (rMsg.m_nDocSize),
147 : : m_aDocName (rMsg.m_aDocName),
148 : : m_xDocLB (rMsg.m_xDocLB)
149 : : {
150 : : ListCopy (rMsg);
151 : : }
152 : :
153 : : INetMessage& operator= (const INetMessage& rMsg)
154 : : {
155 : : m_nDocSize = rMsg.m_nDocSize;
156 : : m_aDocName = rMsg.m_aDocName;
157 : : m_xDocLB = rMsg.m_xDocLB;
158 : : ListCopy (rMsg);
159 : : return *this;
160 : : }
161 : :
162 : : sal_uIntPtr GetHeaderCount() const { return m_aHeaderList.size(); }
163 : :
164 : : rtl::OUString GetHeaderName (sal_uIntPtr nIndex) const
165 : : {
166 : : return GetHeaderName_Impl (nIndex, RTL_TEXTENCODING_ASCII_US);
167 : : }
168 : :
169 : 0 : rtl::OUString GetHeaderValue (sal_uIntPtr nIndex) const
170 : : {
171 : 0 : return GetHeaderValue_Impl (nIndex, INetMIME::HEADER_FIELD_TEXT);
172 : : }
173 : :
174 : : INetMessageHeader GetHeaderField (sal_uIntPtr nIndex) const
175 : : {
176 : : if ( nIndex < m_aHeaderList.size() ) {
177 : : return INetMessageHeader( *m_aHeaderList[ nIndex ] );
178 : : } else {
179 : : return INetMessageHeader();
180 : : }
181 : : }
182 : :
183 : : virtual sal_uIntPtr SetHeaderField (
184 : : const INetMessageHeader &rField,
185 : : sal_uIntPtr nIndex = ((sal_uIntPtr)-1)
186 : : );
187 : :
188 : : sal_uIntPtr GetDocumentSize() const { return m_nDocSize; }
189 : : void SetDocumentSize (sal_uIntPtr nSize) { m_nDocSize = nSize; }
190 : :
191 : : const rtl::OUString& GetDocumentName() const { return m_aDocName; }
192 : : void SetDocumentName (const rtl::OUString& rName) { m_aDocName = rName; }
193 : :
194 : : SvLockBytes* GetDocumentLB() const { return m_xDocLB; }
195 : 0 : void SetDocumentLB (SvLockBytes *pDocLB) { m_xDocLB = pDocLB; }
196 : :
197 : : friend SvStream& operator<< (
198 : : SvStream& rStrm, const INetMessage& rMsg)
199 : : {
200 : : return rMsg.operator<< (rStrm);
201 : : }
202 : :
203 : : friend SvStream& operator>> (
204 : : SvStream& rStrm, INetMessage& rMsg)
205 : : {
206 : : return rMsg.operator>> (rStrm);
207 : : }
208 : : };
209 : :
210 : : #define INETMSG_RFC822_BCC 0
211 : : #define INETMSG_RFC822_CC 1
212 : : #define INETMSG_RFC822_COMMENTS 2
213 : : #define INETMSG_RFC822_DATE 3
214 : : #define INETMSG_RFC822_FROM 4
215 : : #define INETMSG_RFC822_IN_REPLY_TO 5
216 : : #define INETMSG_RFC822_KEYWORDS 6
217 : : #define INETMSG_RFC822_MESSAGE_ID 7
218 : : #define INETMSG_RFC822_REFERENCES 8
219 : : #define INETMSG_RFC822_REPLY_TO 9
220 : : #define INETMSG_RFC822_RETURN_PATH 10
221 : : #define INETMSG_RFC822_SENDER 11
222 : : #define INETMSG_RFC822_SUBJECT 12
223 : : #define INETMSG_RFC822_TO 13
224 : : #define INETMSG_RFC822_X_MAILER 14
225 : : #define INETMSG_RFC822_RETURN_RECEIPT_TO 15
226 : : #define INETMSG_RFC822_NUMHDR 16
227 : :
228 : : class TOOLS_DLLPUBLIC INetRFC822Message : public INetMessage
229 : : {
230 : : sal_uIntPtr m_nIndex[INETMSG_RFC822_NUMHDR];
231 : :
232 : : protected:
233 : : virtual SvStream& operator<< (SvStream& rStrm) const;
234 : : virtual SvStream& operator>> (SvStream& rStrm);
235 : :
236 : : public:
237 : : INetRFC822Message();
238 : : INetRFC822Message (const INetRFC822Message& rMsg);
239 : : virtual ~INetRFC822Message();
240 : :
241 : : INetRFC822Message& operator= (const INetRFC822Message& rMsg);
242 : :
243 : : static sal_Bool ParseDateField (
244 : : const rtl::OUString& rDateField, DateTime& rDateTime);
245 : :
246 : : using INetMessage::SetHeaderField;
247 : : virtual sal_uIntPtr SetHeaderField (
248 : : const INetMessageHeader &rHeader,
249 : : sal_uIntPtr nIndex = ((sal_uIntPtr)-1)
250 : : );
251 : :
252 : : // Header fields.
253 : :
254 : : rtl::OUString GetBCC() const
255 : : {
256 : : return GetHeaderValue_Impl (
257 : : m_nIndex[INETMSG_RFC822_BCC],
258 : : INetMIME::HEADER_FIELD_ADDRESS);
259 : : }
260 : :
261 : : rtl::OUString GetCC() const
262 : : {
263 : : return GetHeaderValue_Impl (
264 : : m_nIndex[INETMSG_RFC822_CC],
265 : : INetMIME::HEADER_FIELD_ADDRESS);
266 : : }
267 : :
268 : : rtl::OUString GetComments() const
269 : : {
270 : : return GetHeaderValue_Impl (
271 : : m_nIndex[INETMSG_RFC822_COMMENTS],
272 : : INetMIME::HEADER_FIELD_TEXT);
273 : : }
274 : :
275 : : rtl::OUString GetDate() const
276 : : {
277 : : return GetHeaderValue_Impl (
278 : : m_nIndex[INETMSG_RFC822_DATE],
279 : : INetMIME::HEADER_FIELD_STRUCTURED);
280 : : }
281 : :
282 : : rtl::OUString GetFrom() const
283 : : {
284 : : return GetHeaderValue_Impl (
285 : : m_nIndex[INETMSG_RFC822_FROM],
286 : : INetMIME::HEADER_FIELD_ADDRESS);
287 : : }
288 : :
289 : : rtl::OUString GetInReplyTo() const
290 : : {
291 : : return GetHeaderValue_Impl (
292 : : m_nIndex[INETMSG_RFC822_IN_REPLY_TO],
293 : : INetMIME::HEADER_FIELD_ADDRESS); // ??? MESSAGE_ID ???
294 : : }
295 : :
296 : : rtl::OUString GetKeywords() const
297 : : {
298 : : return GetHeaderValue_Impl (
299 : : m_nIndex[INETMSG_RFC822_KEYWORDS],
300 : : INetMIME::HEADER_FIELD_PHRASE);
301 : : }
302 : :
303 : : rtl::OUString GetMessageID() const
304 : : {
305 : : return GetHeaderValue_Impl (
306 : : m_nIndex[INETMSG_RFC822_MESSAGE_ID],
307 : : INetMIME::HEADER_FIELD_MESSAGE_ID);
308 : : }
309 : :
310 : : rtl::OUString GetReferences() const
311 : : {
312 : : return GetHeaderValue_Impl (
313 : : m_nIndex[INETMSG_RFC822_REFERENCES],
314 : : INetMIME::HEADER_FIELD_ADDRESS);
315 : : }
316 : :
317 : : rtl::OUString GetReplyTo() const
318 : : {
319 : : return GetHeaderValue_Impl (
320 : : m_nIndex[INETMSG_RFC822_REPLY_TO],
321 : : INetMIME::HEADER_FIELD_ADDRESS);
322 : : }
323 : :
324 : : rtl::OUString GetReturnPath() const
325 : : {
326 : : return GetHeaderValue_Impl (
327 : : m_nIndex[INETMSG_RFC822_RETURN_PATH],
328 : : INetMIME::HEADER_FIELD_ADDRESS);
329 : : }
330 : :
331 : : rtl::OUString GetReturnReceiptTo() const
332 : : {
333 : : return GetHeaderValue_Impl (
334 : : m_nIndex[INETMSG_RFC822_RETURN_RECEIPT_TO],
335 : : INetMIME::HEADER_FIELD_ADDRESS);
336 : : }
337 : :
338 : : rtl::OUString GetSender() const
339 : : {
340 : : return GetHeaderValue_Impl (
341 : : m_nIndex[INETMSG_RFC822_SENDER],
342 : : INetMIME::HEADER_FIELD_ADDRESS);
343 : : }
344 : :
345 : : rtl::OUString GetSubject() const
346 : : {
347 : : return GetHeaderValue_Impl (
348 : : m_nIndex[INETMSG_RFC822_SUBJECT],
349 : : INetMIME::HEADER_FIELD_TEXT);
350 : : }
351 : :
352 : : rtl::OUString GetTo() const
353 : : {
354 : : return GetHeaderValue_Impl (
355 : : m_nIndex[INETMSG_RFC822_TO],
356 : : INetMIME::HEADER_FIELD_TEXT);
357 : : }
358 : :
359 : : // Stream operators.
360 : :
361 : : friend SvStream& operator<< (
362 : : SvStream& rStrm, const INetRFC822Message& rMsg)
363 : : {
364 : : return rMsg.operator<< (rStrm);
365 : : }
366 : :
367 : : friend SvStream& operator>> (
368 : : SvStream& rStrm, INetRFC822Message& rMsg)
369 : : {
370 : : return rMsg.operator>> (rStrm);
371 : : }
372 : : };
373 : :
374 : : #define INETMSG_MIME_VERSION 0
375 : : #define INETMSG_MIME_CONTENT_DESCRIPTION 1
376 : : #define INETMSG_MIME_CONTENT_DISPOSITION 2
377 : : #define INETMSG_MIME_CONTENT_ID 3
378 : : #define INETMSG_MIME_CONTENT_TYPE 4
379 : : #define INETMSG_MIME_CONTENT_TRANSFER_ENCODING 5
380 : : #define INETMSG_MIME_NUMHDR 6
381 : :
382 : : enum INetMessageContainerType
383 : : {
384 : : INETMSG_MESSAGE_RFC822,
385 : : INETMSG_MULTIPART_MIXED,
386 : : INETMSG_MULTIPART_ALTERNATIVE,
387 : : INETMSG_MULTIPART_DIGEST,
388 : : INETMSG_MULTIPART_PARALLEL,
389 : : INETMSG_MULTIPART_RELATED,
390 : : INETMSG_MULTIPART_FORM_DATA
391 : : };
392 : :
393 : : class INetMIMEMessage;
394 : : typedef ::std::vector< INetMIMEMessage* > INetMIMEMessgeList_impl;
395 : :
396 : : class TOOLS_DLLPUBLIC INetMIMEMessage : public INetRFC822Message
397 : : {
398 : : sal_uIntPtr m_nIndex[INETMSG_MIME_NUMHDR];
399 : : INetMIMEMessage* pParent;
400 : : INetMIMEMessgeList_impl aChildren;
401 : : rtl::OString m_aBoundary;
402 : : sal_Bool bHeaderParsed;
403 : :
404 : : friend class INetMIMEMessageStream;
405 : :
406 : : const rtl::OString& GetMultipartBoundary() const { return m_aBoundary; }
407 : : void SetMultipartBoundary (const rtl::OString& rBnd) { m_aBoundary = rBnd; }
408 : :
409 : : void CleanupImp();
410 : : void CopyImp (const INetMIMEMessage& rMsg);
411 : : void SetHeaderParsed() { bHeaderParsed = sal_True; }
412 : :
413 : : protected:
414 : : virtual SvStream& operator<< (SvStream& rStrm) const;
415 : : virtual SvStream& operator>> (SvStream& rStrm);
416 : :
417 : : public:
418 : : INetMIMEMessage();
419 : : INetMIMEMessage (const INetMIMEMessage& rMsg);
420 : : virtual ~INetMIMEMessage();
421 : :
422 : : INetMIMEMessage& operator= (const INetMIMEMessage& rMsg);
423 : :
424 : : sal_Bool HeaderParsed() const { return bHeaderParsed; }
425 : :
426 : : virtual INetMIMEMessage* CreateMessage (
427 : : const INetMIMEMessage& rMsg) const;
428 : :
429 : : using INetRFC822Message::SetHeaderField;
430 : : virtual sal_uIntPtr SetHeaderField (
431 : : const INetMessageHeader &rHeader,
432 : : sal_uIntPtr nIndex = ((sal_uIntPtr)-1)
433 : : );
434 : :
435 : : // Header fields.
436 : :
437 : : void SetMIMEVersion (const UniString& rVersion);
438 : : UniString GetMIMEVersion() const
439 : : {
440 : : return GetHeaderValue (m_nIndex[INETMSG_MIME_VERSION]);
441 : : }
442 : :
443 : : UniString GetContentDescription() const
444 : : {
445 : : return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_DESCRIPTION]);
446 : : }
447 : :
448 : : void SetContentDisposition (const UniString& rDisposition);
449 : : UniString GetContentDisposition() const
450 : : {
451 : : return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_DISPOSITION]);
452 : : }
453 : :
454 : : UniString GetContentID() const
455 : : {
456 : : return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_ID]);
457 : : }
458 : :
459 : : void SetContentType (const UniString& rType);
460 : 0 : UniString GetContentType() const
461 : : {
462 [ # # ]: 0 : return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_TYPE]);
463 : : }
464 : :
465 : : void SetContentTransferEncoding (const rtl::OUString& rEncoding);
466 : : rtl::OUString GetContentTransferEncoding() const
467 : : {
468 : : return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_TRANSFER_ENCODING]);
469 : : }
470 : :
471 : : rtl::OUString GetDefaultContentType ();
472 : :
473 : : // Message container methods.
474 : :
475 : : sal_Bool IsContainer() const
476 : : {
477 : : return (IsMessage() || IsMultipart());
478 : : }
479 : : sal_Bool IsMessage() const
480 : : {
481 : : UniString aType (GetContentType());
482 : : return (aType.CompareIgnoreCaseToAscii("message/", 8) == 0);
483 : : }
484 : : sal_Bool IsMultipart() const
485 : : {
486 : : UniString aType (GetContentType());
487 : : return (aType.CompareIgnoreCaseToAscii("multipart/", 10) == 0);
488 : : }
489 : :
490 : : INetMIMEMessage* GetChild (sal_uIntPtr nIndex) const
491 : : {
492 : : return ( nIndex < aChildren.size() ) ? aChildren[ nIndex ] : NULL;
493 : : }
494 : : INetMIMEMessage* GetParent() const { return pParent; }
495 : :
496 : : sal_Bool EnableAttachChild (
497 : : INetMessageContainerType eType = INETMSG_MULTIPART_MIXED);
498 : : sal_Bool AttachChild (
499 : : INetMIMEMessage& rChildMsg, sal_Bool bOwner = sal_True);
500 : :
501 : : // Stream operators.
502 : :
503 : : friend SvStream& operator<< (
504 : : SvStream& rStrm, const INetMIMEMessage& rMsg)
505 : : {
506 : : return rMsg.operator<< (rStrm);
507 : : }
508 : :
509 : : friend SvStream& operator>> (
510 : : SvStream& rStrm, INetMIMEMessage& rMsg)
511 : : {
512 : : return rMsg.operator>> (rStrm);
513 : : }
514 : : };
515 : :
516 : : #endif
517 : :
518 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|