/src/libreoffice/include/tools/inetmsg.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | #ifndef INCLUDED_TOOLS_INETMSG_HXX |
20 | | #define INCLUDED_TOOLS_INETMSG_HXX |
21 | | |
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> |
27 | | |
28 | | #include <string_view> |
29 | | #include <utility> |
30 | | #include <vector> |
31 | | #include <map> |
32 | | #include <memory> |
33 | | #include <config_options.h> |
34 | | |
35 | | class DateTime; |
36 | | |
37 | | class SAL_WARN_UNUSED INetMessageHeader |
38 | | { |
39 | | OString m_aName; |
40 | | OString m_aValue; |
41 | | |
42 | | public: |
43 | | INetMessageHeader() |
44 | 0 | {} |
45 | | |
46 | | INetMessageHeader(OString aName, OString aValue) |
47 | 0 | : m_aName (std::move(aName)), m_aValue (std::move(aValue)) |
48 | 0 | {} |
49 | | |
50 | | INetMessageHeader ( |
51 | | const INetMessageHeader& rHdr) |
52 | 0 | : m_aName (rHdr.m_aName), m_aValue (rHdr.m_aValue) |
53 | 0 | {} |
54 | | |
55 | | INetMessageHeader& operator= (const INetMessageHeader& rHdr) |
56 | 0 | { |
57 | 0 | m_aName = rHdr.m_aName; |
58 | 0 | m_aValue = rHdr.m_aValue; |
59 | 0 | return *this; |
60 | 0 | } |
61 | | |
62 | 0 | const OString& GetName() const { return m_aName; } |
63 | 0 | const OString& GetValue() const { return m_aValue; } |
64 | | }; |
65 | | |
66 | | enum class InetMessageMime |
67 | | { |
68 | | VERSION = 0, |
69 | | CONTENT_DISPOSITION = 1, |
70 | | CONTENT_TYPE = 2, |
71 | | CONTENT_TRANSFER_ENCODING = 3, |
72 | | NUMHDR = 4, |
73 | | }; |
74 | | |
75 | | class SAL_WARN_UNUSED UNLESS_MERGELIBS(TOOLS_DLLPUBLIC) INetMIMEMessage |
76 | | { |
77 | | ::std::vector< std::unique_ptr<INetMessageHeader> > |
78 | | m_aHeaderList; |
79 | | |
80 | | std::unique_ptr<SvStream> m_xDocLB; |
81 | | |
82 | | ::std::map<InetMessageMime, sal_uInt32> m_nMIMEIndex; |
83 | | INetMIMEMessage* pParent; |
84 | | ::std::vector< std::unique_ptr<INetMIMEMessage> > |
85 | | aChildren; |
86 | | OString m_aBoundary; |
87 | | |
88 | | OUString GetHeaderValue_Impl ( |
89 | | sal_uInt32 nIndex) const |
90 | 0 | { |
91 | 0 | if ( nIndex < m_aHeaderList.size() ) { |
92 | 0 | return INetMIME::decodeHeaderFieldBody(m_aHeaderList[ nIndex ]->GetValue()); |
93 | 0 | } else { |
94 | 0 | return OUString(); |
95 | 0 | } |
96 | 0 | } |
97 | | |
98 | | void SetHeaderField_Impl ( |
99 | | const INetMessageHeader &rHeader, sal_uInt32 &rnIndex) |
100 | 0 | { |
101 | 0 | INetMessageHeader *p = new INetMessageHeader (rHeader); |
102 | 0 | if (m_aHeaderList.size() <= rnIndex) |
103 | 0 | { |
104 | 0 | rnIndex = m_aHeaderList.size(); |
105 | 0 | m_aHeaderList.emplace_back( p ); |
106 | 0 | } |
107 | 0 | else |
108 | 0 | { |
109 | 0 | m_aHeaderList[ rnIndex ].reset(p); |
110 | 0 | } |
111 | 0 | } |
112 | | |
113 | | void SetHeaderField_Impl ( |
114 | | const OString &rName, |
115 | | const OUString &rValue, |
116 | | sal_uInt32 &rnIndex); |
117 | | |
118 | | bool IsMessage() const |
119 | 0 | { |
120 | 0 | OUString aType (GetContentType()); |
121 | 0 | return aType.matchIgnoreAsciiCase("message/"); |
122 | 0 | } |
123 | | |
124 | | INetMIMEMessage (const INetMIMEMessage& rMsg) = delete; |
125 | | INetMIMEMessage& operator= (const INetMIMEMessage& rMsg) = delete; |
126 | | |
127 | | public: |
128 | | INetMIMEMessage(); |
129 | | ~INetMIMEMessage(); |
130 | | |
131 | 0 | sal_uInt32 GetHeaderCount() const { return m_aHeaderList.size(); } |
132 | | |
133 | | INetMessageHeader GetHeaderField (sal_uInt32 nIndex) const |
134 | 0 | { |
135 | 0 | if ( nIndex < m_aHeaderList.size() ) { |
136 | 0 | return *m_aHeaderList[ nIndex ]; |
137 | 0 | } else { |
138 | 0 | return INetMessageHeader(); |
139 | 0 | } |
140 | 0 | } |
141 | | |
142 | 0 | SvStream* GetDocumentLB() const { return m_xDocLB.get(); } |
143 | 0 | void SetDocumentLB (std::unique_ptr<SvStream> pDocLB) { m_xDocLB = std::move(pDocLB); } |
144 | | |
145 | | static bool ParseDateField ( |
146 | | std::u16string_view rDateField, DateTime& rDateTime); |
147 | | |
148 | | void SetMIMEVersion (const OUString& rVersion); |
149 | | void SetContentDisposition (const OUString& rDisposition); |
150 | | void SetContentType (const OUString& rType); |
151 | | OUString GetContentType() const |
152 | 0 | { |
153 | 0 | return GetHeaderValue_Impl( |
154 | 0 | m_nMIMEIndex.at(InetMessageMime::CONTENT_TYPE)); |
155 | 0 | } |
156 | | |
157 | | void SetContentTransferEncoding (const OUString& rEncoding); |
158 | | |
159 | | OUString GetDefaultContentType (); |
160 | | |
161 | | // Message container methods. |
162 | | |
163 | | bool IsContainer() const |
164 | 0 | { |
165 | 0 | return (IsMessage() || IsMultipart()); |
166 | 0 | } |
167 | | bool IsMultipart() const |
168 | 0 | { |
169 | 0 | OUString aType (GetContentType()); |
170 | 0 | return aType.matchIgnoreAsciiCase("multipart/"); |
171 | 0 | } |
172 | | |
173 | | INetMIMEMessage* GetChild (sal_uInt32 nIndex) const |
174 | 0 | { |
175 | 0 | return ( nIndex < aChildren.size() ) ? aChildren[ nIndex ].get() : nullptr; |
176 | 0 | } |
177 | 0 | INetMIMEMessage* GetParent() const { return pParent; } |
178 | | |
179 | | void EnableAttachMultipartFormDataChild(); |
180 | | void AttachChild( std::unique_ptr<INetMIMEMessage> pChildMsg ); |
181 | | |
182 | 0 | const OString& GetMultipartBoundary() const { return m_aBoundary; } |
183 | | }; |
184 | | |
185 | | #endif |
186 | | |
187 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |