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 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>
33 #include <config_options.h>
37 class SAL_WARN_UNUSED INetMessageHeader
46 INetMessageHeader(OString aName
, OString aValue
)
47 : m_aName (std::move(aName
)), m_aValue (std::move(aValue
))
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
;
62 const OString
& GetName() const { return m_aName
; }
63 const OString
& GetValue() const { return m_aValue
; }
66 enum class InetMessageMime
69 CONTENT_DISPOSITION
= 1,
71 CONTENT_TRANSFER_ENCODING
= 3,
75 class SAL_WARN_UNUSED
UNLESS_MERGELIBS(TOOLS_DLLPUBLIC
) INetMIMEMessage
77 ::std::vector
< std::unique_ptr
<INetMessageHeader
> >
80 std::unique_ptr
<SvStream
> m_xDocLB
;
82 ::std::map
<InetMessageMime
, sal_uInt32
> m_nMIMEIndex
;
83 INetMIMEMessage
* pParent
;
84 ::std::vector
< std::unique_ptr
<INetMIMEMessage
> >
88 OUString
GetHeaderValue_Impl (
89 sal_uInt32 nIndex
) const
91 if ( nIndex
< m_aHeaderList
.size() ) {
92 return INetMIME::decodeHeaderFieldBody(m_aHeaderList
[ nIndex
]->GetValue());
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
);
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;
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
];
138 return INetMessageHeader();
142 SvStream
* GetDocumentLB() const { return m_xDocLB
.get(); }
143 void SetDocumentLB (std::unique_ptr
<SvStream
> pDocLB
) { m_xDocLB
= std::move(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
; }
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */