LibreOffice Module tools (master) 1
inetmsg.hxx
Go to the documentation of this file.
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
35class DateTime;
36
38{
39 OString m_aName;
40 OString m_aValue;
41
42public:
44 {}
45
46 INetMessageHeader(OString aName, OString aValue)
47 : m_aName (std::move(aName)), m_aValue (std::move(aValue))
48 {}
49
51 const INetMessageHeader& rHdr)
52 : m_aName (rHdr.m_aName), m_aValue (rHdr.m_aValue)
53 {}
54
55 INetMessageHeader& operator= (const INetMessageHeader& rHdr)
56 {
57 m_aName = rHdr.m_aName;
58 m_aValue = rHdr.m_aValue;
59 return *this;
60 }
61
62 const OString& GetName() const { return m_aName; }
63 const OString& GetValue() const { return m_aValue; }
64};
65
67{
68 VERSION = 0,
70 CONTENT_TYPE = 2,
72 NUMHDR = 4,
73};
74
76{
77 ::std::vector< std::unique_ptr<INetMessageHeader> >
78 m_aHeaderList;
79
80 SvLockBytesRef 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 {
91 if ( nIndex < m_aHeaderList.size() ) {
92 return INetMIME::decodeHeaderFieldBody(m_aHeaderList[ nIndex ]->GetValue());
93 } else {
94 return OUString();
95 }
96 }
97
98 void SetHeaderField_Impl (
99 const INetMessageHeader &rHeader, sal_uInt32 &rnIndex)
100 {
101 INetMessageHeader *p = new INetMessageHeader (rHeader);
102 if (m_aHeaderList.size() <= rnIndex)
103 {
104 rnIndex = m_aHeaderList.size();
105 m_aHeaderList.emplace_back( p );
106 }
107 else
108 {
109 m_aHeaderList[ rnIndex ].reset(p);
110 }
111 }
112
113 void SetHeaderField_Impl (
114 const OString &rName,
115 const OUString &rValue,
116 sal_uInt32 &rnIndex);
117
118 bool IsMessage() const
119 {
120 OUString aType (GetContentType());
121 return aType.matchIgnoreAsciiCase("message/");
122 }
123
124 INetMIMEMessage (const INetMIMEMessage& rMsg) = delete;
125 INetMIMEMessage& operator= (const INetMIMEMessage& rMsg) = delete;
126
127public:
128 INetMIMEMessage();
129 ~INetMIMEMessage();
130
131 sal_uInt32 GetHeaderCount() const { return m_aHeaderList.size(); }
132
133 INetMessageHeader GetHeaderField (sal_uInt32 nIndex) const
134 {
135 if ( nIndex < m_aHeaderList.size() ) {
136 return *m_aHeaderList[ nIndex ];
137 } else {
138 return INetMessageHeader();
139 }
140 }
141
142 SvLockBytes* GetDocumentLB() const { return m_xDocLB.get(); }
143 void SetDocumentLB (SvLockBytes *pDocLB) { m_xDocLB = 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 {
153 return GetHeaderValue_Impl(
154 m_nMIMEIndex.at(InetMessageMime::CONTENT_TYPE));
155 }
156
157 void SetContentTransferEncoding (const OUString& rEncoding);
158
159 OUString GetDefaultContentType ();
160
161 // Message container methods.
162
163 bool IsContainer() const
164 {
165 return (IsMessage() || IsMultipart());
166 }
167 bool IsMultipart() const
168 {
169 OUString aType (GetContentType());
170 return aType.matchIgnoreAsciiCase("multipart/");
171 }
172
173 INetMIMEMessage* GetChild (sal_uInt32 nIndex) const
174 {
175 return ( nIndex < aChildren.size() ) ? aChildren[ nIndex ].get() : nullptr;
176 }
177 INetMIMEMessage* GetParent() const { return pParent; }
178
179 void EnableAttachMultipartFormDataChild();
180 void AttachChild( std::unique_ptr<INetMIMEMessage> pChildMsg );
181
182 const OString& GetMultipartBoundary() const { return m_aBoundary; }
183};
184
185#endif
186
187/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OUString decodeHeaderFieldBody(const OString &rBody)
Definition: inetmime.cxx:1053
const OString & GetValue() const
Definition: inetmsg.hxx:63
INetMessageHeader(const INetMessageHeader &rHdr)
Definition: inetmsg.hxx:50
INetMessageHeader(OString aName, OString aValue)
Definition: inetmsg.hxx:46
const OString & GetName() const
Definition: inetmsg.hxx:62
OString m_aValue
Definition: inetmsg.hxx:40
OString m_aName
Definition: inetmsg.hxx:39
InetMessageMime
Definition: inetmsg.hxx:67
class SAL_WARN_UNUSED UNLESS_MERGELIBS(TOOLS_DLLPUBLIC) INetMIMEMessage
Definition: inetmsg.hxx:75
sal_Int32 nIndex
OUString aName
void * p
const char GetValue[]
OUString m_aName
#define VERSION
#define TOOLS_DLLPUBLIC
Definition: toolsdllapi.h:28
#define SAL_WARN_UNUSED