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>
34 class SAL_WARN_UNUSED INetMessageHeader
44 const OString
& rName
, const OString
& rValue
)
45 : m_aName (rName
), m_aValue (rValue
)
49 const INetMessageHeader
& rHdr
)
50 : m_aName (rHdr
.m_aName
), m_aValue (rHdr
.m_aValue
)
53 INetMessageHeader
& operator= (const INetMessageHeader
& rHdr
)
55 m_aName
= rHdr
.m_aName
;
56 m_aValue
= rHdr
.m_aValue
;
60 const OString
& GetName() const { return m_aName
; }
61 const OString
& GetValue() const { return m_aValue
; }
64 enum class InetMessageMime
67 CONTENT_DISPOSITION
= 1,
69 CONTENT_TRANSFER_ENCODING
= 3,
73 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC INetMIMEMessage
75 ::std::vector
< std::unique_ptr
<INetMessageHeader
> >
78 SvLockBytesRef m_xDocLB
;
80 ::std::map
<InetMessageMime
, sal_uInt32
> m_nMIMEIndex
;
81 INetMIMEMessage
* pParent
;
82 ::std::vector
< std::unique_ptr
<INetMIMEMessage
> >
86 OUString
GetHeaderValue_Impl (
87 sal_uInt32 nIndex
) const
89 if ( nIndex
< m_aHeaderList
.size() ) {
90 return INetMIME::decodeHeaderFieldBody(m_aHeaderList
[ nIndex
]->GetValue());
96 void SetHeaderField_Impl (
97 const INetMessageHeader
&rHeader
, sal_uInt32
&rnIndex
)
99 INetMessageHeader
*p
= new INetMessageHeader (rHeader
);
100 if (m_aHeaderList
.size() <= rnIndex
)
102 rnIndex
= m_aHeaderList
.size();
103 m_aHeaderList
.emplace_back( p
);
107 m_aHeaderList
[ rnIndex
].reset(p
);
111 void SetHeaderField_Impl (
112 const OString
&rName
,
113 const OUString
&rValue
,
114 sal_uInt32
&rnIndex
);
116 bool IsMessage() const
118 OUString
aType (GetContentType());
119 return aType
.matchIgnoreAsciiCase("message/");
122 INetMIMEMessage (const INetMIMEMessage
& rMsg
) = delete;
123 INetMIMEMessage
& operator= (const INetMIMEMessage
& rMsg
) = delete;
129 sal_uInt32
GetHeaderCount() const { return m_aHeaderList
.size(); }
131 INetMessageHeader
GetHeaderField (sal_uInt32 nIndex
) const
133 if ( nIndex
< m_aHeaderList
.size() ) {
134 return *m_aHeaderList
[ nIndex
];
136 return INetMessageHeader();
140 SvLockBytes
* GetDocumentLB() const { return m_xDocLB
.get(); }
141 void SetDocumentLB (SvLockBytes
*pDocLB
) { m_xDocLB
= pDocLB
; }
143 static bool ParseDateField (
144 const OUString
& rDateField
, DateTime
& rDateTime
);
146 void SetMIMEVersion (const OUString
& rVersion
);
147 void SetContentDisposition (const OUString
& rDisposition
);
148 void SetContentType (const OUString
& rType
);
149 OUString
GetContentType() const
151 return GetHeaderValue_Impl(
152 m_nMIMEIndex
.at(InetMessageMime::CONTENT_TYPE
));
155 void SetContentTransferEncoding (const OUString
& rEncoding
);
157 OUString
GetDefaultContentType ();
159 // Message container methods.
161 bool IsContainer() const
163 return (IsMessage() || IsMultipart());
165 bool IsMultipart() const
167 OUString
aType (GetContentType());
168 return aType
.matchIgnoreAsciiCase("multipart/");
171 INetMIMEMessage
* GetChild (sal_uInt32 nIndex
) const
173 return ( nIndex
< aChildren
.size() ) ? aChildren
[ nIndex
].get() : nullptr;
175 INetMIMEMessage
* GetParent() const { return pParent
; }
177 void EnableAttachMultipartFormDataChild();
178 void AttachChild( std::unique_ptr
<INetMIMEMessage
> pChildMsg
);
180 const OString
& GetMultipartBoundary() const { return m_aBoundary
; }
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */