File indexing completed on 2024-04-21 16:06:19

0001 /*  -*- c++ -*-
0002     kmime_util.h
0003 
0004     KMime, the KDE Internet mail/usenet news message library.
0005     SPDX-FileCopyrightText: 2001 the KMime authors.
0006     See file AUTHORS for details
0007 
0008     SPDX-License-Identifier: LGPL-2.0-or-later
0009 */
0010 #pragma once
0011 
0012 #include "kmime_export.h"
0013 #include "kmime_headers.h"
0014 #include "kmime_content.h"
0015 
0016 #include <QList>
0017 #include <QString>
0018 
0019 namespace KMime
0020 {
0021 
0022 class Message;
0023 
0024 /**
0025   Checks whether @p s contains any non-us-ascii characters.
0026   @param s
0027 */
0028 KMIME_EXPORT extern bool isUsAscii(const QString &s);
0029 
0030 /**
0031   Returns a user-visible string for a contentEncoding, for example
0032   "quoted-printable" for CEquPr.
0033   @param enc the contentEncoding to return string for
0034   @ since 4.4
0035   TODO should they be i18n'ed?
0036 */
0037 KMIME_EXPORT extern QString nameForEncoding(KMime::Headers::contentEncoding enc);
0038 
0039 /**
0040   Returns a list of encodings that can correctly encode the @p data.
0041   @param data the data to check encodings for
0042   @ since 4.4
0043 */
0044 [[nodiscard]] KMIME_EXPORT QList<KMime::Headers::contentEncoding>
0045 encodingsForData(const QByteArray &data);
0046 
0047 /**
0048   Constructs a random string (sans leading/trailing "--") that can
0049   be used as a multipart delimiter (ie. as @p boundary parameter
0050   to a multipart/... content-type).
0051 
0052   @return the randomized string.
0053   @see uniqueString
0054 */
0055 KMIME_EXPORT extern QByteArray multiPartBoundary();
0056 
0057 /**
0058   Converts all occurrences of "\r\n" (CRLF) in @p s to "\n" (LF).
0059 
0060   This function is expensive and should be used only if the mail
0061   will be stored locally. All decode functions can cope with both
0062   line endings.
0063 
0064   @param s source string containing CRLF's
0065 
0066   @return the string with CRLF's substituted for LF's
0067   @see CRLFtoLF(const char*) LFtoCRLF
0068 */
0069 KMIME_EXPORT extern QByteArray CRLFtoLF(const QByteArray &s);
0070 
0071 /**
0072   Converts all occurrences of "\r\n" (CRLF) in @p s to "\n" (LF).
0073 
0074   This function is expensive and should be used only if the mail
0075   will be stored locally. All decode functions can cope with both
0076   line endings.
0077 
0078   @param s source string containing CRLF's
0079 
0080   @return the string with CRLF's substituted for LF's
0081   @see CRLFtoLF(const QByteArray&) LFtoCRLF
0082 */
0083 KMIME_EXPORT extern QByteArray CRLFtoLF(const char *s);
0084 
0085 /**
0086   Converts all occurrences of "\n" (LF) in @p s to "\r\n" (CRLF).
0087 
0088   This function is expensive and should be used only if the mail
0089   will be transmitted as an RFC822 message later. All decode
0090   functions can cope with and all encode functions can optionally
0091   produce both line endings, which is much faster.
0092 
0093   @param s source string containing CRLF's
0094 
0095   @return the string with CRLF's substituted for LF's
0096   @see CRLFtoLF(const QByteArray&) LFtoCRLF
0097 */
0098 KMIME_EXPORT extern QByteArray LFtoCRLF(const QByteArray &s);
0099 
0100 /**
0101  * Returns whether or not the given MIME node is an attachment part.
0102  * @param content the MIME node to parse
0103  * @see hasAttachment()
0104  */
0105 KMIME_EXPORT bool isAttachment(Content *content);
0106 
0107 /**
0108  * Returns whether or not the given MIME node contains an attachment part. This function will
0109  *  recursively parse the MIME tree looking for a suitable attachment and return true if one is found.
0110  * @param content the MIME node to parse
0111  * @see isAttachment()
0112  */
0113 KMIME_EXPORT bool hasAttachment(Content *content);
0114 
0115 /**
0116  * Returns whether or not the given MIME node contains an invitation part. This function will
0117  *  recursively parse the MIME tree looking for a suitable invitation and return true if one is found.
0118  * @param content the MIME node to parse
0119  * @since 4.14.6
0120  */
0121 KMIME_EXPORT bool hasInvitation(Content *content);
0122 
0123 /**
0124  * Returns whether or not the given @p message is partly or fully signed.
0125  *
0126  * @param message the message to check for being signed
0127  * @since 4.6
0128  */
0129 KMIME_EXPORT bool isSigned(Message *message);
0130 
0131 /**
0132  * Returns whether or not the given @p message is partly or fully encrypted.
0133  *
0134  * @param message the message to check for being encrypted
0135  * @since 4.6
0136  */
0137 KMIME_EXPORT bool isEncrypted(Message *message);
0138 
0139 /**
0140  * Determines if the MIME part @p content is a crypto part.
0141  * This is, is either an encrypted part or a signature part.
0142  */
0143 KMIME_EXPORT bool isCryptoPart(Content *content);
0144 
0145 /**
0146  * Returns whether or not the given MIME @p content is an invitation
0147  * message of the iTIP protocol.
0148  *
0149  * @since 4.6
0150  */
0151 KMIME_EXPORT bool isInvitation(Content *content);
0152 
0153 } // namespace KMime
0154