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/textenc.h>
25 #include <rtl/ustring.hxx>
26 #include <tools/inetmime.hxx>
27 #include <tools/stream.hxx>
35 class SAL_WARN_UNUSED INetMessageHeader
45 const OString
& rName
, const OString
& rValue
)
46 : m_aName (rName
), m_aValue (rValue
)
50 const INetMessageHeader
& rHdr
)
51 : m_aName (rHdr
.m_aName
), m_aValue (rHdr
.m_aValue
)
54 INetMessageHeader
& operator= (const INetMessageHeader
& rHdr
)
56 m_aName
= rHdr
.m_aName
;
57 m_aValue
= rHdr
.m_aValue
;
61 const OString
& GetName() const { return m_aName
; }
62 const OString
& GetValue() const { return m_aValue
; }
65 enum class InetMessageMime
68 CONTENT_DISPOSITION
= 1,
70 CONTENT_TRANSFER_ENCODING
= 3,
74 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC INetMIMEMessage
76 ::std::vector
< std::unique_ptr
<INetMessageHeader
> >
79 SvLockBytesRef m_xDocLB
;
81 ::std::map
<InetMessageMime
, sal_uInt32
> m_nMIMEIndex
;
82 INetMIMEMessage
* pParent
;
83 ::std::vector
< std::unique_ptr
<INetMIMEMessage
> >
87 OUString
GetHeaderValue_Impl (
88 sal_uInt32 nIndex
) const
90 if ( nIndex
< m_aHeaderList
.size() ) {
91 return INetMIME::decodeHeaderFieldBody(m_aHeaderList
[ nIndex
]->GetValue());
97 void SetHeaderField_Impl (
98 const INetMessageHeader
&rHeader
, sal_uInt32
&rnIndex
)
100 INetMessageHeader
*p
= new INetMessageHeader (rHeader
);
101 if (m_aHeaderList
.size() <= rnIndex
)
103 rnIndex
= m_aHeaderList
.size();
104 m_aHeaderList
.emplace_back( p
);
108 m_aHeaderList
[ rnIndex
].reset(p
);
112 void SetHeaderField_Impl (
113 const OString
&rName
,
114 const OUString
&rValue
,
115 sal_uInt32
&rnIndex
);
117 bool IsMessage() const
119 OUString
aType (GetContentType());
120 return aType
.matchIgnoreAsciiCase("message/");
123 INetMIMEMessage (const INetMIMEMessage
& rMsg
) = delete;
124 INetMIMEMessage
& operator= (const INetMIMEMessage
& rMsg
) = delete;
130 sal_uInt32
GetHeaderCount() const { return m_aHeaderList
.size(); }
132 INetMessageHeader
GetHeaderField (sal_uInt32 nIndex
) const
134 if ( nIndex
< m_aHeaderList
.size() ) {
135 return *m_aHeaderList
[ nIndex
];
137 return INetMessageHeader();
141 SvLockBytes
* GetDocumentLB() const { return m_xDocLB
.get(); }
142 void SetDocumentLB (SvLockBytes
*pDocLB
) { m_xDocLB
= pDocLB
; }
144 static bool ParseDateField (
145 const OUString
& rDateField
, DateTime
& rDateTime
);
147 void SetMIMEVersion (const OUString
& rVersion
);
148 void SetContentDisposition (const OUString
& rDisposition
);
149 void SetContentType (const OUString
& rType
);
150 OUString
GetContentType() const
152 return GetHeaderValue_Impl(
153 m_nMIMEIndex
.at(InetMessageMime::CONTENT_TYPE
));
156 void SetContentTransferEncoding (const OUString
& rEncoding
);
158 OUString
GetDefaultContentType ();
160 // Message container methods.
162 bool IsContainer() const
164 return (IsMessage() || IsMultipart());
166 bool IsMultipart() const
168 OUString
aType (GetContentType());
169 return aType
.matchIgnoreAsciiCase("multipart/");
172 INetMIMEMessage
* GetChild (sal_uInt32 nIndex
) const
174 return ( nIndex
< aChildren
.size() ) ? aChildren
[ nIndex
].get() : nullptr;
176 INetMIMEMessage
* GetParent() const { return pParent
; }
178 void EnableAttachMultipartFormDataChild();
179 void AttachChild( std::unique_ptr
<INetMIMEMessage
> pChildMsg
);
181 const OString
& GetMultipartBoundary() const { return m_aBoundary
; }
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */