Bump version to 6.4-15
[LibreOffice.git] / include / tools / inetmsg.hxx
blobed0e074fb167dbb7be5285941f468fceb53b7a38
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 <vector>
29 #include <map>
30 #include <memory>
32 class DateTime;
34 class SAL_WARN_UNUSED 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& operator= (const INetMessageHeader& rHdr)
55 m_aName = rHdr.m_aName;
56 m_aValue = rHdr.m_aValue;
57 return *this;
60 const OString& GetName() const { return m_aName; }
61 const OString& GetValue() const { return m_aValue; }
64 enum class InetMessageMime
66 VERSION = 0,
67 CONTENT_DISPOSITION = 1,
68 CONTENT_TYPE = 2,
69 CONTENT_TRANSFER_ENCODING = 3,
70 NUMHDR = 4,
73 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC INetMIMEMessage
75 ::std::vector< std::unique_ptr<INetMessageHeader> >
76 m_aHeaderList;
78 SvLockBytesRef m_xDocLB;
80 ::std::map<InetMessageMime, sal_uInt32> m_nMIMEIndex;
81 INetMIMEMessage* pParent;
82 ::std::vector< std::unique_ptr<INetMIMEMessage> >
83 aChildren;
84 OString m_aBoundary;
86 OUString GetHeaderValue_Impl (
87 sal_uInt32 nIndex) const
89 if ( nIndex < m_aHeaderList.size() ) {
90 return INetMIME::decodeHeaderFieldBody(m_aHeaderList[ nIndex ]->GetValue());
91 } else {
92 return OUString();
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 );
105 else
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;
125 public:
126 INetMIMEMessage();
127 ~INetMIMEMessage();
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 ];
135 } else {
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; }
183 #endif
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */