Akonadi Mime

sentbehaviourattribute.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Constantin Berzan <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "sentbehaviourattribute.h"
8 
9 using namespace Akonadi;
10 
11 class Akonadi::SentBehaviourAttributePrivate
12 {
13 public:
14  SentBehaviourAttributePrivate() = default;
15 
17  Akonadi::Collection mMoveToCollection;
18  bool mSilent = false;
19 };
20 
21 SentBehaviourAttribute::SentBehaviourAttribute(SentBehaviour beh, const Collection &moveToCollection, bool sendSilently)
22  : d(new SentBehaviourAttributePrivate)
23 {
24  d->mBehaviour = beh;
25  d->mMoveToCollection = moveToCollection;
26  d->mSilent = sendSilently;
27 }
28 
30 
31 SentBehaviourAttribute *SentBehaviourAttribute::clone() const
32 {
33  return new SentBehaviourAttribute(d->mBehaviour, d->mMoveToCollection, d->mSilent);
34 }
35 
36 QByteArray SentBehaviourAttribute::type() const
37 {
38  static const QByteArray sType("SentBehaviourAttribute");
39  return sType;
40 }
41 
42 QByteArray SentBehaviourAttribute::serialized() const
43 {
44  QByteArray out;
45 
46  switch (d->mBehaviour) {
47  case Delete:
48  out = QByteArrayLiteral("delete");
49  break;
50  case MoveToCollection:
51  out = QByteArrayLiteral("moveTo") + QByteArray::number(d->mMoveToCollection.id());
52  break;
54  out = QByteArrayLiteral("moveToDefault");
55  break;
56  default:
57  Q_ASSERT(false);
58  return {};
59  }
60 
61  if (d->mSilent) {
62  out += QByteArrayLiteral(",silent");
63  }
64 
65  return out;
66 }
67 
68 void SentBehaviourAttribute::deserialize(const QByteArray &data)
69 {
70  const QByteArrayList in = data.split(',');
71  Q_ASSERT(!in.isEmpty());
72 
73  const QByteArray attr0 = in[0];
74  d->mMoveToCollection = Akonadi::Collection(-1);
75  if (attr0 == "delete") {
76  d->mBehaviour = Delete;
77  } else if (attr0 == "moveToDefault") {
78  d->mBehaviour = MoveToDefaultSentCollection;
79  } else if (attr0.startsWith(QByteArrayLiteral("moveTo"))) {
80  d->mBehaviour = MoveToCollection;
81  d->mMoveToCollection = Akonadi::Collection(attr0.mid(6).toLongLong());
82  // NOTE: 6 is the strlen of "moveTo".
83  } else {
84  Q_ASSERT(false);
85  }
86 
87  if (in.size() == 2 && in[1] == "silent") {
88  d->mSilent = true;
89  }
90 }
91 
93 {
94  return d->mBehaviour;
95 }
96 
98 {
99  d->mBehaviour = beh;
100 }
101 
103 {
104  return d->mMoveToCollection;
105 }
106 
108 {
109  d->mMoveToCollection = moveToCollection;
110 }
111 
113 {
114  return d->mSilent;
115 }
116 
118 {
119  d->mSilent = sendSilently;
120 }
SentBehaviour
What to do with the item in the outbox after it has been sent successfully.
@ MoveToCollection
Move the item to a custom collection.
bool sendSilently() const
Returns whether a notification should be shown after the email is sent.
@ MoveToDefaultSentCollection
Move the item to the default sent-mail collection.
QByteArray number(int n, int base)
QList< QByteArray > split(char sep) const const
qlonglong toLongLong(bool *ok, int base) const const
int size() const const
@ Delete
Delete the item from the outbox.
void setSendSilently(bool sendSilently)
Set whether a notification should be shown after the email is sent.
Akonadi::Collection moveToCollection() const
Returns the collection to which the item should be moved after it is sent.
QByteArray mid(int pos, int len) const const
bool startsWith(const QByteArray &ba) const const
bool isEmpty() const const
void setMoveToCollection(const Akonadi::Collection &moveToCollection)
Sets the collection to which the item should be moved after it is sent.
SentBehaviour sentBehaviour() const
Returns the sent-behaviour of the message.
void setSentBehaviour(SentBehaviour beh)
Sets the sent-behaviour of the message.
Attribute determining what will happen to a message after it is sent.
SentBehaviourAttribute(SentBehaviour beh=MoveToDefaultSentCollection, const Akonadi::Collection &moveToCollection=Akonadi::Collection(-1), bool sendSilently=false)
Creates a new SentBehaviourAttribute.
~SentBehaviourAttribute() override
Destroys the SentBehaviourAttribute.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Dec 7 2023 04:11:43 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.