update emoji autocorrect entries from po-files
[LibreOffice.git] / include / tools / inetmsg.hxx
blob95952c042478e7f48c2a8a12de070eaafc4b7659
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 INCLUDED_TOOLS_INETMSG_HXX
20 #define INCLUDED_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>
29 #include <vector>
30 #include <map>
32 class DateTime;
34 class INetMessageHeader
36 OString m_aName;
37 OString m_aValue;
39 public:
40 INetMessageHeader()
43 INetMessageHeader (
44 const OString& rName, const OString& rValue)
45 : m_aName (rName), m_aValue (rValue)
48 INetMessageHeader (
49 const INetMessageHeader& rHdr)
50 : m_aName (rHdr.m_aName), m_aValue (rHdr.m_aValue)
53 ~INetMessageHeader()
56 INetMessageHeader& operator= (const INetMessageHeader& rHdr)
58 m_aName = rHdr.m_aName;
59 m_aValue = rHdr.m_aValue;
60 return *this;
63 const OString& GetName() const { return m_aName; }
64 const OString& GetValue() const { return m_aValue; }
66 friend SvStream& WriteINetMessageHeader(
67 SvStream& rStrm, const INetMessageHeader& rHdr)
69 write_uInt16_lenPrefixed_uInt8s_FromOString(rStrm, rHdr.m_aName);
70 write_uInt16_lenPrefixed_uInt8s_FromOString(rStrm, rHdr.m_aValue);
71 return rStrm;
74 friend SvStream& ReadINetMessageHeader (
75 SvStream& rStrm, INetMessageHeader& rHdr)
77 rHdr.m_aName = read_uInt16_lenPrefixed_uInt8s_ToOString(rStrm);
78 rHdr.m_aValue = read_uInt16_lenPrefixed_uInt8s_ToOString(rStrm);
79 return rStrm;
83 typedef ::std::vector< INetMessageHeader* > HeaderList_impl;
85 /**
86 RFC822 fields
88 enum class InetMessageField
90 BCC = 0,
91 CC = 1,
92 COMMENTS = 2,
93 DATE = 3,
94 FROM = 4,
95 IN_REPLY_TO = 5,
96 KEYWORDS = 6,
97 MESSAGE_ID = 7,
98 REFERENCES = 8,
99 REPLY_TO = 9,
100 RETURN_PATH = 10,
101 SENDER = 11,
102 SUBJECT = 12,
103 TO = 13,
104 X_MAILER = 14,
105 RETURN_RECEIPT_TO = 15,
106 NUMHDR = 16,
109 enum class InetMessageMime
111 VERSION = 0,
112 CONTENT_DESCRIPTION = 1,
113 CONTENT_DISPOSITION = 2,
114 CONTENT_ID = 3,
115 CONTENT_TYPE = 4,
116 CONTENT_TRANSFER_ENCODING = 5,
117 NUMHDR = 6,
120 enum INetMessageContainerType
122 INETMSG_MESSAGE_RFC822,
123 INETMSG_MULTIPART_MIXED,
124 INETMSG_MULTIPART_ALTERNATIVE,
125 INETMSG_MULTIPART_DIGEST,
126 INETMSG_MULTIPART_PARALLEL,
127 INETMSG_MULTIPART_RELATED,
128 INETMSG_MULTIPART_FORM_DATA
131 class INetMIMEMessage;
132 typedef ::std::vector< INetMIMEMessage* > INetMIMEMessgeList_impl;
134 class TOOLS_DLLPUBLIC INetMIMEMessage
136 HeaderList_impl m_aHeaderList;
138 sal_uIntPtr m_nDocSize;
139 OUString m_aDocName;
140 SvLockBytesRef m_xDocLB;
142 void ListCleanup_Impl();
143 void ListCopy (const INetMIMEMessage& rMsg);
145 ::std::map<InetMessageField, sal_uIntPtr> m_nRFC822Index;
147 ::std::map<InetMessageMime, sal_uIntPtr> m_nMIMEIndex;
148 INetMIMEMessage* pParent;
149 INetMIMEMessgeList_impl aChildren;
150 OString m_aBoundary;
151 bool bHeaderParsed;
153 friend class INetMIMEMessageStream;
155 const OString& GetMultipartBoundary() const { return m_aBoundary; }
156 void SetMultipartBoundary (const OString& rBnd) { m_aBoundary = rBnd; }
158 void CleanupImp();
159 void CopyImp (const INetMIMEMessage& rMsg);
160 void SetHeaderParsed() { bHeaderParsed = true; }
162 OUString GetHeaderName_Impl (
163 sal_uIntPtr nIndex, rtl_TextEncoding eEncoding) const
165 if ( nIndex < m_aHeaderList.size() ) {
166 return OStringToOUString(m_aHeaderList[ nIndex ]->GetName(), eEncoding);
167 } else {
168 return OUString();
172 OUString GetHeaderValue_Impl (
173 sal_uIntPtr nIndex, INetMIME::HeaderFieldType eType) const
175 if ( nIndex < m_aHeaderList.size() ) {
176 return INetMIME::decodeHeaderFieldBody(eType, m_aHeaderList[ nIndex ]->GetValue());
177 } else {
178 return OUString();
182 void SetHeaderField_Impl (
183 const INetMessageHeader &rHeader, sal_uIntPtr &rnIndex)
185 INetMessageHeader *p = new INetMessageHeader (rHeader);
186 if (m_aHeaderList.size() <= rnIndex)
188 rnIndex = m_aHeaderList.size();
189 m_aHeaderList.push_back( p );
191 else
193 delete m_aHeaderList[ rnIndex ];
194 m_aHeaderList[ rnIndex ] = p;
198 void SetHeaderField_Impl (
199 INetMIME::HeaderFieldType eType,
200 const OString &rName,
201 const OUString &rValue,
202 sal_uIntPtr &rnIndex);
204 sal_uIntPtr SetRFC822HeaderField (
205 const INetMessageHeader &rHeader, sal_uIntPtr nNewIndex);
207 public:
208 INetMIMEMessage();
209 INetMIMEMessage (const INetMIMEMessage& rMsg);
210 ~INetMIMEMessage();
212 INetMIMEMessage& operator= (const INetMIMEMessage& rMsg);
214 sal_uIntPtr GetHeaderCount() const { return m_aHeaderList.size(); }
216 OUString GetHeaderName (sal_uIntPtr nIndex) const
218 return GetHeaderName_Impl (nIndex, RTL_TEXTENCODING_ASCII_US);
221 OUString GetHeaderValue (sal_uIntPtr nIndex) const
223 return GetHeaderValue_Impl (nIndex, INetMIME::HEADER_FIELD_TEXT);
226 INetMessageHeader GetHeaderField (sal_uIntPtr nIndex) const
228 if ( nIndex < m_aHeaderList.size() ) {
229 return INetMessageHeader( *m_aHeaderList[ nIndex ] );
230 } else {
231 return INetMessageHeader();
235 sal_uIntPtr SetHeaderField (
236 const INetMessageHeader &rField,
237 sal_uIntPtr nIndex = ((sal_uIntPtr)-1)
240 sal_uIntPtr GetDocumentSize() const { return m_nDocSize; }
241 void SetDocumentSize (sal_uIntPtr nSize) { m_nDocSize = nSize; }
243 const OUString& GetDocumentName() const { return m_aDocName; }
244 void SetDocumentName (const OUString& rName) { m_aDocName = rName; }
246 SvLockBytes* GetDocumentLB() const { return m_xDocLB; }
247 void SetDocumentLB (SvLockBytes *pDocLB) { m_xDocLB = pDocLB; }
249 static bool ParseDateField (
250 const OUString& rDateField, DateTime& rDateTime);
252 bool HeaderParsed() const { return bHeaderParsed; }
254 static INetMIMEMessage* CreateMessage (
255 const INetMIMEMessage& rMsg);
257 // Header fields.
259 OUString GetBCC() const
261 return GetHeaderValue_Impl (
262 m_nRFC822Index.at(InetMessageField::BCC),
263 INetMIME::HEADER_FIELD_ADDRESS);
266 OUString GetCC() const
268 return GetHeaderValue_Impl (
269 m_nRFC822Index.at(InetMessageField::CC),
270 INetMIME::HEADER_FIELD_ADDRESS);
273 OUString GetComments() const
275 return GetHeaderValue_Impl (
276 m_nRFC822Index.at(InetMessageField::COMMENTS),
277 INetMIME::HEADER_FIELD_TEXT);
280 OUString GetDate() const
282 return GetHeaderValue_Impl (
283 m_nRFC822Index.at(InetMessageField::DATE),
284 INetMIME::HEADER_FIELD_STRUCTURED);
287 OUString GetFrom() const
289 return GetHeaderValue_Impl (
290 m_nRFC822Index.at(InetMessageField::FROM),
291 INetMIME::HEADER_FIELD_ADDRESS);
294 OUString GetInReplyTo() const
296 return GetHeaderValue_Impl (
297 m_nRFC822Index.at(InetMessageField::REPLY_TO),
298 INetMIME::HEADER_FIELD_ADDRESS); // ??? MESSAGE_ID ???
301 OUString GetKeywords() const
303 return GetHeaderValue_Impl (
304 m_nRFC822Index.at(InetMessageField::KEYWORDS),
305 INetMIME::HEADER_FIELD_PHRASE);
308 OUString GetMessageID() const
310 return GetHeaderValue_Impl (
311 m_nRFC822Index.at(InetMessageField::MESSAGE_ID),
312 INetMIME::HEADER_FIELD_MESSAGE_ID);
315 OUString GetReferences() const
317 return GetHeaderValue_Impl (
318 m_nRFC822Index.at(InetMessageField::REFERENCES),
319 INetMIME::HEADER_FIELD_ADDRESS);
322 OUString GetReplyTo() const
324 return GetHeaderValue_Impl (
325 m_nRFC822Index.at(InetMessageField::REPLY_TO),
326 INetMIME::HEADER_FIELD_ADDRESS);
329 OUString GetReturnPath() const
331 return GetHeaderValue_Impl (
332 m_nRFC822Index.at(InetMessageField::RETURN_PATH),
333 INetMIME::HEADER_FIELD_ADDRESS);
336 OUString GetReturnReceiptTo() const
338 return GetHeaderValue_Impl (
339 m_nRFC822Index.at(InetMessageField::RETURN_RECEIPT_TO),
340 INetMIME::HEADER_FIELD_ADDRESS);
343 OUString GetSender() const
345 return GetHeaderValue_Impl (
346 m_nRFC822Index.at(InetMessageField::SENDER),
347 INetMIME::HEADER_FIELD_ADDRESS);
350 OUString GetSubject() const
352 return GetHeaderValue_Impl (
353 m_nRFC822Index.at(InetMessageField::SUBJECT),
354 INetMIME::HEADER_FIELD_TEXT);
357 OUString GetTo() const
359 return GetHeaderValue_Impl (
360 m_nRFC822Index.at(InetMessageField::TO),
361 INetMIME::HEADER_FIELD_TEXT);
364 void SetMIMEVersion (const OUString& rVersion);
365 OUString GetMIMEVersion() const
367 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::VERSION));
370 OUString GetContentDescription() const
372 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_DESCRIPTION));
375 void SetContentDisposition (const OUString& rDisposition);
376 OUString GetContentDisposition() const
378 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_DISPOSITION));
381 OUString GetContentID() const
383 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_ID));
386 void SetContentType (const OUString& rType);
387 OUString GetContentType() const
389 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_TYPE));
392 void SetContentTransferEncoding (const OUString& rEncoding);
393 OUString GetContentTransferEncoding() const
395 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_TRANSFER_ENCODING));
398 OUString GetDefaultContentType ();
400 // Message container methods.
402 bool IsContainer() const
404 return (IsMessage() || IsMultipart());
406 bool IsMessage() const
408 OUString aType (GetContentType());
409 return aType.matchIgnoreAsciiCase("message/");
411 bool IsMultipart() const
413 OUString aType (GetContentType());
414 return aType.matchIgnoreAsciiCase("multipart/");
417 INetMIMEMessage* GetChild (sal_uIntPtr nIndex) const
419 return ( nIndex < aChildren.size() ) ? aChildren[ nIndex ] : NULL;
421 INetMIMEMessage* GetParent() const { return pParent; }
423 bool EnableAttachChild (
424 INetMessageContainerType eType = INETMSG_MULTIPART_MIXED);
425 bool AttachChild (
426 INetMIMEMessage& rChildMsg, bool bOwner = true );
429 #endif
431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */