File indexing completed on 2022-11-29 19:53:40

0001 /*
0002     SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 // @cond PRIVATE
0010 
0011 /* Internal helper functions. Not part of the public API. */
0012 
0013 namespace KMime
0014 {
0015 
0016 /**
0017  *  Consult the charset cache. Only used for reducing mem usage by
0018  *  keeping strings in a common repository.
0019  *  @param name
0020  */
0021 extern QByteArray cachedCharset(const QByteArray &name);
0022 
0023 /**
0024   Finds the header end in @p src. Aligns the @p dataBegin if needed.
0025   @param dataBegin beginning of the data part of the header
0026   @param folded true if the headder is folded into multiple lines
0027   @returns the end index of the header, -1 if the @p dataBegin was -1.
0028 */
0029 extern int findHeaderLineEnd(const QByteArray &src, int &dataBegin, bool *folded = nullptr);
0030 
0031 /**
0032   Finds the first header of type @p name in @p src.
0033   @param end The end index of the header.
0034   @param dataBegin begin of the data part of the header, -1 if not found.
0035   @param folded true if the headder is folded into multiple lines
0036   @returns the begin index of the header, -1 if not found.
0037 */
0038 extern int indexOfHeader(const QByteArray &src, const QByteArray &name, int &end, int &dataBegin, bool *folded = nullptr);
0039 
0040 /**
0041  *  Uses current time, pid and random numbers to construct a string
0042  *  that aims to be unique on a per-host basis (ie. for the local
0043  *  part of a message-id or for multipart boundaries.
0044  *
0045  *  @return the unique string.
0046  *  @see multiPartBoundary
0047  */
0048 extern QByteArray uniqueString();
0049 
0050 //@cond PRIVATE
0051 extern const uchar aTextMap[16];
0052 extern const uchar tTextMap[16];
0053 
0054 inline bool isOfSet(const uchar map[16], unsigned char ch)
0055 {
0056     return (ch < 128) && (map[ ch / 8 ] & 0x80 >> ch % 8);
0057 }
0058 inline bool isAText(char ch)
0059 {
0060     return isOfSet(aTextMap, ch);
0061 }
0062 inline bool isTText(char ch)
0063 {
0064     return isOfSet(tTextMap, ch);
0065 }
0066 //@endcond
0067 
0068 }
0069 
0070 // @endcond
0071