MailTransport

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

KDE's Doxygen guidelines are available online.