1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _TOOLS_INETMSG_HXX
20 #define _TOOLS_INETMSG_HXX
22 #include "tools/toolsdllapi.h"
23 #include <rtl/string.hxx>
24 #include <rtl/textenc.h>
25 #include <rtl/ustring.hxx>
26 #include <tools/inetmime.hxx>
27 #include <tools/stream.hxx>
33 class INetMessageHeader
43 const OString
& rName
, const OString
& rValue
)
44 : m_aName (rName
), m_aValue (rValue
)
48 const INetMessageHeader
& rHdr
)
49 : m_aName (rHdr
.m_aName
), m_aValue (rHdr
.m_aValue
)
55 INetMessageHeader
& operator= (const INetMessageHeader
& rHdr
)
57 m_aName
= rHdr
.m_aName
;
58 m_aValue
= rHdr
.m_aValue
;
62 const OString
& GetName() const { return m_aName
; }
63 const OString
& GetValue() const { return m_aValue
; }
65 friend SvStream
& operator<< (
66 SvStream
& rStrm
, const INetMessageHeader
& rHdr
)
68 write_lenPrefixed_uInt8s_FromOString
<sal_uInt16
>(rStrm
, rHdr
.m_aName
);
69 write_lenPrefixed_uInt8s_FromOString
<sal_uInt16
>(rStrm
, rHdr
.m_aValue
);
73 friend SvStream
& operator>> (
74 SvStream
& rStrm
, INetMessageHeader
& rHdr
)
76 rHdr
.m_aName
= read_lenPrefixed_uInt8s_ToOString
<sal_uInt16
>(rStrm
);
77 rHdr
.m_aValue
= read_lenPrefixed_uInt8s_ToOString
<sal_uInt16
>(rStrm
);
82 typedef ::std::vector
< INetMessageHeader
* > HeaderList_impl
;
86 HeaderList_impl m_aHeaderList
;
88 sal_uIntPtr m_nDocSize
;
90 SvLockBytesRef m_xDocLB
;
92 void ListCleanup_Impl();
93 void ListCopy (const INetMessage
& rMsg
);
96 OUString
GetHeaderName_Impl (
97 sal_uIntPtr nIndex
, rtl_TextEncoding eEncoding
) const
99 if ( nIndex
< m_aHeaderList
.size() ) {
100 return OStringToOUString(m_aHeaderList
[ nIndex
]->GetName(), eEncoding
);
106 OUString
GetHeaderValue_Impl (
107 sal_uIntPtr nIndex
, INetMIME::HeaderFieldType eType
) const
109 if ( nIndex
< m_aHeaderList
.size() ) {
110 return INetMIME::decodeHeaderFieldBody(eType
, m_aHeaderList
[ nIndex
]->GetValue());
116 void SetHeaderField_Impl (
117 const INetMessageHeader
&rHeader
, sal_uIntPtr
&rnIndex
)
119 INetMessageHeader
*p
= new INetMessageHeader (rHeader
);
120 if (m_aHeaderList
.size() <= rnIndex
)
122 rnIndex
= m_aHeaderList
.size();
123 m_aHeaderList
.push_back( p
);
127 delete m_aHeaderList
[ rnIndex
];
128 m_aHeaderList
[ rnIndex
] = p
;
132 void SetHeaderField_Impl (
133 INetMIME::HeaderFieldType eType
,
134 const OString
&rName
,
135 const OUString
&rValue
,
136 sal_uIntPtr
&rnIndex
);
138 virtual SvStream
& operator<< (SvStream
& rStrm
) const;
139 virtual SvStream
& operator>> (SvStream
& rStrm
);
142 INetMessage() : m_nDocSize(0) {}
143 virtual ~INetMessage();
145 INetMessage (const INetMessage
& rMsg
)
146 : m_nDocSize (rMsg
.m_nDocSize
),
147 m_aDocName (rMsg
.m_aDocName
),
148 m_xDocLB (rMsg
.m_xDocLB
)
153 INetMessage
& operator= (const INetMessage
& rMsg
)
155 m_nDocSize
= rMsg
.m_nDocSize
;
156 m_aDocName
= rMsg
.m_aDocName
;
157 m_xDocLB
= rMsg
.m_xDocLB
;
162 sal_uIntPtr
GetHeaderCount() const { return m_aHeaderList
.size(); }
164 OUString
GetHeaderName (sal_uIntPtr nIndex
) const
166 return GetHeaderName_Impl (nIndex
, RTL_TEXTENCODING_ASCII_US
);
169 OUString
GetHeaderValue (sal_uIntPtr nIndex
) const
171 return GetHeaderValue_Impl (nIndex
, INetMIME::HEADER_FIELD_TEXT
);
174 INetMessageHeader
GetHeaderField (sal_uIntPtr nIndex
) const
176 if ( nIndex
< m_aHeaderList
.size() ) {
177 return INetMessageHeader( *m_aHeaderList
[ nIndex
] );
179 return INetMessageHeader();
183 virtual sal_uIntPtr
SetHeaderField (
184 const INetMessageHeader
&rField
,
185 sal_uIntPtr nIndex
= ((sal_uIntPtr
)-1)
188 sal_uIntPtr
GetDocumentSize() const { return m_nDocSize
; }
189 void SetDocumentSize (sal_uIntPtr nSize
) { m_nDocSize
= nSize
; }
191 const OUString
& GetDocumentName() const { return m_aDocName
; }
192 void SetDocumentName (const OUString
& rName
) { m_aDocName
= rName
; }
194 SvLockBytes
* GetDocumentLB() const { return m_xDocLB
; }
195 void SetDocumentLB (SvLockBytes
*pDocLB
) { m_xDocLB
= pDocLB
; }
197 friend SvStream
& operator<< (
198 SvStream
& rStrm
, const INetMessage
& rMsg
)
200 return rMsg
.operator<< (rStrm
);
203 friend SvStream
& operator>> (
204 SvStream
& rStrm
, INetMessage
& rMsg
)
206 return rMsg
.operator>> (rStrm
);
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
228 class TOOLS_DLLPUBLIC INetRFC822Message
: public INetMessage
230 sal_uIntPtr m_nIndex
[INETMSG_RFC822_NUMHDR
];
233 virtual SvStream
& operator<< (SvStream
& rStrm
) const;
234 virtual SvStream
& operator>> (SvStream
& rStrm
);
238 INetRFC822Message (const INetRFC822Message
& rMsg
);
239 virtual ~INetRFC822Message();
241 INetRFC822Message
& operator= (const INetRFC822Message
& rMsg
);
243 static bool ParseDateField (
244 const OUString
& rDateField
, DateTime
& rDateTime
);
246 using INetMessage::SetHeaderField
;
247 virtual sal_uIntPtr
SetHeaderField (
248 const INetMessageHeader
&rHeader
,
249 sal_uIntPtr nIndex
= ((sal_uIntPtr
)-1)
254 OUString
GetBCC() const
256 return GetHeaderValue_Impl (
257 m_nIndex
[INETMSG_RFC822_BCC
],
258 INetMIME::HEADER_FIELD_ADDRESS
);
261 OUString
GetCC() const
263 return GetHeaderValue_Impl (
264 m_nIndex
[INETMSG_RFC822_CC
],
265 INetMIME::HEADER_FIELD_ADDRESS
);
268 OUString
GetComments() const
270 return GetHeaderValue_Impl (
271 m_nIndex
[INETMSG_RFC822_COMMENTS
],
272 INetMIME::HEADER_FIELD_TEXT
);
275 OUString
GetDate() const
277 return GetHeaderValue_Impl (
278 m_nIndex
[INETMSG_RFC822_DATE
],
279 INetMIME::HEADER_FIELD_STRUCTURED
);
282 OUString
GetFrom() const
284 return GetHeaderValue_Impl (
285 m_nIndex
[INETMSG_RFC822_FROM
],
286 INetMIME::HEADER_FIELD_ADDRESS
);
289 OUString
GetInReplyTo() const
291 return GetHeaderValue_Impl (
292 m_nIndex
[INETMSG_RFC822_IN_REPLY_TO
],
293 INetMIME::HEADER_FIELD_ADDRESS
); // ??? MESSAGE_ID ???
296 OUString
GetKeywords() const
298 return GetHeaderValue_Impl (
299 m_nIndex
[INETMSG_RFC822_KEYWORDS
],
300 INetMIME::HEADER_FIELD_PHRASE
);
303 OUString
GetMessageID() const
305 return GetHeaderValue_Impl (
306 m_nIndex
[INETMSG_RFC822_MESSAGE_ID
],
307 INetMIME::HEADER_FIELD_MESSAGE_ID
);
310 OUString
GetReferences() const
312 return GetHeaderValue_Impl (
313 m_nIndex
[INETMSG_RFC822_REFERENCES
],
314 INetMIME::HEADER_FIELD_ADDRESS
);
317 OUString
GetReplyTo() const
319 return GetHeaderValue_Impl (
320 m_nIndex
[INETMSG_RFC822_REPLY_TO
],
321 INetMIME::HEADER_FIELD_ADDRESS
);
324 OUString
GetReturnPath() const
326 return GetHeaderValue_Impl (
327 m_nIndex
[INETMSG_RFC822_RETURN_PATH
],
328 INetMIME::HEADER_FIELD_ADDRESS
);
331 OUString
GetReturnReceiptTo() const
333 return GetHeaderValue_Impl (
334 m_nIndex
[INETMSG_RFC822_RETURN_RECEIPT_TO
],
335 INetMIME::HEADER_FIELD_ADDRESS
);
338 OUString
GetSender() const
340 return GetHeaderValue_Impl (
341 m_nIndex
[INETMSG_RFC822_SENDER
],
342 INetMIME::HEADER_FIELD_ADDRESS
);
345 OUString
GetSubject() const
347 return GetHeaderValue_Impl (
348 m_nIndex
[INETMSG_RFC822_SUBJECT
],
349 INetMIME::HEADER_FIELD_TEXT
);
352 OUString
GetTo() const
354 return GetHeaderValue_Impl (
355 m_nIndex
[INETMSG_RFC822_TO
],
356 INetMIME::HEADER_FIELD_TEXT
);
361 friend SvStream
& operator<< (
362 SvStream
& rStrm
, const INetRFC822Message
& rMsg
)
364 return rMsg
.operator<< (rStrm
);
367 friend SvStream
& operator>> (
368 SvStream
& rStrm
, INetRFC822Message
& rMsg
)
370 return rMsg
.operator>> (rStrm
);
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
382 enum INetMessageContainerType
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
393 class INetMIMEMessage
;
394 typedef ::std::vector
< INetMIMEMessage
* > INetMIMEMessgeList_impl
;
396 class TOOLS_DLLPUBLIC INetMIMEMessage
: public INetRFC822Message
398 sal_uIntPtr m_nIndex
[INETMSG_MIME_NUMHDR
];
399 INetMIMEMessage
* pParent
;
400 INetMIMEMessgeList_impl aChildren
;
404 friend class INetMIMEMessageStream
;
406 const OString
& GetMultipartBoundary() const { return m_aBoundary
; }
407 void SetMultipartBoundary (const OString
& rBnd
) { m_aBoundary
= rBnd
; }
410 void CopyImp (const INetMIMEMessage
& rMsg
);
411 void SetHeaderParsed() { bHeaderParsed
= sal_True
; }
414 virtual SvStream
& operator<< (SvStream
& rStrm
) const;
415 virtual SvStream
& operator>> (SvStream
& rStrm
);
419 INetMIMEMessage (const INetMIMEMessage
& rMsg
);
420 virtual ~INetMIMEMessage();
422 INetMIMEMessage
& operator= (const INetMIMEMessage
& rMsg
);
424 bool HeaderParsed() const { return bHeaderParsed
; }
426 virtual INetMIMEMessage
* CreateMessage (
427 const INetMIMEMessage
& rMsg
) const;
429 using INetRFC822Message::SetHeaderField
;
430 virtual sal_uIntPtr
SetHeaderField (
431 const INetMessageHeader
&rHeader
,
432 sal_uIntPtr nIndex
= ((sal_uIntPtr
)-1)
437 void SetMIMEVersion (const OUString
& rVersion
);
438 OUString
GetMIMEVersion() const
440 return GetHeaderValue (m_nIndex
[INETMSG_MIME_VERSION
]);
443 OUString
GetContentDescription() const
445 return GetHeaderValue (m_nIndex
[INETMSG_MIME_CONTENT_DESCRIPTION
]);
448 void SetContentDisposition (const OUString
& rDisposition
);
449 OUString
GetContentDisposition() const
451 return GetHeaderValue (m_nIndex
[INETMSG_MIME_CONTENT_DISPOSITION
]);
454 OUString
GetContentID() const
456 return GetHeaderValue (m_nIndex
[INETMSG_MIME_CONTENT_ID
]);
459 void SetContentType (const OUString
& rType
);
460 OUString
GetContentType() const
462 return GetHeaderValue (m_nIndex
[INETMSG_MIME_CONTENT_TYPE
]);
465 void SetContentTransferEncoding (const OUString
& rEncoding
);
466 OUString
GetContentTransferEncoding() const
468 return GetHeaderValue (m_nIndex
[INETMSG_MIME_CONTENT_TRANSFER_ENCODING
]);
471 OUString
GetDefaultContentType ();
473 // Message container methods.
475 bool IsContainer() const
477 return (IsMessage() || IsMultipart());
479 bool IsMessage() const
481 OUString
aType (GetContentType());
482 return aType
.matchIgnoreAsciiCase("message/");
484 bool IsMultipart() const
486 OUString
aType (GetContentType());
487 return aType
.matchIgnoreAsciiCase("multipart/");
490 INetMIMEMessage
* GetChild (sal_uIntPtr nIndex
) const
492 return ( nIndex
< aChildren
.size() ) ? aChildren
[ nIndex
] : NULL
;
494 INetMIMEMessage
* GetParent() const { return pParent
; }
496 bool EnableAttachChild (
497 INetMessageContainerType eType
= INETMSG_MULTIPART_MIXED
);
499 INetMIMEMessage
& rChildMsg
, bool bOwner
= true );
503 friend SvStream
& operator<< (
504 SvStream
& rStrm
, const INetMIMEMessage
& rMsg
)
506 return rMsg
.operator<< (rStrm
);
509 friend SvStream
& operator>> (
510 SvStream
& rStrm
, INetMIMEMessage
& rMsg
)
512 return rMsg
.operator>> (rStrm
);
518 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */