Messagelib

kleo_util.h
1/* -*- c++ -*-
2 kleo_util.h
3
4 This file is part of KMail, the KDE mail client.
5 SPDX-FileCopyrightText: 2004 Marc Mutz <mutz@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#pragma once
11
12#include <Libkleo/Enum>
13
14static const Kleo::CryptoMessageFormat cryptoMessageFormats[] = {Kleo::AutoFormat,
15 Kleo::InlineOpenPGPFormat,
16 Kleo::OpenPGPMIMEFormat,
17 Kleo::SMIMEFormat,
18 Kleo::SMIMEOpaqueFormat};
19static const int numCryptoMessageFormats = sizeof cryptoMessageFormats / sizeof *cryptoMessageFormats;
20
21static const Kleo::CryptoMessageFormat concreteCryptoMessageFormats[] = {Kleo::OpenPGPMIMEFormat,
22 Kleo::SMIMEFormat,
23 Kleo::SMIMEOpaqueFormat,
24 Kleo::InlineOpenPGPFormat};
25static const unsigned int numConcreteCryptoMessageFormats = sizeof concreteCryptoMessageFormats / sizeof *concreteCryptoMessageFormats;
26
27static inline Kleo::CryptoMessageFormat cb2format(int idx)
28{
29 return cryptoMessageFormats[idx >= 0 && idx < numCryptoMessageFormats ? idx : 0];
30}
31
32static inline int format2cb(Kleo::CryptoMessageFormat f)
33{
34 for (int i = 0; i < numCryptoMessageFormats; ++i) {
35 if (f == cryptoMessageFormats[i]) {
36 return i;
37 }
38 }
39 return 0;
40}
41
42//
43// some helper functions indicating the need for CryptoMessageFormat
44// to be a class type :)
45//
46
47static inline bool isSMIME(Kleo::CryptoMessageFormat f)
48{
49 return f == Kleo::SMIMEFormat || f == Kleo::SMIMEOpaqueFormat;
50}
51
52static inline bool isOpenPGP(Kleo::CryptoMessageFormat f)
53{
54 return f == Kleo::InlineOpenPGPFormat || f == Kleo::OpenPGPMIMEFormat;
55}
56
57static inline bool containsSMIME(unsigned int f)
58{
59 return f & (Kleo::SMIMEFormat | Kleo::SMIMEOpaqueFormat);
60}
61
62static inline bool containsOpenPGP(unsigned int f)
63{
64 return f & (Kleo::OpenPGPMIMEFormat | Kleo::InlineOpenPGPFormat);
65}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.