tdf#151548 ContentControls: Add Delete()
[LibreOffice.git] / include / tools / inetmsg.hxx
blob8617b0b91bf173065c70100c5c94ffdf3a195f8a
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/ustring.hxx>
25 #include <tools/inetmime.hxx>
26 #include <tools/stream.hxx>
28 #include <string_view>
29 #include <utility>
30 #include <vector>
31 #include <map>
32 #include <memory>
33 #include <config_options.h>
35 class DateTime;
37 class SAL_WARN_UNUSED INetMessageHeader
39 OString m_aName;
40 OString m_aValue;
42 public:
43 INetMessageHeader()
46 INetMessageHeader(OString aName, OString aValue)
47 : m_aName (std::move(aName)), m_aValue (std::move(aValue))
50 INetMessageHeader (
51 const INetMessageHeader& rHdr)
52 : 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;
59 return *this;
62 const OString& GetName() const { return m_aName; }
63 const OString& GetValue() const { return m_aValue; }
66 enum class InetMessageMime
68 VERSION = 0,
69 CONTENT_DISPOSITION = 1,
70 CONTENT_TYPE = 2,
71 CONTENT_TRANSFER_ENCODING = 3,
72 NUMHDR = 4,
75 class SAL_WARN_UNUSED UNLESS_MERGELIBS(TOOLS_DLLPUBLIC) INetMIMEMessage
77 ::std::vector< std::unique_ptr<INetMessageHeader> >
78 m_aHeaderList;
80 SvLockBytesRef m_xDocLB;
82 ::std::map<InetMessageMime, sal_uInt32> m_nMIMEIndex;
83 INetMIMEMessage* pParent;
84 ::std::vector< std::unique_ptr<INetMIMEMessage> >
85 aChildren;
86 OString m_aBoundary;
88 OUString GetHeaderValue_Impl (
89 sal_uInt32 nIndex) const
91 if ( nIndex < m_aHeaderList.size() ) {
92 return INetMIME::decodeHeaderFieldBody(m_aHeaderList[ nIndex ]->GetValue());
93 } else {
94 return OUString();
98 void SetHeaderField_Impl (
99 const INetMessageHeader &rHeader, sal_uInt32 &rnIndex)
101 INetMessageHeader *p = new INetMessageHeader (rHeader);
102 if (m_aHeaderList.size() <= rnIndex)
104 rnIndex = m_aHeaderList.size();
105 m_aHeaderList.emplace_back( p );
107 else
109 m_aHeaderList[ rnIndex ].reset(p);
113 void SetHeaderField_Impl (
114 const OString &rName,
115 const OUString &rValue,
116 sal_uInt32 &rnIndex);
118 bool IsMessage() const
120 OUString aType (GetContentType());
121 return aType.matchIgnoreAsciiCase("message/");
124 INetMIMEMessage (const INetMIMEMessage& rMsg) = delete;
125 INetMIMEMessage& operator= (const INetMIMEMessage& rMsg) = delete;
127 public:
128 INetMIMEMessage();
129 ~INetMIMEMessage();
131 sal_uInt32 GetHeaderCount() const { return m_aHeaderList.size(); }
133 INetMessageHeader GetHeaderField (sal_uInt32 nIndex) const
135 if ( nIndex < m_aHeaderList.size() ) {
136 return *m_aHeaderList[ nIndex ];
137 } else {
138 return INetMessageHeader();
142 SvLockBytes* GetDocumentLB() const { return m_xDocLB.get(); }
143 void SetDocumentLB (SvLockBytes *pDocLB) { m_xDocLB = pDocLB; }
145 static bool ParseDateField (
146 std::u16string_view rDateField, DateTime& rDateTime);
148 void SetMIMEVersion (const OUString& rVersion);
149 void SetContentDisposition (const OUString& rDisposition);
150 void SetContentType (const OUString& rType);
151 OUString GetContentType() const
153 return GetHeaderValue_Impl(
154 m_nMIMEIndex.at(InetMessageMime::CONTENT_TYPE));
157 void SetContentTransferEncoding (const OUString& rEncoding);
159 OUString GetDefaultContentType ();
161 // Message container methods.
163 bool IsContainer() const
165 return (IsMessage() || IsMultipart());
167 bool IsMultipart() const
169 OUString aType (GetContentType());
170 return aType.matchIgnoreAsciiCase("multipart/");
173 INetMIMEMessage* GetChild (sal_uInt32 nIndex) const
175 return ( nIndex < aChildren.size() ) ? aChildren[ nIndex ].get() : nullptr;
177 INetMIMEMessage* GetParent() const { return pParent; }
179 void EnableAttachMultipartFormDataChild();
180 void AttachChild( std::unique_ptr<INetMIMEMessage> pChildMsg );
182 const OString& GetMultipartBoundary() const { return m_aBoundary; }
185 #endif
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */