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 <[email protected]>
6 
7  SPDX-License-Identifier: GPL-2.0-or-later
8 */
9 
10 #pragma once
11 
12 #include <Libkleo/Enum>
13 
14 static const Kleo::CryptoMessageFormat cryptoMessageFormats[] = {Kleo::AutoFormat,
15  Kleo::InlineOpenPGPFormat,
16  Kleo::OpenPGPMIMEFormat,
17  Kleo::SMIMEFormat,
18  Kleo::SMIMEOpaqueFormat};
19 static const int numCryptoMessageFormats = sizeof cryptoMessageFormats / sizeof *cryptoMessageFormats;
20 
21 static const Kleo::CryptoMessageFormat concreteCryptoMessageFormats[] = {Kleo::OpenPGPMIMEFormat,
22  Kleo::SMIMEFormat,
23  Kleo::SMIMEOpaqueFormat,
24  Kleo::InlineOpenPGPFormat};
25 static const unsigned int numConcreteCryptoMessageFormats = sizeof concreteCryptoMessageFormats / sizeof *concreteCryptoMessageFormats;
26 
27 static inline Kleo::CryptoMessageFormat cb2format(int idx)
28 {
29  return cryptoMessageFormats[idx >= 0 && idx < numCryptoMessageFormats ? idx : 0];
30 }
31 
32 static 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 
47 static inline bool isSMIME(Kleo::CryptoMessageFormat f)
48 {
49  return f == Kleo::SMIMEFormat || f == Kleo::SMIMEOpaqueFormat;
50 }
51 
52 static inline bool isOpenPGP(Kleo::CryptoMessageFormat f)
53 {
54  return f == Kleo::InlineOpenPGPFormat || f == Kleo::OpenPGPMIMEFormat;
55 }
56 
57 static inline bool containsSMIME(unsigned int f)
58 {
59  return f & (Kleo::SMIMEFormat | Kleo::SMIMEOpaqueFormat);
60 }
61 
62 static inline bool containsOpenPGP(unsigned int f)
63 {
64  return f & (Kleo::OpenPGPMIMEFormat | Kleo::InlineOpenPGPFormat);
65 }
66 
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 23:05:47 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.