189b56da7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
389b56da7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
489b56da7SAndrew Rist * or more contributor license agreements. See the NOTICE file
589b56da7SAndrew Rist * distributed with this work for additional information
689b56da7SAndrew Rist * regarding copyright ownership. The ASF licenses this file
789b56da7SAndrew Rist * to you under the Apache License, Version 2.0 (the
889b56da7SAndrew Rist * "License"); you may not use this file except in compliance
989b56da7SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
1189b56da7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
1389b56da7SAndrew Rist * Unless required by applicable law or agreed to in writing,
1489b56da7SAndrew Rist * software distributed under the License is distributed on an
1589b56da7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1689b56da7SAndrew Rist * KIND, either express or implied. See the License for the
1789b56da7SAndrew Rist * specific language governing permissions and limitations
1889b56da7SAndrew Rist * under the License.
19cdf0e10cSrcweir *
2089b56da7SAndrew Rist *************************************************************/
2189b56da7SAndrew Rist
2289b56da7SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_tools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <cstddef>
28cdf0e10cSrcweir #include <limits>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include "rtl/tencinfo.h"
31cdf0e10cSrcweir #include <tools/datetime.hxx>
32cdf0e10cSrcweir #include <tools/inetmime.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir namespace unnamed_tools_inetmime {} using namespace unnamed_tools_inetmime;
35cdf0e10cSrcweir // unnamed namespaces don't work well yet
36cdf0e10cSrcweir
37cdf0e10cSrcweir //============================================================================
38cdf0e10cSrcweir namespace unnamed_tools_inetmime {
39cdf0e10cSrcweir
40cdf0e10cSrcweir class Charset
41cdf0e10cSrcweir {
42cdf0e10cSrcweir rtl_TextEncoding m_eEncoding;
43cdf0e10cSrcweir const sal_uInt32 * m_pRanges;
44cdf0e10cSrcweir
45cdf0e10cSrcweir public:
46cdf0e10cSrcweir inline Charset(rtl_TextEncoding eTheEncoding,
47cdf0e10cSrcweir const sal_uInt32 * pTheRanges);
48cdf0e10cSrcweir
getEncoding() const49cdf0e10cSrcweir rtl_TextEncoding getEncoding() const { return m_eEncoding; }
50cdf0e10cSrcweir
51cdf0e10cSrcweir bool contains(sal_uInt32 nChar) const;
52cdf0e10cSrcweir };
53cdf0e10cSrcweir
Charset(rtl_TextEncoding eTheEncoding,const sal_uInt32 * pTheRanges)54cdf0e10cSrcweir inline Charset::Charset(rtl_TextEncoding eTheEncoding,
55cdf0e10cSrcweir const sal_uInt32 * pTheRanges):
56cdf0e10cSrcweir m_eEncoding(eTheEncoding),
57cdf0e10cSrcweir m_pRanges(pTheRanges)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir DBG_ASSERT(m_pRanges, "Charset::Charset(): Bad ranges");
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
62cdf0e10cSrcweir //============================================================================
63cdf0e10cSrcweir void appendISO88591(UniString & rText, sal_Char const * pBegin,
64cdf0e10cSrcweir sal_Char const * pEnd);
65cdf0e10cSrcweir
66cdf0e10cSrcweir }
67cdf0e10cSrcweir
68cdf0e10cSrcweir //============================================================================
69cdf0e10cSrcweir class INetMIMECharsetList_Impl
70cdf0e10cSrcweir {
71cdf0e10cSrcweir struct Node
72cdf0e10cSrcweir {
73cdf0e10cSrcweir Charset m_aCharset;
74cdf0e10cSrcweir bool m_bDisabled;
75cdf0e10cSrcweir Node * m_pNext;
76cdf0e10cSrcweir
77cdf0e10cSrcweir inline Node(const Charset & rTheCharset, bool bTheDisabled,
78cdf0e10cSrcweir Node * pTheNext);
79cdf0e10cSrcweir };
80cdf0e10cSrcweir
81cdf0e10cSrcweir Node * m_pFirst;
82cdf0e10cSrcweir
83cdf0e10cSrcweir public:
INetMIMECharsetList_Impl()84cdf0e10cSrcweir INetMIMECharsetList_Impl(): m_pFirst(0) {}
85cdf0e10cSrcweir
86cdf0e10cSrcweir ~INetMIMECharsetList_Impl();
87cdf0e10cSrcweir
prepend(const Charset & rCharset)88cdf0e10cSrcweir void prepend(const Charset & rCharset)
89cdf0e10cSrcweir { m_pFirst = new Node(rCharset, false, m_pFirst); }
90cdf0e10cSrcweir
91cdf0e10cSrcweir void includes(sal_uInt32 nChar);
92cdf0e10cSrcweir
93cdf0e10cSrcweir rtl_TextEncoding getPreferredEncoding(rtl_TextEncoding eDefault
94cdf0e10cSrcweir = RTL_TEXTENCODING_DONTKNOW)
95cdf0e10cSrcweir const;
96cdf0e10cSrcweir
97cdf0e10cSrcweir void reset();
98cdf0e10cSrcweir };
99cdf0e10cSrcweir
Node(const Charset & rTheCharset,bool bTheDisabled,Node * pTheNext)100cdf0e10cSrcweir inline INetMIMECharsetList_Impl::Node::Node(const Charset & rTheCharset,
101cdf0e10cSrcweir bool bTheDisabled,
102cdf0e10cSrcweir Node * pTheNext):
103cdf0e10cSrcweir m_aCharset(rTheCharset),
104cdf0e10cSrcweir m_bDisabled(bTheDisabled),
105cdf0e10cSrcweir m_pNext(pTheNext)
106cdf0e10cSrcweir {}
107cdf0e10cSrcweir
108cdf0e10cSrcweir //============================================================================
109cdf0e10cSrcweir namespace unnamed_tools_inetmime {
110cdf0e10cSrcweir
111cdf0e10cSrcweir struct Parameter
112cdf0e10cSrcweir {
113cdf0e10cSrcweir Parameter * m_pNext;
114cdf0e10cSrcweir ByteString m_aAttribute;
115cdf0e10cSrcweir ByteString m_aCharset;
116cdf0e10cSrcweir ByteString m_aLanguage;
117cdf0e10cSrcweir ByteString m_aValue;
118cdf0e10cSrcweir sal_uInt32 m_nSection;
119cdf0e10cSrcweir bool m_bExtended;
120cdf0e10cSrcweir
121cdf0e10cSrcweir inline Parameter(Parameter * pTheNext, ByteString const & rTheAttribute,
122cdf0e10cSrcweir ByteString const & rTheCharset,
123cdf0e10cSrcweir ByteString const & rTheLanguage,
124cdf0e10cSrcweir ByteString const & rTheValue, sal_uInt32 nTheSection,
125cdf0e10cSrcweir bool bTheExtended);
126cdf0e10cSrcweir };
127cdf0e10cSrcweir
Parameter(Parameter * pTheNext,ByteString const & rTheAttribute,ByteString const & rTheCharset,ByteString const & rTheLanguage,ByteString const & rTheValue,sal_uInt32 nTheSection,bool bTheExtended)128cdf0e10cSrcweir inline Parameter::Parameter(Parameter * pTheNext,
129cdf0e10cSrcweir ByteString const & rTheAttribute,
130cdf0e10cSrcweir ByteString const & rTheCharset,
131cdf0e10cSrcweir ByteString const & rTheLanguage,
132cdf0e10cSrcweir ByteString const & rTheValue,
133cdf0e10cSrcweir sal_uInt32 nTheSection, bool bTheExtended):
134cdf0e10cSrcweir m_pNext(pTheNext),
135cdf0e10cSrcweir m_aAttribute(rTheAttribute),
136cdf0e10cSrcweir m_aCharset(rTheCharset),
137cdf0e10cSrcweir m_aLanguage(rTheLanguage),
138cdf0e10cSrcweir m_aValue(rTheValue),
139cdf0e10cSrcweir m_nSection(nTheSection),
140cdf0e10cSrcweir m_bExtended(bTheExtended)
141cdf0e10cSrcweir {}
142cdf0e10cSrcweir
143cdf0e10cSrcweir //============================================================================
144cdf0e10cSrcweir struct ParameterList
145cdf0e10cSrcweir {
146cdf0e10cSrcweir Parameter * m_pList;
147cdf0e10cSrcweir
ParameterListunnamed_tools_inetmime::ParameterList148cdf0e10cSrcweir ParameterList(): m_pList(0) {}
149cdf0e10cSrcweir
150cdf0e10cSrcweir inline ~ParameterList();
151cdf0e10cSrcweir
152cdf0e10cSrcweir Parameter ** find(ByteString const & rAttribute, sal_uInt32 nSection,
153cdf0e10cSrcweir bool & rPresent);
154cdf0e10cSrcweir };
155cdf0e10cSrcweir
~ParameterList()156cdf0e10cSrcweir inline ParameterList::~ParameterList()
157cdf0e10cSrcweir {
158cdf0e10cSrcweir while (m_pList)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir Parameter * pNext = m_pList->m_pNext;
161cdf0e10cSrcweir delete m_pList;
162cdf0e10cSrcweir m_pList = pNext;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
166cdf0e10cSrcweir //============================================================================
167cdf0e10cSrcweir bool parseParameters(ParameterList const & rInput,
168cdf0e10cSrcweir INetContentTypeParameterList * pOutput);
169cdf0e10cSrcweir
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir //============================================================================
173cdf0e10cSrcweir //
174cdf0e10cSrcweir // Charset
175cdf0e10cSrcweir //
176cdf0e10cSrcweir //============================================================================
177cdf0e10cSrcweir
contains(sal_uInt32 nChar) const178cdf0e10cSrcweir bool Charset::contains(sal_uInt32 nChar) const
179cdf0e10cSrcweir {
180cdf0e10cSrcweir for (const sal_uInt32 * p = m_pRanges;;)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir if (nChar < *p++)
183cdf0e10cSrcweir return false;
184cdf0e10cSrcweir if (nChar <= *p++)
185cdf0e10cSrcweir return true;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir }
188cdf0e10cSrcweir
189cdf0e10cSrcweir //============================================================================
190cdf0e10cSrcweir //
191cdf0e10cSrcweir // appendISO88591
192cdf0e10cSrcweir //
193cdf0e10cSrcweir //============================================================================
194cdf0e10cSrcweir
195cdf0e10cSrcweir namespace unnamed_tools_inetmime {
196cdf0e10cSrcweir
appendISO88591(UniString & rText,sal_Char const * pBegin,sal_Char const * pEnd)197cdf0e10cSrcweir void appendISO88591(UniString & rText, sal_Char const * pBegin,
198cdf0e10cSrcweir sal_Char const * pEnd)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir xub_StrLen nLength = static_cast< xub_StrLen >(pEnd - pBegin);
201cdf0e10cSrcweir sal_Unicode * pBuffer = new sal_Unicode[nLength];
202cdf0e10cSrcweir for (sal_Unicode * p = pBuffer; pBegin != pEnd;)
203cdf0e10cSrcweir *p++ = sal_uChar(*pBegin++);
204cdf0e10cSrcweir rText.Append(pBuffer, nLength);
205cdf0e10cSrcweir delete[] pBuffer;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir
208cdf0e10cSrcweir }
209cdf0e10cSrcweir
210cdf0e10cSrcweir //============================================================================
211cdf0e10cSrcweir //
212cdf0e10cSrcweir // INetMIMECharsetList_Impl
213cdf0e10cSrcweir //
214cdf0e10cSrcweir //============================================================================
215cdf0e10cSrcweir
~INetMIMECharsetList_Impl()216cdf0e10cSrcweir INetMIMECharsetList_Impl::~INetMIMECharsetList_Impl()
217cdf0e10cSrcweir {
218cdf0e10cSrcweir while (m_pFirst)
219cdf0e10cSrcweir {
220cdf0e10cSrcweir Node * pRemove = m_pFirst;
221cdf0e10cSrcweir m_pFirst = m_pFirst->m_pNext;
222cdf0e10cSrcweir delete pRemove;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir }
225cdf0e10cSrcweir
226cdf0e10cSrcweir //============================================================================
includes(sal_uInt32 nChar)227cdf0e10cSrcweir void INetMIMECharsetList_Impl::includes(sal_uInt32 nChar)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir for (Node * p = m_pFirst; p; p = p->m_pNext)
230cdf0e10cSrcweir if (!(p->m_bDisabled || p->m_aCharset.contains(nChar)))
231cdf0e10cSrcweir p->m_bDisabled = true;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir
234cdf0e10cSrcweir //============================================================================
235cdf0e10cSrcweir rtl_TextEncoding
getPreferredEncoding(rtl_TextEncoding eDefault) const236cdf0e10cSrcweir INetMIMECharsetList_Impl::getPreferredEncoding(rtl_TextEncoding eDefault)
237cdf0e10cSrcweir const
238cdf0e10cSrcweir {
239cdf0e10cSrcweir for (Node * p = m_pFirst; p; p = p->m_pNext)
240cdf0e10cSrcweir if (!p->m_bDisabled)
241cdf0e10cSrcweir return p->m_aCharset.getEncoding();
242cdf0e10cSrcweir return eDefault;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir
245cdf0e10cSrcweir //============================================================================
reset()246cdf0e10cSrcweir void INetMIMECharsetList_Impl::reset()
247cdf0e10cSrcweir {
248cdf0e10cSrcweir for (Node * p = m_pFirst; p; p = p->m_pNext)
249cdf0e10cSrcweir p->m_bDisabled = false;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
252cdf0e10cSrcweir //============================================================================
253cdf0e10cSrcweir //
254cdf0e10cSrcweir // ParameterList
255cdf0e10cSrcweir //
256cdf0e10cSrcweir //============================================================================
257cdf0e10cSrcweir
find(ByteString const & rAttribute,sal_uInt32 nSection,bool & rPresent)258cdf0e10cSrcweir Parameter ** ParameterList::find(ByteString const & rAttribute,
259cdf0e10cSrcweir sal_uInt32 nSection, bool & rPresent)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir Parameter ** p = &m_pList;
262cdf0e10cSrcweir for (; *p; p = &(*p)->m_pNext)
263cdf0e10cSrcweir {
264cdf0e10cSrcweir StringCompare eCompare = rAttribute.CompareTo((*p)->m_aAttribute);
265cdf0e10cSrcweir if (eCompare == COMPARE_GREATER)
266cdf0e10cSrcweir break;
267cdf0e10cSrcweir else if (eCompare == COMPARE_EQUAL)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir if (nSection > (*p)->m_nSection)
270cdf0e10cSrcweir break;
271cdf0e10cSrcweir else if (nSection == (*p)->m_nSection)
272cdf0e10cSrcweir {
273cdf0e10cSrcweir rPresent = true;
274cdf0e10cSrcweir return p;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir }
277cdf0e10cSrcweir }
278cdf0e10cSrcweir rPresent = false;
279cdf0e10cSrcweir return p;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir
282cdf0e10cSrcweir //============================================================================
283cdf0e10cSrcweir //
284cdf0e10cSrcweir // parseParameters
285cdf0e10cSrcweir //
286cdf0e10cSrcweir //============================================================================
287cdf0e10cSrcweir
288cdf0e10cSrcweir namespace unnamed_tools_inetmime {
289cdf0e10cSrcweir
parseParameters(ParameterList const & rInput,INetContentTypeParameterList * pOutput)290cdf0e10cSrcweir bool parseParameters(ParameterList const & rInput,
291cdf0e10cSrcweir INetContentTypeParameterList * pOutput)
292cdf0e10cSrcweir {
293cdf0e10cSrcweir if (pOutput)
294cdf0e10cSrcweir pOutput->Clear();
295cdf0e10cSrcweir
296cdf0e10cSrcweir Parameter * pPrev = 0;
297cdf0e10cSrcweir for (Parameter * p = rInput.m_pList; p; p = p->m_pNext)
298cdf0e10cSrcweir {
299cdf0e10cSrcweir if (p->m_nSection > 0
300cdf0e10cSrcweir && (!pPrev
301cdf0e10cSrcweir || pPrev->m_nSection != p->m_nSection - 1
302cdf0e10cSrcweir || pPrev->m_aAttribute != p->m_aAttribute))
303cdf0e10cSrcweir return false;
304cdf0e10cSrcweir pPrev = p;
305cdf0e10cSrcweir }
306cdf0e10cSrcweir
307cdf0e10cSrcweir if (pOutput)
308cdf0e10cSrcweir for (Parameter * p = rInput.m_pList; p;)
309cdf0e10cSrcweir {
310cdf0e10cSrcweir bool bCharset = p->m_aCharset.Len() != 0;
311cdf0e10cSrcweir rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW;
312cdf0e10cSrcweir if (bCharset)
313cdf0e10cSrcweir eEncoding
314cdf0e10cSrcweir = INetMIME::getCharsetEncoding(p->m_aCharset.GetBuffer(),
315cdf0e10cSrcweir p->m_aCharset.GetBuffer()
316cdf0e10cSrcweir + rInput.m_pList->
317cdf0e10cSrcweir m_aCharset.
318cdf0e10cSrcweir Len());
319cdf0e10cSrcweir UniString aValue;
320cdf0e10cSrcweir bool bBadEncoding = false;
321cdf0e10cSrcweir Parameter * pNext = p;
322cdf0e10cSrcweir do
323cdf0e10cSrcweir {
324cdf0e10cSrcweir sal_Size nSize;
325cdf0e10cSrcweir sal_Unicode * pUnicode
326cdf0e10cSrcweir = INetMIME::convertToUnicode(pNext->m_aValue.GetBuffer(),
327cdf0e10cSrcweir pNext->m_aValue.GetBuffer()
328cdf0e10cSrcweir + pNext->m_aValue.Len(),
329cdf0e10cSrcweir bCharset && p->m_bExtended ?
330cdf0e10cSrcweir eEncoding :
331cdf0e10cSrcweir RTL_TEXTENCODING_UTF8,
332cdf0e10cSrcweir nSize);
333cdf0e10cSrcweir if (!pUnicode && !(bCharset && p->m_bExtended))
334cdf0e10cSrcweir pUnicode = INetMIME::convertToUnicode(
335cdf0e10cSrcweir pNext->m_aValue.GetBuffer(),
336cdf0e10cSrcweir pNext->m_aValue.GetBuffer()
337cdf0e10cSrcweir + pNext->m_aValue.Len(),
338cdf0e10cSrcweir RTL_TEXTENCODING_ISO_8859_1, nSize);
339cdf0e10cSrcweir if (!pUnicode)
340cdf0e10cSrcweir {
341cdf0e10cSrcweir bBadEncoding = true;
342cdf0e10cSrcweir break;
343cdf0e10cSrcweir }
344cdf0e10cSrcweir aValue += UniString(pUnicode, static_cast< xub_StrLen >(nSize));
345cdf0e10cSrcweir delete[] pUnicode;
346cdf0e10cSrcweir pNext = pNext->m_pNext;
347cdf0e10cSrcweir }
348cdf0e10cSrcweir while (pNext && pNext->m_nSection > 0);
349cdf0e10cSrcweir if (bBadEncoding)
350cdf0e10cSrcweir {
351cdf0e10cSrcweir aValue.Erase();
352cdf0e10cSrcweir for (pNext = p;;)
353cdf0e10cSrcweir {
354cdf0e10cSrcweir if (pNext->m_bExtended)
355cdf0e10cSrcweir for (xub_StrLen i = 0; i < pNext->m_aValue.Len(); ++i)
356cdf0e10cSrcweir aValue += sal_Unicode(
357cdf0e10cSrcweir sal_Unicode(
358cdf0e10cSrcweir sal_uChar(pNext->m_aValue.GetChar(i)))
359cdf0e10cSrcweir | 0xF800);
360cdf0e10cSrcweir else
361cdf0e10cSrcweir for (xub_StrLen i = 0; i < pNext->m_aValue.Len(); ++i)
362cdf0e10cSrcweir aValue
363cdf0e10cSrcweir += sal_Unicode(sal_uChar
364cdf0e10cSrcweir (pNext->
365cdf0e10cSrcweir m_aValue.GetChar(i)));
366cdf0e10cSrcweir pNext = pNext->m_pNext;
367cdf0e10cSrcweir if (!pNext || pNext->m_nSection == 0)
368cdf0e10cSrcweir break;
369cdf0e10cSrcweir };
370cdf0e10cSrcweir }
371cdf0e10cSrcweir pOutput->Insert(new INetContentTypeParameter(p->m_aAttribute,
372cdf0e10cSrcweir p->m_aCharset,
373cdf0e10cSrcweir p->m_aLanguage,
374cdf0e10cSrcweir aValue,
375cdf0e10cSrcweir !bBadEncoding),
376cdf0e10cSrcweir LIST_APPEND);
377cdf0e10cSrcweir p = pNext;
378cdf0e10cSrcweir }
379cdf0e10cSrcweir return true;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir
382cdf0e10cSrcweir }
383cdf0e10cSrcweir
384cdf0e10cSrcweir //============================================================================
385cdf0e10cSrcweir //
386cdf0e10cSrcweir // INetMIME
387cdf0e10cSrcweir //
388cdf0e10cSrcweir //============================================================================
389cdf0e10cSrcweir
390cdf0e10cSrcweir // static
isAtomChar(sal_uInt32 nChar)391cdf0e10cSrcweir bool INetMIME::isAtomChar(sal_uInt32 nChar)
392cdf0e10cSrcweir {
393cdf0e10cSrcweir static const bool aMap[128]
394cdf0e10cSrcweir = { false, false, false, false, false, false, false, false,
395cdf0e10cSrcweir false, false, false, false, false, false, false, false,
396cdf0e10cSrcweir false, false, false, false, false, false, false, false,
397cdf0e10cSrcweir false, false, false, false, false, false, false, false,
398cdf0e10cSrcweir false, true, false, true, true, true, true, true, // !"#$%&'
399cdf0e10cSrcweir false, false, true, true, false, true, false, true, //()*+,-./
400cdf0e10cSrcweir true, true, true, true, true, true, true, true, //01234567
401cdf0e10cSrcweir true, true, false, false, false, true, false, true, //89:;<=>?
402cdf0e10cSrcweir false, true, true, true, true, true, true, true, //@ABCDEFG
403cdf0e10cSrcweir true, true, true, true, true, true, true, true, //HIJKLMNO
404cdf0e10cSrcweir true, true, true, true, true, true, true, true, //PQRSTUVW
405cdf0e10cSrcweir true, true, true, false, false, false, true, true, //XYZ[\]^_
406cdf0e10cSrcweir true, true, true, true, true, true, true, true, //`abcdefg
407cdf0e10cSrcweir true, true, true, true, true, true, true, true, //hijklmno
408cdf0e10cSrcweir true, true, true, true, true, true, true, true, //pqrstuvw
409cdf0e10cSrcweir true, true, true, true, true, true, true, false //xyz{|}~
410cdf0e10cSrcweir };
411cdf0e10cSrcweir return isUSASCII(nChar) && aMap[nChar];
412cdf0e10cSrcweir }
413cdf0e10cSrcweir
414cdf0e10cSrcweir //============================================================================
415cdf0e10cSrcweir // static
isTokenChar(sal_uInt32 nChar)416cdf0e10cSrcweir bool INetMIME::isTokenChar(sal_uInt32 nChar)
417cdf0e10cSrcweir {
418cdf0e10cSrcweir static const sal_Char aMap[128]
419cdf0e10cSrcweir = { false, false, false, false, false, false, false, false,
420cdf0e10cSrcweir false, false, false, false, false, false, false, false,
421cdf0e10cSrcweir false, false, false, false, false, false, false, false,
422cdf0e10cSrcweir false, false, false, false, false, false, false, false,
423cdf0e10cSrcweir false, true, false, true, true, true, true, true, // !"#$%&'
424cdf0e10cSrcweir false, false, true, true, false, true, true, false, //()*+,-./
425cdf0e10cSrcweir true, true, true, true, true, true, true, true, //01234567
426cdf0e10cSrcweir true, true, false, false, false, false, false, false, //89:;<=>?
427cdf0e10cSrcweir false, true, true, true, true, true, true, true, //@ABCDEFG
428cdf0e10cSrcweir true, true, true, true, true, true, true, true, //HIJKLMNO
429cdf0e10cSrcweir true, true, true, true, true, true, true, true, //PQRSTUVW
430cdf0e10cSrcweir true, true, true, false, false, false, true, true, //XYZ[\]^_
431cdf0e10cSrcweir true, true, true, true, true, true, true, true, //`abcdefg
432cdf0e10cSrcweir true, true, true, true, true, true, true, true, //hijklmno
433cdf0e10cSrcweir true, true, true, true, true, true, true, true, //pqrstuvw
434cdf0e10cSrcweir true, true, true, true, true, true, true, false //xyz{|}~
435cdf0e10cSrcweir };
436cdf0e10cSrcweir return isUSASCII(nChar) && aMap[nChar];
437cdf0e10cSrcweir }
438cdf0e10cSrcweir
439cdf0e10cSrcweir //============================================================================
440cdf0e10cSrcweir // static
isEncodedWordTokenChar(sal_uInt32 nChar)441cdf0e10cSrcweir bool INetMIME::isEncodedWordTokenChar(sal_uInt32 nChar)
442cdf0e10cSrcweir {
443cdf0e10cSrcweir static const sal_Char aMap[128]
444cdf0e10cSrcweir = { false, false, false, false, false, false, false, false,
445cdf0e10cSrcweir false, false, false, false, false, false, false, false,
446cdf0e10cSrcweir false, false, false, false, false, false, false, false,
447cdf0e10cSrcweir false, false, false, false, false, false, false, false,
448cdf0e10cSrcweir false, true, false, true, true, true, true, true, // !"#$%&'
449cdf0e10cSrcweir false, false, true, true, false, true, false, false, //()*+,-./
450cdf0e10cSrcweir true, true, true, true, true, true, true, true, //01234567
451cdf0e10cSrcweir true, true, false, false, false, false, false, false, //89:;<=>?
452cdf0e10cSrcweir false, true, true, true, true, true, true, true, //@ABCDEFG
453cdf0e10cSrcweir true, true, true, true, true, true, true, true, //HIJKLMNO
454cdf0e10cSrcweir true, true, true, true, true, true, true, true, //PQRSTUVW
455cdf0e10cSrcweir true, true, true, false, false, false, true, true, //XYZ[\]^_
456cdf0e10cSrcweir true, true, true, true, true, true, true, true, //`abcdefg
457cdf0e10cSrcweir true, true, true, true, true, true, true, true, //hijklmno
458cdf0e10cSrcweir true, true, true, true, true, true, true, true, //pqrstuvw
459cdf0e10cSrcweir true, true, true, true, true, true, true, false //xyz{|}~
460cdf0e10cSrcweir };
461cdf0e10cSrcweir return isUSASCII(nChar) && aMap[nChar];
462cdf0e10cSrcweir }
463cdf0e10cSrcweir
464cdf0e10cSrcweir //============================================================================
465cdf0e10cSrcweir // static
isIMAPAtomChar(sal_uInt32 nChar)466cdf0e10cSrcweir bool INetMIME::isIMAPAtomChar(sal_uInt32 nChar)
467cdf0e10cSrcweir {
468cdf0e10cSrcweir static const sal_Char aMap[128]
469cdf0e10cSrcweir = { false, false, false, false, false, false, false, false,
470cdf0e10cSrcweir false, false, false, false, false, false, false, false,
471cdf0e10cSrcweir false, false, false, false, false, false, false, false,
472cdf0e10cSrcweir false, false, false, false, false, false, false, false,
473cdf0e10cSrcweir false, true, false, true, true, false, true, true, // !"#$%&'
474cdf0e10cSrcweir false, false, false, true, true, true, true, true, //()*+,-./
475cdf0e10cSrcweir true, true, true, true, true, true, true, true, //01234567
476cdf0e10cSrcweir true, true, true, true, true, true, true, true, //89:;<=>?
477cdf0e10cSrcweir true, true, true, true, true, true, true, true, //@ABCDEFG
478cdf0e10cSrcweir true, true, true, true, true, true, true, true, //HIJKLMNO
479cdf0e10cSrcweir true, true, true, true, true, true, true, true, //PQRSTUVW
480cdf0e10cSrcweir true, true, true, true, false, true, true, true, //XYZ[\]^_
481cdf0e10cSrcweir true, true, true, true, true, true, true, true, //`abcdefg
482cdf0e10cSrcweir true, true, true, true, true, true, true, true, //hijklmno
483cdf0e10cSrcweir true, true, true, true, true, true, true, true, //pqrstuvw
484cdf0e10cSrcweir true, true, true, false, true, true, true, false //xyz{|}~
485cdf0e10cSrcweir };
486cdf0e10cSrcweir return isUSASCII(nChar) && aMap[nChar];
487cdf0e10cSrcweir }
488cdf0e10cSrcweir
489cdf0e10cSrcweir //============================================================================
490cdf0e10cSrcweir // static
getDigit(int nWeight)491cdf0e10cSrcweir sal_uInt32 INetMIME::getDigit(int nWeight)
492cdf0e10cSrcweir {
493cdf0e10cSrcweir DBG_ASSERT(nWeight >= 0 && nWeight < 10,
494cdf0e10cSrcweir "INetMIME::getDigit(): Bad weight");
495cdf0e10cSrcweir
496cdf0e10cSrcweir static const sal_Char aDigits[16]
497cdf0e10cSrcweir = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
498cdf0e10cSrcweir return aDigits[nWeight];
499cdf0e10cSrcweir }
500cdf0e10cSrcweir
501cdf0e10cSrcweir //============================================================================
502cdf0e10cSrcweir // static
getHexDigit(int nWeight)503cdf0e10cSrcweir sal_uInt32 INetMIME::getHexDigit(int nWeight)
504cdf0e10cSrcweir {
505cdf0e10cSrcweir DBG_ASSERT(nWeight >= 0 && nWeight < 16,
506cdf0e10cSrcweir "INetMIME::getHexDigit(): Bad weight");
507cdf0e10cSrcweir
508cdf0e10cSrcweir static const sal_Char aDigits[16]
509cdf0e10cSrcweir = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
510cdf0e10cSrcweir 'D', 'E', 'F' };
511cdf0e10cSrcweir return aDigits[nWeight];
512cdf0e10cSrcweir }
513cdf0e10cSrcweir
514cdf0e10cSrcweir //============================================================================
515cdf0e10cSrcweir // static
getBase64Digit(int nWeight)516cdf0e10cSrcweir sal_uInt32 INetMIME::getBase64Digit(int nWeight)
517cdf0e10cSrcweir {
518cdf0e10cSrcweir DBG_ASSERT(nWeight >= 0 && nWeight < 64,
519cdf0e10cSrcweir "INetMIME::getBase64Digit(): Bad weight");
520cdf0e10cSrcweir
521cdf0e10cSrcweir static const sal_Char aDigits[64]
522cdf0e10cSrcweir = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
523cdf0e10cSrcweir 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
524cdf0e10cSrcweir 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
525cdf0e10cSrcweir 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
526cdf0e10cSrcweir '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
527cdf0e10cSrcweir return aDigits[nWeight];
528cdf0e10cSrcweir }
529cdf0e10cSrcweir
530cdf0e10cSrcweir //============================================================================
531cdf0e10cSrcweir // static
equalIgnoreCase(const sal_Char * pBegin1,const sal_Char * pEnd1,const sal_Char * pBegin2,const sal_Char * pEnd2)532cdf0e10cSrcweir bool INetMIME::equalIgnoreCase(const sal_Char * pBegin1,
533cdf0e10cSrcweir const sal_Char * pEnd1,
534cdf0e10cSrcweir const sal_Char * pBegin2,
535cdf0e10cSrcweir const sal_Char * pEnd2)
536cdf0e10cSrcweir {
537cdf0e10cSrcweir DBG_ASSERT(pBegin1 && pBegin1 <= pEnd1 && pBegin2 && pBegin2 <= pEnd2,
538cdf0e10cSrcweir "INetMIME::equalIgnoreCase(): Bad sequences");
539cdf0e10cSrcweir
540cdf0e10cSrcweir if (pEnd1 - pBegin1 != pEnd2 - pBegin2)
541cdf0e10cSrcweir return false;
542cdf0e10cSrcweir while (pBegin1 != pEnd1)
543cdf0e10cSrcweir if (toUpperCase(*pBegin1++) != toUpperCase(*pBegin2++))
544cdf0e10cSrcweir return false;
545cdf0e10cSrcweir return true;
546cdf0e10cSrcweir }
547cdf0e10cSrcweir
548cdf0e10cSrcweir //============================================================================
549cdf0e10cSrcweir // static
equalIgnoreCase(const sal_Char * pBegin1,const sal_Char * pEnd1,const sal_Char * pString2)550cdf0e10cSrcweir bool INetMIME::equalIgnoreCase(const sal_Char * pBegin1,
551cdf0e10cSrcweir const sal_Char * pEnd1,
552cdf0e10cSrcweir const sal_Char * pString2)
553cdf0e10cSrcweir {
554cdf0e10cSrcweir DBG_ASSERT(pBegin1 && pBegin1 <= pEnd1 && pString2,
555cdf0e10cSrcweir "INetMIME::equalIgnoreCase(): Bad sequences");
556cdf0e10cSrcweir
557cdf0e10cSrcweir while (*pString2 != 0)
558cdf0e10cSrcweir if (pBegin1 == pEnd1
559cdf0e10cSrcweir || toUpperCase(*pBegin1++) != toUpperCase(*pString2++))
560cdf0e10cSrcweir return false;
561cdf0e10cSrcweir return pBegin1 == pEnd1;
562cdf0e10cSrcweir }
563cdf0e10cSrcweir
564cdf0e10cSrcweir //============================================================================
565cdf0e10cSrcweir // static
equalIgnoreCase(const sal_Unicode * pBegin1,const sal_Unicode * pEnd1,const sal_Char * pString2)566cdf0e10cSrcweir bool INetMIME::equalIgnoreCase(const sal_Unicode * pBegin1,
567cdf0e10cSrcweir const sal_Unicode * pEnd1,
568cdf0e10cSrcweir const sal_Char * pString2)
569cdf0e10cSrcweir {
570cdf0e10cSrcweir DBG_ASSERT(pBegin1 && pBegin1 <= pEnd1 && pString2,
571cdf0e10cSrcweir "INetMIME::equalIgnoreCase(): Bad sequences");
572cdf0e10cSrcweir
573cdf0e10cSrcweir while (*pString2 != 0)
574cdf0e10cSrcweir if (pBegin1 == pEnd1
575cdf0e10cSrcweir || toUpperCase(*pBegin1++) != toUpperCase(*pString2++))
576cdf0e10cSrcweir return false;
577cdf0e10cSrcweir return pBegin1 == pEnd1;
578cdf0e10cSrcweir }
579cdf0e10cSrcweir
580cdf0e10cSrcweir //============================================================================
581cdf0e10cSrcweir // static
skipLinearWhiteSpace(const sal_Char * pBegin,const sal_Char * pEnd)582cdf0e10cSrcweir const sal_Char * INetMIME::skipLinearWhiteSpace(const sal_Char * pBegin,
583cdf0e10cSrcweir const sal_Char * pEnd)
584cdf0e10cSrcweir {
585cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
586cdf0e10cSrcweir "INetMIME::skipLinearWhiteSpace(): Bad sequence");
587cdf0e10cSrcweir
588cdf0e10cSrcweir while (pBegin != pEnd)
589cdf0e10cSrcweir switch (*pBegin)
590cdf0e10cSrcweir {
591cdf0e10cSrcweir case '\t':
592cdf0e10cSrcweir case ' ':
593cdf0e10cSrcweir ++pBegin;
594cdf0e10cSrcweir break;
595cdf0e10cSrcweir
596cdf0e10cSrcweir case 0x0D: // CR
597cdf0e10cSrcweir if (startsWithLineFolding(pBegin, pEnd))
598cdf0e10cSrcweir pBegin += 3;
599cdf0e10cSrcweir else
600cdf0e10cSrcweir return pBegin;
601cdf0e10cSrcweir break;
602cdf0e10cSrcweir
603cdf0e10cSrcweir default:
604cdf0e10cSrcweir return pBegin;
605cdf0e10cSrcweir }
606cdf0e10cSrcweir return pBegin;
607cdf0e10cSrcweir }
608cdf0e10cSrcweir
609cdf0e10cSrcweir //============================================================================
610cdf0e10cSrcweir // static
skipLinearWhiteSpace(const sal_Unicode * pBegin,const sal_Unicode * pEnd)611cdf0e10cSrcweir const sal_Unicode * INetMIME::skipLinearWhiteSpace(const sal_Unicode * pBegin,
612cdf0e10cSrcweir const sal_Unicode * pEnd)
613cdf0e10cSrcweir {
614cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
615cdf0e10cSrcweir "INetMIME::skipLinearWhiteSpace(): Bad sequence");
616cdf0e10cSrcweir
617cdf0e10cSrcweir while (pBegin != pEnd)
618cdf0e10cSrcweir switch (*pBegin)
619cdf0e10cSrcweir {
620cdf0e10cSrcweir case '\t':
621cdf0e10cSrcweir case ' ':
622cdf0e10cSrcweir ++pBegin;
623cdf0e10cSrcweir break;
624cdf0e10cSrcweir
625cdf0e10cSrcweir case 0x0D: // CR
626cdf0e10cSrcweir if (startsWithLineFolding(pBegin, pEnd))
627cdf0e10cSrcweir pBegin += 3;
628cdf0e10cSrcweir else
629cdf0e10cSrcweir return pBegin;
630cdf0e10cSrcweir break;
631cdf0e10cSrcweir
632cdf0e10cSrcweir default:
633cdf0e10cSrcweir return pBegin;
634cdf0e10cSrcweir }
635cdf0e10cSrcweir return pBegin;
636cdf0e10cSrcweir }
637cdf0e10cSrcweir
638cdf0e10cSrcweir //============================================================================
639cdf0e10cSrcweir // static
skipComment(const sal_Char * pBegin,const sal_Char * pEnd)640cdf0e10cSrcweir const sal_Char * INetMIME::skipComment(const sal_Char * pBegin,
641cdf0e10cSrcweir const sal_Char * pEnd)
642cdf0e10cSrcweir {
643cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
644cdf0e10cSrcweir "INetMIME::skipComment(): Bad sequence");
645cdf0e10cSrcweir
646cdf0e10cSrcweir if (pBegin != pEnd && *pBegin == '(')
647cdf0e10cSrcweir {
648cdf0e10cSrcweir sal_uInt32 nLevel = 0;
649cdf0e10cSrcweir for (const sal_Char * p = pBegin; p != pEnd;)
650cdf0e10cSrcweir switch (*p++)
651cdf0e10cSrcweir {
652cdf0e10cSrcweir case '(':
653cdf0e10cSrcweir ++nLevel;
654cdf0e10cSrcweir break;
655cdf0e10cSrcweir
656cdf0e10cSrcweir case ')':
657cdf0e10cSrcweir if (--nLevel == 0)
658cdf0e10cSrcweir return p;
659cdf0e10cSrcweir break;
660cdf0e10cSrcweir
661cdf0e10cSrcweir case '\\':
662cdf0e10cSrcweir if (p != pEnd)
663cdf0e10cSrcweir ++p;
664cdf0e10cSrcweir break;
665cdf0e10cSrcweir }
666cdf0e10cSrcweir }
667cdf0e10cSrcweir return pBegin;
668cdf0e10cSrcweir }
669cdf0e10cSrcweir
670cdf0e10cSrcweir //============================================================================
671cdf0e10cSrcweir // static
skipComment(const sal_Unicode * pBegin,const sal_Unicode * pEnd)672cdf0e10cSrcweir const sal_Unicode * INetMIME::skipComment(const sal_Unicode * pBegin,
673cdf0e10cSrcweir const sal_Unicode * pEnd)
674cdf0e10cSrcweir {
675cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
676cdf0e10cSrcweir "INetMIME::skipComment(): Bad sequence");
677cdf0e10cSrcweir
678cdf0e10cSrcweir if (pBegin != pEnd && *pBegin == '(')
679cdf0e10cSrcweir {
680cdf0e10cSrcweir sal_uInt32 nLevel = 0;
681cdf0e10cSrcweir for (const sal_Unicode * p = pBegin; p != pEnd;)
682cdf0e10cSrcweir switch (*p++)
683cdf0e10cSrcweir {
684cdf0e10cSrcweir case '(':
685cdf0e10cSrcweir ++nLevel;
686cdf0e10cSrcweir break;
687cdf0e10cSrcweir
688cdf0e10cSrcweir case ')':
689cdf0e10cSrcweir if (--nLevel == 0)
690cdf0e10cSrcweir return p;
691cdf0e10cSrcweir break;
692cdf0e10cSrcweir
693cdf0e10cSrcweir case '\\':
694cdf0e10cSrcweir if (p != pEnd)
695cdf0e10cSrcweir ++p;
696cdf0e10cSrcweir break;
697cdf0e10cSrcweir }
698cdf0e10cSrcweir }
699cdf0e10cSrcweir return pBegin;
700cdf0e10cSrcweir }
701cdf0e10cSrcweir
702cdf0e10cSrcweir //============================================================================
703cdf0e10cSrcweir // static
skipLinearWhiteSpaceComment(const sal_Char * pBegin,const sal_Char * pEnd)704cdf0e10cSrcweir const sal_Char * INetMIME::skipLinearWhiteSpaceComment(const sal_Char *
705cdf0e10cSrcweir pBegin,
706cdf0e10cSrcweir const sal_Char * pEnd)
707cdf0e10cSrcweir {
708cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
709cdf0e10cSrcweir "INetMIME::skipLinearWhiteSpaceComment(): Bad sequence");
710cdf0e10cSrcweir
711cdf0e10cSrcweir while (pBegin != pEnd)
712cdf0e10cSrcweir switch (*pBegin)
713cdf0e10cSrcweir {
714cdf0e10cSrcweir case '\t':
715cdf0e10cSrcweir case ' ':
716cdf0e10cSrcweir ++pBegin;
717cdf0e10cSrcweir break;
718cdf0e10cSrcweir
719cdf0e10cSrcweir case 0x0D: // CR
720cdf0e10cSrcweir if (startsWithLineFolding(pBegin, pEnd))
721cdf0e10cSrcweir pBegin += 3;
722cdf0e10cSrcweir else
723cdf0e10cSrcweir return pBegin;
724cdf0e10cSrcweir break;
725cdf0e10cSrcweir
726cdf0e10cSrcweir case '(':
727cdf0e10cSrcweir {
728cdf0e10cSrcweir const sal_Char * p = skipComment(pBegin, pEnd);
729cdf0e10cSrcweir if (p == pBegin)
730cdf0e10cSrcweir return pBegin;
731cdf0e10cSrcweir pBegin = p;
732cdf0e10cSrcweir break;
733cdf0e10cSrcweir }
734cdf0e10cSrcweir
735cdf0e10cSrcweir default:
736cdf0e10cSrcweir return pBegin;
737cdf0e10cSrcweir }
738cdf0e10cSrcweir return pBegin;
739cdf0e10cSrcweir }
740cdf0e10cSrcweir
741cdf0e10cSrcweir //============================================================================
742cdf0e10cSrcweir // static
skipLinearWhiteSpaceComment(const sal_Unicode * pBegin,const sal_Unicode * pEnd)743cdf0e10cSrcweir const sal_Unicode * INetMIME::skipLinearWhiteSpaceComment(const sal_Unicode *
744cdf0e10cSrcweir pBegin,
745cdf0e10cSrcweir const sal_Unicode *
746cdf0e10cSrcweir pEnd)
747cdf0e10cSrcweir {
748cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
749cdf0e10cSrcweir "INetMIME::skipLinearWhiteSpaceComment(): Bad sequence");
750cdf0e10cSrcweir
751cdf0e10cSrcweir while (pBegin != pEnd)
752cdf0e10cSrcweir switch (*pBegin)
753cdf0e10cSrcweir {
754cdf0e10cSrcweir case '\t':
755cdf0e10cSrcweir case ' ':
756cdf0e10cSrcweir ++pBegin;
757cdf0e10cSrcweir break;
758cdf0e10cSrcweir
759cdf0e10cSrcweir case 0x0D: // CR
760cdf0e10cSrcweir if (startsWithLineFolding(pBegin, pEnd))
761cdf0e10cSrcweir pBegin += 3;
762cdf0e10cSrcweir else
763cdf0e10cSrcweir return pBegin;
764cdf0e10cSrcweir break;
765cdf0e10cSrcweir
766cdf0e10cSrcweir case '(':
767cdf0e10cSrcweir {
768cdf0e10cSrcweir const sal_Unicode * p = skipComment(pBegin, pEnd);
769cdf0e10cSrcweir if (p == pBegin)
770cdf0e10cSrcweir return pBegin;
771cdf0e10cSrcweir pBegin = p;
772cdf0e10cSrcweir break;
773cdf0e10cSrcweir }
774cdf0e10cSrcweir
775cdf0e10cSrcweir default:
776cdf0e10cSrcweir return pBegin;
777cdf0e10cSrcweir }
778cdf0e10cSrcweir return pBegin;
779cdf0e10cSrcweir }
780cdf0e10cSrcweir
781cdf0e10cSrcweir //============================================================================
782cdf0e10cSrcweir // static
skipQuotedString(const sal_Char * pBegin,const sal_Char * pEnd)783cdf0e10cSrcweir const sal_Char * INetMIME::skipQuotedString(const sal_Char * pBegin,
784cdf0e10cSrcweir const sal_Char * pEnd)
785cdf0e10cSrcweir {
786cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
787cdf0e10cSrcweir "INetMIME::skipQuotedString(): Bad sequence");
788cdf0e10cSrcweir
789cdf0e10cSrcweir if (pBegin != pEnd && *pBegin == '"')
790cdf0e10cSrcweir for (const sal_Char * p = pBegin + 1; p != pEnd;)
791cdf0e10cSrcweir switch (*p++)
792cdf0e10cSrcweir {
793cdf0e10cSrcweir case 0x0D: // CR
794cdf0e10cSrcweir if (pEnd - p < 2 || *p++ != 0x0A // LF
795cdf0e10cSrcweir || !isWhiteSpace(*p++))
796cdf0e10cSrcweir return pBegin;
797cdf0e10cSrcweir break;
798cdf0e10cSrcweir
799cdf0e10cSrcweir case '"':
800cdf0e10cSrcweir return p;
801cdf0e10cSrcweir
802cdf0e10cSrcweir case '\\':
803cdf0e10cSrcweir if (p != pEnd)
804cdf0e10cSrcweir ++p;
805cdf0e10cSrcweir break;
806cdf0e10cSrcweir }
807cdf0e10cSrcweir return pBegin;
808cdf0e10cSrcweir }
809cdf0e10cSrcweir
810cdf0e10cSrcweir //============================================================================
811cdf0e10cSrcweir // static
skipQuotedString(const sal_Unicode * pBegin,const sal_Unicode * pEnd)812cdf0e10cSrcweir const sal_Unicode * INetMIME::skipQuotedString(const sal_Unicode * pBegin,
813cdf0e10cSrcweir const sal_Unicode * pEnd)
814cdf0e10cSrcweir {
815cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
816cdf0e10cSrcweir "INetMIME::skipQuotedString(): Bad sequence");
817cdf0e10cSrcweir
818cdf0e10cSrcweir if (pBegin != pEnd && *pBegin == '"')
819cdf0e10cSrcweir for (const sal_Unicode * p = pBegin + 1; p != pEnd;)
820cdf0e10cSrcweir switch (*p++)
821cdf0e10cSrcweir {
822cdf0e10cSrcweir case 0x0D: // CR
823cdf0e10cSrcweir if (pEnd - p < 2 || *p++ != 0x0A // LF
824cdf0e10cSrcweir || !isWhiteSpace(*p++))
825cdf0e10cSrcweir return pBegin;
826cdf0e10cSrcweir break;
827cdf0e10cSrcweir
828cdf0e10cSrcweir case '"':
829cdf0e10cSrcweir return p;
830cdf0e10cSrcweir
831cdf0e10cSrcweir case '\\':
832cdf0e10cSrcweir if (p != pEnd)
833cdf0e10cSrcweir ++p;
834cdf0e10cSrcweir break;
835cdf0e10cSrcweir }
836cdf0e10cSrcweir return pBegin;
837cdf0e10cSrcweir }
838cdf0e10cSrcweir
839cdf0e10cSrcweir //============================================================================
840cdf0e10cSrcweir // static
scanAtom(const sal_Char * pBegin,const sal_Char * pEnd)841cdf0e10cSrcweir const sal_Char * INetMIME::scanAtom(const sal_Char * pBegin,
842cdf0e10cSrcweir const sal_Char * pEnd)
843cdf0e10cSrcweir {
844cdf0e10cSrcweir while (pBegin != pEnd && isAtomChar(*pBegin))
845cdf0e10cSrcweir ++pBegin;
846cdf0e10cSrcweir return pBegin;
847cdf0e10cSrcweir }
848cdf0e10cSrcweir
849cdf0e10cSrcweir //============================================================================
850cdf0e10cSrcweir // static
scanAtom(const sal_Unicode * pBegin,const sal_Unicode * pEnd)851cdf0e10cSrcweir const sal_Unicode * INetMIME::scanAtom(const sal_Unicode * pBegin,
852cdf0e10cSrcweir const sal_Unicode * pEnd)
853cdf0e10cSrcweir {
854cdf0e10cSrcweir while (pBegin != pEnd && isAtomChar(*pBegin))
855cdf0e10cSrcweir ++pBegin;
856cdf0e10cSrcweir return pBegin;
857cdf0e10cSrcweir }
858cdf0e10cSrcweir
859cdf0e10cSrcweir //============================================================================
860cdf0e10cSrcweir // static
scanUnsigned(const sal_Char * & rBegin,const sal_Char * pEnd,bool bLeadingZeroes,sal_uInt32 & rValue)861cdf0e10cSrcweir bool INetMIME::scanUnsigned(const sal_Char *& rBegin, const sal_Char * pEnd,
862cdf0e10cSrcweir bool bLeadingZeroes, sal_uInt32 & rValue)
863cdf0e10cSrcweir {
864cdf0e10cSrcweir sal_uInt64 nTheValue = 0;
865cdf0e10cSrcweir const sal_Char * p = rBegin;
866cdf0e10cSrcweir for ( ; p != pEnd; ++p)
867cdf0e10cSrcweir {
868cdf0e10cSrcweir int nWeight = getWeight(*p);
869cdf0e10cSrcweir if (nWeight < 0)
870cdf0e10cSrcweir break;
871cdf0e10cSrcweir nTheValue = 10 * nTheValue + nWeight;
872cdf0e10cSrcweir if (nTheValue > std::numeric_limits< sal_uInt32 >::max())
873cdf0e10cSrcweir return false;
874cdf0e10cSrcweir }
875cdf0e10cSrcweir if (nTheValue == 0 && (p == rBegin || (!bLeadingZeroes && p - rBegin != 1)))
876cdf0e10cSrcweir return false;
877cdf0e10cSrcweir rBegin = p;
878cdf0e10cSrcweir rValue = sal_uInt32(nTheValue);
879cdf0e10cSrcweir return true;
880cdf0e10cSrcweir }
881cdf0e10cSrcweir
882cdf0e10cSrcweir //============================================================================
883cdf0e10cSrcweir // static
scanUnsigned(const sal_Unicode * & rBegin,const sal_Unicode * pEnd,bool bLeadingZeroes,sal_uInt32 & rValue)884cdf0e10cSrcweir bool INetMIME::scanUnsigned(const sal_Unicode *& rBegin,
885cdf0e10cSrcweir const sal_Unicode * pEnd, bool bLeadingZeroes,
886cdf0e10cSrcweir sal_uInt32 & rValue)
887cdf0e10cSrcweir {
888cdf0e10cSrcweir sal_uInt64 nTheValue = 0;
889cdf0e10cSrcweir const sal_Unicode * p = rBegin;
890cdf0e10cSrcweir for ( ; p != pEnd; ++p)
891cdf0e10cSrcweir {
892cdf0e10cSrcweir int nWeight = getWeight(*p);
893cdf0e10cSrcweir if (nWeight < 0)
894cdf0e10cSrcweir break;
895cdf0e10cSrcweir nTheValue = 10 * nTheValue + nWeight;
896cdf0e10cSrcweir if (nTheValue > std::numeric_limits< sal_uInt32 >::max())
897cdf0e10cSrcweir return false;
898cdf0e10cSrcweir }
899cdf0e10cSrcweir if (nTheValue == 0 && (p == rBegin || (!bLeadingZeroes && p - rBegin != 1)))
900cdf0e10cSrcweir return false;
901cdf0e10cSrcweir rBegin = p;
902cdf0e10cSrcweir rValue = sal_uInt32(nTheValue);
903cdf0e10cSrcweir return true;
904cdf0e10cSrcweir }
905cdf0e10cSrcweir
906cdf0e10cSrcweir //============================================================================
907cdf0e10cSrcweir // static
scanUnsignedHex(const sal_Char * & rBegin,const sal_Char * pEnd,bool bLeadingZeroes,sal_uInt32 & rValue)908cdf0e10cSrcweir bool INetMIME::scanUnsignedHex(const sal_Char *& rBegin,
909cdf0e10cSrcweir const sal_Char * pEnd, bool bLeadingZeroes,
910cdf0e10cSrcweir sal_uInt32 & rValue)
911cdf0e10cSrcweir {
912cdf0e10cSrcweir sal_uInt64 nTheValue = 0;
913cdf0e10cSrcweir const sal_Char * p = rBegin;
914cdf0e10cSrcweir for ( p = rBegin; p != pEnd; ++p)
915cdf0e10cSrcweir {
916cdf0e10cSrcweir int nWeight = getHexWeight(*p);
917cdf0e10cSrcweir if (nWeight < 0)
918cdf0e10cSrcweir break;
919cdf0e10cSrcweir nTheValue = nTheValue << 4 | nWeight;
920cdf0e10cSrcweir if (nTheValue > std::numeric_limits< sal_uInt32 >::max())
921cdf0e10cSrcweir return false;
922cdf0e10cSrcweir }
923cdf0e10cSrcweir if (nTheValue == 0 && (p == rBegin || (!bLeadingZeroes && p - rBegin != 1)))
924cdf0e10cSrcweir return false;
925cdf0e10cSrcweir rBegin = p;
926cdf0e10cSrcweir rValue = sal_uInt32(nTheValue);
927cdf0e10cSrcweir return true;
928cdf0e10cSrcweir }
929cdf0e10cSrcweir
930cdf0e10cSrcweir //============================================================================
931cdf0e10cSrcweir // static
scanUnsignedHex(const sal_Unicode * & rBegin,const sal_Unicode * pEnd,bool bLeadingZeroes,sal_uInt32 & rValue)932cdf0e10cSrcweir bool INetMIME::scanUnsignedHex(const sal_Unicode *& rBegin,
933cdf0e10cSrcweir const sal_Unicode * pEnd, bool bLeadingZeroes,
934cdf0e10cSrcweir sal_uInt32 & rValue)
935cdf0e10cSrcweir {
936cdf0e10cSrcweir sal_uInt64 nTheValue = 0;
937cdf0e10cSrcweir const sal_Unicode * p = rBegin;
938cdf0e10cSrcweir for ( ; p != pEnd; ++p)
939cdf0e10cSrcweir {
940cdf0e10cSrcweir int nWeight = getHexWeight(*p);
941cdf0e10cSrcweir if (nWeight < 0)
942cdf0e10cSrcweir break;
943cdf0e10cSrcweir nTheValue = nTheValue << 4 | nWeight;
944cdf0e10cSrcweir if (nTheValue > std::numeric_limits< sal_uInt32 >::max())
945cdf0e10cSrcweir return false;
946cdf0e10cSrcweir }
947cdf0e10cSrcweir if (nTheValue == 0 && (p == rBegin || (!bLeadingZeroes && p - rBegin != 1)))
948cdf0e10cSrcweir return false;
949cdf0e10cSrcweir rBegin = p;
950cdf0e10cSrcweir rValue = sal_uInt32(nTheValue);
951cdf0e10cSrcweir return true;
952cdf0e10cSrcweir }
953cdf0e10cSrcweir
954cdf0e10cSrcweir //============================================================================
955cdf0e10cSrcweir // static
scanQuotedBlock(const sal_Char * pBegin,const sal_Char * pEnd,sal_uInt32 nOpening,sal_uInt32 nClosing,sal_Size & rLength,bool & rModify)956cdf0e10cSrcweir const sal_Char * INetMIME::scanQuotedBlock(const sal_Char * pBegin,
957cdf0e10cSrcweir const sal_Char * pEnd,
958cdf0e10cSrcweir sal_uInt32 nOpening,
959cdf0e10cSrcweir sal_uInt32 nClosing,
960cdf0e10cSrcweir sal_Size & rLength,
961cdf0e10cSrcweir bool & rModify)
962cdf0e10cSrcweir {
963cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
964cdf0e10cSrcweir "INetMIME::scanQuotedBlock(): Bad sequence");
965cdf0e10cSrcweir
966cdf0e10cSrcweir if (pBegin != pEnd && static_cast< unsigned char >(*pBegin) == nOpening)
967cdf0e10cSrcweir {
968cdf0e10cSrcweir ++rLength;
969cdf0e10cSrcweir ++pBegin;
970cdf0e10cSrcweir while (pBegin != pEnd)
971cdf0e10cSrcweir if (static_cast< unsigned char >(*pBegin) == nClosing)
972cdf0e10cSrcweir {
973cdf0e10cSrcweir ++rLength;
974cdf0e10cSrcweir return ++pBegin;
975cdf0e10cSrcweir }
976cdf0e10cSrcweir else
977cdf0e10cSrcweir {
978cdf0e10cSrcweir sal_uInt32 c = *pBegin++;
979cdf0e10cSrcweir switch (c)
980cdf0e10cSrcweir {
981cdf0e10cSrcweir case 0x0D: // CR
982cdf0e10cSrcweir if (pBegin != pEnd && *pBegin == 0x0A) // LF
983cdf0e10cSrcweir if (pEnd - pBegin >= 2 && isWhiteSpace(pBegin[1]))
984cdf0e10cSrcweir {
985cdf0e10cSrcweir ++rLength;
986cdf0e10cSrcweir rModify = true;
987cdf0e10cSrcweir pBegin += 2;
988cdf0e10cSrcweir }
989cdf0e10cSrcweir else
990cdf0e10cSrcweir {
991cdf0e10cSrcweir rLength += 3;
992cdf0e10cSrcweir rModify = true;
993cdf0e10cSrcweir ++pBegin;
994cdf0e10cSrcweir }
995cdf0e10cSrcweir else
996cdf0e10cSrcweir ++rLength;
997cdf0e10cSrcweir break;
998cdf0e10cSrcweir
999cdf0e10cSrcweir case '\\':
1000cdf0e10cSrcweir ++rLength;
1001cdf0e10cSrcweir if (pBegin != pEnd)
1002cdf0e10cSrcweir {
1003cdf0e10cSrcweir if (startsWithLineBreak(pBegin, pEnd)
1004cdf0e10cSrcweir && (pEnd - pBegin < 3
1005cdf0e10cSrcweir || !isWhiteSpace(pBegin[2])))
1006cdf0e10cSrcweir {
1007cdf0e10cSrcweir rLength += 3;
1008cdf0e10cSrcweir rModify = true;
1009cdf0e10cSrcweir pBegin += 2;
1010cdf0e10cSrcweir }
1011cdf0e10cSrcweir else
1012cdf0e10cSrcweir ++pBegin;
1013cdf0e10cSrcweir }
1014cdf0e10cSrcweir break;
1015cdf0e10cSrcweir
1016cdf0e10cSrcweir default:
1017cdf0e10cSrcweir ++rLength;
1018cdf0e10cSrcweir if (!isUSASCII(c))
1019cdf0e10cSrcweir rModify = true;
1020cdf0e10cSrcweir break;
1021cdf0e10cSrcweir }
1022cdf0e10cSrcweir }
1023cdf0e10cSrcweir }
1024cdf0e10cSrcweir return pBegin;
1025cdf0e10cSrcweir }
1026cdf0e10cSrcweir
1027cdf0e10cSrcweir //============================================================================
1028cdf0e10cSrcweir // static
scanQuotedBlock(const sal_Unicode * pBegin,const sal_Unicode * pEnd,sal_uInt32 nOpening,sal_uInt32 nClosing,sal_Size & rLength,bool & rModify)1029cdf0e10cSrcweir const sal_Unicode * INetMIME::scanQuotedBlock(const sal_Unicode * pBegin,
1030cdf0e10cSrcweir const sal_Unicode * pEnd,
1031cdf0e10cSrcweir sal_uInt32 nOpening,
1032cdf0e10cSrcweir sal_uInt32 nClosing,
1033cdf0e10cSrcweir sal_Size & rLength,
1034cdf0e10cSrcweir bool & rModify)
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
1037cdf0e10cSrcweir "INetMIME::scanQuotedBlock(): Bad sequence");
1038cdf0e10cSrcweir
1039cdf0e10cSrcweir if (pBegin != pEnd && *pBegin == nOpening)
1040cdf0e10cSrcweir {
1041cdf0e10cSrcweir ++rLength;
1042cdf0e10cSrcweir ++pBegin;
1043cdf0e10cSrcweir while (pBegin != pEnd)
1044cdf0e10cSrcweir if (*pBegin == nClosing)
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir ++rLength;
1047cdf0e10cSrcweir return ++pBegin;
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir else
1050cdf0e10cSrcweir {
1051cdf0e10cSrcweir sal_uInt32 c = *pBegin++;
1052cdf0e10cSrcweir switch (c)
1053cdf0e10cSrcweir {
1054cdf0e10cSrcweir case 0x0D: // CR
1055cdf0e10cSrcweir if (pBegin != pEnd && *pBegin == 0x0A) // LF
1056cdf0e10cSrcweir if (pEnd - pBegin >= 2 && isWhiteSpace(pBegin[1]))
1057cdf0e10cSrcweir {
1058cdf0e10cSrcweir ++rLength;
1059cdf0e10cSrcweir rModify = true;
1060cdf0e10cSrcweir pBegin += 2;
1061cdf0e10cSrcweir }
1062cdf0e10cSrcweir else
1063cdf0e10cSrcweir {
1064cdf0e10cSrcweir rLength += 3;
1065cdf0e10cSrcweir rModify = true;
1066cdf0e10cSrcweir ++pBegin;
1067cdf0e10cSrcweir }
1068cdf0e10cSrcweir else
1069cdf0e10cSrcweir ++rLength;
1070cdf0e10cSrcweir break;
1071cdf0e10cSrcweir
1072cdf0e10cSrcweir case '\\':
1073cdf0e10cSrcweir ++rLength;
1074cdf0e10cSrcweir if (pBegin != pEnd)
1075cdf0e10cSrcweir {
1076cdf0e10cSrcweir if (startsWithLineBreak(pBegin, pEnd)
1077cdf0e10cSrcweir && (pEnd - pBegin < 3
1078cdf0e10cSrcweir || !isWhiteSpace(pBegin[2])))
1079cdf0e10cSrcweir {
1080cdf0e10cSrcweir rLength += 3;
1081cdf0e10cSrcweir rModify = true;
1082cdf0e10cSrcweir pBegin += 2;
1083cdf0e10cSrcweir }
1084cdf0e10cSrcweir else
1085cdf0e10cSrcweir ++pBegin;
1086cdf0e10cSrcweir }
1087cdf0e10cSrcweir break;
1088cdf0e10cSrcweir
1089cdf0e10cSrcweir default:
1090cdf0e10cSrcweir ++rLength;
1091cdf0e10cSrcweir if (!isUSASCII(c))
1092cdf0e10cSrcweir rModify = true;
1093cdf0e10cSrcweir break;
1094cdf0e10cSrcweir }
1095cdf0e10cSrcweir }
1096cdf0e10cSrcweir }
1097cdf0e10cSrcweir return pBegin;
1098cdf0e10cSrcweir }
1099cdf0e10cSrcweir
1100cdf0e10cSrcweir //============================================================================
1101cdf0e10cSrcweir // static
scanParameters(sal_Char const * pBegin,sal_Char const * pEnd,INetContentTypeParameterList * pParameters)1102cdf0e10cSrcweir sal_Char const * INetMIME::scanParameters(sal_Char const * pBegin,
1103cdf0e10cSrcweir sal_Char const * pEnd,
1104cdf0e10cSrcweir INetContentTypeParameterList *
1105cdf0e10cSrcweir pParameters)
1106cdf0e10cSrcweir {
1107cdf0e10cSrcweir ParameterList aList;
1108cdf0e10cSrcweir sal_Char const * pParameterBegin = pBegin;
1109cdf0e10cSrcweir for (sal_Char const * p = pParameterBegin;; pParameterBegin = p)
1110cdf0e10cSrcweir {
1111cdf0e10cSrcweir pParameterBegin = skipLinearWhiteSpaceComment(p, pEnd);
1112cdf0e10cSrcweir if (pParameterBegin == pEnd || *pParameterBegin != ';')
1113cdf0e10cSrcweir break;
1114cdf0e10cSrcweir p = pParameterBegin + 1;
1115cdf0e10cSrcweir
1116cdf0e10cSrcweir sal_Char const * pAttributeBegin = skipLinearWhiteSpaceComment(p,
1117cdf0e10cSrcweir pEnd);
1118cdf0e10cSrcweir p = pAttributeBegin;
1119cdf0e10cSrcweir bool bDowncaseAttribute = false;
1120cdf0e10cSrcweir while (p != pEnd && isTokenChar(*p) && *p != '*')
1121cdf0e10cSrcweir {
1122cdf0e10cSrcweir bDowncaseAttribute = bDowncaseAttribute || isUpperCase(*p);
1123cdf0e10cSrcweir ++p;
1124cdf0e10cSrcweir }
1125cdf0e10cSrcweir if (p == pAttributeBegin)
1126cdf0e10cSrcweir break;
1127cdf0e10cSrcweir ByteString aAttribute(
1128cdf0e10cSrcweir pAttributeBegin, static_cast< xub_StrLen >(p - pAttributeBegin));
1129cdf0e10cSrcweir if (bDowncaseAttribute)
1130cdf0e10cSrcweir aAttribute.ToLowerAscii();
1131cdf0e10cSrcweir
1132cdf0e10cSrcweir sal_uInt32 nSection = 0;
1133cdf0e10cSrcweir if (p != pEnd && *p == '*')
1134cdf0e10cSrcweir {
1135cdf0e10cSrcweir ++p;
1136cdf0e10cSrcweir if (p != pEnd && isDigit(*p)
1137cdf0e10cSrcweir && !scanUnsigned(p, pEnd, false, nSection))
1138cdf0e10cSrcweir break;
1139cdf0e10cSrcweir }
1140cdf0e10cSrcweir
1141cdf0e10cSrcweir bool bPresent;
1142cdf0e10cSrcweir Parameter ** pPos = aList.find(aAttribute, nSection, bPresent);
1143cdf0e10cSrcweir if (bPresent)
1144cdf0e10cSrcweir break;
1145cdf0e10cSrcweir
1146cdf0e10cSrcweir bool bExtended = false;
1147cdf0e10cSrcweir if (p != pEnd && *p == '*')
1148cdf0e10cSrcweir {
1149cdf0e10cSrcweir ++p;
1150cdf0e10cSrcweir bExtended = true;
1151cdf0e10cSrcweir }
1152cdf0e10cSrcweir
1153cdf0e10cSrcweir p = skipLinearWhiteSpaceComment(p, pEnd);
1154cdf0e10cSrcweir
1155cdf0e10cSrcweir if (p == pEnd || *p != '=')
1156cdf0e10cSrcweir break;
1157cdf0e10cSrcweir
1158cdf0e10cSrcweir p = skipLinearWhiteSpaceComment(p + 1, pEnd);
1159cdf0e10cSrcweir
1160cdf0e10cSrcweir ByteString aCharset;
1161cdf0e10cSrcweir ByteString aLanguage;
1162cdf0e10cSrcweir ByteString aValue;
1163cdf0e10cSrcweir if (bExtended)
1164cdf0e10cSrcweir {
1165cdf0e10cSrcweir if (nSection == 0)
1166cdf0e10cSrcweir {
1167cdf0e10cSrcweir sal_Char const * pCharsetBegin = p;
1168cdf0e10cSrcweir bool bDowncaseCharset = false;
1169cdf0e10cSrcweir while (p != pEnd && isTokenChar(*p) && *p != '\'')
1170cdf0e10cSrcweir {
1171cdf0e10cSrcweir bDowncaseCharset = bDowncaseCharset || isUpperCase(*p);
1172cdf0e10cSrcweir ++p;
1173cdf0e10cSrcweir }
1174cdf0e10cSrcweir if (p == pCharsetBegin)
1175cdf0e10cSrcweir break;
1176cdf0e10cSrcweir if (pParameters)
1177cdf0e10cSrcweir {
1178cdf0e10cSrcweir aCharset = ByteString(
1179cdf0e10cSrcweir pCharsetBegin,
1180cdf0e10cSrcweir static_cast< xub_StrLen >(p - pCharsetBegin));
1181cdf0e10cSrcweir if (bDowncaseCharset)
1182cdf0e10cSrcweir aCharset.ToLowerAscii();
1183cdf0e10cSrcweir }
1184cdf0e10cSrcweir
1185cdf0e10cSrcweir if (p == pEnd || *p != '\'')
1186cdf0e10cSrcweir break;
1187cdf0e10cSrcweir ++p;
1188cdf0e10cSrcweir
1189cdf0e10cSrcweir sal_Char const * pLanguageBegin = p;
1190cdf0e10cSrcweir bool bDowncaseLanguage = false;
1191cdf0e10cSrcweir int nLetters = 0;
1192cdf0e10cSrcweir for (; p != pEnd; ++p)
1193cdf0e10cSrcweir if (isAlpha(*p))
1194cdf0e10cSrcweir {
1195cdf0e10cSrcweir if (++nLetters > 8)
1196cdf0e10cSrcweir break;
1197cdf0e10cSrcweir bDowncaseLanguage = bDowncaseLanguage
1198cdf0e10cSrcweir || isUpperCase(*p);
1199cdf0e10cSrcweir }
1200cdf0e10cSrcweir else if (*p == '-')
1201cdf0e10cSrcweir {
1202cdf0e10cSrcweir if (nLetters == 0)
1203cdf0e10cSrcweir break;
1204cdf0e10cSrcweir nLetters = 0;
1205cdf0e10cSrcweir }
1206cdf0e10cSrcweir else
1207cdf0e10cSrcweir break;
1208cdf0e10cSrcweir if (nLetters == 0 || nLetters > 8)
1209cdf0e10cSrcweir break;
1210cdf0e10cSrcweir if (pParameters)
1211cdf0e10cSrcweir {
1212cdf0e10cSrcweir aLanguage = ByteString(
1213cdf0e10cSrcweir pLanguageBegin,
1214cdf0e10cSrcweir static_cast< xub_StrLen >(p - pLanguageBegin));
1215cdf0e10cSrcweir if (bDowncaseLanguage)
1216cdf0e10cSrcweir aLanguage.ToLowerAscii();
1217cdf0e10cSrcweir }
1218cdf0e10cSrcweir
1219cdf0e10cSrcweir if (p == pEnd || *p != '\'')
1220cdf0e10cSrcweir break;
1221cdf0e10cSrcweir ++p;
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir if (pParameters)
1224cdf0e10cSrcweir while (p != pEnd && (isTokenChar(*p) || !isUSASCII(*p)))
1225cdf0e10cSrcweir {
1226cdf0e10cSrcweir if (*p == '%')
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir if (p + 2 < pEnd)
1229cdf0e10cSrcweir {
1230cdf0e10cSrcweir int nWeight1 = getHexWeight(p[1]);
1231cdf0e10cSrcweir int nWeight2 = getHexWeight(p[2]);
1232cdf0e10cSrcweir if (nWeight1 >= 0 && nWeight2 >= 0)
1233cdf0e10cSrcweir {
1234cdf0e10cSrcweir aValue += sal_Char(nWeight1 << 4 | nWeight2);
1235cdf0e10cSrcweir p += 3;
1236cdf0e10cSrcweir continue;
1237cdf0e10cSrcweir }
1238cdf0e10cSrcweir }
1239cdf0e10cSrcweir }
1240cdf0e10cSrcweir aValue += *p++;
1241cdf0e10cSrcweir }
1242cdf0e10cSrcweir else
1243cdf0e10cSrcweir while (p != pEnd && (isTokenChar(*p) || !isUSASCII(*p)))
1244cdf0e10cSrcweir ++p;
1245cdf0e10cSrcweir }
1246cdf0e10cSrcweir else if (p != pEnd && *p == '"')
1247cdf0e10cSrcweir if (pParameters)
1248cdf0e10cSrcweir {
1249cdf0e10cSrcweir bool bInvalid = false;
1250cdf0e10cSrcweir for (++p;;)
1251cdf0e10cSrcweir {
1252cdf0e10cSrcweir if (p == pEnd)
1253cdf0e10cSrcweir {
1254cdf0e10cSrcweir bInvalid = true;
1255cdf0e10cSrcweir break;
1256cdf0e10cSrcweir }
1257cdf0e10cSrcweir else if (*p == '"')
1258cdf0e10cSrcweir {
1259cdf0e10cSrcweir ++p;
1260cdf0e10cSrcweir break;
1261cdf0e10cSrcweir }
1262cdf0e10cSrcweir else if (*p == 0x0D) // CR
1263cdf0e10cSrcweir {
1264cdf0e10cSrcweir if (pEnd - p < 3 || p[1] != 0x0A // LF
1265cdf0e10cSrcweir || !isWhiteSpace(p[2]))
1266cdf0e10cSrcweir {
1267cdf0e10cSrcweir bInvalid = true;
1268cdf0e10cSrcweir break;
1269cdf0e10cSrcweir }
1270cdf0e10cSrcweir p += 2;
1271cdf0e10cSrcweir }
1272cdf0e10cSrcweir else if (*p == '\\' && ++p == pEnd)
1273cdf0e10cSrcweir {
1274cdf0e10cSrcweir bInvalid = true;
1275cdf0e10cSrcweir break;
1276cdf0e10cSrcweir }
1277cdf0e10cSrcweir aValue += *p++;
1278cdf0e10cSrcweir }
1279cdf0e10cSrcweir if (bInvalid)
1280cdf0e10cSrcweir break;
1281cdf0e10cSrcweir }
1282cdf0e10cSrcweir else
1283cdf0e10cSrcweir {
1284cdf0e10cSrcweir sal_Char const * pStringEnd = skipQuotedString(p, pEnd);
1285cdf0e10cSrcweir if (p == pStringEnd)
1286cdf0e10cSrcweir break;
1287cdf0e10cSrcweir p = pStringEnd;
1288cdf0e10cSrcweir }
1289cdf0e10cSrcweir else
1290cdf0e10cSrcweir {
1291cdf0e10cSrcweir sal_Char const * pTokenBegin = p;
1292cdf0e10cSrcweir while (p != pEnd && (isTokenChar(*p) || !isUSASCII(*p)))
1293cdf0e10cSrcweir ++p;
1294cdf0e10cSrcweir if (p == pTokenBegin)
1295cdf0e10cSrcweir break;
1296cdf0e10cSrcweir if (pParameters)
1297cdf0e10cSrcweir aValue = ByteString(
1298cdf0e10cSrcweir pTokenBegin, static_cast< xub_StrLen >(p - pTokenBegin));
1299cdf0e10cSrcweir }
1300cdf0e10cSrcweir
1301cdf0e10cSrcweir *pPos = new Parameter(*pPos, aAttribute, aCharset, aLanguage, aValue,
1302cdf0e10cSrcweir nSection, bExtended);
1303cdf0e10cSrcweir }
1304cdf0e10cSrcweir return parseParameters(aList, pParameters) ? pParameterBegin : pBegin;
1305cdf0e10cSrcweir }
1306cdf0e10cSrcweir
1307cdf0e10cSrcweir //============================================================================
1308cdf0e10cSrcweir // static
scanParameters(sal_Unicode const * pBegin,sal_Unicode const * pEnd,INetContentTypeParameterList * pParameters)1309cdf0e10cSrcweir sal_Unicode const * INetMIME::scanParameters(sal_Unicode const * pBegin,
1310cdf0e10cSrcweir sal_Unicode const * pEnd,
1311cdf0e10cSrcweir INetContentTypeParameterList *
1312cdf0e10cSrcweir pParameters)
1313cdf0e10cSrcweir {
1314cdf0e10cSrcweir ParameterList aList;
1315cdf0e10cSrcweir sal_Unicode const * pParameterBegin = pBegin;
1316cdf0e10cSrcweir for (sal_Unicode const * p = pParameterBegin;; pParameterBegin = p)
1317cdf0e10cSrcweir {
1318cdf0e10cSrcweir pParameterBegin = skipLinearWhiteSpaceComment(p, pEnd);
1319cdf0e10cSrcweir if (pParameterBegin == pEnd || *pParameterBegin != ';')
1320cdf0e10cSrcweir break;
1321cdf0e10cSrcweir p = pParameterBegin + 1;
1322cdf0e10cSrcweir
1323cdf0e10cSrcweir sal_Unicode const * pAttributeBegin
1324cdf0e10cSrcweir = skipLinearWhiteSpaceComment(p, pEnd);
1325cdf0e10cSrcweir p = pAttributeBegin;
1326cdf0e10cSrcweir bool bDowncaseAttribute = false;
1327cdf0e10cSrcweir while (p != pEnd && isTokenChar(*p) && *p != '*')
1328cdf0e10cSrcweir {
1329cdf0e10cSrcweir bDowncaseAttribute = bDowncaseAttribute || isUpperCase(*p);
1330cdf0e10cSrcweir ++p;
1331cdf0e10cSrcweir }
1332cdf0e10cSrcweir if (p == pAttributeBegin)
1333cdf0e10cSrcweir break;
1334cdf0e10cSrcweir ByteString aAttribute = ByteString(
1335cdf0e10cSrcweir pAttributeBegin, static_cast< xub_StrLen >(p - pAttributeBegin),
1336cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US);
1337cdf0e10cSrcweir if (bDowncaseAttribute)
1338cdf0e10cSrcweir aAttribute.ToLowerAscii();
1339cdf0e10cSrcweir
1340cdf0e10cSrcweir sal_uInt32 nSection = 0;
1341cdf0e10cSrcweir if (p != pEnd && *p == '*')
1342cdf0e10cSrcweir {
1343cdf0e10cSrcweir ++p;
1344cdf0e10cSrcweir if (p != pEnd && isDigit(*p)
1345cdf0e10cSrcweir && !scanUnsigned(p, pEnd, false, nSection))
1346cdf0e10cSrcweir break;
1347cdf0e10cSrcweir }
1348cdf0e10cSrcweir
1349cdf0e10cSrcweir bool bPresent;
1350cdf0e10cSrcweir Parameter ** pPos = aList.find(aAttribute, nSection, bPresent);
1351cdf0e10cSrcweir if (bPresent)
1352cdf0e10cSrcweir break;
1353cdf0e10cSrcweir
1354cdf0e10cSrcweir bool bExtended = false;
1355cdf0e10cSrcweir if (p != pEnd && *p == '*')
1356cdf0e10cSrcweir {
1357cdf0e10cSrcweir ++p;
1358cdf0e10cSrcweir bExtended = true;
1359cdf0e10cSrcweir }
1360cdf0e10cSrcweir
1361cdf0e10cSrcweir p = skipLinearWhiteSpaceComment(p, pEnd);
1362cdf0e10cSrcweir
1363cdf0e10cSrcweir if (p == pEnd || *p != '=')
1364cdf0e10cSrcweir break;
1365cdf0e10cSrcweir
1366cdf0e10cSrcweir p = skipLinearWhiteSpaceComment(p + 1, pEnd);
1367cdf0e10cSrcweir
1368cdf0e10cSrcweir ByteString aCharset;
1369cdf0e10cSrcweir ByteString aLanguage;
1370cdf0e10cSrcweir ByteString aValue;
1371cdf0e10cSrcweir if (bExtended)
1372cdf0e10cSrcweir {
1373cdf0e10cSrcweir if (nSection == 0)
1374cdf0e10cSrcweir {
1375cdf0e10cSrcweir sal_Unicode const * pCharsetBegin = p;
1376cdf0e10cSrcweir bool bDowncaseCharset = false;
1377cdf0e10cSrcweir while (p != pEnd && isTokenChar(*p) && *p != '\'')
1378cdf0e10cSrcweir {
1379cdf0e10cSrcweir bDowncaseCharset = bDowncaseCharset || isUpperCase(*p);
1380cdf0e10cSrcweir ++p;
1381cdf0e10cSrcweir }
1382cdf0e10cSrcweir if (p == pCharsetBegin)
1383cdf0e10cSrcweir break;
1384cdf0e10cSrcweir if (pParameters)
1385cdf0e10cSrcweir {
1386cdf0e10cSrcweir aCharset = ByteString(
1387cdf0e10cSrcweir pCharsetBegin,
1388cdf0e10cSrcweir static_cast< xub_StrLen >(p - pCharsetBegin),
1389cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US);
1390cdf0e10cSrcweir if (bDowncaseCharset)
1391cdf0e10cSrcweir aCharset.ToLowerAscii();
1392cdf0e10cSrcweir }
1393cdf0e10cSrcweir
1394cdf0e10cSrcweir if (p == pEnd || *p != '\'')
1395cdf0e10cSrcweir break;
1396cdf0e10cSrcweir ++p;
1397cdf0e10cSrcweir
1398cdf0e10cSrcweir sal_Unicode const * pLanguageBegin = p;
1399cdf0e10cSrcweir bool bDowncaseLanguage = false;
1400cdf0e10cSrcweir int nLetters = 0;
1401cdf0e10cSrcweir for (; p != pEnd; ++p)
1402cdf0e10cSrcweir if (isAlpha(*p))
1403cdf0e10cSrcweir {
1404cdf0e10cSrcweir if (++nLetters > 8)
1405cdf0e10cSrcweir break;
1406cdf0e10cSrcweir bDowncaseLanguage = bDowncaseLanguage
1407cdf0e10cSrcweir || isUpperCase(*p);
1408cdf0e10cSrcweir }
1409cdf0e10cSrcweir else if (*p == '-')
1410cdf0e10cSrcweir {
1411cdf0e10cSrcweir if (nLetters == 0)
1412cdf0e10cSrcweir break;
1413cdf0e10cSrcweir nLetters = 0;
1414cdf0e10cSrcweir }
1415cdf0e10cSrcweir else
1416cdf0e10cSrcweir break;
1417cdf0e10cSrcweir if (nLetters == 0 || nLetters > 8)
1418cdf0e10cSrcweir break;
1419cdf0e10cSrcweir if (pParameters)
1420cdf0e10cSrcweir {
1421cdf0e10cSrcweir aLanguage = ByteString(
1422cdf0e10cSrcweir pLanguageBegin,
1423cdf0e10cSrcweir static_cast< xub_StrLen >(p - pLanguageBegin),
1424cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US);
1425cdf0e10cSrcweir if (bDowncaseLanguage)
1426cdf0e10cSrcweir aLanguage.ToLowerAscii();
1427cdf0e10cSrcweir }
1428cdf0e10cSrcweir
1429cdf0e10cSrcweir if (p == pEnd || *p != '\'')
1430cdf0e10cSrcweir break;
1431cdf0e10cSrcweir ++p;
1432cdf0e10cSrcweir }
1433cdf0e10cSrcweir if (pParameters)
1434cdf0e10cSrcweir {
1435cdf0e10cSrcweir INetMIMEStringOutputSink
1436cdf0e10cSrcweir aSink(0, INetMIMEOutputSink::NO_LINE_LENGTH_LIMIT);
1437cdf0e10cSrcweir while (p != pEnd)
1438cdf0e10cSrcweir {
1439cdf0e10cSrcweir sal_uInt32 nChar = INetMIME::getUTF32Character(p, pEnd);
1440cdf0e10cSrcweir if (isUSASCII(nChar) && !isTokenChar(nChar))
1441cdf0e10cSrcweir break;
1442cdf0e10cSrcweir if (nChar == '%' && p + 1 < pEnd)
1443cdf0e10cSrcweir {
1444cdf0e10cSrcweir int nWeight1 = getHexWeight(p[0]);
1445cdf0e10cSrcweir int nWeight2 = getHexWeight(p[1]);
1446cdf0e10cSrcweir if (nWeight1 >= 0 && nWeight2 >= 0)
1447cdf0e10cSrcweir {
1448cdf0e10cSrcweir aSink << sal_Char(nWeight1 << 4 | nWeight2);
1449cdf0e10cSrcweir p += 2;
1450cdf0e10cSrcweir continue;
1451cdf0e10cSrcweir }
1452cdf0e10cSrcweir }
1453cdf0e10cSrcweir INetMIME::writeUTF8(aSink, nChar);
1454cdf0e10cSrcweir }
1455cdf0e10cSrcweir aValue = aSink.takeBuffer();
1456cdf0e10cSrcweir }
1457cdf0e10cSrcweir else
1458cdf0e10cSrcweir while (p != pEnd && (isTokenChar(*p) || !isUSASCII(*p)))
1459cdf0e10cSrcweir ++p;
1460cdf0e10cSrcweir }
1461cdf0e10cSrcweir else if (p != pEnd && *p == '"')
1462cdf0e10cSrcweir if (pParameters)
1463cdf0e10cSrcweir {
1464cdf0e10cSrcweir INetMIMEStringOutputSink
1465cdf0e10cSrcweir aSink(0, INetMIMEOutputSink::NO_LINE_LENGTH_LIMIT);
1466cdf0e10cSrcweir bool bInvalid = false;
1467cdf0e10cSrcweir for (++p;;)
1468cdf0e10cSrcweir {
1469cdf0e10cSrcweir if (p == pEnd)
1470cdf0e10cSrcweir {
1471cdf0e10cSrcweir bInvalid = true;
1472cdf0e10cSrcweir break;
1473cdf0e10cSrcweir }
1474cdf0e10cSrcweir sal_uInt32 nChar = INetMIME::getUTF32Character(p, pEnd);
1475cdf0e10cSrcweir if (nChar == '"')
1476cdf0e10cSrcweir break;
1477cdf0e10cSrcweir else if (nChar == 0x0D) // CR
1478cdf0e10cSrcweir {
1479cdf0e10cSrcweir if (pEnd - p < 2 || *p++ != 0x0A // LF
1480cdf0e10cSrcweir || !isWhiteSpace(*p))
1481cdf0e10cSrcweir {
1482cdf0e10cSrcweir bInvalid = true;
1483cdf0e10cSrcweir break;
1484cdf0e10cSrcweir }
1485cdf0e10cSrcweir nChar = sal_uChar(*p++);
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir else if (nChar == '\\')
1488cdf0e10cSrcweir {
1489cdf0e10cSrcweir if (p == pEnd)
1490cdf0e10cSrcweir {
1491cdf0e10cSrcweir bInvalid = true;
1492cdf0e10cSrcweir break;
1493cdf0e10cSrcweir }
1494cdf0e10cSrcweir nChar = INetMIME::getUTF32Character(p, pEnd);
1495cdf0e10cSrcweir }
1496cdf0e10cSrcweir INetMIME::writeUTF8(aSink, nChar);
1497cdf0e10cSrcweir }
1498cdf0e10cSrcweir if (bInvalid)
1499cdf0e10cSrcweir break;
1500cdf0e10cSrcweir aValue = aSink.takeBuffer();
1501cdf0e10cSrcweir }
1502cdf0e10cSrcweir else
1503cdf0e10cSrcweir {
1504cdf0e10cSrcweir sal_Unicode const * pStringEnd = skipQuotedString(p, pEnd);
1505cdf0e10cSrcweir if (p == pStringEnd)
1506cdf0e10cSrcweir break;
1507cdf0e10cSrcweir p = pStringEnd;
1508cdf0e10cSrcweir }
1509cdf0e10cSrcweir else
1510cdf0e10cSrcweir {
1511cdf0e10cSrcweir sal_Unicode const * pTokenBegin = p;
1512cdf0e10cSrcweir while (p != pEnd && (isTokenChar(*p) || !isUSASCII(*p)))
1513cdf0e10cSrcweir ++p;
1514cdf0e10cSrcweir if (p == pTokenBegin)
1515cdf0e10cSrcweir break;
1516cdf0e10cSrcweir if (pParameters)
1517cdf0e10cSrcweir aValue = ByteString(
1518cdf0e10cSrcweir pTokenBegin, static_cast< xub_StrLen >(p - pTokenBegin),
1519cdf0e10cSrcweir RTL_TEXTENCODING_UTF8);
1520cdf0e10cSrcweir }
1521cdf0e10cSrcweir
1522cdf0e10cSrcweir *pPos = new Parameter(*pPos, aAttribute, aCharset, aLanguage, aValue,
1523cdf0e10cSrcweir nSection, bExtended);
1524cdf0e10cSrcweir }
1525cdf0e10cSrcweir return parseParameters(aList, pParameters) ? pParameterBegin : pBegin;
1526cdf0e10cSrcweir }
1527cdf0e10cSrcweir
1528cdf0e10cSrcweir //============================================================================
1529cdf0e10cSrcweir // static
getCharsetName(rtl_TextEncoding eEncoding)1530cdf0e10cSrcweir const sal_Char * INetMIME::getCharsetName(rtl_TextEncoding eEncoding)
1531cdf0e10cSrcweir {
1532cdf0e10cSrcweir if (rtl_isOctetTextEncoding(eEncoding))
1533cdf0e10cSrcweir {
1534cdf0e10cSrcweir char const * p = rtl_getMimeCharsetFromTextEncoding(eEncoding);
1535cdf0e10cSrcweir DBG_ASSERT(p, "INetMIME::getCharsetName(): Unsupported encoding");
1536cdf0e10cSrcweir return p;
1537cdf0e10cSrcweir }
1538cdf0e10cSrcweir else
1539cdf0e10cSrcweir switch (eEncoding)
1540cdf0e10cSrcweir {
1541cdf0e10cSrcweir case RTL_TEXTENCODING_UCS4:
1542cdf0e10cSrcweir return "ISO-10646-UCS-4";
1543cdf0e10cSrcweir
1544cdf0e10cSrcweir case RTL_TEXTENCODING_UCS2:
1545cdf0e10cSrcweir return "ISO-10646-UCS-2";
1546cdf0e10cSrcweir
1547cdf0e10cSrcweir default:
1548cdf0e10cSrcweir DBG_ERROR("INetMIME::getCharsetName(): Unsupported encoding");
1549cdf0e10cSrcweir return 0;
1550cdf0e10cSrcweir }
1551cdf0e10cSrcweir }
1552cdf0e10cSrcweir
1553cdf0e10cSrcweir //============================================================================
1554cdf0e10cSrcweir namespace unnamed_tools_inetmime {
1555cdf0e10cSrcweir
1556cdf0e10cSrcweir struct EncodingEntry
1557cdf0e10cSrcweir {
1558cdf0e10cSrcweir sal_Char const * m_aName;
1559cdf0e10cSrcweir rtl_TextEncoding m_eEncoding;
1560cdf0e10cSrcweir };
1561cdf0e10cSrcweir
1562cdf0e10cSrcweir //============================================================================
1563cdf0e10cSrcweir // The source for the following table is <ftp://ftp.iana.org/in-notes/iana/
1564cdf0e10cSrcweir // assignments/character-sets> as of Jan, 21 2000 12:46:00, unless otherwise
1565cdf0e10cSrcweir // noted:
1566cdf0e10cSrcweir EncodingEntry const aEncodingMap[]
1567cdf0e10cSrcweir = { { "US-ASCII", RTL_TEXTENCODING_ASCII_US },
1568cdf0e10cSrcweir { "ANSI_X3.4-1968", RTL_TEXTENCODING_ASCII_US },
1569cdf0e10cSrcweir { "ISO-IR-6", RTL_TEXTENCODING_ASCII_US },
1570cdf0e10cSrcweir { "ANSI_X3.4-1986", RTL_TEXTENCODING_ASCII_US },
1571cdf0e10cSrcweir { "ISO_646.IRV:1991", RTL_TEXTENCODING_ASCII_US },
1572cdf0e10cSrcweir { "ASCII", RTL_TEXTENCODING_ASCII_US },
1573cdf0e10cSrcweir { "ISO646-US", RTL_TEXTENCODING_ASCII_US },
1574cdf0e10cSrcweir { "US", RTL_TEXTENCODING_ASCII_US },
1575cdf0e10cSrcweir { "IBM367", RTL_TEXTENCODING_ASCII_US },
1576cdf0e10cSrcweir { "CP367", RTL_TEXTENCODING_ASCII_US },
1577cdf0e10cSrcweir { "CSASCII", RTL_TEXTENCODING_ASCII_US },
1578cdf0e10cSrcweir { "ISO-8859-1", RTL_TEXTENCODING_ISO_8859_1 },
1579cdf0e10cSrcweir { "ISO_8859-1:1987", RTL_TEXTENCODING_ISO_8859_1 },
1580cdf0e10cSrcweir { "ISO-IR-100", RTL_TEXTENCODING_ISO_8859_1 },
1581cdf0e10cSrcweir { "ISO_8859-1", RTL_TEXTENCODING_ISO_8859_1 },
1582cdf0e10cSrcweir { "LATIN1", RTL_TEXTENCODING_ISO_8859_1 },
1583cdf0e10cSrcweir { "L1", RTL_TEXTENCODING_ISO_8859_1 },
1584cdf0e10cSrcweir { "IBM819", RTL_TEXTENCODING_ISO_8859_1 },
1585cdf0e10cSrcweir { "CP819", RTL_TEXTENCODING_ISO_8859_1 },
1586cdf0e10cSrcweir { "CSISOLATIN1", RTL_TEXTENCODING_ISO_8859_1 },
1587cdf0e10cSrcweir { "ISO-8859-2", RTL_TEXTENCODING_ISO_8859_2 },
1588cdf0e10cSrcweir { "ISO_8859-2:1987", RTL_TEXTENCODING_ISO_8859_2 },
1589cdf0e10cSrcweir { "ISO-IR-101", RTL_TEXTENCODING_ISO_8859_2 },
1590cdf0e10cSrcweir { "ISO_8859-2", RTL_TEXTENCODING_ISO_8859_2 },
1591cdf0e10cSrcweir { "LATIN2", RTL_TEXTENCODING_ISO_8859_2 },
1592cdf0e10cSrcweir { "L2", RTL_TEXTENCODING_ISO_8859_2 },
1593cdf0e10cSrcweir { "CSISOLATIN2", RTL_TEXTENCODING_ISO_8859_2 },
1594cdf0e10cSrcweir { "ISO-8859-3", RTL_TEXTENCODING_ISO_8859_3 },
1595cdf0e10cSrcweir { "ISO_8859-3:1988", RTL_TEXTENCODING_ISO_8859_3 },
1596cdf0e10cSrcweir { "ISO-IR-109", RTL_TEXTENCODING_ISO_8859_3 },
1597cdf0e10cSrcweir { "ISO_8859-3", RTL_TEXTENCODING_ISO_8859_3 },
1598cdf0e10cSrcweir { "LATIN3", RTL_TEXTENCODING_ISO_8859_3 },
1599cdf0e10cSrcweir { "L3", RTL_TEXTENCODING_ISO_8859_3 },
1600cdf0e10cSrcweir { "CSISOLATIN3", RTL_TEXTENCODING_ISO_8859_3 },
1601cdf0e10cSrcweir { "ISO-8859-4", RTL_TEXTENCODING_ISO_8859_4 },
1602cdf0e10cSrcweir { "ISO_8859-4:1988", RTL_TEXTENCODING_ISO_8859_4 },
1603cdf0e10cSrcweir { "ISO-IR-110", RTL_TEXTENCODING_ISO_8859_4 },
1604cdf0e10cSrcweir { "ISO_8859-4", RTL_TEXTENCODING_ISO_8859_4 },
1605cdf0e10cSrcweir { "LATIN4", RTL_TEXTENCODING_ISO_8859_4 },
1606cdf0e10cSrcweir { "L4", RTL_TEXTENCODING_ISO_8859_4 },
1607cdf0e10cSrcweir { "CSISOLATIN4", RTL_TEXTENCODING_ISO_8859_4 },
1608cdf0e10cSrcweir { "ISO-8859-5", RTL_TEXTENCODING_ISO_8859_5 },
1609cdf0e10cSrcweir { "ISO_8859-5:1988", RTL_TEXTENCODING_ISO_8859_5 },
1610cdf0e10cSrcweir { "ISO-IR-144", RTL_TEXTENCODING_ISO_8859_5 },
1611cdf0e10cSrcweir { "ISO_8859-5", RTL_TEXTENCODING_ISO_8859_5 },
1612cdf0e10cSrcweir { "CYRILLIC", RTL_TEXTENCODING_ISO_8859_5 },
1613cdf0e10cSrcweir { "CSISOLATINCYRILLIC", RTL_TEXTENCODING_ISO_8859_5 },
1614cdf0e10cSrcweir { "ISO-8859-6", RTL_TEXTENCODING_ISO_8859_6 },
1615cdf0e10cSrcweir { "ISO_8859-6:1987", RTL_TEXTENCODING_ISO_8859_6 },
1616cdf0e10cSrcweir { "ISO-IR-127", RTL_TEXTENCODING_ISO_8859_6 },
1617cdf0e10cSrcweir { "ISO_8859-6", RTL_TEXTENCODING_ISO_8859_6 },
1618cdf0e10cSrcweir { "ECMA-114", RTL_TEXTENCODING_ISO_8859_6 },
1619cdf0e10cSrcweir { "ASMO-708", RTL_TEXTENCODING_ISO_8859_6 },
1620cdf0e10cSrcweir { "ARABIC", RTL_TEXTENCODING_ISO_8859_6 },
1621cdf0e10cSrcweir { "CSISOLATINARABIC", RTL_TEXTENCODING_ISO_8859_6 },
1622cdf0e10cSrcweir { "ISO-8859-7", RTL_TEXTENCODING_ISO_8859_7 },
1623cdf0e10cSrcweir { "ISO_8859-7:1987", RTL_TEXTENCODING_ISO_8859_7 },
1624cdf0e10cSrcweir { "ISO-IR-126", RTL_TEXTENCODING_ISO_8859_7 },
1625cdf0e10cSrcweir { "ISO_8859-7", RTL_TEXTENCODING_ISO_8859_7 },
1626cdf0e10cSrcweir { "ELOT_928", RTL_TEXTENCODING_ISO_8859_7 },
1627cdf0e10cSrcweir { "ECMA-118", RTL_TEXTENCODING_ISO_8859_7 },
1628cdf0e10cSrcweir { "GREEK", RTL_TEXTENCODING_ISO_8859_7 },
1629cdf0e10cSrcweir { "GREEK8", RTL_TEXTENCODING_ISO_8859_7 },
1630cdf0e10cSrcweir { "CSISOLATINGREEK", RTL_TEXTENCODING_ISO_8859_7 },
1631cdf0e10cSrcweir { "ISO-8859-8", RTL_TEXTENCODING_ISO_8859_8 },
1632cdf0e10cSrcweir { "ISO_8859-8:1988", RTL_TEXTENCODING_ISO_8859_8 },
1633cdf0e10cSrcweir { "ISO-IR-138", RTL_TEXTENCODING_ISO_8859_8 },
1634cdf0e10cSrcweir { "ISO_8859-8", RTL_TEXTENCODING_ISO_8859_8 },
1635cdf0e10cSrcweir { "HEBREW", RTL_TEXTENCODING_ISO_8859_8 },
1636cdf0e10cSrcweir { "CSISOLATINHEBREW", RTL_TEXTENCODING_ISO_8859_8 },
1637cdf0e10cSrcweir { "ISO-8859-9", RTL_TEXTENCODING_ISO_8859_9 },
1638cdf0e10cSrcweir { "ISO_8859-9:1989", RTL_TEXTENCODING_ISO_8859_9 },
1639cdf0e10cSrcweir { "ISO-IR-148", RTL_TEXTENCODING_ISO_8859_9 },
1640cdf0e10cSrcweir { "ISO_8859-9", RTL_TEXTENCODING_ISO_8859_9 },
1641cdf0e10cSrcweir { "LATIN5", RTL_TEXTENCODING_ISO_8859_9 },
1642cdf0e10cSrcweir { "L5", RTL_TEXTENCODING_ISO_8859_9 },
1643cdf0e10cSrcweir { "CSISOLATIN5", RTL_TEXTENCODING_ISO_8859_9 },
1644cdf0e10cSrcweir { "ISO-8859-14", RTL_TEXTENCODING_ISO_8859_14 }, // RFC 2047
1645cdf0e10cSrcweir { "ISO_8859-15", RTL_TEXTENCODING_ISO_8859_15 },
1646cdf0e10cSrcweir { "ISO-8859-15", RTL_TEXTENCODING_ISO_8859_15 }, // RFC 2047
1647cdf0e10cSrcweir { "MACINTOSH", RTL_TEXTENCODING_APPLE_ROMAN },
1648cdf0e10cSrcweir { "MAC", RTL_TEXTENCODING_APPLE_ROMAN },
1649cdf0e10cSrcweir { "CSMACINTOSH", RTL_TEXTENCODING_APPLE_ROMAN },
1650cdf0e10cSrcweir { "IBM437", RTL_TEXTENCODING_IBM_437 },
1651cdf0e10cSrcweir { "CP437", RTL_TEXTENCODING_IBM_437 },
1652cdf0e10cSrcweir { "437", RTL_TEXTENCODING_IBM_437 },
1653cdf0e10cSrcweir { "CSPC8CODEPAGE437", RTL_TEXTENCODING_IBM_437 },
1654cdf0e10cSrcweir { "IBM850", RTL_TEXTENCODING_IBM_850 },
1655cdf0e10cSrcweir { "CP850", RTL_TEXTENCODING_IBM_850 },
1656cdf0e10cSrcweir { "850", RTL_TEXTENCODING_IBM_850 },
1657cdf0e10cSrcweir { "CSPC850MULTILINGUAL", RTL_TEXTENCODING_IBM_850 },
1658cdf0e10cSrcweir { "IBM860", RTL_TEXTENCODING_IBM_860 },
1659cdf0e10cSrcweir { "CP860", RTL_TEXTENCODING_IBM_860 },
1660cdf0e10cSrcweir { "860", RTL_TEXTENCODING_IBM_860 },
1661cdf0e10cSrcweir { "CSIBM860", RTL_TEXTENCODING_IBM_860 },
1662cdf0e10cSrcweir { "IBM861", RTL_TEXTENCODING_IBM_861 },
1663cdf0e10cSrcweir { "CP861", RTL_TEXTENCODING_IBM_861 },
1664cdf0e10cSrcweir { "861", RTL_TEXTENCODING_IBM_861 },
1665cdf0e10cSrcweir { "CP-IS", RTL_TEXTENCODING_IBM_861 },
1666cdf0e10cSrcweir { "CSIBM861", RTL_TEXTENCODING_IBM_861 },
1667cdf0e10cSrcweir { "IBM863", RTL_TEXTENCODING_IBM_863 },
1668cdf0e10cSrcweir { "CP863", RTL_TEXTENCODING_IBM_863 },
1669cdf0e10cSrcweir { "863", RTL_TEXTENCODING_IBM_863 },
1670cdf0e10cSrcweir { "CSIBM863", RTL_TEXTENCODING_IBM_863 },
1671cdf0e10cSrcweir { "IBM865", RTL_TEXTENCODING_IBM_865 },
1672cdf0e10cSrcweir { "CP865", RTL_TEXTENCODING_IBM_865 },
1673cdf0e10cSrcweir { "865", RTL_TEXTENCODING_IBM_865 },
1674cdf0e10cSrcweir { "CSIBM865", RTL_TEXTENCODING_IBM_865 },
1675cdf0e10cSrcweir { "IBM775", RTL_TEXTENCODING_IBM_775 },
1676cdf0e10cSrcweir { "CP775", RTL_TEXTENCODING_IBM_775 },
1677cdf0e10cSrcweir { "CSPC775BALTIC", RTL_TEXTENCODING_IBM_775 },
1678cdf0e10cSrcweir { "IBM852", RTL_TEXTENCODING_IBM_852 },
1679cdf0e10cSrcweir { "CP852", RTL_TEXTENCODING_IBM_852 },
1680cdf0e10cSrcweir { "852", RTL_TEXTENCODING_IBM_852 },
1681cdf0e10cSrcweir { "CSPCP852", RTL_TEXTENCODING_IBM_852 },
1682cdf0e10cSrcweir { "IBM855", RTL_TEXTENCODING_IBM_855 },
1683cdf0e10cSrcweir { "CP855", RTL_TEXTENCODING_IBM_855 },
1684cdf0e10cSrcweir { "855", RTL_TEXTENCODING_IBM_855 },
1685cdf0e10cSrcweir { "CSIBM855", RTL_TEXTENCODING_IBM_855 },
1686cdf0e10cSrcweir { "IBM857", RTL_TEXTENCODING_IBM_857 },
1687cdf0e10cSrcweir { "CP857", RTL_TEXTENCODING_IBM_857 },
1688cdf0e10cSrcweir { "857", RTL_TEXTENCODING_IBM_857 },
1689cdf0e10cSrcweir { "CSIBM857", RTL_TEXTENCODING_IBM_857 },
1690cdf0e10cSrcweir { "IBM862", RTL_TEXTENCODING_IBM_862 },
1691cdf0e10cSrcweir { "CP862", RTL_TEXTENCODING_IBM_862 },
1692cdf0e10cSrcweir { "862", RTL_TEXTENCODING_IBM_862 },
1693cdf0e10cSrcweir { "CSPC862LATINHEBREW", RTL_TEXTENCODING_IBM_862 },
1694cdf0e10cSrcweir { "IBM864", RTL_TEXTENCODING_IBM_864 },
1695cdf0e10cSrcweir { "CP864", RTL_TEXTENCODING_IBM_864 },
1696cdf0e10cSrcweir { "CSIBM864", RTL_TEXTENCODING_IBM_864 },
1697cdf0e10cSrcweir { "IBM866", RTL_TEXTENCODING_IBM_866 },
1698cdf0e10cSrcweir { "CP866", RTL_TEXTENCODING_IBM_866 },
1699cdf0e10cSrcweir { "866", RTL_TEXTENCODING_IBM_866 },
1700cdf0e10cSrcweir { "CSIBM866", RTL_TEXTENCODING_IBM_866 },
1701cdf0e10cSrcweir { "IBM869", RTL_TEXTENCODING_IBM_869 },
1702cdf0e10cSrcweir { "CP869", RTL_TEXTENCODING_IBM_869 },
1703cdf0e10cSrcweir { "869", RTL_TEXTENCODING_IBM_869 },
1704cdf0e10cSrcweir { "CP-GR", RTL_TEXTENCODING_IBM_869 },
1705cdf0e10cSrcweir { "CSIBM869", RTL_TEXTENCODING_IBM_869 },
1706cdf0e10cSrcweir { "WINDOWS-1250", RTL_TEXTENCODING_MS_1250 },
1707cdf0e10cSrcweir { "WINDOWS-1251", RTL_TEXTENCODING_MS_1251 },
1708cdf0e10cSrcweir { "WINDOWS-1253", RTL_TEXTENCODING_MS_1253 },
1709cdf0e10cSrcweir { "WINDOWS-1254", RTL_TEXTENCODING_MS_1254 },
1710cdf0e10cSrcweir { "WINDOWS-1255", RTL_TEXTENCODING_MS_1255 },
1711cdf0e10cSrcweir { "WINDOWS-1256", RTL_TEXTENCODING_MS_1256 },
1712cdf0e10cSrcweir { "WINDOWS-1257", RTL_TEXTENCODING_MS_1257 },
1713cdf0e10cSrcweir { "WINDOWS-1258", RTL_TEXTENCODING_MS_1258 },
1714cdf0e10cSrcweir { "SHIFT_JIS", RTL_TEXTENCODING_SHIFT_JIS },
1715cdf0e10cSrcweir { "MS_KANJI", RTL_TEXTENCODING_SHIFT_JIS },
1716cdf0e10cSrcweir { "CSSHIFTJIS", RTL_TEXTENCODING_SHIFT_JIS },
1717cdf0e10cSrcweir { "GB2312", RTL_TEXTENCODING_GB_2312 },
1718cdf0e10cSrcweir { "CSGB2312", RTL_TEXTENCODING_GB_2312 },
1719cdf0e10cSrcweir { "BIG5", RTL_TEXTENCODING_BIG5 },
1720cdf0e10cSrcweir { "CSBIG5", RTL_TEXTENCODING_BIG5 },
1721cdf0e10cSrcweir { "EUC-JP", RTL_TEXTENCODING_EUC_JP },
1722cdf0e10cSrcweir { "EXTENDED_UNIX_CODE_PACKED_FORMAT_FOR_JAPANESE",
1723cdf0e10cSrcweir RTL_TEXTENCODING_EUC_JP },
1724cdf0e10cSrcweir { "CSEUCPKDFMTJAPANESE", RTL_TEXTENCODING_EUC_JP },
1725cdf0e10cSrcweir { "ISO-2022-JP", RTL_TEXTENCODING_ISO_2022_JP },
1726cdf0e10cSrcweir { "CSISO2022JP", RTL_TEXTENCODING_ISO_2022_JP },
1727cdf0e10cSrcweir { "ISO-2022-CN", RTL_TEXTENCODING_ISO_2022_CN },
1728cdf0e10cSrcweir { "KOI8-R", RTL_TEXTENCODING_KOI8_R },
1729cdf0e10cSrcweir { "CSKOI8R", RTL_TEXTENCODING_KOI8_R },
1730cdf0e10cSrcweir { "UTF-7", RTL_TEXTENCODING_UTF7 },
1731cdf0e10cSrcweir { "UTF-8", RTL_TEXTENCODING_UTF8 },
1732cdf0e10cSrcweir { "ISO-8859-10", RTL_TEXTENCODING_ISO_8859_10 }, // RFC 2047
1733cdf0e10cSrcweir { "ISO-8859-13", RTL_TEXTENCODING_ISO_8859_13 }, // RFC 2047
1734cdf0e10cSrcweir { "EUC-KR", RTL_TEXTENCODING_EUC_KR },
1735cdf0e10cSrcweir { "CSEUCKR", RTL_TEXTENCODING_EUC_KR },
1736cdf0e10cSrcweir { "ISO-2022-KR", RTL_TEXTENCODING_ISO_2022_KR },
1737cdf0e10cSrcweir { "CSISO2022KR", RTL_TEXTENCODING_ISO_2022_KR },
1738cdf0e10cSrcweir { "ISO-10646-UCS-4", RTL_TEXTENCODING_UCS4 },
1739cdf0e10cSrcweir { "CSUCS4", RTL_TEXTENCODING_UCS4 },
1740cdf0e10cSrcweir { "ISO-10646-UCS-2", RTL_TEXTENCODING_UCS2 },
1741cdf0e10cSrcweir { "CSUNICODE", RTL_TEXTENCODING_UCS2 } };
1742cdf0e10cSrcweir
1743cdf0e10cSrcweir //============================================================================
1744cdf0e10cSrcweir template< typename T >
getCharsetEncoding_Impl(T const * pBegin,T const * pEnd)1745cdf0e10cSrcweir inline rtl_TextEncoding getCharsetEncoding_Impl(T const * pBegin,
1746cdf0e10cSrcweir T const * pEnd)
1747cdf0e10cSrcweir {
1748cdf0e10cSrcweir for (sal_Size i = 0; i < sizeof aEncodingMap / sizeof (EncodingEntry);
1749cdf0e10cSrcweir ++i)
1750cdf0e10cSrcweir if (INetMIME::equalIgnoreCase(pBegin, pEnd, aEncodingMap[i].m_aName))
1751cdf0e10cSrcweir return aEncodingMap[i].m_eEncoding;
1752cdf0e10cSrcweir return RTL_TEXTENCODING_DONTKNOW;
1753cdf0e10cSrcweir }
1754cdf0e10cSrcweir
1755cdf0e10cSrcweir }
1756cdf0e10cSrcweir
1757cdf0e10cSrcweir //============================================================================
1758cdf0e10cSrcweir // static
getCharsetEncoding(sal_Char const * pBegin,sal_Char const * pEnd)1759cdf0e10cSrcweir rtl_TextEncoding INetMIME::getCharsetEncoding(sal_Char const * pBegin,
1760cdf0e10cSrcweir sal_Char const * pEnd)
1761cdf0e10cSrcweir {
1762cdf0e10cSrcweir return getCharsetEncoding_Impl(pBegin, pEnd);
1763cdf0e10cSrcweir }
1764cdf0e10cSrcweir
1765cdf0e10cSrcweir //============================================================================
1766cdf0e10cSrcweir // static
getCharsetEncoding(sal_Unicode const * pBegin,sal_Unicode const * pEnd)1767cdf0e10cSrcweir rtl_TextEncoding INetMIME::getCharsetEncoding(sal_Unicode const * pBegin,
1768cdf0e10cSrcweir sal_Unicode const * pEnd)
1769cdf0e10cSrcweir {
1770cdf0e10cSrcweir return getCharsetEncoding_Impl(pBegin, pEnd);
1771cdf0e10cSrcweir }
1772cdf0e10cSrcweir
1773cdf0e10cSrcweir //============================================================================
1774cdf0e10cSrcweir // static
1775cdf0e10cSrcweir INetMIMECharsetList_Impl *
createPreferredCharsetList(rtl_TextEncoding eEncoding)1776cdf0e10cSrcweir INetMIME::createPreferredCharsetList(rtl_TextEncoding eEncoding)
1777cdf0e10cSrcweir {
1778cdf0e10cSrcweir static const sal_uInt32 aUSASCIIRanges[] = { 0, 0x7F, sal_uInt32(-1) };
1779cdf0e10cSrcweir
1780cdf0e10cSrcweir static const sal_uInt32 aISO88591Ranges[] = { 0, 0xFF, sal_uInt32(-1) };
1781cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-1.TXT> version
1782cdf0e10cSrcweir // 1.0 of 1999 July 27
1783cdf0e10cSrcweir
1784cdf0e10cSrcweir static const sal_uInt32 aISO88592Ranges[]
1785cdf0e10cSrcweir = { 0, 0xA0, 0xA4, 0xA4, 0xA7, 0xA8, 0xAD, 0xAD, 0xB0, 0xB0,
1786cdf0e10cSrcweir 0xB4, 0xB4, 0xB8, 0xB8, 0xC1, 0xC2, 0xC4, 0xC4, 0xC7, 0xC7,
1787cdf0e10cSrcweir 0xC9, 0xC9, 0xCB, 0xCB, 0xCD, 0xCE, 0xD3, 0xD4, 0xD6, 0xD7,
1788cdf0e10cSrcweir 0xDA, 0xDA, 0xDC, 0xDD, 0xDF, 0xDF, 0xE1, 0xE2, 0xE4, 0xE4,
1789cdf0e10cSrcweir 0xE7, 0xE7, 0xE9, 0xE9, 0xEB, 0xEB, 0xED, 0xEE, 0xF3, 0xF4,
1790cdf0e10cSrcweir 0xF6, 0xF7, 0xFA, 0xFA, 0xFC, 0xFD, 0x102, 0x107, 0x10C, 0x111,
1791cdf0e10cSrcweir 0x118, 0x11B, 0x139, 0x13A, 0x13D, 0x13E, 0x141, 0x144,
1792cdf0e10cSrcweir 0x147, 0x148, 0x150, 0x151, 0x154, 0x155, 0x158, 0x15B,
1793cdf0e10cSrcweir 0x15E, 0x165, 0x16E, 0x171, 0x179, 0x17E, 0x2C7, 0x2C7,
1794cdf0e10cSrcweir 0x2D8, 0x2D9, 0x2DB, 0x2DB, 0x2DD, 0x2DD, sal_uInt32(-1) };
1795cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-2.TXT> version
1796cdf0e10cSrcweir // 1.0 of 1999 July 27
1797cdf0e10cSrcweir
1798cdf0e10cSrcweir static const sal_uInt32 aISO88593Ranges[]
1799cdf0e10cSrcweir = { 0, 0xA0, 0xA3, 0xA4, 0xA7, 0xA8, 0xAD, 0xAD, 0xB0, 0xB0,
1800cdf0e10cSrcweir 0xB2, 0xB5, 0xB7, 0xB8, 0xBD, 0xBD, 0xC0, 0xC2, 0xC4, 0xC4,
1801cdf0e10cSrcweir 0xC7, 0xCF, 0xD1, 0xD4, 0xD6, 0xD7, 0xD9, 0xDC, 0xDF, 0xE2,
1802cdf0e10cSrcweir 0xE4, 0xE4, 0xE7, 0xEF, 0xF1, 0xF4, 0xF6, 0xF7, 0xF9, 0xFC,
1803cdf0e10cSrcweir 0x108, 0x10B, 0x11C, 0x121, 0x124, 0x127, 0x130, 0x131,
1804cdf0e10cSrcweir 0x134, 0x135, 0x15C, 0x15F, 0x16C, 0x16D, 0x17B, 0x17C,
1805cdf0e10cSrcweir 0x2D8, 0x2D9, sal_uInt32(-1) };
1806cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-3.TXT> version
1807cdf0e10cSrcweir // 1.0 of 1999 July 27
1808cdf0e10cSrcweir
1809cdf0e10cSrcweir static const sal_uInt32 aISO88594Ranges[]
1810cdf0e10cSrcweir = { 0, 0xA0, 0xA4, 0xA4, 0xA7, 0xA8, 0xAD, 0xAD, 0xAF, 0xB0,
1811cdf0e10cSrcweir 0xB4, 0xB4, 0xB8, 0xB8, 0xC1, 0xC6, 0xC9, 0xC9, 0xCB, 0xCB,
1812cdf0e10cSrcweir 0xCD, 0xCE, 0xD4, 0xD8, 0xDA, 0xDC, 0xDF, 0xDF, 0xE1, 0xE6,
1813cdf0e10cSrcweir 0xE9, 0xE9, 0xEB, 0xEB, 0xED, 0xEE, 0xF4, 0xF8, 0xFA, 0xFC,
1814cdf0e10cSrcweir 0x100, 0x101, 0x104, 0x105, 0x10C, 0x10D, 0x110, 0x113,
1815cdf0e10cSrcweir 0x116, 0x119, 0x122, 0x123, 0x128, 0x12B, 0x12E, 0x12F,
1816cdf0e10cSrcweir 0x136, 0x138, 0x13B, 0x13C, 0x145, 0x146, 0x14A, 0x14D,
1817cdf0e10cSrcweir 0x156, 0x157, 0x160, 0x161, 0x166, 0x16B, 0x172, 0x173,
1818cdf0e10cSrcweir 0x17D, 0x17E, 0x2C7, 0x2C7, 0x2D9, 0x2D9, 0x2DB, 0x2DB,
1819cdf0e10cSrcweir sal_uInt32(-1) };
1820cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-4.TXT> version
1821cdf0e10cSrcweir // 1.0 of 1999 July 27
1822cdf0e10cSrcweir
1823cdf0e10cSrcweir static const sal_uInt32 aISO88595Ranges[]
1824cdf0e10cSrcweir = { 0, 0xA0, 0xA7, 0xA7, 0xAD, 0xAD, 0x401, 0x40C, 0x40E, 0x44F,
1825cdf0e10cSrcweir 0x451, 0x45C, 0x45E, 0x45F, 0x2116, 0x2116, sal_uInt32(-1) };
1826cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-5.TXT> version
1827cdf0e10cSrcweir // 1.0 of 1999 July 27
1828cdf0e10cSrcweir
1829cdf0e10cSrcweir static const sal_uInt32 aISO88596Ranges[]
1830cdf0e10cSrcweir = { 0, 0xA0, 0xA4, 0xA4, 0xAD, 0xAD, 0x60C, 0x60C, 0x61B, 0x61B,
1831cdf0e10cSrcweir 0x61F, 0x61F, 0x621, 0x63A, 0x640, 0x652, sal_uInt32(-1) };
1832cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-6.TXT> version
1833cdf0e10cSrcweir // 1.0 of 1999 July 27
1834cdf0e10cSrcweir
1835cdf0e10cSrcweir static const sal_uInt32 aISO88597Ranges[]
1836cdf0e10cSrcweir = { 0, 0xA0, 0xA3, 0xA3, 0xA6, 0xA9, 0xAB, 0xAD, 0xB0, 0xB3,
1837cdf0e10cSrcweir 0xB7, 0xB7, 0xBB, 0xBB, 0xBD, 0xBD, 0x384, 0x386, 0x388, 0x38A,
1838cdf0e10cSrcweir 0x38C, 0x38C, 0x38E, 0x3A1, 0x3A3, 0x3CE, 0x2015, 0x2015,
1839cdf0e10cSrcweir 0x2018, 0x2019, sal_uInt32(-1) };
1840cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-7.TXT> version
1841cdf0e10cSrcweir // 1.0 of 1999 July 27
1842cdf0e10cSrcweir
1843cdf0e10cSrcweir static const sal_uInt32 aISO88598Ranges[]
1844cdf0e10cSrcweir = { 0, 0xA0, 0xA2, 0xA9, 0xAB, 0xB9, 0xBB, 0xBE, 0xD7, 0xD7,
1845cdf0e10cSrcweir 0xF7, 0xF7, 0x5D0, 0x5EA, 0x200E, 0x200F, 0x2017, 0x2017,
1846cdf0e10cSrcweir sal_uInt32(-1) };
1847cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-8.TXT> version
1848cdf0e10cSrcweir // 1.1 of 2000-Jan-03
1849cdf0e10cSrcweir
1850cdf0e10cSrcweir static const sal_uInt32 aISO88599Ranges[]
1851cdf0e10cSrcweir = { 0, 0xCF, 0xD1, 0xDC, 0xDF, 0xEF, 0xF1, 0xFC, 0xFF, 0xFF,
1852cdf0e10cSrcweir 0x11E, 0x11F, 0x130, 0x131, 0x15E, 0x15F, sal_uInt32(-1) };
1853cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-9.TXT> version
1854cdf0e10cSrcweir // 1.0 of 1999 July 27
1855cdf0e10cSrcweir
1856cdf0e10cSrcweir static const sal_uInt32 aISO885910Ranges[]
1857cdf0e10cSrcweir = { 0, 0xA0, 0xA7, 0xA7, 0xAD, 0xAD, 0xB0, 0xB0, 0xB7, 0xB7,
1858cdf0e10cSrcweir 0xC1, 0xC6, 0xC9, 0xC9, 0xCB, 0xCB, 0xCD, 0xD0, 0xD3, 0xD6,
1859cdf0e10cSrcweir 0xD8, 0xD8, 0xDA, 0xDF, 0xE1, 0xE6, 0xE9, 0xE9, 0xEB, 0xEB,
1860cdf0e10cSrcweir 0xED, 0xF0, 0xF3, 0xF6, 0xF8, 0xF8, 0xFA, 0xFE, 0x100, 0x101,
1861cdf0e10cSrcweir 0x104, 0x105, 0x10C, 0x10D, 0x110, 0x113, 0x116, 0x119,
1862cdf0e10cSrcweir 0x122, 0x123, 0x128, 0x12B, 0x12E, 0x12F, 0x136, 0x138,
1863cdf0e10cSrcweir 0x13B, 0x13C, 0x145, 0x146, 0x14A, 0x14D, 0x160, 0x161,
1864cdf0e10cSrcweir 0x166, 0x16B, 0x172, 0x173, 0x17D, 0x17E, 0x2015, 0x2015,
1865cdf0e10cSrcweir sal_uInt32(-1) };
1866cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-10.TXT> version
1867cdf0e10cSrcweir // 1.1 of 1999 October 11
1868cdf0e10cSrcweir
1869cdf0e10cSrcweir static const sal_uInt32 aISO885913Ranges[]
1870cdf0e10cSrcweir = { 0, 0xA0, 0xA2, 0xA4, 0xA6, 0xA7, 0xA9, 0xA9, 0xAB, 0xAE,
1871cdf0e10cSrcweir 0xB0, 0xB3, 0xB5, 0xB7, 0xB9, 0xB9, 0xBB, 0xBE, 0xC4, 0xC6,
1872cdf0e10cSrcweir 0xC9, 0xC9, 0xD3, 0xD3, 0xD5, 0xD8, 0xDC, 0xDC, 0xDF, 0xDF,
1873cdf0e10cSrcweir 0xE4, 0xE6, 0xE9, 0xE9, 0xF3, 0xF3, 0xF5, 0xF8, 0xFC, 0xFC,
1874cdf0e10cSrcweir 0x100, 0x101, 0x104, 0x107, 0x10C, 0x10D, 0x112, 0x113,
1875cdf0e10cSrcweir 0x116, 0x119, 0x122, 0x123, 0x12A, 0x12B, 0x12E, 0x12F,
1876cdf0e10cSrcweir 0x136, 0x137, 0x13B, 0x13C, 0x141, 0x146, 0x14C, 0x14D,
1877cdf0e10cSrcweir 0x156, 0x157, 0x15A, 0x15B, 0x160, 0x161, 0x16A, 0x16B,
1878cdf0e10cSrcweir 0x172, 0x173, 0x179, 0x17E, 0x2019, 0x2019, 0x201C, 0x201E,
1879cdf0e10cSrcweir sal_uInt32(-1) };
1880cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-13.TXT> version
1881cdf0e10cSrcweir // 1.0 of 1999 July 27
1882cdf0e10cSrcweir
1883cdf0e10cSrcweir static const sal_uInt32 aISO885914Ranges[]
1884cdf0e10cSrcweir = { 0, 0xA0, 0xA3, 0xA3, 0xA7, 0xA7, 0xA9, 0xA9, 0xAD, 0xAE,
1885cdf0e10cSrcweir 0xB6, 0xB6, 0xC0, 0xCF, 0xD1, 0xD6, 0xD8, 0xDD, 0xDF, 0xEF,
1886cdf0e10cSrcweir 0xF1, 0xF6, 0xF8, 0xFD, 0xFF, 0xFF, 0x10A, 0x10B, 0x120, 0x121,
1887cdf0e10cSrcweir 0x174, 0x178, 0x1E02, 0x1E03, 0x1E0A, 0x1E0B, 0x1E1E, 0x1E1F,
1888cdf0e10cSrcweir 0x1E40, 0x1E41, 0x1E56, 0x1E57, 0x1E60, 0x1E61, 0x1E6A, 0x1E6B,
1889cdf0e10cSrcweir 0x1E80, 0x1E85, 0x1EF2, 0x1EF3, sal_uInt32(-1) };
1890cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-14.TXT> version
1891cdf0e10cSrcweir // 1.0 of 1999 July 27
1892cdf0e10cSrcweir
1893cdf0e10cSrcweir static const sal_uInt32 aISO885915Ranges[]
1894cdf0e10cSrcweir = { 0, 0xA3, 0xA5, 0xA5, 0xA7, 0xA7, 0xA9, 0xB3, 0xB5, 0xB7,
1895cdf0e10cSrcweir 0xB9, 0xBB, 0xBF, 0xFF, 0x152, 0x153, 0x160, 0x161, 0x178, 0x178,
1896cdf0e10cSrcweir 0x17D, 0x17E, 0x20AC, 0x20AC, sal_uInt32(-1) };
1897cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/8859-15.TXT> version
1898cdf0e10cSrcweir // 1.0 of 1999 July 27
1899cdf0e10cSrcweir
1900cdf0e10cSrcweir static const sal_uInt32 aKOI8RRanges[]
1901cdf0e10cSrcweir = { 0, 0x7F, 0xA0, 0xA0, 0xA9, 0xA9, 0xB0, 0xB0, 0xB2, 0xB2,
1902cdf0e10cSrcweir 0xB7, 0xB7, 0xF7, 0xF7, 0x401, 0x401, 0x410, 0x44F, 0x451, 0x451,
1903cdf0e10cSrcweir 0x2219, 0x221A, 0x2248, 0x2248, 0x2264, 0x2265, 0x2320, 0x2321,
1904cdf0e10cSrcweir 0x2500, 0x2500, 0x2502, 0x2502, 0x250C, 0x250C, 0x2510, 0x2510,
1905cdf0e10cSrcweir 0x2514, 0x2514, 0x2518, 0x2518, 0x251C, 0x251C, 0x2524, 0x2524,
1906cdf0e10cSrcweir 0x252C, 0x252C, 0x2534, 0x2534, 0x253C, 0x253C, 0x2550, 0x256C,
1907cdf0e10cSrcweir 0x2580, 0x2580, 0x2584, 0x2584, 0x2588, 0x2588, 0x258C, 0x258C,
1908cdf0e10cSrcweir 0x2590, 0x2593, 0x25A0, 0x25A0, sal_uInt32(-1) };
1909cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MISC/KOI8-R.TXT>
1910cdf0e10cSrcweir // version 1.0 of 18 August 1999
1911cdf0e10cSrcweir
1912cdf0e10cSrcweir #if defined WNT
1913cdf0e10cSrcweir static const sal_uInt32 aWindows1252Ranges[]
1914cdf0e10cSrcweir = { 0, 0x7F, 0xA0, 0xFF, 0x152, 0x153, 0x160, 0x161, 0x178, 0x178,
1915cdf0e10cSrcweir 0x17D, 0x17E, 0x192, 0x192, 0x2C6, 0x2C6, 0x2DC, 0x2DC,
1916cdf0e10cSrcweir 0x2013, 0x2014, 0x2018, 0x201A, 0x201C, 0x201E, 0x2020, 0x2022,
1917cdf0e10cSrcweir 0x2026, 0x2026, 0x2030, 0x2030, 0x2039, 0x203A, 0x20AC, 0x20AC,
1918cdf0e10cSrcweir 0x2122, 0x2122, sal_uInt32(-1) };
1919cdf0e10cSrcweir // <ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/
1920cdf0e10cSrcweir // CP1252.TXT> version 2.01 of 04/15/98
1921cdf0e10cSrcweir #endif // WNT
1922cdf0e10cSrcweir
1923cdf0e10cSrcweir INetMIMECharsetList_Impl * pList = new INetMIMECharsetList_Impl;
1924cdf0e10cSrcweir switch (eEncoding)
1925cdf0e10cSrcweir {
1926cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1252:
1927cdf0e10cSrcweir #if defined WNT
1928cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_MS_1252,
1929cdf0e10cSrcweir aWindows1252Ranges));
1930cdf0e10cSrcweir #endif // WNT
1931cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_1:
1932cdf0e10cSrcweir case RTL_TEXTENCODING_UTF7:
1933cdf0e10cSrcweir case RTL_TEXTENCODING_UTF8:
1934cdf0e10cSrcweir break;
1935cdf0e10cSrcweir
1936cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_2:
1937cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_2,
1938cdf0e10cSrcweir aISO88592Ranges));
1939cdf0e10cSrcweir break;
1940cdf0e10cSrcweir
1941cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_3:
1942cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_3,
1943cdf0e10cSrcweir aISO88593Ranges));
1944cdf0e10cSrcweir break;
1945cdf0e10cSrcweir
1946cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_4:
1947cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_4,
1948cdf0e10cSrcweir aISO88594Ranges));
1949cdf0e10cSrcweir break;
1950cdf0e10cSrcweir
1951cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_5:
1952cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_5,
1953cdf0e10cSrcweir aISO88595Ranges));
1954cdf0e10cSrcweir break;
1955cdf0e10cSrcweir
1956cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_6:
1957cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_6,
1958cdf0e10cSrcweir aISO88596Ranges));
1959cdf0e10cSrcweir break;
1960cdf0e10cSrcweir
1961cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_7:
1962cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_7,
1963cdf0e10cSrcweir aISO88597Ranges));
1964cdf0e10cSrcweir break;
1965cdf0e10cSrcweir
1966cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_8:
1967cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_8,
1968cdf0e10cSrcweir aISO88598Ranges));
1969cdf0e10cSrcweir break;
1970cdf0e10cSrcweir
1971cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_9:
1972cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_9,
1973cdf0e10cSrcweir aISO88599Ranges));
1974cdf0e10cSrcweir break;
1975cdf0e10cSrcweir
1976cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_10:
1977cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_10,
1978cdf0e10cSrcweir aISO885910Ranges));
1979cdf0e10cSrcweir break;
1980cdf0e10cSrcweir
1981cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_13:
1982cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_13,
1983cdf0e10cSrcweir aISO885913Ranges));
1984cdf0e10cSrcweir break;
1985cdf0e10cSrcweir
1986cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_14:
1987cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_14,
1988cdf0e10cSrcweir aISO885914Ranges));
1989cdf0e10cSrcweir break;
1990cdf0e10cSrcweir
1991cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_15:
1992cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_15,
1993cdf0e10cSrcweir aISO885915Ranges));
1994cdf0e10cSrcweir break;
1995cdf0e10cSrcweir
1996cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1250:
1997cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_2,
1998cdf0e10cSrcweir aISO88592Ranges));
1999cdf0e10cSrcweir break;
2000cdf0e10cSrcweir
2001cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1251:
2002cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_5,
2003cdf0e10cSrcweir aISO88595Ranges));
2004cdf0e10cSrcweir break;
2005cdf0e10cSrcweir
2006cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1253:
2007cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_7,
2008cdf0e10cSrcweir aISO88597Ranges));
2009cdf0e10cSrcweir break;
2010cdf0e10cSrcweir
2011cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1254:
2012cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_9,
2013cdf0e10cSrcweir aISO88599Ranges));
2014cdf0e10cSrcweir break;
2015cdf0e10cSrcweir
2016cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1255:
2017cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_8,
2018cdf0e10cSrcweir aISO88598Ranges));
2019cdf0e10cSrcweir break;
2020cdf0e10cSrcweir
2021cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1256:
2022cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_6,
2023cdf0e10cSrcweir aISO88596Ranges));
2024cdf0e10cSrcweir break;
2025cdf0e10cSrcweir
2026cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1257:
2027cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_4,
2028cdf0e10cSrcweir aISO88594Ranges));
2029cdf0e10cSrcweir break;
2030cdf0e10cSrcweir
2031cdf0e10cSrcweir case RTL_TEXTENCODING_KOI8_R:
2032cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_5,
2033cdf0e10cSrcweir aISO88595Ranges));
2034cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_KOI8_R, aKOI8RRanges));
2035cdf0e10cSrcweir break;
2036cdf0e10cSrcweir
2037cdf0e10cSrcweir default: //@@@ more cases are missing!
2038cdf0e10cSrcweir DBG_ERROR("INetMIME::createPreferredCharsetList():"
2039cdf0e10cSrcweir " Unsupported encoding");
2040cdf0e10cSrcweir break;
2041cdf0e10cSrcweir }
2042cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ISO_8859_1, aISO88591Ranges));
2043cdf0e10cSrcweir pList->prepend(Charset(RTL_TEXTENCODING_ASCII_US, aUSASCIIRanges));
2044cdf0e10cSrcweir return pList;
2045cdf0e10cSrcweir }
2046cdf0e10cSrcweir
2047cdf0e10cSrcweir //============================================================================
2048cdf0e10cSrcweir // static
convertToUnicode(const sal_Char * pBegin,const sal_Char * pEnd,rtl_TextEncoding eEncoding,sal_Size & rSize)2049cdf0e10cSrcweir sal_Unicode * INetMIME::convertToUnicode(const sal_Char * pBegin,
2050cdf0e10cSrcweir const sal_Char * pEnd,
2051cdf0e10cSrcweir rtl_TextEncoding eEncoding,
2052cdf0e10cSrcweir sal_Size & rSize)
2053cdf0e10cSrcweir {
2054cdf0e10cSrcweir if (eEncoding == RTL_TEXTENCODING_DONTKNOW)
2055cdf0e10cSrcweir return 0;
2056cdf0e10cSrcweir rtl_TextToUnicodeConverter hConverter
2057cdf0e10cSrcweir = rtl_createTextToUnicodeConverter(eEncoding);
2058cdf0e10cSrcweir rtl_TextToUnicodeContext hContext
2059cdf0e10cSrcweir = rtl_createTextToUnicodeContext(hConverter);
2060cdf0e10cSrcweir sal_Unicode * pBuffer;
2061cdf0e10cSrcweir sal_uInt32 nInfo;
2062cdf0e10cSrcweir for (sal_Size nBufferSize = pEnd - pBegin;;
2063cdf0e10cSrcweir nBufferSize += nBufferSize / 3 + 1)
2064cdf0e10cSrcweir {
2065cdf0e10cSrcweir pBuffer = new sal_Unicode[nBufferSize];
2066cdf0e10cSrcweir sal_Size nSrcCvtBytes;
2067cdf0e10cSrcweir rSize = rtl_convertTextToUnicode(
2068cdf0e10cSrcweir hConverter, hContext, pBegin, pEnd - pBegin, pBuffer,
2069cdf0e10cSrcweir nBufferSize,
2070cdf0e10cSrcweir RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
2071cdf0e10cSrcweir | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
2072cdf0e10cSrcweir | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR,
2073cdf0e10cSrcweir &nInfo, &nSrcCvtBytes);
2074cdf0e10cSrcweir if (nInfo != RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL)
2075cdf0e10cSrcweir break;
2076cdf0e10cSrcweir delete[] pBuffer;
2077cdf0e10cSrcweir rtl_resetTextToUnicodeContext(hConverter, hContext);
2078cdf0e10cSrcweir }
2079cdf0e10cSrcweir rtl_destroyTextToUnicodeContext(hConverter, hContext);
2080cdf0e10cSrcweir rtl_destroyTextToUnicodeConverter(hConverter);
2081cdf0e10cSrcweir if (nInfo != 0)
2082cdf0e10cSrcweir {
2083cdf0e10cSrcweir delete[] pBuffer;
2084cdf0e10cSrcweir pBuffer = 0;
2085cdf0e10cSrcweir }
2086cdf0e10cSrcweir return pBuffer;
2087cdf0e10cSrcweir }
2088cdf0e10cSrcweir
2089cdf0e10cSrcweir //============================================================================
2090cdf0e10cSrcweir // static
convertFromUnicode(const sal_Unicode * pBegin,const sal_Unicode * pEnd,rtl_TextEncoding eEncoding,sal_Size & rSize)2091cdf0e10cSrcweir sal_Char * INetMIME::convertFromUnicode(const sal_Unicode * pBegin,
2092cdf0e10cSrcweir const sal_Unicode * pEnd,
2093cdf0e10cSrcweir rtl_TextEncoding eEncoding,
2094cdf0e10cSrcweir sal_Size & rSize)
2095cdf0e10cSrcweir {
2096cdf0e10cSrcweir if (eEncoding == RTL_TEXTENCODING_DONTKNOW)
2097cdf0e10cSrcweir return 0;
2098cdf0e10cSrcweir rtl_UnicodeToTextConverter hConverter
2099cdf0e10cSrcweir = rtl_createUnicodeToTextConverter(eEncoding);
2100cdf0e10cSrcweir rtl_UnicodeToTextContext hContext
2101cdf0e10cSrcweir = rtl_createUnicodeToTextContext(hConverter);
2102cdf0e10cSrcweir sal_Char * pBuffer;
2103cdf0e10cSrcweir sal_uInt32 nInfo;
2104cdf0e10cSrcweir for (sal_Size nBufferSize = pEnd - pBegin;;
2105cdf0e10cSrcweir nBufferSize += nBufferSize / 3 + 1)
2106cdf0e10cSrcweir {
2107cdf0e10cSrcweir pBuffer = new sal_Char[nBufferSize];
2108cdf0e10cSrcweir sal_Size nSrcCvtBytes;
2109cdf0e10cSrcweir rSize = rtl_convertUnicodeToText(
2110cdf0e10cSrcweir hConverter, hContext, pBegin, pEnd - pBegin, pBuffer,
2111cdf0e10cSrcweir nBufferSize,
2112cdf0e10cSrcweir RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
2113cdf0e10cSrcweir | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
2114cdf0e10cSrcweir | RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE
2115cdf0e10cSrcweir | RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR,
2116cdf0e10cSrcweir &nInfo, &nSrcCvtBytes);
2117cdf0e10cSrcweir if (nInfo != RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL)
2118cdf0e10cSrcweir break;
2119cdf0e10cSrcweir delete[] pBuffer;
2120cdf0e10cSrcweir rtl_resetUnicodeToTextContext(hConverter, hContext);
2121cdf0e10cSrcweir }
2122cdf0e10cSrcweir rtl_destroyUnicodeToTextContext(hConverter, hContext);
2123cdf0e10cSrcweir rtl_destroyUnicodeToTextConverter(hConverter);
2124cdf0e10cSrcweir if (nInfo != 0)
2125cdf0e10cSrcweir {
2126cdf0e10cSrcweir delete[] pBuffer;
2127cdf0e10cSrcweir pBuffer = 0;
2128cdf0e10cSrcweir }
2129cdf0e10cSrcweir return pBuffer;
2130cdf0e10cSrcweir }
2131cdf0e10cSrcweir
2132cdf0e10cSrcweir //============================================================================
2133cdf0e10cSrcweir // static
writeUTF8(INetMIMEOutputSink & rSink,sal_uInt32 nChar)2134cdf0e10cSrcweir void INetMIME::writeUTF8(INetMIMEOutputSink & rSink, sal_uInt32 nChar)
2135cdf0e10cSrcweir {
2136cdf0e10cSrcweir // See RFC 2279 for a discussion of UTF-8.
2137cdf0e10cSrcweir DBG_ASSERT(nChar < 0x80000000, "INetMIME::writeUTF8(): Bad char");
2138cdf0e10cSrcweir
2139cdf0e10cSrcweir if (nChar < 0x80)
2140cdf0e10cSrcweir rSink << sal_Char(nChar);
2141cdf0e10cSrcweir else if (nChar < 0x800)
2142cdf0e10cSrcweir rSink << sal_Char(nChar >> 6 | 0xC0)
2143cdf0e10cSrcweir << sal_Char((nChar & 0x3F) | 0x80);
2144cdf0e10cSrcweir else if (nChar < 0x10000)
2145cdf0e10cSrcweir rSink << sal_Char(nChar >> 12 | 0xE0)
2146cdf0e10cSrcweir << sal_Char((nChar >> 6 & 0x3F) | 0x80)
2147cdf0e10cSrcweir << sal_Char((nChar & 0x3F) | 0x80);
2148cdf0e10cSrcweir else if (nChar < 0x200000)
2149cdf0e10cSrcweir rSink << sal_Char(nChar >> 18 | 0xF0)
2150cdf0e10cSrcweir << sal_Char((nChar >> 12 & 0x3F) | 0x80)
2151cdf0e10cSrcweir << sal_Char((nChar >> 6 & 0x3F) | 0x80)
2152cdf0e10cSrcweir << sal_Char((nChar & 0x3F) | 0x80);
2153cdf0e10cSrcweir else if (nChar < 0x4000000)
2154cdf0e10cSrcweir rSink << sal_Char(nChar >> 24 | 0xF8)
2155cdf0e10cSrcweir << sal_Char((nChar >> 18 & 0x3F) | 0x80)
2156cdf0e10cSrcweir << sal_Char((nChar >> 12 & 0x3F) | 0x80)
2157cdf0e10cSrcweir << sal_Char((nChar >> 6 & 0x3F) | 0x80)
2158cdf0e10cSrcweir << sal_Char((nChar & 0x3F) | 0x80);
2159cdf0e10cSrcweir else
2160cdf0e10cSrcweir rSink << sal_Char(nChar >> 30 | 0xFC)
2161cdf0e10cSrcweir << sal_Char((nChar >> 24 & 0x3F) | 0x80)
2162cdf0e10cSrcweir << sal_Char((nChar >> 18 & 0x3F) | 0x80)
2163cdf0e10cSrcweir << sal_Char((nChar >> 12 & 0x3F) | 0x80)
2164cdf0e10cSrcweir << sal_Char((nChar >> 6 & 0x3F) | 0x80)
2165cdf0e10cSrcweir << sal_Char((nChar & 0x3F) | 0x80);
2166cdf0e10cSrcweir }
2167cdf0e10cSrcweir
2168cdf0e10cSrcweir //============================================================================
2169cdf0e10cSrcweir // static
writeUnsigned(INetMIMEOutputSink & rSink,sal_uInt32 nValue,int nMinDigits)2170cdf0e10cSrcweir void INetMIME::writeUnsigned(INetMIMEOutputSink & rSink, sal_uInt32 nValue,
2171cdf0e10cSrcweir int nMinDigits)
2172cdf0e10cSrcweir {
2173cdf0e10cSrcweir sal_Char aBuffer[10];
2174cdf0e10cSrcweir // max unsigned 32 bit value (4294967295) has 10 places
2175cdf0e10cSrcweir sal_Char * p = aBuffer;
2176cdf0e10cSrcweir for (; nValue > 0; nValue /= 10)
2177cdf0e10cSrcweir *p++ = sal_Char(getDigit(nValue % 10));
2178cdf0e10cSrcweir nMinDigits -= p - aBuffer;
2179cdf0e10cSrcweir while (nMinDigits-- > 0)
2180cdf0e10cSrcweir rSink << '0';
2181cdf0e10cSrcweir while (p != aBuffer)
2182cdf0e10cSrcweir rSink << *--p;
2183cdf0e10cSrcweir }
2184cdf0e10cSrcweir
2185cdf0e10cSrcweir //============================================================================
2186cdf0e10cSrcweir // static
writeDateTime(INetMIMEOutputSink & rSink,const DateTime & rUTC)2187cdf0e10cSrcweir void INetMIME::writeDateTime(INetMIMEOutputSink & rSink,
2188cdf0e10cSrcweir const DateTime & rUTC)
2189cdf0e10cSrcweir {
2190cdf0e10cSrcweir static const sal_Char aDay[7][3]
2191cdf0e10cSrcweir = { { 'M', 'o', 'n' },
2192cdf0e10cSrcweir { 'T', 'u', 'e' },
2193cdf0e10cSrcweir { 'W', 'e', 'd' },
2194cdf0e10cSrcweir { 'T', 'h', 'u' },
2195cdf0e10cSrcweir { 'F', 'r', 'i' },
2196cdf0e10cSrcweir { 'S', 'a', 't' },
2197cdf0e10cSrcweir { 'S', 'u', 'n' } };
2198cdf0e10cSrcweir const sal_Char * pTheDay = aDay[rUTC.GetDayOfWeek()];
2199cdf0e10cSrcweir rSink.write(pTheDay, pTheDay + 3);
2200cdf0e10cSrcweir rSink << ", ";
2201cdf0e10cSrcweir writeUnsigned(rSink, rUTC.GetDay());
2202cdf0e10cSrcweir rSink << ' ';
2203cdf0e10cSrcweir static const sal_Char aMonth[12][3]
2204cdf0e10cSrcweir = { { 'J', 'a', 'n' },
2205cdf0e10cSrcweir { 'F', 'e', 'b' },
2206cdf0e10cSrcweir { 'M', 'a', 'r' },
2207cdf0e10cSrcweir { 'A', 'p', 'r' },
2208cdf0e10cSrcweir { 'M', 'a', 'y' },
2209cdf0e10cSrcweir { 'J', 'u', 'n' },
2210cdf0e10cSrcweir { 'J', 'u', 'l' },
2211cdf0e10cSrcweir { 'A', 'u', 'g' },
2212cdf0e10cSrcweir { 'S', 'e', 'p' },
2213cdf0e10cSrcweir { 'O', 'c', 't' },
2214cdf0e10cSrcweir { 'N', 'o', 'v' },
2215cdf0e10cSrcweir { 'D', 'e', 'c' } };
2216cdf0e10cSrcweir const sal_Char * pTheMonth = aMonth[rUTC.GetMonth() - 1];
2217cdf0e10cSrcweir rSink.write(pTheMonth, pTheMonth + 3);
2218cdf0e10cSrcweir rSink << ' ';
2219cdf0e10cSrcweir writeUnsigned(rSink, rUTC.GetYear());
2220cdf0e10cSrcweir rSink << ' ';
2221cdf0e10cSrcweir writeUnsigned(rSink, rUTC.GetHour(), 2);
2222cdf0e10cSrcweir rSink << ':';
2223cdf0e10cSrcweir writeUnsigned(rSink, rUTC.GetMin(), 2);
2224cdf0e10cSrcweir rSink << ':';
2225cdf0e10cSrcweir writeUnsigned(rSink, rUTC.GetSec(), 2);
2226cdf0e10cSrcweir rSink << " +0000";
2227cdf0e10cSrcweir }
2228cdf0e10cSrcweir
2229cdf0e10cSrcweir //============================================================================
2230cdf0e10cSrcweir // static
writeHeaderFieldBody(INetMIMEOutputSink & rSink,HeaderFieldType eType,const ByteString & rBody,rtl_TextEncoding ePreferredEncoding,bool bInitialSpace)2231cdf0e10cSrcweir void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
2232cdf0e10cSrcweir HeaderFieldType eType,
2233cdf0e10cSrcweir const ByteString & rBody,
2234cdf0e10cSrcweir rtl_TextEncoding ePreferredEncoding,
2235cdf0e10cSrcweir bool bInitialSpace)
2236cdf0e10cSrcweir {
2237cdf0e10cSrcweir writeHeaderFieldBody(rSink, eType,
2238cdf0e10cSrcweir UniString(rBody, RTL_TEXTENCODING_UTF8),
2239cdf0e10cSrcweir ePreferredEncoding, bInitialSpace);
2240cdf0e10cSrcweir }
2241cdf0e10cSrcweir
2242cdf0e10cSrcweir //============================================================================
2243cdf0e10cSrcweir // static
writeHeaderFieldBody(INetMIMEOutputSink & rSink,HeaderFieldType eType,const UniString & rBody,rtl_TextEncoding ePreferredEncoding,bool bInitialSpace)2244cdf0e10cSrcweir void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
2245cdf0e10cSrcweir HeaderFieldType eType,
2246cdf0e10cSrcweir const UniString & rBody,
2247cdf0e10cSrcweir rtl_TextEncoding ePreferredEncoding,
2248cdf0e10cSrcweir bool bInitialSpace)
2249cdf0e10cSrcweir {
2250cdf0e10cSrcweir if (eType == HEADER_FIELD_TEXT)
2251cdf0e10cSrcweir {
2252cdf0e10cSrcweir INetMIMEEncodedWordOutputSink
2253cdf0e10cSrcweir aOutput(rSink, INetMIMEEncodedWordOutputSink::CONTEXT_TEXT,
2254cdf0e10cSrcweir bInitialSpace ?
2255cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::SPACE_ALWAYS :
2256cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::SPACE_NO,
2257cdf0e10cSrcweir ePreferredEncoding);
2258cdf0e10cSrcweir aOutput.write(rBody.GetBuffer(), rBody.GetBuffer() + rBody.Len());
2259cdf0e10cSrcweir aOutput.flush();
2260cdf0e10cSrcweir }
2261cdf0e10cSrcweir else
2262cdf0e10cSrcweir {
2263cdf0e10cSrcweir enum Brackets { BRACKETS_OUTSIDE, BRACKETS_OPENING, BRACKETS_INSIDE };
2264cdf0e10cSrcweir Brackets eBrackets = BRACKETS_OUTSIDE;
2265cdf0e10cSrcweir
2266cdf0e10cSrcweir const sal_Unicode * pBodyPtr = rBody.GetBuffer();
2267cdf0e10cSrcweir const sal_Unicode * pBodyEnd = pBodyPtr + rBody.Len();
2268cdf0e10cSrcweir while (pBodyPtr != pBodyEnd)
2269cdf0e10cSrcweir switch (*pBodyPtr)
2270cdf0e10cSrcweir {
2271cdf0e10cSrcweir case '\t':
2272cdf0e10cSrcweir case ' ':
2273cdf0e10cSrcweir // A WSP adds to accumulated space:
2274cdf0e10cSrcweir bInitialSpace = true;
2275cdf0e10cSrcweir ++pBodyPtr;
2276cdf0e10cSrcweir break;
2277cdf0e10cSrcweir
2278cdf0e10cSrcweir case '(':
2279cdf0e10cSrcweir {
2280cdf0e10cSrcweir // Write a pending '<' if necessary:
2281cdf0e10cSrcweir if (eBrackets == BRACKETS_OPENING)
2282cdf0e10cSrcweir {
2283cdf0e10cSrcweir if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
2284cdf0e10cSrcweir >= rSink.getLineLengthLimit())
2285cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2286cdf0e10cSrcweir else if (bInitialSpace)
2287cdf0e10cSrcweir rSink << ' ';
2288cdf0e10cSrcweir rSink << '<';
2289cdf0e10cSrcweir bInitialSpace = false;
2290cdf0e10cSrcweir eBrackets = BRACKETS_INSIDE;
2291cdf0e10cSrcweir }
2292cdf0e10cSrcweir
2293cdf0e10cSrcweir // Write the comment, introducing encoded-words where
2294cdf0e10cSrcweir // necessary:
2295cdf0e10cSrcweir int nLevel = 0;
2296cdf0e10cSrcweir INetMIMEEncodedWordOutputSink
2297cdf0e10cSrcweir aOutput(
2298cdf0e10cSrcweir rSink,
2299cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT,
2300cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::SPACE_NO,
2301cdf0e10cSrcweir ePreferredEncoding);
2302cdf0e10cSrcweir while (pBodyPtr != pBodyEnd)
2303cdf0e10cSrcweir switch (*pBodyPtr)
2304cdf0e10cSrcweir {
2305cdf0e10cSrcweir case '(':
2306cdf0e10cSrcweir aOutput.flush();
2307cdf0e10cSrcweir if (rSink.getColumn()
2308cdf0e10cSrcweir + (bInitialSpace ? 1 : 0)
2309cdf0e10cSrcweir >= rSink.getLineLengthLimit())
2310cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2311cdf0e10cSrcweir else if (bInitialSpace)
2312cdf0e10cSrcweir rSink << ' ';
2313cdf0e10cSrcweir rSink << '(';
2314cdf0e10cSrcweir bInitialSpace = false;
2315cdf0e10cSrcweir ++nLevel;
2316cdf0e10cSrcweir ++pBodyPtr;
2317cdf0e10cSrcweir break;
2318cdf0e10cSrcweir
2319cdf0e10cSrcweir case ')':
2320cdf0e10cSrcweir aOutput.flush();
2321cdf0e10cSrcweir if (rSink.getColumn()
2322cdf0e10cSrcweir >= rSink.getLineLengthLimit())
2323cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2324cdf0e10cSrcweir rSink << ')';
2325cdf0e10cSrcweir ++pBodyPtr;
2326cdf0e10cSrcweir if (--nLevel == 0)
2327cdf0e10cSrcweir goto comment_done;
2328cdf0e10cSrcweir break;
2329cdf0e10cSrcweir
2330cdf0e10cSrcweir case '\\':
2331cdf0e10cSrcweir if (++pBodyPtr == pBodyEnd)
2332cdf0e10cSrcweir break;
2333cdf0e10cSrcweir default:
2334cdf0e10cSrcweir aOutput << *pBodyPtr++;
2335cdf0e10cSrcweir break;
2336cdf0e10cSrcweir }
2337cdf0e10cSrcweir comment_done:
2338cdf0e10cSrcweir break;
2339cdf0e10cSrcweir }
2340cdf0e10cSrcweir
2341cdf0e10cSrcweir case '<':
2342cdf0e10cSrcweir // Write an already pending '<' if necessary:
2343cdf0e10cSrcweir if (eBrackets == BRACKETS_OPENING)
2344cdf0e10cSrcweir {
2345cdf0e10cSrcweir if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
2346cdf0e10cSrcweir >= rSink.getLineLengthLimit())
2347cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2348cdf0e10cSrcweir else if (bInitialSpace)
2349cdf0e10cSrcweir rSink << ' ';
2350cdf0e10cSrcweir rSink << '<';
2351cdf0e10cSrcweir bInitialSpace = false;
2352cdf0e10cSrcweir }
2353cdf0e10cSrcweir
2354cdf0e10cSrcweir // Remember this '<' as pending, and open a bracketed
2355cdf0e10cSrcweir // block:
2356cdf0e10cSrcweir eBrackets = BRACKETS_OPENING;
2357cdf0e10cSrcweir ++pBodyPtr;
2358cdf0e10cSrcweir break;
2359cdf0e10cSrcweir
2360cdf0e10cSrcweir case '>':
2361cdf0e10cSrcweir // Write a pending '<' if necessary:
2362cdf0e10cSrcweir if (eBrackets == BRACKETS_OPENING)
2363cdf0e10cSrcweir {
2364cdf0e10cSrcweir if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
2365cdf0e10cSrcweir >= rSink.getLineLengthLimit())
2366cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2367cdf0e10cSrcweir else if (bInitialSpace)
2368cdf0e10cSrcweir rSink << ' ';
2369cdf0e10cSrcweir rSink << '<';
2370cdf0e10cSrcweir bInitialSpace = false;
2371cdf0e10cSrcweir }
2372cdf0e10cSrcweir
2373cdf0e10cSrcweir // Write this '>', and close any bracketed block:
2374cdf0e10cSrcweir if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
2375cdf0e10cSrcweir >= rSink.getLineLengthLimit())
2376cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2377cdf0e10cSrcweir else if (bInitialSpace)
2378cdf0e10cSrcweir rSink << ' ';
2379cdf0e10cSrcweir rSink << '>';
2380cdf0e10cSrcweir bInitialSpace = false;
2381cdf0e10cSrcweir eBrackets = BRACKETS_OUTSIDE;
2382cdf0e10cSrcweir ++pBodyPtr;
2383cdf0e10cSrcweir break;
2384cdf0e10cSrcweir
2385cdf0e10cSrcweir case ',':
2386cdf0e10cSrcweir case ':':
2387cdf0e10cSrcweir case ';':
2388cdf0e10cSrcweir case '\\':
2389cdf0e10cSrcweir case ']':
2390cdf0e10cSrcweir // Write a pending '<' if necessary:
2391cdf0e10cSrcweir if (eBrackets == BRACKETS_OPENING)
2392cdf0e10cSrcweir {
2393cdf0e10cSrcweir if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
2394cdf0e10cSrcweir >= rSink.getLineLengthLimit())
2395cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2396cdf0e10cSrcweir else if (bInitialSpace)
2397cdf0e10cSrcweir rSink << ' ';
2398cdf0e10cSrcweir rSink << '<';
2399cdf0e10cSrcweir bInitialSpace = false;
2400cdf0e10cSrcweir eBrackets = BRACKETS_INSIDE;
2401cdf0e10cSrcweir }
2402cdf0e10cSrcweir
2403cdf0e10cSrcweir // Write this specials:
2404cdf0e10cSrcweir if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
2405cdf0e10cSrcweir >= rSink.getLineLengthLimit())
2406cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2407cdf0e10cSrcweir else if (bInitialSpace)
2408cdf0e10cSrcweir rSink << ' ';
2409cdf0e10cSrcweir rSink << sal_Char(*pBodyPtr++);
2410cdf0e10cSrcweir bInitialSpace = false;
2411cdf0e10cSrcweir break;
2412cdf0e10cSrcweir
2413cdf0e10cSrcweir case '\x0D': // CR
2414cdf0e10cSrcweir // A <CRLF WSP> adds to accumulated space, a <CR> not
2415cdf0e10cSrcweir // followed by <LF WSP> starts 'junk':
2416cdf0e10cSrcweir if (startsWithLineFolding(pBodyPtr, pBodyEnd))
2417cdf0e10cSrcweir {
2418cdf0e10cSrcweir bInitialSpace = true;
2419cdf0e10cSrcweir pBodyPtr += 3;
2420cdf0e10cSrcweir break;
2421cdf0e10cSrcweir }
2422cdf0e10cSrcweir default:
2423cdf0e10cSrcweir {
2424cdf0e10cSrcweir // The next token is either one of <"." / "@" / atom /
2425cdf0e10cSrcweir // quoted-string / domain-literal>, or it's 'junk'; if it
2426cdf0e10cSrcweir // is not 'junk', it is either a 'phrase' (i.e., it may
2427cdf0e10cSrcweir // contain encoded-words) or a 'non-phrase' (i.e., it may
2428cdf0e10cSrcweir // not contain encoded-words):
2429cdf0e10cSrcweir enum Entity { ENTITY_JUNK, ENTITY_NON_PHRASE,
2430cdf0e10cSrcweir ENTITY_PHRASE };
2431cdf0e10cSrcweir Entity eEntity = ENTITY_JUNK;
2432cdf0e10cSrcweir switch (*pBodyPtr)
2433cdf0e10cSrcweir {
2434cdf0e10cSrcweir case '.':
2435cdf0e10cSrcweir case '@':
2436cdf0e10cSrcweir case '[':
2437cdf0e10cSrcweir // A token of <"." / "@" / domain-literal> always
2438cdf0e10cSrcweir // starts a 'non-phrase':
2439cdf0e10cSrcweir eEntity = ENTITY_NON_PHRASE;
2440cdf0e10cSrcweir break;
2441cdf0e10cSrcweir
2442cdf0e10cSrcweir default:
2443cdf0e10cSrcweir if (isUSASCII(*pBodyPtr)
2444cdf0e10cSrcweir && !isAtomChar(*pBodyPtr))
2445cdf0e10cSrcweir {
2446cdf0e10cSrcweir eEntity = ENTITY_JUNK;
2447cdf0e10cSrcweir break;
2448cdf0e10cSrcweir }
2449cdf0e10cSrcweir case '"':
2450cdf0e10cSrcweir // A token of <atom / quoted-string> can either be
2451cdf0e10cSrcweir // a 'phrase' or a 'non-phrase':
2452cdf0e10cSrcweir switch (eType)
2453cdf0e10cSrcweir {
2454cdf0e10cSrcweir case HEADER_FIELD_STRUCTURED:
2455cdf0e10cSrcweir eEntity = ENTITY_NON_PHRASE;
2456cdf0e10cSrcweir break;
2457cdf0e10cSrcweir
2458cdf0e10cSrcweir case HEADER_FIELD_PHRASE:
2459cdf0e10cSrcweir eEntity = ENTITY_PHRASE;
2460cdf0e10cSrcweir break;
2461cdf0e10cSrcweir
2462cdf0e10cSrcweir case HEADER_FIELD_MESSAGE_ID:
2463cdf0e10cSrcweir // A 'phrase' if and only if outside any
2464cdf0e10cSrcweir // bracketed block:
2465cdf0e10cSrcweir eEntity
2466cdf0e10cSrcweir = eBrackets == BRACKETS_OUTSIDE ?
2467cdf0e10cSrcweir ENTITY_PHRASE :
2468cdf0e10cSrcweir ENTITY_NON_PHRASE;
2469cdf0e10cSrcweir break;
2470cdf0e10cSrcweir
2471cdf0e10cSrcweir case HEADER_FIELD_ADDRESS:
2472cdf0e10cSrcweir {
2473cdf0e10cSrcweir // A 'non-phrase' if and only if, after
2474cdf0e10cSrcweir // skipping this token and any following
2475cdf0e10cSrcweir // <linear-white-space> and <comment>s,
2476cdf0e10cSrcweir // there is no token left, or the next
2477cdf0e10cSrcweir // token is any of <"." / "@" / ">" / ","
2478cdf0e10cSrcweir // / ";">, or the next token is <":"> and
2479cdf0e10cSrcweir // is within a bracketed block:
2480cdf0e10cSrcweir const sal_Unicode * pLookAhead = pBodyPtr;
2481cdf0e10cSrcweir if (*pLookAhead == '"')
2482cdf0e10cSrcweir {
2483cdf0e10cSrcweir pLookAhead
2484cdf0e10cSrcweir = skipQuotedString(pLookAhead,
2485cdf0e10cSrcweir pBodyEnd);
2486cdf0e10cSrcweir if (pLookAhead == pBodyPtr)
2487cdf0e10cSrcweir pLookAhead = pBodyEnd;
2488cdf0e10cSrcweir }
2489cdf0e10cSrcweir else
2490cdf0e10cSrcweir while (pLookAhead != pBodyEnd
2491cdf0e10cSrcweir && (isAtomChar(*pLookAhead)
2492cdf0e10cSrcweir || !isUSASCII(
2493cdf0e10cSrcweir *pLookAhead)))
2494cdf0e10cSrcweir ++pLookAhead;
2495cdf0e10cSrcweir while (pLookAhead != pBodyEnd)
2496cdf0e10cSrcweir switch (*pLookAhead)
2497cdf0e10cSrcweir {
2498cdf0e10cSrcweir case '\t':
2499cdf0e10cSrcweir case ' ':
2500cdf0e10cSrcweir ++pLookAhead;
2501cdf0e10cSrcweir break;
2502cdf0e10cSrcweir
2503cdf0e10cSrcweir case '(':
2504cdf0e10cSrcweir {
2505cdf0e10cSrcweir const sal_Unicode * pPast
2506cdf0e10cSrcweir = skipComment(pLookAhead,
2507cdf0e10cSrcweir pBodyEnd);
2508cdf0e10cSrcweir pLookAhead
2509cdf0e10cSrcweir = pPast == pLookAhead ?
2510cdf0e10cSrcweir pBodyEnd : pPast;
2511cdf0e10cSrcweir break;
2512cdf0e10cSrcweir }
2513cdf0e10cSrcweir
2514cdf0e10cSrcweir case ',':
2515cdf0e10cSrcweir case '.':
2516cdf0e10cSrcweir case ';':
2517cdf0e10cSrcweir case '>':
2518cdf0e10cSrcweir case '@':
2519cdf0e10cSrcweir eEntity = ENTITY_NON_PHRASE;
2520cdf0e10cSrcweir goto entity_determined;
2521cdf0e10cSrcweir
2522cdf0e10cSrcweir case ':':
2523cdf0e10cSrcweir eEntity
2524cdf0e10cSrcweir = eBrackets
2525cdf0e10cSrcweir == BRACKETS_OUTSIDE ?
2526cdf0e10cSrcweir ENTITY_PHRASE :
2527cdf0e10cSrcweir ENTITY_NON_PHRASE;
2528cdf0e10cSrcweir goto entity_determined;
2529cdf0e10cSrcweir
2530cdf0e10cSrcweir case '\x0D': // CR
2531cdf0e10cSrcweir if (startsWithLineFolding(
2532cdf0e10cSrcweir pLookAhead, pBodyEnd))
2533cdf0e10cSrcweir {
2534cdf0e10cSrcweir pLookAhead += 3;
2535cdf0e10cSrcweir break;
2536cdf0e10cSrcweir }
2537cdf0e10cSrcweir default:
2538cdf0e10cSrcweir eEntity = ENTITY_PHRASE;
2539cdf0e10cSrcweir goto entity_determined;
2540cdf0e10cSrcweir }
2541cdf0e10cSrcweir eEntity = ENTITY_NON_PHRASE;
2542cdf0e10cSrcweir entity_determined:
2543cdf0e10cSrcweir break;
2544cdf0e10cSrcweir }
2545cdf0e10cSrcweir
2546cdf0e10cSrcweir case HEADER_FIELD_TEXT:
2547cdf0e10cSrcweir OSL_ASSERT(false);
2548cdf0e10cSrcweir break;
2549cdf0e10cSrcweir }
2550cdf0e10cSrcweir
2551cdf0e10cSrcweir // In a 'non-phrase', a non-US-ASCII character
2552cdf0e10cSrcweir // cannot be part of an <atom>, but instead the
2553cdf0e10cSrcweir // whole entity is 'junk' rather than 'non-
2554cdf0e10cSrcweir // phrase':
2555cdf0e10cSrcweir if (eEntity == ENTITY_NON_PHRASE
2556cdf0e10cSrcweir && !isUSASCII(*pBodyPtr))
2557cdf0e10cSrcweir eEntity = ENTITY_JUNK;
2558cdf0e10cSrcweir break;
2559cdf0e10cSrcweir }
2560cdf0e10cSrcweir
2561cdf0e10cSrcweir switch (eEntity)
2562cdf0e10cSrcweir {
2563cdf0e10cSrcweir case ENTITY_JUNK:
2564cdf0e10cSrcweir {
2565cdf0e10cSrcweir // Write a pending '<' if necessary:
2566cdf0e10cSrcweir if (eBrackets == BRACKETS_OPENING)
2567cdf0e10cSrcweir {
2568cdf0e10cSrcweir if (rSink.getColumn()
2569cdf0e10cSrcweir + (bInitialSpace ? 1 : 0)
2570cdf0e10cSrcweir >= rSink.getLineLengthLimit())
2571cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2572cdf0e10cSrcweir else if (bInitialSpace)
2573cdf0e10cSrcweir rSink << ' ';
2574cdf0e10cSrcweir rSink << '<';
2575cdf0e10cSrcweir bInitialSpace = false;
2576cdf0e10cSrcweir eBrackets = BRACKETS_INSIDE;
2577cdf0e10cSrcweir }
2578cdf0e10cSrcweir
2579cdf0e10cSrcweir // Calculate the length of in- and output:
2580cdf0e10cSrcweir const sal_Unicode * pStart = pBodyPtr;
2581cdf0e10cSrcweir sal_Size nLength = 0;
2582cdf0e10cSrcweir bool bModify = false;
2583cdf0e10cSrcweir bool bEnd = false;
2584cdf0e10cSrcweir while (pBodyPtr != pBodyEnd && !bEnd)
2585cdf0e10cSrcweir switch (*pBodyPtr)
2586cdf0e10cSrcweir {
2587cdf0e10cSrcweir case '\x0D': // CR
2588cdf0e10cSrcweir if (startsWithLineFolding(pBodyPtr,
2589cdf0e10cSrcweir pBodyEnd))
2590cdf0e10cSrcweir bEnd = true;
2591cdf0e10cSrcweir else if (startsWithLineBreak(
2592cdf0e10cSrcweir pBodyPtr, pBodyEnd))
2593cdf0e10cSrcweir {
2594cdf0e10cSrcweir nLength += 3;
2595cdf0e10cSrcweir bModify = true;
2596cdf0e10cSrcweir pBodyPtr += 2;
2597cdf0e10cSrcweir }
2598cdf0e10cSrcweir else
2599cdf0e10cSrcweir {
2600cdf0e10cSrcweir ++nLength;
2601cdf0e10cSrcweir ++pBodyPtr;
2602cdf0e10cSrcweir }
2603cdf0e10cSrcweir break;
2604cdf0e10cSrcweir
2605cdf0e10cSrcweir case '\t':
2606cdf0e10cSrcweir case ' ':
2607cdf0e10cSrcweir bEnd = true;
2608cdf0e10cSrcweir break;
2609cdf0e10cSrcweir
2610cdf0e10cSrcweir default:
2611cdf0e10cSrcweir if (isVisible(*pBodyPtr))
2612cdf0e10cSrcweir bEnd = true;
2613cdf0e10cSrcweir else if (isUSASCII(*pBodyPtr))
2614cdf0e10cSrcweir {
2615cdf0e10cSrcweir ++nLength;
2616cdf0e10cSrcweir ++pBodyPtr;
2617cdf0e10cSrcweir }
2618cdf0e10cSrcweir else
2619cdf0e10cSrcweir {
2620cdf0e10cSrcweir nLength += getUTF8OctetCount(
2621cdf0e10cSrcweir *pBodyPtr++);
2622cdf0e10cSrcweir bModify = true;
2623cdf0e10cSrcweir }
2624cdf0e10cSrcweir break;
2625cdf0e10cSrcweir }
2626cdf0e10cSrcweir
2627cdf0e10cSrcweir // Write the output:
2628cdf0e10cSrcweir if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
2629cdf0e10cSrcweir + nLength
2630cdf0e10cSrcweir > rSink.getLineLengthLimit())
2631cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2632cdf0e10cSrcweir else if (bInitialSpace)
2633cdf0e10cSrcweir rSink << ' ';
2634cdf0e10cSrcweir bInitialSpace = false;
2635cdf0e10cSrcweir if (bModify)
2636cdf0e10cSrcweir while (pStart != pBodyPtr)
2637cdf0e10cSrcweir if (startsWithLineBreak(pStart, pBodyPtr))
2638cdf0e10cSrcweir {
2639cdf0e10cSrcweir rSink << "\x0D\\\x0A"; // CR, '\', LF
2640cdf0e10cSrcweir pStart += 2;
2641cdf0e10cSrcweir }
2642cdf0e10cSrcweir else
2643cdf0e10cSrcweir writeUTF8(rSink, *pStart++);
2644cdf0e10cSrcweir else
2645cdf0e10cSrcweir rSink.write(pStart, pBodyPtr);
2646cdf0e10cSrcweir break;
2647cdf0e10cSrcweir }
2648cdf0e10cSrcweir
2649cdf0e10cSrcweir case ENTITY_NON_PHRASE:
2650cdf0e10cSrcweir {
2651cdf0e10cSrcweir // Calculate the length of in- and output:
2652cdf0e10cSrcweir const sal_Unicode * pStart = pBodyPtr;
2653cdf0e10cSrcweir sal_Size nLength = 0;
2654cdf0e10cSrcweir bool bBracketedBlock = false;
2655cdf0e10cSrcweir bool bSymbol = *pStart != '.' && *pStart != '@';
2656cdf0e10cSrcweir bool bModify = false;
2657cdf0e10cSrcweir bool bEnd = false;
2658cdf0e10cSrcweir while (pBodyPtr != pBodyEnd && !bEnd)
2659cdf0e10cSrcweir switch (*pBodyPtr)
2660cdf0e10cSrcweir {
2661cdf0e10cSrcweir case '\t':
2662cdf0e10cSrcweir case ' ':
2663cdf0e10cSrcweir case '\x0D': // CR
2664cdf0e10cSrcweir {
2665cdf0e10cSrcweir const sal_Unicode * pLookAhead
2666cdf0e10cSrcweir = skipLinearWhiteSpace(pBodyPtr,
2667cdf0e10cSrcweir pBodyEnd);
2668cdf0e10cSrcweir if (pLookAhead < pBodyEnd
2669cdf0e10cSrcweir && (bSymbol ?
2670cdf0e10cSrcweir isAtomChar(*pLookAhead)
2671cdf0e10cSrcweir || *pLookAhead == '"'
2672cdf0e10cSrcweir || *pLookAhead == '[' :
2673cdf0e10cSrcweir *pLookAhead == '.'
2674cdf0e10cSrcweir || *pLookAhead == '@'
2675cdf0e10cSrcweir || (*pLookAhead == '>'
2676cdf0e10cSrcweir && eType
2677cdf0e10cSrcweir >= HEADER_FIELD_MESSAGE_ID
2678cdf0e10cSrcweir && eBrackets
2679cdf0e10cSrcweir == BRACKETS_OPENING)))
2680cdf0e10cSrcweir {
2681cdf0e10cSrcweir bModify = true;
2682cdf0e10cSrcweir pBodyPtr = pLookAhead;
2683cdf0e10cSrcweir }
2684cdf0e10cSrcweir else
2685cdf0e10cSrcweir bEnd = true;
2686cdf0e10cSrcweir break;
2687cdf0e10cSrcweir }
2688cdf0e10cSrcweir
2689cdf0e10cSrcweir case '"':
2690cdf0e10cSrcweir if (bSymbol)
2691cdf0e10cSrcweir {
2692cdf0e10cSrcweir pBodyPtr
2693cdf0e10cSrcweir = scanQuotedBlock(pBodyPtr,
2694cdf0e10cSrcweir pBodyEnd,
2695cdf0e10cSrcweir '"', '"',
2696cdf0e10cSrcweir nLength,
2697cdf0e10cSrcweir bModify);
2698cdf0e10cSrcweir bSymbol = false;
2699cdf0e10cSrcweir }
2700cdf0e10cSrcweir else
2701cdf0e10cSrcweir bEnd = true;
2702cdf0e10cSrcweir break;
2703cdf0e10cSrcweir
2704cdf0e10cSrcweir case '[':
2705cdf0e10cSrcweir if (bSymbol)
2706cdf0e10cSrcweir {
2707cdf0e10cSrcweir pBodyPtr
2708cdf0e10cSrcweir = scanQuotedBlock(pBodyPtr,
2709cdf0e10cSrcweir pBodyEnd,
2710cdf0e10cSrcweir '[', ']',
2711cdf0e10cSrcweir nLength,
2712cdf0e10cSrcweir bModify);
2713cdf0e10cSrcweir bSymbol = false;
2714cdf0e10cSrcweir }
2715cdf0e10cSrcweir else
2716cdf0e10cSrcweir bEnd = true;
2717cdf0e10cSrcweir break;
2718cdf0e10cSrcweir
2719cdf0e10cSrcweir case '.':
2720cdf0e10cSrcweir case '@':
2721cdf0e10cSrcweir if (bSymbol)
2722cdf0e10cSrcweir bEnd = true;
2723cdf0e10cSrcweir else
2724cdf0e10cSrcweir {
2725cdf0e10cSrcweir ++nLength;
2726cdf0e10cSrcweir bSymbol = true;
2727cdf0e10cSrcweir ++pBodyPtr;
2728cdf0e10cSrcweir }
2729cdf0e10cSrcweir break;
2730cdf0e10cSrcweir
2731cdf0e10cSrcweir case '>':
2732cdf0e10cSrcweir if (eBrackets == BRACKETS_OPENING
2733cdf0e10cSrcweir && eType
2734cdf0e10cSrcweir >= HEADER_FIELD_MESSAGE_ID)
2735cdf0e10cSrcweir {
2736cdf0e10cSrcweir ++nLength;
2737cdf0e10cSrcweir bBracketedBlock = true;
2738cdf0e10cSrcweir ++pBodyPtr;
2739cdf0e10cSrcweir }
2740cdf0e10cSrcweir bEnd = true;
2741cdf0e10cSrcweir break;
2742cdf0e10cSrcweir
2743cdf0e10cSrcweir default:
2744cdf0e10cSrcweir if (isAtomChar(*pBodyPtr) && bSymbol)
2745cdf0e10cSrcweir {
2746cdf0e10cSrcweir while (pBodyPtr != pBodyEnd
2747cdf0e10cSrcweir && isAtomChar(*pBodyPtr))
2748cdf0e10cSrcweir {
2749cdf0e10cSrcweir ++nLength;
2750cdf0e10cSrcweir ++pBodyPtr;
2751cdf0e10cSrcweir }
2752cdf0e10cSrcweir bSymbol = false;
2753cdf0e10cSrcweir }
2754cdf0e10cSrcweir else
2755cdf0e10cSrcweir {
2756cdf0e10cSrcweir if (!isUSASCII(*pBodyPtr))
2757cdf0e10cSrcweir bModify = true;
2758cdf0e10cSrcweir bEnd = true;
2759cdf0e10cSrcweir }
2760cdf0e10cSrcweir break;
2761cdf0e10cSrcweir }
2762cdf0e10cSrcweir
2763cdf0e10cSrcweir // Write a pending '<' if necessary:
2764cdf0e10cSrcweir if (eBrackets == BRACKETS_OPENING
2765cdf0e10cSrcweir && !bBracketedBlock)
2766cdf0e10cSrcweir {
2767cdf0e10cSrcweir if (rSink.getColumn()
2768cdf0e10cSrcweir + (bInitialSpace ? 1 : 0)
2769cdf0e10cSrcweir >= rSink.getLineLengthLimit())
2770cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2771cdf0e10cSrcweir else if (bInitialSpace)
2772cdf0e10cSrcweir rSink << ' ';
2773cdf0e10cSrcweir rSink << '<';
2774cdf0e10cSrcweir bInitialSpace = false;
2775cdf0e10cSrcweir eBrackets = BRACKETS_INSIDE;
2776cdf0e10cSrcweir }
2777cdf0e10cSrcweir
2778cdf0e10cSrcweir // Write the output:
2779cdf0e10cSrcweir if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
2780cdf0e10cSrcweir + nLength
2781cdf0e10cSrcweir > rSink.getLineLengthLimit())
2782cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2783cdf0e10cSrcweir else if (bInitialSpace)
2784cdf0e10cSrcweir rSink << ' ';
2785cdf0e10cSrcweir bInitialSpace = false;
2786cdf0e10cSrcweir if (bBracketedBlock)
2787cdf0e10cSrcweir {
2788cdf0e10cSrcweir rSink << '<';
2789cdf0e10cSrcweir eBrackets = BRACKETS_OUTSIDE;
2790cdf0e10cSrcweir }
2791cdf0e10cSrcweir if (bModify)
2792cdf0e10cSrcweir {
2793cdf0e10cSrcweir enum Mode { MODE_PLAIN, MODE_QUOTED_STRING,
2794cdf0e10cSrcweir MODE_DOMAIN_LITERAL };
2795cdf0e10cSrcweir Mode eMode = MODE_PLAIN;
2796cdf0e10cSrcweir while (pStart != pBodyPtr)
2797cdf0e10cSrcweir switch (*pStart)
2798cdf0e10cSrcweir {
2799cdf0e10cSrcweir case '\x0D': // CR
2800cdf0e10cSrcweir if (startsWithLineFolding(
2801cdf0e10cSrcweir pStart, pBodyPtr))
2802cdf0e10cSrcweir {
2803cdf0e10cSrcweir if (eMode != MODE_PLAIN)
2804cdf0e10cSrcweir rSink << sal_Char(
2805cdf0e10cSrcweir pStart[2]);
2806cdf0e10cSrcweir pStart += 3;
2807cdf0e10cSrcweir }
2808cdf0e10cSrcweir else if (startsWithLineBreak(
2809cdf0e10cSrcweir pStart, pBodyPtr))
2810cdf0e10cSrcweir {
2811cdf0e10cSrcweir rSink << "\x0D\\\x0A";
2812cdf0e10cSrcweir // CR, '\', LF
2813cdf0e10cSrcweir pStart += 2;
2814cdf0e10cSrcweir }
2815cdf0e10cSrcweir else
2816cdf0e10cSrcweir {
2817cdf0e10cSrcweir rSink << '\x0D'; // CR
2818cdf0e10cSrcweir ++pStart;
2819cdf0e10cSrcweir }
2820cdf0e10cSrcweir break;
2821cdf0e10cSrcweir
2822cdf0e10cSrcweir case '\t':
2823cdf0e10cSrcweir case ' ':
2824cdf0e10cSrcweir if (eMode != MODE_PLAIN)
2825cdf0e10cSrcweir rSink << sal_Char(*pStart);
2826cdf0e10cSrcweir ++pStart;
2827cdf0e10cSrcweir break;
2828cdf0e10cSrcweir
2829cdf0e10cSrcweir case '"':
2830cdf0e10cSrcweir if (eMode == MODE_PLAIN)
2831cdf0e10cSrcweir eMode = MODE_QUOTED_STRING;
2832cdf0e10cSrcweir else if (eMode
2833cdf0e10cSrcweir == MODE_QUOTED_STRING)
2834cdf0e10cSrcweir eMode = MODE_PLAIN;
2835cdf0e10cSrcweir rSink << '"';
2836cdf0e10cSrcweir ++pStart;
2837cdf0e10cSrcweir break;
2838cdf0e10cSrcweir
2839cdf0e10cSrcweir case '[':
2840cdf0e10cSrcweir if (eMode == MODE_PLAIN)
2841cdf0e10cSrcweir eMode = MODE_DOMAIN_LITERAL;
2842cdf0e10cSrcweir rSink << '[';
2843cdf0e10cSrcweir ++pStart;
2844cdf0e10cSrcweir break;
2845cdf0e10cSrcweir
2846cdf0e10cSrcweir case ']':
2847cdf0e10cSrcweir if (eMode == MODE_DOMAIN_LITERAL)
2848cdf0e10cSrcweir eMode = MODE_PLAIN;
2849cdf0e10cSrcweir rSink << ']';
2850cdf0e10cSrcweir ++pStart;
2851cdf0e10cSrcweir break;
2852cdf0e10cSrcweir
2853cdf0e10cSrcweir case '\\':
2854cdf0e10cSrcweir rSink << '\\';
2855cdf0e10cSrcweir if (++pStart < pBodyPtr)
2856cdf0e10cSrcweir writeUTF8(rSink, *pStart++);
2857cdf0e10cSrcweir break;
2858cdf0e10cSrcweir
2859cdf0e10cSrcweir default:
2860cdf0e10cSrcweir writeUTF8(rSink, *pStart++);
2861cdf0e10cSrcweir break;
2862cdf0e10cSrcweir }
2863cdf0e10cSrcweir }
2864cdf0e10cSrcweir else
2865cdf0e10cSrcweir rSink.write(pStart, pBodyPtr);
2866cdf0e10cSrcweir break;
2867cdf0e10cSrcweir }
2868cdf0e10cSrcweir
2869cdf0e10cSrcweir case ENTITY_PHRASE:
2870cdf0e10cSrcweir {
2871cdf0e10cSrcweir // Write a pending '<' if necessary:
2872cdf0e10cSrcweir if (eBrackets == BRACKETS_OPENING)
2873cdf0e10cSrcweir {
2874cdf0e10cSrcweir if (rSink.getColumn()
2875cdf0e10cSrcweir + (bInitialSpace ? 1 : 0)
2876cdf0e10cSrcweir >= rSink.getLineLengthLimit())
2877cdf0e10cSrcweir rSink << INetMIMEOutputSink::endl << ' ';
2878cdf0e10cSrcweir else if (bInitialSpace)
2879cdf0e10cSrcweir rSink << ' ';
2880cdf0e10cSrcweir rSink << '<';
2881cdf0e10cSrcweir bInitialSpace = false;
2882cdf0e10cSrcweir eBrackets = BRACKETS_INSIDE;
2883cdf0e10cSrcweir }
2884cdf0e10cSrcweir
2885cdf0e10cSrcweir // Calculate the length of in- and output:
2886cdf0e10cSrcweir const sal_Unicode * pStart = pBodyPtr;
2887cdf0e10cSrcweir bool bQuotedString = false;
2888cdf0e10cSrcweir bool bEnd = false;
2889cdf0e10cSrcweir while (pBodyPtr != pBodyEnd && !bEnd)
2890cdf0e10cSrcweir switch (*pBodyPtr)
2891cdf0e10cSrcweir {
2892cdf0e10cSrcweir case '\t':
2893cdf0e10cSrcweir case ' ':
2894cdf0e10cSrcweir case '\x0D': // CR
2895cdf0e10cSrcweir if (bQuotedString)
2896cdf0e10cSrcweir ++pBodyPtr;
2897cdf0e10cSrcweir else
2898cdf0e10cSrcweir {
2899cdf0e10cSrcweir const sal_Unicode * pLookAhead
2900cdf0e10cSrcweir = skipLinearWhiteSpace(
2901cdf0e10cSrcweir pBodyPtr, pBodyEnd);
2902cdf0e10cSrcweir if (pLookAhead != pBodyEnd
2903cdf0e10cSrcweir && (isAtomChar(*pLookAhead)
2904cdf0e10cSrcweir || !isUSASCII(*pLookAhead)
2905cdf0e10cSrcweir || *pLookAhead == '"'))
2906cdf0e10cSrcweir pBodyPtr = pLookAhead;
2907cdf0e10cSrcweir else
2908cdf0e10cSrcweir bEnd = true;
2909cdf0e10cSrcweir }
2910cdf0e10cSrcweir break;
2911cdf0e10cSrcweir
2912cdf0e10cSrcweir case '"':
2913cdf0e10cSrcweir bQuotedString = !bQuotedString;
2914cdf0e10cSrcweir ++pBodyPtr;
2915cdf0e10cSrcweir break;
2916cdf0e10cSrcweir
2917cdf0e10cSrcweir case '\\':
2918cdf0e10cSrcweir if (bQuotedString)
2919cdf0e10cSrcweir {
2920cdf0e10cSrcweir if (++pBodyPtr != pBodyEnd)
2921cdf0e10cSrcweir ++pBodyPtr;
2922cdf0e10cSrcweir }
2923cdf0e10cSrcweir else
2924cdf0e10cSrcweir bEnd = true;
2925cdf0e10cSrcweir break;
2926cdf0e10cSrcweir
2927cdf0e10cSrcweir default:
2928cdf0e10cSrcweir if (bQuotedString
2929cdf0e10cSrcweir || isAtomChar(*pBodyPtr)
2930cdf0e10cSrcweir || !isUSASCII(*pBodyPtr))
2931cdf0e10cSrcweir ++pBodyPtr;
2932cdf0e10cSrcweir else
2933cdf0e10cSrcweir bEnd = true;
2934cdf0e10cSrcweir break;
2935cdf0e10cSrcweir }
2936cdf0e10cSrcweir
2937cdf0e10cSrcweir // Write the phrase, introducing encoded-words
2938cdf0e10cSrcweir // where necessary:
2939cdf0e10cSrcweir INetMIMEEncodedWordOutputSink
2940cdf0e10cSrcweir aOutput(
2941cdf0e10cSrcweir rSink,
2942cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE,
2943cdf0e10cSrcweir bInitialSpace ?
2944cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::SPACE_ALWAYS :
2945cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::SPACE_ENCODED,
2946cdf0e10cSrcweir ePreferredEncoding);
2947cdf0e10cSrcweir while (pStart != pBodyPtr)
2948cdf0e10cSrcweir switch (*pStart)
2949cdf0e10cSrcweir {
2950cdf0e10cSrcweir case '"':
2951cdf0e10cSrcweir ++pStart;
2952cdf0e10cSrcweir break;
2953cdf0e10cSrcweir
2954cdf0e10cSrcweir case '\\':
2955cdf0e10cSrcweir if (++pStart != pBodyPtr)
2956cdf0e10cSrcweir aOutput << *pStart++;
2957cdf0e10cSrcweir break;
2958cdf0e10cSrcweir
2959cdf0e10cSrcweir case '\x0D': // CR
2960cdf0e10cSrcweir pStart += 2;
2961cdf0e10cSrcweir aOutput << *pStart++;
2962cdf0e10cSrcweir break;
2963cdf0e10cSrcweir
2964cdf0e10cSrcweir default:
2965cdf0e10cSrcweir aOutput << *pStart++;
2966cdf0e10cSrcweir break;
2967cdf0e10cSrcweir }
2968cdf0e10cSrcweir bInitialSpace = aOutput.flush();
2969cdf0e10cSrcweir break;
2970cdf0e10cSrcweir }
2971cdf0e10cSrcweir }
2972cdf0e10cSrcweir break;
2973cdf0e10cSrcweir }
2974cdf0e10cSrcweir }
2975cdf0e10cSrcweir }
2976cdf0e10cSrcweir }
2977cdf0e10cSrcweir
2978cdf0e10cSrcweir //============================================================================
2979cdf0e10cSrcweir // static
translateUTF8Char(const sal_Char * & rBegin,const sal_Char * pEnd,rtl_TextEncoding eEncoding,sal_uInt32 & rCharacter)2980cdf0e10cSrcweir bool INetMIME::translateUTF8Char(const sal_Char *& rBegin,
2981cdf0e10cSrcweir const sal_Char * pEnd,
2982cdf0e10cSrcweir rtl_TextEncoding eEncoding,
2983cdf0e10cSrcweir sal_uInt32 & rCharacter)
2984cdf0e10cSrcweir {
2985cdf0e10cSrcweir if (rBegin == pEnd || static_cast< unsigned char >(*rBegin) < 0x80
2986cdf0e10cSrcweir || static_cast< unsigned char >(*rBegin) >= 0xFE)
2987cdf0e10cSrcweir return false;
2988cdf0e10cSrcweir
2989cdf0e10cSrcweir int nCount;
2990cdf0e10cSrcweir sal_uInt32 nMin;
2991cdf0e10cSrcweir sal_uInt32 nUCS4;
2992cdf0e10cSrcweir const sal_Char * p = rBegin;
2993cdf0e10cSrcweir if (static_cast< unsigned char >(*p) < 0xE0)
2994cdf0e10cSrcweir {
2995cdf0e10cSrcweir nCount = 1;
2996cdf0e10cSrcweir nMin = 0x80;
2997cdf0e10cSrcweir nUCS4 = static_cast< unsigned char >(*p) & 0x1F;
2998cdf0e10cSrcweir }
2999cdf0e10cSrcweir else if (static_cast< unsigned char >(*p) < 0xF0)
3000cdf0e10cSrcweir {
3001cdf0e10cSrcweir nCount = 2;
3002cdf0e10cSrcweir nMin = 0x800;
3003cdf0e10cSrcweir nUCS4 = static_cast< unsigned char >(*p) & 0xF;
3004cdf0e10cSrcweir }
3005cdf0e10cSrcweir else if (static_cast< unsigned char >(*p) < 0xF8)
3006cdf0e10cSrcweir {
3007cdf0e10cSrcweir nCount = 3;
3008cdf0e10cSrcweir nMin = 0x10000;
3009cdf0e10cSrcweir nUCS4 = static_cast< unsigned char >(*p) & 7;
3010cdf0e10cSrcweir }
3011cdf0e10cSrcweir else if (static_cast< unsigned char >(*p) < 0xFC)
3012cdf0e10cSrcweir {
3013cdf0e10cSrcweir nCount = 4;
3014cdf0e10cSrcweir nMin = 0x200000;
3015cdf0e10cSrcweir nUCS4 = static_cast< unsigned char >(*p) & 3;
3016cdf0e10cSrcweir }
3017cdf0e10cSrcweir else
3018cdf0e10cSrcweir {
3019cdf0e10cSrcweir nCount = 5;
3020cdf0e10cSrcweir nMin = 0x4000000;
3021cdf0e10cSrcweir nUCS4 = static_cast< unsigned char >(*p) & 1;
3022cdf0e10cSrcweir }
3023cdf0e10cSrcweir ++p;
3024cdf0e10cSrcweir
3025cdf0e10cSrcweir for (; nCount-- > 0; ++p)
3026cdf0e10cSrcweir if ((static_cast< unsigned char >(*p) & 0xC0) == 0x80)
3027cdf0e10cSrcweir nUCS4 = (nUCS4 << 6) | (static_cast< unsigned char >(*p) & 0x3F);
3028cdf0e10cSrcweir else
3029cdf0e10cSrcweir return false;
3030cdf0e10cSrcweir
3031cdf0e10cSrcweir if (nUCS4 < nMin || nUCS4 > 0x10FFFF)
3032cdf0e10cSrcweir return false;
3033cdf0e10cSrcweir
3034cdf0e10cSrcweir if (eEncoding >= RTL_TEXTENCODING_UCS4)
3035cdf0e10cSrcweir rCharacter = nUCS4;
3036cdf0e10cSrcweir else
3037cdf0e10cSrcweir {
3038cdf0e10cSrcweir sal_Unicode aUTF16[2];
3039cdf0e10cSrcweir const sal_Unicode * pUTF16End = putUTF32Character(aUTF16, nUCS4);
3040cdf0e10cSrcweir sal_Size nSize;
3041cdf0e10cSrcweir sal_Char * pBuffer = convertFromUnicode(aUTF16, pUTF16End, eEncoding,
3042cdf0e10cSrcweir nSize);
3043cdf0e10cSrcweir if (!pBuffer)
3044cdf0e10cSrcweir return false;
3045cdf0e10cSrcweir DBG_ASSERT(nSize == 1,
3046cdf0e10cSrcweir "INetMIME::translateUTF8Char(): Bad conversion");
3047cdf0e10cSrcweir rCharacter = *pBuffer;
3048cdf0e10cSrcweir delete[] pBuffer;
3049cdf0e10cSrcweir }
3050cdf0e10cSrcweir rBegin = p;
3051cdf0e10cSrcweir return true;
3052cdf0e10cSrcweir }
3053cdf0e10cSrcweir
3054cdf0e10cSrcweir //============================================================================
3055cdf0e10cSrcweir // static
decodeUTF8(const ByteString & rText,rtl_TextEncoding eEncoding)3056cdf0e10cSrcweir ByteString INetMIME::decodeUTF8(const ByteString & rText,
3057cdf0e10cSrcweir rtl_TextEncoding eEncoding)
3058cdf0e10cSrcweir {
3059cdf0e10cSrcweir const sal_Char * p = rText.GetBuffer();
3060cdf0e10cSrcweir const sal_Char * pEnd = p + rText.Len();
3061cdf0e10cSrcweir ByteString sDecoded;
3062cdf0e10cSrcweir while (p != pEnd)
3063cdf0e10cSrcweir {
3064cdf0e10cSrcweir sal_uInt32 nCharacter;
3065cdf0e10cSrcweir if (translateUTF8Char(p, pEnd, eEncoding, nCharacter))
3066cdf0e10cSrcweir sDecoded += sal_Char(nCharacter);
3067cdf0e10cSrcweir else
3068cdf0e10cSrcweir sDecoded += sal_Char(*p++);
3069cdf0e10cSrcweir }
3070cdf0e10cSrcweir return sDecoded;
3071cdf0e10cSrcweir }
3072cdf0e10cSrcweir
3073cdf0e10cSrcweir //============================================================================
3074cdf0e10cSrcweir // static
decodeHeaderFieldBody(HeaderFieldType eType,const ByteString & rBody)3075cdf0e10cSrcweir UniString INetMIME::decodeHeaderFieldBody(HeaderFieldType eType,
3076cdf0e10cSrcweir const ByteString & rBody)
3077cdf0e10cSrcweir {
3078cdf0e10cSrcweir // Due to a bug in INetCoreRFC822MessageStream::ConvertTo7Bit(), old
3079cdf0e10cSrcweir // versions of StarOffice send mails with header fields where encoded
3080cdf0e10cSrcweir // words can be preceded by '=', ',', '.', '"', or '(', and followed by
3081cdf0e10cSrcweir // '=', ',', '.', '"', ')', without any required white space in between.
3082cdf0e10cSrcweir // And there appear to exist some broken mailers that only encode single
3083cdf0e10cSrcweir // letters within words, like "Appel
3084cdf0e10cSrcweir // =?iso-8859-1?Q?=E0?=t=?iso-8859-1?Q?=E9?=moin", so it seems best to
3085*86e1cf34SPedro Giffuni // detect encoded words even when not properly surrounded by white space.
3086cdf0e10cSrcweir //
3087cdf0e10cSrcweir // Non US-ASCII characters in rBody are treated as ISO-8859-1.
3088cdf0e10cSrcweir //
3089cdf0e10cSrcweir // encoded-word = "=?"
3090cdf0e10cSrcweir // 1*(%x21 / %x23-27 / %x2A-2B / %x2D / %30-39 / %x41-5A / %x5E-7E)
3091cdf0e10cSrcweir // ["*" 1*8ALPHA *("-" 1*8ALPHA)] "?"
3092cdf0e10cSrcweir // ("B?" *(4base64) (4base64 / 3base64 "=" / 2base64 "==")
3093cdf0e10cSrcweir // / "Q?" 1*(%x21-3C / %x3E / %x40-7E / "=" 2HEXDIG))
3094cdf0e10cSrcweir // "?="
3095cdf0e10cSrcweir //
3096cdf0e10cSrcweir // base64 = ALPHA / DIGIT / "+" / "/"
3097cdf0e10cSrcweir
3098cdf0e10cSrcweir const sal_Char * pBegin = rBody.GetBuffer();
3099cdf0e10cSrcweir const sal_Char * pEnd = pBegin + rBody.Len();
3100cdf0e10cSrcweir
3101cdf0e10cSrcweir UniString sDecoded;
3102cdf0e10cSrcweir const sal_Char * pCopyBegin = pBegin;
3103cdf0e10cSrcweir
3104cdf0e10cSrcweir /* bool bStartEncodedWord = true; */
3105cdf0e10cSrcweir const sal_Char * pWSPBegin = pBegin;
3106cdf0e10cSrcweir UniString sEncodedText;
3107cdf0e10cSrcweir bool bQuotedEncodedText = false;
3108cdf0e10cSrcweir sal_uInt32 nCommentLevel = 0;
3109cdf0e10cSrcweir
3110cdf0e10cSrcweir for (const sal_Char * p = pBegin; p != pEnd;)
3111cdf0e10cSrcweir {
3112cdf0e10cSrcweir if (p != pEnd && *p == '=' /* && bStartEncodedWord */)
3113cdf0e10cSrcweir {
3114cdf0e10cSrcweir const sal_Char * q = p + 1;
3115cdf0e10cSrcweir bool bEncodedWord = q != pEnd && *q++ == '?';
3116cdf0e10cSrcweir
3117cdf0e10cSrcweir rtl_TextEncoding eCharsetEncoding = RTL_TEXTENCODING_DONTKNOW;
3118cdf0e10cSrcweir if (bEncodedWord)
3119cdf0e10cSrcweir {
3120cdf0e10cSrcweir const sal_Char * pCharsetBegin = q;
3121cdf0e10cSrcweir const sal_Char * pLanguageBegin = 0;
3122cdf0e10cSrcweir int nAlphaCount = 0;
3123cdf0e10cSrcweir for (bool bDone = false; !bDone;)
3124cdf0e10cSrcweir if (q == pEnd)
3125cdf0e10cSrcweir {
3126cdf0e10cSrcweir bEncodedWord = false;
3127cdf0e10cSrcweir bDone = true;
3128cdf0e10cSrcweir }
3129cdf0e10cSrcweir else
3130cdf0e10cSrcweir {
3131cdf0e10cSrcweir sal_Char cChar = *q++;
3132cdf0e10cSrcweir switch (cChar)
3133cdf0e10cSrcweir {
3134cdf0e10cSrcweir case '*':
3135cdf0e10cSrcweir pLanguageBegin = q - 1;
3136cdf0e10cSrcweir nAlphaCount = 0;
3137cdf0e10cSrcweir break;
3138cdf0e10cSrcweir
3139cdf0e10cSrcweir case '-':
3140cdf0e10cSrcweir if (pLanguageBegin != 0)
3141cdf0e10cSrcweir {
3142cdf0e10cSrcweir if (nAlphaCount == 0)
3143cdf0e10cSrcweir pLanguageBegin = 0;
3144cdf0e10cSrcweir else
3145cdf0e10cSrcweir nAlphaCount = 0;
3146cdf0e10cSrcweir }
3147cdf0e10cSrcweir break;
3148cdf0e10cSrcweir
3149cdf0e10cSrcweir case '?':
3150cdf0e10cSrcweir if (pCharsetBegin == q - 1)
3151cdf0e10cSrcweir bEncodedWord = false;
3152cdf0e10cSrcweir else
3153cdf0e10cSrcweir {
3154cdf0e10cSrcweir eCharsetEncoding
3155cdf0e10cSrcweir = getCharsetEncoding(
3156cdf0e10cSrcweir pCharsetBegin,
3157cdf0e10cSrcweir pLanguageBegin == 0
3158cdf0e10cSrcweir || nAlphaCount == 0 ?
3159cdf0e10cSrcweir q - 1 : pLanguageBegin);
3160cdf0e10cSrcweir bEncodedWord = isMIMECharsetEncoding(
3161cdf0e10cSrcweir eCharsetEncoding);
3162cdf0e10cSrcweir eCharsetEncoding
3163cdf0e10cSrcweir = translateFromMIME(eCharsetEncoding);
3164cdf0e10cSrcweir }
3165cdf0e10cSrcweir bDone = true;
3166cdf0e10cSrcweir break;
3167cdf0e10cSrcweir
3168cdf0e10cSrcweir default:
3169cdf0e10cSrcweir if (pLanguageBegin != 0
3170cdf0e10cSrcweir && (!isAlpha(cChar) || ++nAlphaCount > 8))
3171cdf0e10cSrcweir pLanguageBegin = 0;
3172cdf0e10cSrcweir break;
3173cdf0e10cSrcweir }
3174cdf0e10cSrcweir }
3175cdf0e10cSrcweir }
3176cdf0e10cSrcweir
3177cdf0e10cSrcweir bool bEncodingB = false;
3178cdf0e10cSrcweir if (bEncodedWord)
3179cdf0e10cSrcweir {
3180cdf0e10cSrcweir if (q == pEnd)
3181cdf0e10cSrcweir bEncodedWord = false;
3182cdf0e10cSrcweir else
3183cdf0e10cSrcweir {
3184cdf0e10cSrcweir switch (*q++)
3185cdf0e10cSrcweir {
3186cdf0e10cSrcweir case 'B':
3187cdf0e10cSrcweir case 'b':
3188cdf0e10cSrcweir bEncodingB = true;
3189cdf0e10cSrcweir break;
3190cdf0e10cSrcweir
3191cdf0e10cSrcweir case 'Q':
3192cdf0e10cSrcweir case 'q':
3193cdf0e10cSrcweir bEncodingB = false;
3194cdf0e10cSrcweir break;
3195cdf0e10cSrcweir
3196cdf0e10cSrcweir default:
3197cdf0e10cSrcweir bEncodedWord = false;
3198cdf0e10cSrcweir break;
3199cdf0e10cSrcweir }
3200cdf0e10cSrcweir }
3201cdf0e10cSrcweir }
3202cdf0e10cSrcweir
3203cdf0e10cSrcweir bEncodedWord = bEncodedWord && q != pEnd && *q++ == '?';
3204cdf0e10cSrcweir
3205cdf0e10cSrcweir ByteString sText;
3206cdf0e10cSrcweir if (bEncodedWord)
3207cdf0e10cSrcweir {
3208cdf0e10cSrcweir if (bEncodingB)
3209cdf0e10cSrcweir {
3210cdf0e10cSrcweir for (bool bDone = false; !bDone;)
3211cdf0e10cSrcweir {
3212cdf0e10cSrcweir if (pEnd - q < 4)
3213cdf0e10cSrcweir {
3214cdf0e10cSrcweir bEncodedWord = false;
3215cdf0e10cSrcweir bDone = true;
3216cdf0e10cSrcweir }
3217cdf0e10cSrcweir else
3218cdf0e10cSrcweir {
3219cdf0e10cSrcweir bool bFinal = false;
3220cdf0e10cSrcweir int nCount = 3;
3221cdf0e10cSrcweir sal_uInt32 nValue = 0;
3222cdf0e10cSrcweir for (int nShift = 18; nShift >= 0; nShift -= 6)
3223cdf0e10cSrcweir {
3224cdf0e10cSrcweir int nWeight = getBase64Weight(*q++);
3225cdf0e10cSrcweir if (nWeight == -2)
3226cdf0e10cSrcweir {
3227cdf0e10cSrcweir bEncodedWord = false;
3228cdf0e10cSrcweir bDone = true;
3229cdf0e10cSrcweir break;
3230cdf0e10cSrcweir }
3231cdf0e10cSrcweir if (nWeight == -1)
3232cdf0e10cSrcweir {
3233cdf0e10cSrcweir if (!bFinal)
3234cdf0e10cSrcweir {
3235cdf0e10cSrcweir if (nShift >= 12)
3236cdf0e10cSrcweir {
3237cdf0e10cSrcweir bEncodedWord = false;
3238cdf0e10cSrcweir bDone = true;
3239cdf0e10cSrcweir break;
3240cdf0e10cSrcweir }
3241cdf0e10cSrcweir bFinal = true;
3242cdf0e10cSrcweir nCount = nShift == 6 ? 1 : 2;
3243cdf0e10cSrcweir }
3244cdf0e10cSrcweir }
3245cdf0e10cSrcweir else
3246cdf0e10cSrcweir nValue |= nWeight << nShift;
3247cdf0e10cSrcweir }
3248cdf0e10cSrcweir if (bEncodedWord)
3249cdf0e10cSrcweir {
3250cdf0e10cSrcweir for (int nShift = 16; nCount-- > 0;
3251cdf0e10cSrcweir nShift -= 8)
3252cdf0e10cSrcweir sText += sal_Char(nValue >> nShift
3253cdf0e10cSrcweir & 0xFF);
3254cdf0e10cSrcweir if (*q == '?')
3255cdf0e10cSrcweir {
3256cdf0e10cSrcweir ++q;
3257cdf0e10cSrcweir bDone = true;
3258cdf0e10cSrcweir }
3259cdf0e10cSrcweir if (bFinal && !bDone)
3260cdf0e10cSrcweir {
3261cdf0e10cSrcweir bEncodedWord = false;
3262cdf0e10cSrcweir bDone = true;
3263cdf0e10cSrcweir }
3264cdf0e10cSrcweir }
3265cdf0e10cSrcweir }
3266cdf0e10cSrcweir }
3267cdf0e10cSrcweir }
3268cdf0e10cSrcweir else
3269cdf0e10cSrcweir {
3270cdf0e10cSrcweir const sal_Char * pEncodedTextBegin = q;
3271cdf0e10cSrcweir const sal_Char * pEncodedTextCopyBegin = q;
3272cdf0e10cSrcweir for (bool bDone = false; !bDone;)
3273cdf0e10cSrcweir if (q == pEnd)
3274cdf0e10cSrcweir {
3275cdf0e10cSrcweir bEncodedWord = false;
3276cdf0e10cSrcweir bDone = true;
3277cdf0e10cSrcweir }
3278cdf0e10cSrcweir else
3279cdf0e10cSrcweir {
3280cdf0e10cSrcweir sal_uInt32 nChar = *q++;
3281cdf0e10cSrcweir switch (nChar)
3282cdf0e10cSrcweir {
3283cdf0e10cSrcweir case '=':
3284cdf0e10cSrcweir {
3285cdf0e10cSrcweir if (pEnd - q < 2)
3286cdf0e10cSrcweir {
3287cdf0e10cSrcweir bEncodedWord = false;
3288cdf0e10cSrcweir bDone = true;
3289cdf0e10cSrcweir break;
3290cdf0e10cSrcweir }
3291cdf0e10cSrcweir int nDigit1 = getHexWeight(q[0]);
3292cdf0e10cSrcweir int nDigit2 = getHexWeight(q[1]);
3293cdf0e10cSrcweir if (nDigit1 < 0 || nDigit2 < 0)
3294cdf0e10cSrcweir {
3295cdf0e10cSrcweir bEncodedWord = false;
3296cdf0e10cSrcweir bDone = true;
3297cdf0e10cSrcweir break;
3298cdf0e10cSrcweir }
3299cdf0e10cSrcweir sText += rBody.Copy(
3300cdf0e10cSrcweir static_cast< xub_StrLen >(
3301cdf0e10cSrcweir pEncodedTextCopyBegin - pBegin),
3302cdf0e10cSrcweir static_cast< xub_StrLen >(
3303cdf0e10cSrcweir q - 1 - pEncodedTextCopyBegin));
3304cdf0e10cSrcweir sText += sal_Char(nDigit1 << 4 | nDigit2);
3305cdf0e10cSrcweir q += 2;
3306cdf0e10cSrcweir pEncodedTextCopyBegin = q;
3307cdf0e10cSrcweir break;
3308cdf0e10cSrcweir }
3309cdf0e10cSrcweir
3310cdf0e10cSrcweir case '?':
3311cdf0e10cSrcweir if (q - pEncodedTextBegin > 1)
3312cdf0e10cSrcweir sText += rBody.Copy(
3313cdf0e10cSrcweir static_cast< xub_StrLen >(
3314cdf0e10cSrcweir pEncodedTextCopyBegin - pBegin),
3315cdf0e10cSrcweir static_cast< xub_StrLen >(
3316cdf0e10cSrcweir q - 1 - pEncodedTextCopyBegin));
3317cdf0e10cSrcweir else
3318cdf0e10cSrcweir bEncodedWord = false;
3319cdf0e10cSrcweir bDone = true;
3320cdf0e10cSrcweir break;
3321cdf0e10cSrcweir
3322cdf0e10cSrcweir case '_':
3323cdf0e10cSrcweir sText += rBody.Copy(
3324cdf0e10cSrcweir static_cast< xub_StrLen >(
3325cdf0e10cSrcweir pEncodedTextCopyBegin - pBegin),
3326cdf0e10cSrcweir static_cast< xub_StrLen >(
3327cdf0e10cSrcweir q - 1 - pEncodedTextCopyBegin));
3328cdf0e10cSrcweir sText += ' ';
3329cdf0e10cSrcweir pEncodedTextCopyBegin = q;
3330cdf0e10cSrcweir break;
3331cdf0e10cSrcweir
3332cdf0e10cSrcweir default:
3333cdf0e10cSrcweir if (!isVisible(nChar))
3334cdf0e10cSrcweir {
3335cdf0e10cSrcweir bEncodedWord = false;
3336cdf0e10cSrcweir bDone = true;
3337cdf0e10cSrcweir }
3338cdf0e10cSrcweir break;
3339cdf0e10cSrcweir }
3340cdf0e10cSrcweir }
3341cdf0e10cSrcweir }
3342cdf0e10cSrcweir }
3343cdf0e10cSrcweir
3344cdf0e10cSrcweir bEncodedWord = bEncodedWord && q != pEnd && *q++ == '=';
3345cdf0e10cSrcweir
3346cdf0e10cSrcweir // if (bEncodedWord && q != pEnd)
3347cdf0e10cSrcweir // switch (*q)
3348cdf0e10cSrcweir // {
3349cdf0e10cSrcweir // case '\t':
3350cdf0e10cSrcweir // case ' ':
3351cdf0e10cSrcweir // case '"':
3352cdf0e10cSrcweir // case ')':
3353cdf0e10cSrcweir // case ',':
3354cdf0e10cSrcweir // case '.':
3355cdf0e10cSrcweir // case '=':
3356cdf0e10cSrcweir // break;
3357cdf0e10cSrcweir //
3358cdf0e10cSrcweir // default:
3359cdf0e10cSrcweir // bEncodedWord = false;
3360cdf0e10cSrcweir // break;
3361cdf0e10cSrcweir // }
3362cdf0e10cSrcweir
3363cdf0e10cSrcweir sal_Unicode * pUnicodeBuffer = 0;
3364cdf0e10cSrcweir sal_Size nUnicodeSize = 0;
3365cdf0e10cSrcweir if (bEncodedWord)
3366cdf0e10cSrcweir {
3367cdf0e10cSrcweir pUnicodeBuffer
3368cdf0e10cSrcweir = convertToUnicode(sText.GetBuffer(),
3369cdf0e10cSrcweir sText.GetBuffer() + sText.Len(),
3370cdf0e10cSrcweir eCharsetEncoding, nUnicodeSize);
3371cdf0e10cSrcweir if (pUnicodeBuffer == 0)
3372cdf0e10cSrcweir bEncodedWord = false;
3373cdf0e10cSrcweir }
3374cdf0e10cSrcweir
3375cdf0e10cSrcweir if (bEncodedWord)
3376cdf0e10cSrcweir {
3377cdf0e10cSrcweir appendISO88591(sDecoded, pCopyBegin, pWSPBegin);
3378cdf0e10cSrcweir if (eType == HEADER_FIELD_TEXT)
3379cdf0e10cSrcweir sDecoded.Append(
3380cdf0e10cSrcweir pUnicodeBuffer,
3381cdf0e10cSrcweir static_cast< xub_StrLen >(nUnicodeSize));
3382cdf0e10cSrcweir else if (nCommentLevel == 0)
3383cdf0e10cSrcweir {
3384cdf0e10cSrcweir sEncodedText.Append(
3385cdf0e10cSrcweir pUnicodeBuffer,
3386cdf0e10cSrcweir static_cast< xub_StrLen >(nUnicodeSize));
3387cdf0e10cSrcweir if (!bQuotedEncodedText)
3388cdf0e10cSrcweir {
3389cdf0e10cSrcweir const sal_Unicode * pTextPtr = pUnicodeBuffer;
3390cdf0e10cSrcweir const sal_Unicode * pTextEnd = pTextPtr
3391cdf0e10cSrcweir + nUnicodeSize;
3392cdf0e10cSrcweir for (; pTextPtr != pTextEnd; ++pTextPtr)
3393cdf0e10cSrcweir if (!isEncodedWordTokenChar(*pTextPtr))
3394cdf0e10cSrcweir {
3395cdf0e10cSrcweir bQuotedEncodedText = true;
3396cdf0e10cSrcweir break;
3397cdf0e10cSrcweir }
3398cdf0e10cSrcweir }
3399cdf0e10cSrcweir }
3400cdf0e10cSrcweir else
3401cdf0e10cSrcweir {
3402cdf0e10cSrcweir const sal_Unicode * pTextPtr = pUnicodeBuffer;
3403cdf0e10cSrcweir const sal_Unicode * pTextEnd = pTextPtr + nUnicodeSize;
3404cdf0e10cSrcweir for (; pTextPtr != pTextEnd; ++pTextPtr)
3405cdf0e10cSrcweir {
3406cdf0e10cSrcweir switch (*pTextPtr)
3407cdf0e10cSrcweir {
3408cdf0e10cSrcweir case '(':
3409cdf0e10cSrcweir case ')':
3410cdf0e10cSrcweir case '\\':
3411cdf0e10cSrcweir case '\x0D':
3412cdf0e10cSrcweir case '=':
3413cdf0e10cSrcweir sDecoded += '\\';
3414cdf0e10cSrcweir break;
3415cdf0e10cSrcweir }
3416cdf0e10cSrcweir sDecoded += *pTextPtr;
3417cdf0e10cSrcweir }
3418cdf0e10cSrcweir }
3419cdf0e10cSrcweir delete[] pUnicodeBuffer;
3420cdf0e10cSrcweir p = q;
3421cdf0e10cSrcweir pCopyBegin = p;
3422cdf0e10cSrcweir
3423cdf0e10cSrcweir pWSPBegin = p;
3424cdf0e10cSrcweir while (p != pEnd && isWhiteSpace(*p))
3425cdf0e10cSrcweir ++p;
3426cdf0e10cSrcweir /* bStartEncodedWord = p != pWSPBegin; */
3427cdf0e10cSrcweir continue;
3428cdf0e10cSrcweir }
3429cdf0e10cSrcweir }
3430cdf0e10cSrcweir
3431cdf0e10cSrcweir if (sEncodedText.Len() != 0)
3432cdf0e10cSrcweir {
3433cdf0e10cSrcweir if (bQuotedEncodedText)
3434cdf0e10cSrcweir {
3435cdf0e10cSrcweir sDecoded += '"';
3436cdf0e10cSrcweir const sal_Unicode * pTextPtr = sEncodedText.GetBuffer();
3437cdf0e10cSrcweir const sal_Unicode * pTextEnd = pTextPtr + sEncodedText.Len();
3438cdf0e10cSrcweir for (;pTextPtr != pTextEnd; ++pTextPtr)
3439cdf0e10cSrcweir {
3440cdf0e10cSrcweir switch (*pTextPtr)
3441cdf0e10cSrcweir {
3442cdf0e10cSrcweir case '"':
3443cdf0e10cSrcweir case '\\':
3444cdf0e10cSrcweir case '\x0D':
3445cdf0e10cSrcweir sDecoded += '\\';
3446cdf0e10cSrcweir break;
3447cdf0e10cSrcweir }
3448cdf0e10cSrcweir sDecoded += *pTextPtr;
3449cdf0e10cSrcweir }
3450cdf0e10cSrcweir sDecoded += '"';
3451cdf0e10cSrcweir }
3452cdf0e10cSrcweir else
3453cdf0e10cSrcweir sDecoded += sEncodedText;
3454cdf0e10cSrcweir sEncodedText.Erase();
3455cdf0e10cSrcweir bQuotedEncodedText = false;
3456cdf0e10cSrcweir }
3457cdf0e10cSrcweir
3458cdf0e10cSrcweir if (p == pEnd)
3459cdf0e10cSrcweir break;
3460cdf0e10cSrcweir
3461cdf0e10cSrcweir switch (*p++)
3462cdf0e10cSrcweir {
3463cdf0e10cSrcweir // case '\t':
3464cdf0e10cSrcweir // case ' ':
3465cdf0e10cSrcweir // case ',':
3466cdf0e10cSrcweir // case '.':
3467cdf0e10cSrcweir // case '=':
3468cdf0e10cSrcweir // bStartEncodedWord = true;
3469cdf0e10cSrcweir // break;
3470cdf0e10cSrcweir
3471cdf0e10cSrcweir case '"':
3472cdf0e10cSrcweir if (eType != HEADER_FIELD_TEXT && nCommentLevel == 0)
3473cdf0e10cSrcweir {
3474cdf0e10cSrcweir const sal_Char * pQuotedStringEnd
3475cdf0e10cSrcweir = skipQuotedString(p - 1, pEnd);
3476cdf0e10cSrcweir p = pQuotedStringEnd == p - 1 ? pEnd : pQuotedStringEnd;
3477cdf0e10cSrcweir }
3478cdf0e10cSrcweir /* bStartEncodedWord = true; */
3479cdf0e10cSrcweir break;
3480cdf0e10cSrcweir
3481cdf0e10cSrcweir case '(':
3482cdf0e10cSrcweir if (eType != HEADER_FIELD_TEXT)
3483cdf0e10cSrcweir ++nCommentLevel;
3484cdf0e10cSrcweir /* bStartEncodedWord = true; */
3485cdf0e10cSrcweir break;
3486cdf0e10cSrcweir
3487cdf0e10cSrcweir case ')':
3488cdf0e10cSrcweir if (nCommentLevel > 0)
3489cdf0e10cSrcweir --nCommentLevel;
3490cdf0e10cSrcweir /* bStartEncodedWord = false; */
3491cdf0e10cSrcweir break;
3492cdf0e10cSrcweir
3493cdf0e10cSrcweir default:
3494cdf0e10cSrcweir {
3495cdf0e10cSrcweir const sal_Char * pUTF8Begin = p - 1;
3496cdf0e10cSrcweir const sal_Char * pUTF8End = pUTF8Begin;
3497cdf0e10cSrcweir sal_uInt32 nCharacter;
3498cdf0e10cSrcweir if (translateUTF8Char(pUTF8End, pEnd, RTL_TEXTENCODING_UCS4,
3499cdf0e10cSrcweir nCharacter))
3500cdf0e10cSrcweir {
3501cdf0e10cSrcweir appendISO88591(sDecoded, pCopyBegin, p - 1);
3502cdf0e10cSrcweir sal_Unicode aUTF16Buf[2];
3503cdf0e10cSrcweir xub_StrLen nUTF16Len = static_cast< xub_StrLen >(
3504cdf0e10cSrcweir putUTF32Character(aUTF16Buf, nCharacter) - aUTF16Buf);
3505cdf0e10cSrcweir sDecoded.Append(aUTF16Buf, nUTF16Len);
3506cdf0e10cSrcweir p = pUTF8End;
3507cdf0e10cSrcweir pCopyBegin = p;
3508cdf0e10cSrcweir }
3509cdf0e10cSrcweir /* bStartEncodedWord = false; */
3510cdf0e10cSrcweir break;
3511cdf0e10cSrcweir }
3512cdf0e10cSrcweir }
3513cdf0e10cSrcweir pWSPBegin = p;
3514cdf0e10cSrcweir }
3515cdf0e10cSrcweir
3516cdf0e10cSrcweir appendISO88591(sDecoded, pCopyBegin, pEnd);
3517cdf0e10cSrcweir return sDecoded;
3518cdf0e10cSrcweir }
3519cdf0e10cSrcweir
3520cdf0e10cSrcweir //============================================================================
3521cdf0e10cSrcweir //
3522cdf0e10cSrcweir // INetMIMEOutputSink
3523cdf0e10cSrcweir //
3524cdf0e10cSrcweir //============================================================================
3525cdf0e10cSrcweir
3526cdf0e10cSrcweir // virtual
writeSequence(const sal_Char * pSequence)3527cdf0e10cSrcweir sal_Size INetMIMEOutputSink::writeSequence(const sal_Char * pSequence)
3528cdf0e10cSrcweir {
3529cdf0e10cSrcweir sal_Size nLength = rtl_str_getLength(pSequence);
3530cdf0e10cSrcweir writeSequence(pSequence, pSequence + nLength);
3531cdf0e10cSrcweir return nLength;
3532cdf0e10cSrcweir }
3533cdf0e10cSrcweir
3534cdf0e10cSrcweir //============================================================================
3535cdf0e10cSrcweir // virtual
writeSequence(const sal_uInt32 * pBegin,const sal_uInt32 * pEnd)3536cdf0e10cSrcweir void INetMIMEOutputSink::writeSequence(const sal_uInt32 * pBegin,
3537cdf0e10cSrcweir const sal_uInt32 * pEnd)
3538cdf0e10cSrcweir {
3539cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
3540cdf0e10cSrcweir "INetMIMEOutputSink::writeSequence(): Bad sequence");
3541cdf0e10cSrcweir
3542cdf0e10cSrcweir sal_Char * pBufferBegin = new sal_Char[pEnd - pBegin];
3543cdf0e10cSrcweir sal_Char * pBufferEnd = pBufferBegin;
3544cdf0e10cSrcweir while (pBegin != pEnd)
3545cdf0e10cSrcweir {
3546cdf0e10cSrcweir DBG_ASSERT(*pBegin < 256,
3547cdf0e10cSrcweir "INetMIMEOutputSink::writeSequence(): Bad octet");
3548cdf0e10cSrcweir *pBufferEnd++ = sal_Char(*pBegin++);
3549cdf0e10cSrcweir }
3550cdf0e10cSrcweir writeSequence(pBufferBegin, pBufferEnd);
3551cdf0e10cSrcweir delete[] pBufferBegin;
3552cdf0e10cSrcweir }
3553cdf0e10cSrcweir
3554cdf0e10cSrcweir //============================================================================
3555cdf0e10cSrcweir // virtual
writeSequence(const sal_Unicode * pBegin,const sal_Unicode * pEnd)3556cdf0e10cSrcweir void INetMIMEOutputSink::writeSequence(const sal_Unicode * pBegin,
3557cdf0e10cSrcweir const sal_Unicode * pEnd)
3558cdf0e10cSrcweir {
3559cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
3560cdf0e10cSrcweir "INetMIMEOutputSink::writeSequence(): Bad sequence");
3561cdf0e10cSrcweir
3562cdf0e10cSrcweir sal_Char * pBufferBegin = new sal_Char[pEnd - pBegin];
3563cdf0e10cSrcweir sal_Char * pBufferEnd = pBufferBegin;
3564cdf0e10cSrcweir while (pBegin != pEnd)
3565cdf0e10cSrcweir {
3566cdf0e10cSrcweir DBG_ASSERT(*pBegin < 256,
3567cdf0e10cSrcweir "INetMIMEOutputSink::writeSequence(): Bad octet");
3568cdf0e10cSrcweir *pBufferEnd++ = sal_Char(*pBegin++);
3569cdf0e10cSrcweir }
3570cdf0e10cSrcweir writeSequence(pBufferBegin, pBufferEnd);
3571cdf0e10cSrcweir delete[] pBufferBegin;
3572cdf0e10cSrcweir }
3573cdf0e10cSrcweir
3574cdf0e10cSrcweir //============================================================================
3575cdf0e10cSrcweir // virtual
getError() const3576cdf0e10cSrcweir ErrCode INetMIMEOutputSink::getError() const
3577cdf0e10cSrcweir {
3578cdf0e10cSrcweir return ERRCODE_NONE;
3579cdf0e10cSrcweir }
3580cdf0e10cSrcweir
3581cdf0e10cSrcweir //============================================================================
writeLineEnd()3582cdf0e10cSrcweir void INetMIMEOutputSink::writeLineEnd()
3583cdf0e10cSrcweir {
3584cdf0e10cSrcweir static const sal_Char aCRLF[2] = { 0x0D, 0x0A };
3585cdf0e10cSrcweir writeSequence(aCRLF, aCRLF + 2);
3586cdf0e10cSrcweir m_nColumn = 0;
3587cdf0e10cSrcweir }
3588cdf0e10cSrcweir
3589cdf0e10cSrcweir //============================================================================
3590cdf0e10cSrcweir //
3591cdf0e10cSrcweir // INetMIMEStringOutputSink
3592cdf0e10cSrcweir //
3593cdf0e10cSrcweir //============================================================================
3594cdf0e10cSrcweir
3595cdf0e10cSrcweir // virtual
writeSequence(const sal_Char * pBegin,const sal_Char * pEnd)3596cdf0e10cSrcweir void INetMIMEStringOutputSink::writeSequence(const sal_Char * pBegin,
3597cdf0e10cSrcweir const sal_Char * pEnd)
3598cdf0e10cSrcweir {
3599cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
3600cdf0e10cSrcweir "INetMIMEStringOutputSink::writeSequence(): Bad sequence");
3601cdf0e10cSrcweir
3602cdf0e10cSrcweir m_bOverflow = m_bOverflow
3603cdf0e10cSrcweir || pEnd - pBegin > STRING_MAXLEN - m_aBuffer.Len();
3604cdf0e10cSrcweir if (!m_bOverflow)
3605cdf0e10cSrcweir m_aBuffer.Append(pBegin, static_cast< xub_StrLen >(pEnd - pBegin));
3606cdf0e10cSrcweir }
3607cdf0e10cSrcweir
3608cdf0e10cSrcweir //============================================================================
3609cdf0e10cSrcweir // virtual
getError() const3610cdf0e10cSrcweir ErrCode INetMIMEStringOutputSink::getError() const
3611cdf0e10cSrcweir {
3612cdf0e10cSrcweir return m_bOverflow ? ERRCODE_IO_OUTOFMEMORY : ERRCODE_NONE;
3613cdf0e10cSrcweir }
3614cdf0e10cSrcweir
3615cdf0e10cSrcweir //============================================================================
3616cdf0e10cSrcweir //
3617cdf0e10cSrcweir // INetMIMEUnicodeOutputSink
3618cdf0e10cSrcweir //
3619cdf0e10cSrcweir //============================================================================
3620cdf0e10cSrcweir
3621cdf0e10cSrcweir // virtual
writeSequence(const sal_Char * pBegin,const sal_Char * pEnd)3622cdf0e10cSrcweir void INetMIMEUnicodeOutputSink::writeSequence(const sal_Char * pBegin,
3623cdf0e10cSrcweir const sal_Char * pEnd)
3624cdf0e10cSrcweir {
3625cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
3626cdf0e10cSrcweir "INetMIMEUnicodeOutputSink::writeSequence(): Bad sequence");
3627cdf0e10cSrcweir
3628cdf0e10cSrcweir sal_Unicode * pBufferBegin = new sal_Unicode[pEnd - pBegin];
3629cdf0e10cSrcweir sal_Unicode * pBufferEnd = pBufferBegin;
3630cdf0e10cSrcweir while (pBegin != pEnd)
3631cdf0e10cSrcweir *pBufferEnd++ = sal_uChar(*pBegin++);
3632cdf0e10cSrcweir writeSequence(pBufferBegin, pBufferEnd);
3633cdf0e10cSrcweir delete[] pBufferBegin;
3634cdf0e10cSrcweir }
3635cdf0e10cSrcweir
3636cdf0e10cSrcweir //============================================================================
3637cdf0e10cSrcweir // virtual
writeSequence(const sal_uInt32 * pBegin,const sal_uInt32 * pEnd)3638cdf0e10cSrcweir void INetMIMEUnicodeOutputSink::writeSequence(const sal_uInt32 * pBegin,
3639cdf0e10cSrcweir const sal_uInt32 * pEnd)
3640cdf0e10cSrcweir {
3641cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
3642cdf0e10cSrcweir "INetMIMEUnicodeOutputSink::writeSequence(): Bad sequence");
3643cdf0e10cSrcweir
3644cdf0e10cSrcweir sal_Unicode * pBufferBegin = new sal_Unicode[pEnd - pBegin];
3645cdf0e10cSrcweir sal_Unicode * pBufferEnd = pBufferBegin;
3646cdf0e10cSrcweir while (pBegin != pEnd)
3647cdf0e10cSrcweir {
3648cdf0e10cSrcweir DBG_ASSERT(*pBegin < 256,
3649cdf0e10cSrcweir "INetMIMEOutputSink::writeSequence(): Bad octet");
3650cdf0e10cSrcweir *pBufferEnd++ = sal_Unicode(*pBegin++);
3651cdf0e10cSrcweir }
3652cdf0e10cSrcweir writeSequence(pBufferBegin, pBufferEnd);
3653cdf0e10cSrcweir delete[] pBufferBegin;
3654cdf0e10cSrcweir }
3655cdf0e10cSrcweir
3656cdf0e10cSrcweir //============================================================================
3657cdf0e10cSrcweir // virtual
writeSequence(const sal_Unicode * pBegin,const sal_Unicode * pEnd)3658cdf0e10cSrcweir void INetMIMEUnicodeOutputSink::writeSequence(const sal_Unicode * pBegin,
3659cdf0e10cSrcweir const sal_Unicode * pEnd)
3660cdf0e10cSrcweir {
3661cdf0e10cSrcweir DBG_ASSERT(pBegin && pBegin <= pEnd,
3662cdf0e10cSrcweir "INetMIMEUnicodeOutputSink::writeSequence(): Bad sequence");
3663cdf0e10cSrcweir
3664cdf0e10cSrcweir m_bOverflow = m_bOverflow
3665cdf0e10cSrcweir || pEnd - pBegin > STRING_MAXLEN - m_aBuffer.Len();
3666cdf0e10cSrcweir if (!m_bOverflow)
3667cdf0e10cSrcweir m_aBuffer.Append(pBegin, static_cast< xub_StrLen >(pEnd - pBegin));
3668cdf0e10cSrcweir }
3669cdf0e10cSrcweir
3670cdf0e10cSrcweir //============================================================================
3671cdf0e10cSrcweir // virtual
getError() const3672cdf0e10cSrcweir ErrCode INetMIMEUnicodeOutputSink::getError() const
3673cdf0e10cSrcweir {
3674cdf0e10cSrcweir return m_bOverflow ? ERRCODE_IO_OUTOFMEMORY : ERRCODE_NONE;
3675cdf0e10cSrcweir }
3676cdf0e10cSrcweir
3677cdf0e10cSrcweir //============================================================================
3678cdf0e10cSrcweir //
3679cdf0e10cSrcweir // INetMIMEEncodedWordOutputSink
3680cdf0e10cSrcweir //
3681cdf0e10cSrcweir //============================================================================
3682cdf0e10cSrcweir
3683cdf0e10cSrcweir static const sal_Char aEscape[128]
3684cdf0e10cSrcweir = { INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x00
3685cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x01
3686cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x02
3687cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x03
3688cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x04
3689cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x05
3690cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x06
3691cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x07
3692cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x08
3693cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x09
3694cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x0A
3695cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x0B
3696cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x0C
3697cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x0D
3698cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x0E
3699cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x0F
3700cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x10
3701cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x11
3702cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x12
3703cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x13
3704cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x14
3705cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x15
3706cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x16
3707cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x17
3708cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x18
3709cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x19
3710cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x1A
3711cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x1B
3712cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x1C
3713cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x1D
3714cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x1E
3715cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // 0x1F
3716cdf0e10cSrcweir 0, // ' '
3717cdf0e10cSrcweir 0, // '!'
3718cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '"'
3719cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '#'
3720cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '$'
3721cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '%'
3722cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '&'
3723cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '''
3724cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '('
3725cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // ')'
3726cdf0e10cSrcweir 0, // '*'
3727cdf0e10cSrcweir 0, // '+'
3728cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // ','
3729cdf0e10cSrcweir 0, // '-'
3730cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '.'
3731cdf0e10cSrcweir 0, // '/'
3732cdf0e10cSrcweir 0, // '0'
3733cdf0e10cSrcweir 0, // '1'
3734cdf0e10cSrcweir 0, // '2'
3735cdf0e10cSrcweir 0, // '3'
3736cdf0e10cSrcweir 0, // '4'
3737cdf0e10cSrcweir 0, // '5'
3738cdf0e10cSrcweir 0, // '6'
3739cdf0e10cSrcweir 0, // '7'
3740cdf0e10cSrcweir 0, // '8'
3741cdf0e10cSrcweir 0, // '9'
3742cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // ':'
3743cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // ';'
3744cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '<'
3745cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '='
3746cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '>'
3747cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '?'
3748cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '@'
3749cdf0e10cSrcweir 0, // 'A'
3750cdf0e10cSrcweir 0, // 'B'
3751cdf0e10cSrcweir 0, // 'C'
3752cdf0e10cSrcweir 0, // 'D'
3753cdf0e10cSrcweir 0, // 'E'
3754cdf0e10cSrcweir 0, // 'F'
3755cdf0e10cSrcweir 0, // 'G'
3756cdf0e10cSrcweir 0, // 'H'
3757cdf0e10cSrcweir 0, // 'I'
3758cdf0e10cSrcweir 0, // 'J'
3759cdf0e10cSrcweir 0, // 'K'
3760cdf0e10cSrcweir 0, // 'L'
3761cdf0e10cSrcweir 0, // 'M'
3762cdf0e10cSrcweir 0, // 'N'
3763cdf0e10cSrcweir 0, // 'O'
3764cdf0e10cSrcweir 0, // 'P'
3765cdf0e10cSrcweir 0, // 'Q'
3766cdf0e10cSrcweir 0, // 'R'
3767cdf0e10cSrcweir 0, // 'S'
3768cdf0e10cSrcweir 0, // 'T'
3769cdf0e10cSrcweir 0, // 'U'
3770cdf0e10cSrcweir 0, // 'V'
3771cdf0e10cSrcweir 0, // 'W'
3772cdf0e10cSrcweir 0, // 'X'
3773cdf0e10cSrcweir 0, // 'Y'
3774cdf0e10cSrcweir 0, // 'Z'
3775cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '['
3776cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '\'
3777cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // ']'
3778cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '^'
3779cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '_'
3780cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '`'
3781cdf0e10cSrcweir 0, // 'a'
3782cdf0e10cSrcweir 0, // 'b'
3783cdf0e10cSrcweir 0, // 'c'
3784cdf0e10cSrcweir 0, // 'd'
3785cdf0e10cSrcweir 0, // 'e'
3786cdf0e10cSrcweir 0, // 'f'
3787cdf0e10cSrcweir 0, // 'g'
3788cdf0e10cSrcweir 0, // 'h'
3789cdf0e10cSrcweir 0, // 'i'
3790cdf0e10cSrcweir 0, // 'j'
3791cdf0e10cSrcweir 0, // 'k'
3792cdf0e10cSrcweir 0, // 'l'
3793cdf0e10cSrcweir 0, // 'm'
3794cdf0e10cSrcweir 0, // 'n'
3795cdf0e10cSrcweir 0, // 'o'
3796cdf0e10cSrcweir 0, // 'p'
3797cdf0e10cSrcweir 0, // 'q'
3798cdf0e10cSrcweir 0, // 'r'
3799cdf0e10cSrcweir 0, // 's'
3800cdf0e10cSrcweir 0, // 't'
3801cdf0e10cSrcweir 0, // 'u'
3802cdf0e10cSrcweir 0, // 'v'
3803cdf0e10cSrcweir 0, // 'w'
3804cdf0e10cSrcweir 0, // 'x'
3805cdf0e10cSrcweir 0, // 'y'
3806cdf0e10cSrcweir 0, // 'z'
3807cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '{'
3808cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '|'
3809cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '}'
3810cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, // '~'
3811cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::CONTEXT_TEXT | INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT | INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE }; // DEL
3812cdf0e10cSrcweir
3813cdf0e10cSrcweir inline bool
needsEncodedWordEscape(sal_uInt32 nChar) const3814cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::needsEncodedWordEscape(sal_uInt32 nChar) const
3815cdf0e10cSrcweir {
3816cdf0e10cSrcweir return !INetMIME::isUSASCII(nChar) || aEscape[nChar] & m_eContext;
3817cdf0e10cSrcweir }
3818cdf0e10cSrcweir
3819cdf0e10cSrcweir //============================================================================
finish(bool bWriteTrailer)3820cdf0e10cSrcweir void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
3821cdf0e10cSrcweir {
3822cdf0e10cSrcweir if (m_eInitialSpace == SPACE_ALWAYS && m_nExtraSpaces == 0)
3823cdf0e10cSrcweir m_nExtraSpaces = 1;
3824cdf0e10cSrcweir
3825cdf0e10cSrcweir if (m_eEncodedWordState == STATE_SECOND_EQUALS)
3826cdf0e10cSrcweir {
3827cdf0e10cSrcweir // If the text is already an encoded word, copy it verbatim:
3828cdf0e10cSrcweir sal_uInt32 nSize = m_pBufferEnd - m_pBuffer;
3829cdf0e10cSrcweir switch (m_ePrevCoding)
3830cdf0e10cSrcweir {
3831cdf0e10cSrcweir case CODING_QUOTED:
3832cdf0e10cSrcweir m_rSink << '"';
3833cdf0e10cSrcweir case CODING_NONE:
3834cdf0e10cSrcweir if (m_eInitialSpace == SPACE_ENCODED && m_nExtraSpaces == 0)
3835cdf0e10cSrcweir m_nExtraSpaces = 1;
3836cdf0e10cSrcweir for (; m_nExtraSpaces > 1; --m_nExtraSpaces)
3837cdf0e10cSrcweir {
3838cdf0e10cSrcweir if (m_rSink.getColumn() >= m_rSink.getLineLengthLimit())
3839cdf0e10cSrcweir m_rSink << INetMIMEOutputSink::endl;
3840cdf0e10cSrcweir m_rSink << ' ';
3841cdf0e10cSrcweir }
3842cdf0e10cSrcweir if (m_nExtraSpaces == 1)
3843cdf0e10cSrcweir {
3844cdf0e10cSrcweir if (m_rSink.getColumn() + nSize
3845cdf0e10cSrcweir >= m_rSink.getLineLengthLimit())
3846cdf0e10cSrcweir m_rSink << INetMIMEOutputSink::endl;
3847cdf0e10cSrcweir m_rSink << ' ';
3848cdf0e10cSrcweir }
3849cdf0e10cSrcweir break;
3850cdf0e10cSrcweir
3851cdf0e10cSrcweir case CODING_ENCODED:
3852cdf0e10cSrcweir {
3853cdf0e10cSrcweir const sal_Char * pCharsetName
3854cdf0e10cSrcweir = INetMIME::getCharsetName(m_ePrevMIMEEncoding);
3855cdf0e10cSrcweir while (m_nExtraSpaces-- > 0)
3856cdf0e10cSrcweir {
3857cdf0e10cSrcweir if (m_rSink.getColumn()
3858cdf0e10cSrcweir > m_rSink.getLineLengthLimit() - 3)
3859cdf0e10cSrcweir m_rSink << "?=" << INetMIMEOutputSink::endl << " =?"
3860cdf0e10cSrcweir << pCharsetName << "?Q?";
3861cdf0e10cSrcweir m_rSink << '_';
3862cdf0e10cSrcweir }
3863cdf0e10cSrcweir m_rSink << "?=";
3864cdf0e10cSrcweir }
3865cdf0e10cSrcweir case CODING_ENCODED_TERMINATED:
3866cdf0e10cSrcweir if (m_rSink.getColumn() + nSize
3867cdf0e10cSrcweir > m_rSink.getLineLengthLimit() - 1)
3868cdf0e10cSrcweir m_rSink << INetMIMEOutputSink::endl;
3869cdf0e10cSrcweir m_rSink << ' ';
3870cdf0e10cSrcweir break;
3871cdf0e10cSrcweir }
3872cdf0e10cSrcweir m_rSink.write(m_pBuffer, m_pBufferEnd);
3873cdf0e10cSrcweir m_eCoding = CODING_ENCODED_TERMINATED;
3874cdf0e10cSrcweir }
3875cdf0e10cSrcweir else
3876cdf0e10cSrcweir {
3877cdf0e10cSrcweir // If the text itself is too long to fit into a single line, make it
3878cdf0e10cSrcweir // into multiple encoded words:
3879cdf0e10cSrcweir switch (m_eCoding)
3880cdf0e10cSrcweir {
3881cdf0e10cSrcweir case CODING_NONE:
3882cdf0e10cSrcweir if (m_nExtraSpaces == 0)
3883cdf0e10cSrcweir {
3884cdf0e10cSrcweir DBG_ASSERT(m_ePrevCoding == CODING_NONE
3885cdf0e10cSrcweir || m_pBuffer == m_pBufferEnd,
3886cdf0e10cSrcweir "INetMIMEEncodedWordOutputSink::finish():"
3887cdf0e10cSrcweir " Bad state");
3888cdf0e10cSrcweir if (m_rSink.getColumn() + (m_pBufferEnd - m_pBuffer)
3889cdf0e10cSrcweir > m_rSink.getLineLengthLimit())
3890cdf0e10cSrcweir m_eCoding = CODING_ENCODED;
3891cdf0e10cSrcweir }
3892cdf0e10cSrcweir else
3893cdf0e10cSrcweir {
3894cdf0e10cSrcweir OSL_ASSERT(m_pBufferEnd >= m_pBuffer);
3895cdf0e10cSrcweir if (static_cast< std::size_t >(m_pBufferEnd - m_pBuffer)
3896cdf0e10cSrcweir > m_rSink.getLineLengthLimit() - 1)
3897cdf0e10cSrcweir {
3898cdf0e10cSrcweir m_eCoding = CODING_ENCODED;
3899cdf0e10cSrcweir }
3900cdf0e10cSrcweir }
3901cdf0e10cSrcweir break;
3902cdf0e10cSrcweir
3903cdf0e10cSrcweir case CODING_QUOTED:
3904cdf0e10cSrcweir if (m_nExtraSpaces == 0)
3905cdf0e10cSrcweir {
3906cdf0e10cSrcweir DBG_ASSERT(m_ePrevCoding == CODING_NONE,
3907cdf0e10cSrcweir "INetMIMEEncodedWordOutputSink::finish():"
3908cdf0e10cSrcweir " Bad state");
3909cdf0e10cSrcweir if (m_rSink.getColumn() + (m_pBufferEnd - m_pBuffer)
3910cdf0e10cSrcweir + m_nQuotedEscaped
3911cdf0e10cSrcweir > m_rSink.getLineLengthLimit() - 2)
3912cdf0e10cSrcweir m_eCoding = CODING_ENCODED;
3913cdf0e10cSrcweir }
3914cdf0e10cSrcweir else if ((m_pBufferEnd - m_pBuffer) + m_nQuotedEscaped
3915cdf0e10cSrcweir > m_rSink.getLineLengthLimit() - 3)
3916cdf0e10cSrcweir m_eCoding = CODING_ENCODED;
3917cdf0e10cSrcweir break;
3918cdf0e10cSrcweir
3919cdf0e10cSrcweir default:
3920cdf0e10cSrcweir break;
3921cdf0e10cSrcweir }
3922cdf0e10cSrcweir
3923cdf0e10cSrcweir switch (m_eCoding)
3924cdf0e10cSrcweir {
3925cdf0e10cSrcweir case CODING_NONE:
3926cdf0e10cSrcweir switch (m_ePrevCoding)
3927cdf0e10cSrcweir {
3928cdf0e10cSrcweir case CODING_QUOTED:
3929cdf0e10cSrcweir if (m_rSink.getColumn() + m_nExtraSpaces
3930cdf0e10cSrcweir + (m_pBufferEnd - m_pBuffer)
3931cdf0e10cSrcweir < m_rSink.getLineLengthLimit())
3932cdf0e10cSrcweir m_eCoding = CODING_QUOTED;
3933cdf0e10cSrcweir else
3934cdf0e10cSrcweir m_rSink << '"';
3935cdf0e10cSrcweir break;
3936cdf0e10cSrcweir
3937cdf0e10cSrcweir case CODING_ENCODED:
3938cdf0e10cSrcweir m_rSink << "?=";
3939cdf0e10cSrcweir break;
3940cdf0e10cSrcweir
3941cdf0e10cSrcweir default:
3942cdf0e10cSrcweir break;
3943cdf0e10cSrcweir }
3944cdf0e10cSrcweir for (; m_nExtraSpaces > 1; --m_nExtraSpaces)
3945cdf0e10cSrcweir {
3946cdf0e10cSrcweir if (m_rSink.getColumn() >= m_rSink.getLineLengthLimit())
3947cdf0e10cSrcweir m_rSink << INetMIMEOutputSink::endl;
3948cdf0e10cSrcweir m_rSink << ' ';
3949cdf0e10cSrcweir }
3950cdf0e10cSrcweir if (m_nExtraSpaces == 1)
3951cdf0e10cSrcweir {
3952cdf0e10cSrcweir if (m_rSink.getColumn() + (m_pBufferEnd - m_pBuffer)
3953cdf0e10cSrcweir >= m_rSink.getLineLengthLimit())
3954cdf0e10cSrcweir m_rSink << INetMIMEOutputSink::endl;
3955cdf0e10cSrcweir m_rSink << ' ';
3956cdf0e10cSrcweir }
3957cdf0e10cSrcweir m_rSink.write(m_pBuffer, m_pBufferEnd);
3958cdf0e10cSrcweir if (m_eCoding == CODING_QUOTED && bWriteTrailer)
3959cdf0e10cSrcweir {
3960cdf0e10cSrcweir m_rSink << '"';
3961cdf0e10cSrcweir m_eCoding = CODING_NONE;
3962cdf0e10cSrcweir }
3963cdf0e10cSrcweir break;
3964cdf0e10cSrcweir
3965cdf0e10cSrcweir case CODING_QUOTED:
3966cdf0e10cSrcweir {
3967cdf0e10cSrcweir bool bInsertLeadingQuote = true;
3968cdf0e10cSrcweir sal_uInt32 nSize = (m_pBufferEnd - m_pBuffer)
3969cdf0e10cSrcweir + m_nQuotedEscaped + 2;
3970cdf0e10cSrcweir switch (m_ePrevCoding)
3971cdf0e10cSrcweir {
3972cdf0e10cSrcweir case CODING_QUOTED:
3973cdf0e10cSrcweir if (m_rSink.getColumn() + m_nExtraSpaces + nSize - 1
3974cdf0e10cSrcweir < m_rSink.getLineLengthLimit())
3975cdf0e10cSrcweir {
3976cdf0e10cSrcweir bInsertLeadingQuote = false;
3977cdf0e10cSrcweir --nSize;
3978cdf0e10cSrcweir }
3979cdf0e10cSrcweir else
3980cdf0e10cSrcweir m_rSink << '"';
3981cdf0e10cSrcweir break;
3982cdf0e10cSrcweir
3983cdf0e10cSrcweir case CODING_ENCODED:
3984cdf0e10cSrcweir m_rSink << "?=";
3985cdf0e10cSrcweir break;
3986cdf0e10cSrcweir
3987cdf0e10cSrcweir default:
3988cdf0e10cSrcweir break;
3989cdf0e10cSrcweir }
3990cdf0e10cSrcweir for (; m_nExtraSpaces > 1; --m_nExtraSpaces)
3991cdf0e10cSrcweir {
3992cdf0e10cSrcweir if (m_rSink.getColumn() >= m_rSink.getLineLengthLimit())
3993cdf0e10cSrcweir m_rSink << INetMIMEOutputSink::endl;
3994cdf0e10cSrcweir m_rSink << ' ';
3995cdf0e10cSrcweir }
3996cdf0e10cSrcweir if (m_nExtraSpaces == 1)
3997cdf0e10cSrcweir {
3998cdf0e10cSrcweir if (m_rSink.getColumn() + nSize
3999cdf0e10cSrcweir >= m_rSink.getLineLengthLimit())
4000cdf0e10cSrcweir m_rSink << INetMIMEOutputSink::endl;
4001cdf0e10cSrcweir m_rSink << ' ';
4002cdf0e10cSrcweir }
4003cdf0e10cSrcweir if (bInsertLeadingQuote)
4004cdf0e10cSrcweir m_rSink << '"';
4005cdf0e10cSrcweir for (const sal_Unicode * p = m_pBuffer; p != m_pBufferEnd;
4006cdf0e10cSrcweir ++p)
4007cdf0e10cSrcweir {
4008cdf0e10cSrcweir if (INetMIME::needsQuotedStringEscape(*p))
4009cdf0e10cSrcweir m_rSink << '\\';
4010cdf0e10cSrcweir m_rSink << sal_Char(*p);
4011cdf0e10cSrcweir }
4012cdf0e10cSrcweir if (bWriteTrailer)
4013cdf0e10cSrcweir {
4014cdf0e10cSrcweir m_rSink << '"';
4015cdf0e10cSrcweir m_eCoding = CODING_NONE;
4016cdf0e10cSrcweir }
4017cdf0e10cSrcweir break;
4018cdf0e10cSrcweir }
4019cdf0e10cSrcweir
4020cdf0e10cSrcweir case CODING_ENCODED:
4021cdf0e10cSrcweir {
4022cdf0e10cSrcweir rtl_TextEncoding eCharsetEncoding
4023cdf0e10cSrcweir = m_pEncodingList->
4024cdf0e10cSrcweir getPreferredEncoding(RTL_TEXTENCODING_UTF8);
4025cdf0e10cSrcweir rtl_TextEncoding eMIMEEncoding
4026cdf0e10cSrcweir = INetMIME::translateToMIME(eCharsetEncoding);
4027cdf0e10cSrcweir
4028cdf0e10cSrcweir // The non UTF-8 code will only work for stateless single byte
4029cdf0e10cSrcweir // character encodings (see also below):
4030cdf0e10cSrcweir sal_Char * pTargetBuffer = NULL;
4031cdf0e10cSrcweir sal_Size nTargetSize = 0;
4032cdf0e10cSrcweir sal_uInt32 nSize;
4033cdf0e10cSrcweir if (eMIMEEncoding == RTL_TEXTENCODING_UTF8)
4034cdf0e10cSrcweir {
4035cdf0e10cSrcweir nSize = 0;
4036cdf0e10cSrcweir for (sal_Unicode const * p = m_pBuffer;
4037cdf0e10cSrcweir p != m_pBufferEnd;)
4038cdf0e10cSrcweir {
4039cdf0e10cSrcweir sal_uInt32 nUTF32
4040cdf0e10cSrcweir = INetMIME::getUTF32Character(p, m_pBufferEnd);
4041cdf0e10cSrcweir nSize += needsEncodedWordEscape(nUTF32) ?
4042cdf0e10cSrcweir 3 * INetMIME::getUTF8OctetCount(nUTF32) :
4043cdf0e10cSrcweir 1;
4044cdf0e10cSrcweir // only US-ASCII characters (that are converted to
4045cdf0e10cSrcweir // a single byte by UTF-8) need no encoded word
4046cdf0e10cSrcweir // escapes...
4047cdf0e10cSrcweir }
4048cdf0e10cSrcweir }
4049cdf0e10cSrcweir else
4050cdf0e10cSrcweir {
4051cdf0e10cSrcweir rtl_UnicodeToTextConverter hConverter
4052cdf0e10cSrcweir = rtl_createUnicodeToTextConverter(eCharsetEncoding);
4053cdf0e10cSrcweir rtl_UnicodeToTextContext hContext
4054cdf0e10cSrcweir = rtl_createUnicodeToTextContext(hConverter);
4055cdf0e10cSrcweir for (sal_Size nBufferSize = m_pBufferEnd - m_pBuffer;;
4056cdf0e10cSrcweir nBufferSize += nBufferSize / 3 + 1)
4057cdf0e10cSrcweir {
4058cdf0e10cSrcweir pTargetBuffer = new sal_Char[nBufferSize];
4059cdf0e10cSrcweir sal_uInt32 nInfo;
4060cdf0e10cSrcweir sal_Size nSrcCvtBytes;
4061cdf0e10cSrcweir nTargetSize
4062cdf0e10cSrcweir = rtl_convertUnicodeToText(
4063cdf0e10cSrcweir hConverter, hContext, m_pBuffer,
4064cdf0e10cSrcweir m_pBufferEnd - m_pBuffer, pTargetBuffer,
4065cdf0e10cSrcweir nBufferSize,
4066cdf0e10cSrcweir RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
4067cdf0e10cSrcweir | RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE,
4068cdf0e10cSrcweir &nInfo, &nSrcCvtBytes);
4069cdf0e10cSrcweir if (!(nInfo
4070cdf0e10cSrcweir & RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL))
4071cdf0e10cSrcweir break;
4072cdf0e10cSrcweir delete[] pTargetBuffer;
4073cdf0e10cSrcweir pTargetBuffer = NULL;
4074cdf0e10cSrcweir rtl_resetUnicodeToTextContext(hConverter, hContext);
4075cdf0e10cSrcweir }
4076cdf0e10cSrcweir rtl_destroyUnicodeToTextContext(hConverter, hContext);
4077cdf0e10cSrcweir rtl_destroyUnicodeToTextConverter(hConverter);
4078cdf0e10cSrcweir
4079cdf0e10cSrcweir nSize = nTargetSize;
4080cdf0e10cSrcweir for (sal_Size k = 0; k < nTargetSize; ++k)
4081cdf0e10cSrcweir if (needsEncodedWordEscape(sal_uChar(
4082cdf0e10cSrcweir pTargetBuffer[k])))
4083cdf0e10cSrcweir nSize += 2;
4084cdf0e10cSrcweir }
4085cdf0e10cSrcweir
4086cdf0e10cSrcweir const sal_Char * pCharsetName
4087cdf0e10cSrcweir = INetMIME::getCharsetName(eMIMEEncoding);
4088cdf0e10cSrcweir sal_uInt32 nWrapperSize = rtl_str_getLength(pCharsetName) + 7;
4089cdf0e10cSrcweir // '=?', '?Q?', '?='
4090cdf0e10cSrcweir
4091cdf0e10cSrcweir switch (m_ePrevCoding)
4092cdf0e10cSrcweir {
4093cdf0e10cSrcweir case CODING_QUOTED:
4094cdf0e10cSrcweir m_rSink << '"';
4095cdf0e10cSrcweir case CODING_NONE:
4096cdf0e10cSrcweir if (m_eInitialSpace == SPACE_ENCODED
4097cdf0e10cSrcweir && m_nExtraSpaces == 0)
4098cdf0e10cSrcweir m_nExtraSpaces = 1;
4099cdf0e10cSrcweir nSize += nWrapperSize;
4100cdf0e10cSrcweir for (; m_nExtraSpaces > 1; --m_nExtraSpaces)
4101cdf0e10cSrcweir {
4102cdf0e10cSrcweir if (m_rSink.getColumn()
4103cdf0e10cSrcweir >= m_rSink.getLineLengthLimit())
4104cdf0e10cSrcweir m_rSink << INetMIMEOutputSink::endl;
4105cdf0e10cSrcweir m_rSink << ' ';
4106cdf0e10cSrcweir }
4107cdf0e10cSrcweir if (m_nExtraSpaces == 1)
4108cdf0e10cSrcweir {
4109cdf0e10cSrcweir if (m_rSink.getColumn() + nSize
4110cdf0e10cSrcweir >= m_rSink.getLineLengthLimit())
4111cdf0e10cSrcweir m_rSink << INetMIMEOutputSink::endl;
4112cdf0e10cSrcweir m_rSink << ' ';
4113cdf0e10cSrcweir }
4114cdf0e10cSrcweir m_rSink << "=?" << pCharsetName << "?Q?";
4115cdf0e10cSrcweir break;
4116cdf0e10cSrcweir
4117cdf0e10cSrcweir case CODING_ENCODED:
4118cdf0e10cSrcweir if (m_ePrevMIMEEncoding != eMIMEEncoding
4119cdf0e10cSrcweir || m_rSink.getColumn() + m_nExtraSpaces + nSize
4120cdf0e10cSrcweir > m_rSink.getLineLengthLimit() - 2)
4121cdf0e10cSrcweir {
4122cdf0e10cSrcweir m_rSink << "?=";
4123cdf0e10cSrcweir if (m_rSink.getColumn() + nWrapperSize
4124cdf0e10cSrcweir + m_nExtraSpaces + nSize
4125cdf0e10cSrcweir > m_rSink.getLineLengthLimit() - 1)
4126cdf0e10cSrcweir m_rSink << INetMIMEOutputSink::endl;
4127cdf0e10cSrcweir m_rSink << " =?" << pCharsetName << "?Q?";
4128cdf0e10cSrcweir }
4129cdf0e10cSrcweir while (m_nExtraSpaces-- > 0)
4130cdf0e10cSrcweir {
4131cdf0e10cSrcweir if (m_rSink.getColumn()
4132cdf0e10cSrcweir > m_rSink.getLineLengthLimit() - 3)
4133cdf0e10cSrcweir m_rSink << "?=" << INetMIMEOutputSink::endl
4134cdf0e10cSrcweir << " =?" << pCharsetName << "?Q?";
4135cdf0e10cSrcweir m_rSink << '_';
4136cdf0e10cSrcweir }
4137cdf0e10cSrcweir break;
4138cdf0e10cSrcweir
4139cdf0e10cSrcweir case CODING_ENCODED_TERMINATED:
4140cdf0e10cSrcweir if (m_rSink.getColumn() + nWrapperSize
4141cdf0e10cSrcweir + m_nExtraSpaces + nSize
4142cdf0e10cSrcweir > m_rSink.getLineLengthLimit() - 1)
4143cdf0e10cSrcweir m_rSink << INetMIMEOutputSink::endl;
4144cdf0e10cSrcweir m_rSink << " =?" << pCharsetName << "?Q?";
4145cdf0e10cSrcweir while (m_nExtraSpaces-- > 0)
4146cdf0e10cSrcweir {
4147cdf0e10cSrcweir if (m_rSink.getColumn()
4148cdf0e10cSrcweir > m_rSink.getLineLengthLimit() - 3)
4149cdf0e10cSrcweir m_rSink << "?=" << INetMIMEOutputSink::endl
4150cdf0e10cSrcweir << " =?" << pCharsetName << "?Q?";
4151cdf0e10cSrcweir m_rSink << '_';
4152cdf0e10cSrcweir }
4153cdf0e10cSrcweir break;
4154cdf0e10cSrcweir }
4155cdf0e10cSrcweir
4156cdf0e10cSrcweir // The non UTF-8 code will only work for stateless single byte
4157cdf0e10cSrcweir // character encodings (see also above):
4158cdf0e10cSrcweir if (eMIMEEncoding == RTL_TEXTENCODING_UTF8)
4159cdf0e10cSrcweir {
4160cdf0e10cSrcweir bool bInitial = true;
4161cdf0e10cSrcweir for (sal_Unicode const * p = m_pBuffer;
4162cdf0e10cSrcweir p != m_pBufferEnd;)
4163cdf0e10cSrcweir {
4164cdf0e10cSrcweir sal_uInt32 nUTF32
4165cdf0e10cSrcweir = INetMIME::getUTF32Character(p, m_pBufferEnd);
4166cdf0e10cSrcweir bool bEscape = needsEncodedWordEscape(nUTF32);
4167cdf0e10cSrcweir sal_uInt32 nWidth
4168cdf0e10cSrcweir = bEscape ?
4169cdf0e10cSrcweir 3 * INetMIME::getUTF8OctetCount(nUTF32) : 1;
4170cdf0e10cSrcweir // only US-ASCII characters (that are converted to
4171cdf0e10cSrcweir // a single byte by UTF-8) need no encoded word
4172cdf0e10cSrcweir // escapes...
4173cdf0e10cSrcweir if (!bInitial
4174cdf0e10cSrcweir && m_rSink.getColumn() + nWidth + 2
4175cdf0e10cSrcweir > m_rSink.getLineLengthLimit())
4176cdf0e10cSrcweir m_rSink << "?=" << INetMIMEOutputSink::endl
4177cdf0e10cSrcweir << " =?" << pCharsetName << "?Q?";
4178cdf0e10cSrcweir if (bEscape)
4179cdf0e10cSrcweir {
4180cdf0e10cSrcweir DBG_ASSERT(
4181cdf0e10cSrcweir nUTF32 < 0x10FFFF,
4182cdf0e10cSrcweir "INetMIMEEncodedWordOutputSink::finish():"
4183cdf0e10cSrcweir " Bad char");
4184cdf0e10cSrcweir if (nUTF32 < 0x80)
4185cdf0e10cSrcweir INetMIME::writeEscapeSequence(m_rSink,
4186cdf0e10cSrcweir nUTF32);
4187cdf0e10cSrcweir else if (nUTF32 < 0x800)
4188cdf0e10cSrcweir {
4189cdf0e10cSrcweir INetMIME::writeEscapeSequence(m_rSink,
4190cdf0e10cSrcweir (nUTF32 >> 6)
4191cdf0e10cSrcweir | 0xC0);
4192cdf0e10cSrcweir INetMIME::writeEscapeSequence(m_rSink,
4193cdf0e10cSrcweir (nUTF32 & 0x3F)
4194cdf0e10cSrcweir | 0x80);
4195cdf0e10cSrcweir }
4196cdf0e10cSrcweir else if (nUTF32 < 0x10000)
4197cdf0e10cSrcweir {
4198cdf0e10cSrcweir INetMIME::writeEscapeSequence(m_rSink,
4199cdf0e10cSrcweir (nUTF32 >> 12)
4200cdf0e10cSrcweir | 0xE0);
4201cdf0e10cSrcweir INetMIME::writeEscapeSequence(m_rSink,
4202cdf0e10cSrcweir ((nUTF32 >> 6)
4203cdf0e10cSrcweir & 0x3F)
4204cdf0e10cSrcweir | 0x80);
4205cdf0e10cSrcweir INetMIME::writeEscapeSequence(m_rSink,
4206cdf0e10cSrcweir (nUTF32 & 0x3F)
4207cdf0e10cSrcweir | 0x80);
4208cdf0e10cSrcweir }
4209cdf0e10cSrcweir else
4210cdf0e10cSrcweir {
4211cdf0e10cSrcweir INetMIME::writeEscapeSequence(m_rSink,
4212cdf0e10cSrcweir (nUTF32 >> 18)
4213cdf0e10cSrcweir | 0xF0);
4214cdf0e10cSrcweir INetMIME::writeEscapeSequence(m_rSink,
4215cdf0e10cSrcweir ((nUTF32 >> 12)
4216cdf0e10cSrcweir & 0x3F)
4217cdf0e10cSrcweir | 0x80);
4218cdf0e10cSrcweir INetMIME::writeEscapeSequence(m_rSink,
4219cdf0e10cSrcweir ((nUTF32 >> 6)
4220cdf0e10cSrcweir & 0x3F)
4221cdf0e10cSrcweir | 0x80);
4222cdf0e10cSrcweir INetMIME::writeEscapeSequence(m_rSink,
4223cdf0e10cSrcweir (nUTF32 & 0x3F)
4224cdf0e10cSrcweir | 0x80);
4225cdf0e10cSrcweir }
4226cdf0e10cSrcweir }
4227cdf0e10cSrcweir else
4228cdf0e10cSrcweir m_rSink << sal_Char(nUTF32);
4229cdf0e10cSrcweir bInitial = false;
4230cdf0e10cSrcweir }
4231cdf0e10cSrcweir }
4232cdf0e10cSrcweir else
4233cdf0e10cSrcweir {
4234cdf0e10cSrcweir for (sal_Size k = 0; k < nTargetSize; ++k)
4235cdf0e10cSrcweir {
4236cdf0e10cSrcweir sal_uInt32 nUCS4 = sal_uChar(pTargetBuffer[k]);
4237cdf0e10cSrcweir bool bEscape = needsEncodedWordEscape(nUCS4);
4238cdf0e10cSrcweir if (k > 0
4239cdf0e10cSrcweir && m_rSink.getColumn() + (bEscape ? 5 : 3)
4240cdf0e10cSrcweir > m_rSink.getLineLengthLimit())
4241cdf0e10cSrcweir m_rSink << "?=" << INetMIMEOutputSink::endl
4242cdf0e10cSrcweir << " =?" << pCharsetName << "?Q?";
4243cdf0e10cSrcweir if (bEscape)
4244cdf0e10cSrcweir INetMIME::writeEscapeSequence(m_rSink, nUCS4);
4245cdf0e10cSrcweir else
4246cdf0e10cSrcweir m_rSink << sal_Char(nUCS4);
4247cdf0e10cSrcweir }
4248cdf0e10cSrcweir delete[] pTargetBuffer;
4249cdf0e10cSrcweir }
4250cdf0e10cSrcweir
4251cdf0e10cSrcweir if (bWriteTrailer)
4252cdf0e10cSrcweir {
4253cdf0e10cSrcweir m_rSink << "?=";
4254cdf0e10cSrcweir m_eCoding = CODING_ENCODED_TERMINATED;
4255cdf0e10cSrcweir }
4256cdf0e10cSrcweir
4257cdf0e10cSrcweir m_ePrevMIMEEncoding = eMIMEEncoding;
4258cdf0e10cSrcweir break;
4259cdf0e10cSrcweir }
4260cdf0e10cSrcweir
4261cdf0e10cSrcweir default:
4262cdf0e10cSrcweir OSL_ASSERT(false);
4263cdf0e10cSrcweir break;
4264cdf0e10cSrcweir }
4265cdf0e10cSrcweir }
4266cdf0e10cSrcweir
4267cdf0e10cSrcweir m_eInitialSpace = SPACE_NO;
4268cdf0e10cSrcweir m_nExtraSpaces = 0;
4269cdf0e10cSrcweir m_pEncodingList->reset();
4270cdf0e10cSrcweir m_pBufferEnd = m_pBuffer;
4271cdf0e10cSrcweir m_ePrevCoding = m_eCoding;
4272cdf0e10cSrcweir m_eCoding = CODING_NONE;
4273cdf0e10cSrcweir m_nQuotedEscaped = 0;
4274cdf0e10cSrcweir m_eEncodedWordState = STATE_INITIAL;
4275cdf0e10cSrcweir }
4276cdf0e10cSrcweir
4277cdf0e10cSrcweir //============================================================================
~INetMIMEEncodedWordOutputSink()4278cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::~INetMIMEEncodedWordOutputSink()
4279cdf0e10cSrcweir {
4280cdf0e10cSrcweir rtl_freeMemory(m_pBuffer);
4281cdf0e10cSrcweir delete m_pEncodingList;
4282cdf0e10cSrcweir }
4283cdf0e10cSrcweir
4284cdf0e10cSrcweir //============================================================================
4285cdf0e10cSrcweir INetMIMEEncodedWordOutputSink &
operator <<(sal_uInt32 nChar)4286cdf0e10cSrcweir INetMIMEEncodedWordOutputSink::operator <<(sal_uInt32 nChar)
4287cdf0e10cSrcweir {
4288cdf0e10cSrcweir if (nChar == ' ')
4289cdf0e10cSrcweir {
4290cdf0e10cSrcweir if (m_pBufferEnd != m_pBuffer)
4291cdf0e10cSrcweir finish(false);
4292cdf0e10cSrcweir ++m_nExtraSpaces;
4293cdf0e10cSrcweir }
4294cdf0e10cSrcweir else
4295cdf0e10cSrcweir {
4296cdf0e10cSrcweir // Check for an already encoded word:
4297cdf0e10cSrcweir switch (m_eEncodedWordState)
4298cdf0e10cSrcweir {
4299cdf0e10cSrcweir case STATE_INITIAL:
4300cdf0e10cSrcweir if (nChar == '=')
4301cdf0e10cSrcweir m_eEncodedWordState = STATE_FIRST_EQUALS;
4302cdf0e10cSrcweir else
4303cdf0e10cSrcweir m_eEncodedWordState = STATE_BAD;
4304cdf0e10cSrcweir break;
4305cdf0e10cSrcweir
4306cdf0e10cSrcweir case STATE_FIRST_EQUALS:
4307cdf0e10cSrcweir if (nChar == '?')
4308cdf0e10cSrcweir m_eEncodedWordState = STATE_FIRST_EQUALS;
4309cdf0e10cSrcweir else
4310cdf0e10cSrcweir m_eEncodedWordState = STATE_BAD;
4311cdf0e10cSrcweir break;
4312cdf0e10cSrcweir
4313cdf0e10cSrcweir case STATE_FIRST_QUESTION:
4314cdf0e10cSrcweir if (INetMIME::isEncodedWordTokenChar(nChar))
4315cdf0e10cSrcweir m_eEncodedWordState = STATE_CHARSET;
4316cdf0e10cSrcweir else
4317cdf0e10cSrcweir m_eEncodedWordState = STATE_BAD;
4318cdf0e10cSrcweir break;
4319cdf0e10cSrcweir
4320cdf0e10cSrcweir case STATE_CHARSET:
4321cdf0e10cSrcweir if (nChar == '?')
4322cdf0e10cSrcweir m_eEncodedWordState = STATE_SECOND_QUESTION;
4323cdf0e10cSrcweir else if (!INetMIME::isEncodedWordTokenChar(nChar))
4324cdf0e10cSrcweir m_eEncodedWordState = STATE_BAD;
4325cdf0e10cSrcweir break;
4326cdf0e10cSrcweir
4327cdf0e10cSrcweir case STATE_SECOND_QUESTION:
4328cdf0e10cSrcweir if (nChar == 'B' || nChar == 'Q'
4329cdf0e10cSrcweir || nChar == 'b' || nChar == 'q')
4330cdf0e10cSrcweir m_eEncodedWordState = STATE_ENCODING;
4331cdf0e10cSrcweir else
4332cdf0e10cSrcweir m_eEncodedWordState = STATE_BAD;
4333cdf0e10cSrcweir break;
4334cdf0e10cSrcweir
4335cdf0e10cSrcweir case STATE_ENCODING:
4336cdf0e10cSrcweir if (nChar == '?')
4337cdf0e10cSrcweir m_eEncodedWordState = STATE_THIRD_QUESTION;
4338cdf0e10cSrcweir else
4339cdf0e10cSrcweir m_eEncodedWordState = STATE_BAD;
4340cdf0e10cSrcweir break;
4341cdf0e10cSrcweir
4342cdf0e10cSrcweir case STATE_THIRD_QUESTION:
4343cdf0e10cSrcweir if (INetMIME::isVisible(nChar) && nChar != '?')
4344cdf0e10cSrcweir m_eEncodedWordState = STATE_ENCODED_TEXT;
4345cdf0e10cSrcweir else
4346cdf0e10cSrcweir m_eEncodedWordState = STATE_BAD;
4347cdf0e10cSrcweir break;
4348cdf0e10cSrcweir
4349cdf0e10cSrcweir case STATE_ENCODED_TEXT:
4350cdf0e10cSrcweir if (nChar == '?')
4351cdf0e10cSrcweir m_eEncodedWordState = STATE_FOURTH_QUESTION;
4352cdf0e10cSrcweir else if (!INetMIME::isVisible(nChar))
4353cdf0e10cSrcweir m_eEncodedWordState = STATE_BAD;
4354cdf0e10cSrcweir break;
4355cdf0e10cSrcweir
4356cdf0e10cSrcweir case STATE_FOURTH_QUESTION:
4357cdf0e10cSrcweir if (nChar == '=')
4358cdf0e10cSrcweir m_eEncodedWordState = STATE_SECOND_EQUALS;
4359cdf0e10cSrcweir else
4360cdf0e10cSrcweir m_eEncodedWordState = STATE_BAD;
4361cdf0e10cSrcweir break;
4362cdf0e10cSrcweir
4363cdf0e10cSrcweir case STATE_SECOND_EQUALS:
4364cdf0e10cSrcweir m_eEncodedWordState = STATE_BAD;
4365cdf0e10cSrcweir break;
4366cdf0e10cSrcweir
4367cdf0e10cSrcweir case STATE_BAD:
4368cdf0e10cSrcweir break;
4369cdf0e10cSrcweir }
4370cdf0e10cSrcweir
4371cdf0e10cSrcweir // Update encoding:
4372cdf0e10cSrcweir m_pEncodingList->includes(nChar);
4373cdf0e10cSrcweir
4374cdf0e10cSrcweir // Update coding:
4375cdf0e10cSrcweir enum { TENQ = 1, // CONTEXT_TEXT, CODING_ENCODED
4376cdf0e10cSrcweir CENQ = 2, // CONTEXT_COMMENT, CODING_ENCODED
4377cdf0e10cSrcweir PQTD = 4, // CONTEXT_PHRASE, CODING_QUOTED
4378cdf0e10cSrcweir PENQ = 8 }; // CONTEXT_PHRASE, CODING_ENCODED
4379cdf0e10cSrcweir static const sal_Char aMinimal[128]
4380cdf0e10cSrcweir = { TENQ | CENQ | PENQ, // 0x00
4381cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x01
4382cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x02
4383cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x03
4384cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x04
4385cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x05
4386cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x06
4387cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x07
4388cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x08
4389cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x09
4390cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x0A
4391cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x0B
4392cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x0C
4393cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x0D
4394cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x0E
4395cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x0F
4396cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x10
4397cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x11
4398cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x12
4399cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x13
4400cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x14
4401cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x15
4402cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x16
4403cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x17
4404cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x18
4405cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x19
4406cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x1A
4407cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x1B
4408cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x1C
4409cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x1D
4410cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x1E
4411cdf0e10cSrcweir TENQ | CENQ | PENQ, // 0x1F
4412cdf0e10cSrcweir 0, // ' '
4413cdf0e10cSrcweir 0, // '!'
4414cdf0e10cSrcweir PQTD , // '"'
4415cdf0e10cSrcweir 0, // '#'
4416cdf0e10cSrcweir 0, // '$'
4417cdf0e10cSrcweir 0, // '%'
4418cdf0e10cSrcweir 0, // '&'
4419cdf0e10cSrcweir 0, // '''
4420cdf0e10cSrcweir CENQ | PQTD , // '('
4421cdf0e10cSrcweir CENQ | PQTD , // ')'
4422cdf0e10cSrcweir 0, // '*'
4423cdf0e10cSrcweir 0, // '+'
4424cdf0e10cSrcweir PQTD , // ','
4425cdf0e10cSrcweir 0, // '-'
4426cdf0e10cSrcweir PQTD , // '.'
4427cdf0e10cSrcweir 0, // '/'
4428cdf0e10cSrcweir 0, // '0'
4429cdf0e10cSrcweir 0, // '1'
4430cdf0e10cSrcweir 0, // '2'
4431cdf0e10cSrcweir 0, // '3'
4432cdf0e10cSrcweir 0, // '4'
4433cdf0e10cSrcweir 0, // '5'
4434cdf0e10cSrcweir 0, // '6'
4435cdf0e10cSrcweir 0, // '7'
4436cdf0e10cSrcweir 0, // '8'
4437cdf0e10cSrcweir 0, // '9'
4438cdf0e10cSrcweir PQTD , // ':'
4439cdf0e10cSrcweir PQTD , // ';'
4440cdf0e10cSrcweir PQTD , // '<'
4441cdf0e10cSrcweir 0, // '='
4442cdf0e10cSrcweir PQTD , // '>'
4443cdf0e10cSrcweir 0, // '?'
4444cdf0e10cSrcweir PQTD , // '@'
4445cdf0e10cSrcweir 0, // 'A'
4446cdf0e10cSrcweir 0, // 'B'
4447cdf0e10cSrcweir 0, // 'C'
4448cdf0e10cSrcweir 0, // 'D'
4449cdf0e10cSrcweir 0, // 'E'
4450cdf0e10cSrcweir 0, // 'F'
4451cdf0e10cSrcweir 0, // 'G'
4452cdf0e10cSrcweir 0, // 'H'
4453cdf0e10cSrcweir 0, // 'I'
4454cdf0e10cSrcweir 0, // 'J'
4455cdf0e10cSrcweir 0, // 'K'
4456cdf0e10cSrcweir 0, // 'L'
4457cdf0e10cSrcweir 0, // 'M'
4458cdf0e10cSrcweir 0, // 'N'
4459cdf0e10cSrcweir 0, // 'O'
4460cdf0e10cSrcweir 0, // 'P'
4461cdf0e10cSrcweir 0, // 'Q'
4462cdf0e10cSrcweir 0, // 'R'
4463cdf0e10cSrcweir 0, // 'S'
4464cdf0e10cSrcweir 0, // 'T'
4465cdf0e10cSrcweir 0, // 'U'
4466cdf0e10cSrcweir 0, // 'V'
4467cdf0e10cSrcweir 0, // 'W'
4468cdf0e10cSrcweir 0, // 'X'
4469cdf0e10cSrcweir 0, // 'Y'
4470cdf0e10cSrcweir 0, // 'Z'
4471cdf0e10cSrcweir PQTD , // '['
4472cdf0e10cSrcweir CENQ | PQTD , // '\'
4473cdf0e10cSrcweir PQTD , // ']'
4474cdf0e10cSrcweir 0, // '^'
4475cdf0e10cSrcweir 0, // '_'
4476cdf0e10cSrcweir 0, // '`'
4477cdf0e10cSrcweir 0, // 'a'
4478cdf0e10cSrcweir 0, // 'b'
4479cdf0e10cSrcweir 0, // 'c'
4480cdf0e10cSrcweir 0, // 'd'
4481cdf0e10cSrcweir 0, // 'e'
4482cdf0e10cSrcweir 0, // 'f'
4483cdf0e10cSrcweir 0, // 'g'
4484cdf0e10cSrcweir 0, // 'h'
4485cdf0e10cSrcweir 0, // 'i'
4486cdf0e10cSrcweir 0, // 'j'
4487cdf0e10cSrcweir 0, // 'k'
4488cdf0e10cSrcweir 0, // 'l'
4489cdf0e10cSrcweir 0, // 'm'
4490cdf0e10cSrcweir 0, // 'n'
4491cdf0e10cSrcweir 0, // 'o'
4492cdf0e10cSrcweir 0, // 'p'
4493cdf0e10cSrcweir 0, // 'q'
4494cdf0e10cSrcweir 0, // 'r'
4495cdf0e10cSrcweir 0, // 's'
4496cdf0e10cSrcweir 0, // 't'
4497cdf0e10cSrcweir 0, // 'u'
4498cdf0e10cSrcweir 0, // 'v'
4499cdf0e10cSrcweir 0, // 'w'
4500cdf0e10cSrcweir 0, // 'x'
4501cdf0e10cSrcweir 0, // 'y'
4502cdf0e10cSrcweir 0, // 'z'
4503cdf0e10cSrcweir 0, // '{'
4504cdf0e10cSrcweir 0, // '|'
4505cdf0e10cSrcweir 0, // '}'
4506cdf0e10cSrcweir 0, // '~'
4507cdf0e10cSrcweir TENQ | CENQ | PENQ }; // DEL
4508cdf0e10cSrcweir Coding eNewCoding = !INetMIME::isUSASCII(nChar) ? CODING_ENCODED :
4509cdf0e10cSrcweir m_eContext == CONTEXT_PHRASE ?
4510cdf0e10cSrcweir Coding(aMinimal[nChar] >> 2) :
4511cdf0e10cSrcweir aMinimal[nChar] & m_eContext ? CODING_ENCODED :
4512cdf0e10cSrcweir CODING_NONE;
4513cdf0e10cSrcweir if (eNewCoding > m_eCoding)
4514cdf0e10cSrcweir m_eCoding = eNewCoding;
4515cdf0e10cSrcweir if (m_eCoding == CODING_QUOTED
4516cdf0e10cSrcweir && INetMIME::needsQuotedStringEscape(nChar))
4517cdf0e10cSrcweir ++m_nQuotedEscaped;
4518cdf0e10cSrcweir
4519cdf0e10cSrcweir // Append to buffer:
4520cdf0e10cSrcweir if (sal_uInt32(m_pBufferEnd - m_pBuffer) == m_nBufferSize)
4521cdf0e10cSrcweir {
4522cdf0e10cSrcweir m_pBuffer
4523cdf0e10cSrcweir = static_cast< sal_Unicode * >(
4524cdf0e10cSrcweir rtl_reallocateMemory(m_pBuffer,
4525cdf0e10cSrcweir (m_nBufferSize + BUFFER_SIZE)
4526cdf0e10cSrcweir * sizeof (sal_Unicode)));
4527cdf0e10cSrcweir m_pBufferEnd = m_pBuffer + m_nBufferSize;
4528cdf0e10cSrcweir m_nBufferSize += BUFFER_SIZE;
4529cdf0e10cSrcweir }
4530cdf0e10cSrcweir *m_pBufferEnd++ = sal_Unicode(nChar);
4531cdf0e10cSrcweir }
4532cdf0e10cSrcweir return *this;
4533cdf0e10cSrcweir }
4534cdf0e10cSrcweir
4535cdf0e10cSrcweir //============================================================================
4536cdf0e10cSrcweir //
4537cdf0e10cSrcweir // INetContentTypeParameterList
4538cdf0e10cSrcweir //
4539cdf0e10cSrcweir //============================================================================
4540cdf0e10cSrcweir
Clear()4541cdf0e10cSrcweir void INetContentTypeParameterList::Clear()
4542cdf0e10cSrcweir {
4543cdf0e10cSrcweir while (Count() > 0)
4544cdf0e10cSrcweir delete static_cast< INetContentTypeParameter * >(Remove(Count() - 1));
4545cdf0e10cSrcweir }
4546cdf0e10cSrcweir
4547cdf0e10cSrcweir //============================================================================
4548cdf0e10cSrcweir const INetContentTypeParameter *
find(const ByteString & rAttribute) const4549cdf0e10cSrcweir INetContentTypeParameterList::find(const ByteString & rAttribute) const
4550cdf0e10cSrcweir {
4551cdf0e10cSrcweir for (sal_uIntPtr i = 0; i < Count(); ++i)
4552cdf0e10cSrcweir {
4553cdf0e10cSrcweir const INetContentTypeParameter * pParameter = GetObject(i);
4554cdf0e10cSrcweir if (pParameter->m_sAttribute.EqualsIgnoreCaseAscii(rAttribute))
4555cdf0e10cSrcweir return pParameter;
4556cdf0e10cSrcweir }
4557cdf0e10cSrcweir return 0;
4558cdf0e10cSrcweir }
4559