1/*
2 Copyright (c) 2002-2004 Marc Mutz <mutz@kde.org>
3 Copyright (c) 2007 Tom Albers <tomalbers@kde.nl>
4 Author: Stefan Taferner <taferner@kde.org>
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20*/
21
22#ifndef KPIMIDENTITES_IDENTITY_H
23#define KPIMIDENTITES_IDENTITY_H
24
25#include "kpimidentities_export.h"
26#include "signature.h"
27
28#include <kdemacros.h>
29
30#include <QtCore/QString>
31#include <QtCore/QStringList>
32#include <QtCore/QList>
33#include <QtCore/QHash>
34#include <QtCore/QVariant>
35
36namespace KPIMIdentities
37{
38 class Identity;
39 class Signature;
40}
41class KConfigGroup;
42class QDataStream;
43class QMimeData;
44
45namespace KPIMIdentities
46{
47
48 static const char s_uoid[] = "uoid";
49 static const char s_identity[] = "Identity";
50 static const char s_name[] = "Name";
51 static const char s_organization[] = "Organization";
52 static const char s_pgps[] = "PGP Signing Key";
53 static const char s_pgpe[] = "PGP Encryption Key";
54 static const char s_smimes[] = "SMIME Signing Key";
55 static const char s_smimee[] = "SMIME Encryption Key";
56 static const char s_prefcrypt[] = "Preferred Crypto Message Format";
57 static const char s_email[] = "Email Address"; // TODO: KDE5: Rename to s_primaryEmail
58 static const char s_replyto[] = "Reply-To Address";
59 static const char s_bcc[] = "Bcc";
60 static const char s_cc[] = "Cc";
61 static const char s_vcard[] = "VCardFile";
62 static const char s_transport[] = "Transport";
63 static const char s_fcc[] = "Fcc";
64 static const char s_drafts[] = "Drafts";
65 static const char s_templates[] = "Templates";
66 static const char s_dict[] = "Dictionary";
67 static const char s_xface[] = "X-Face";
68 static const char s_xfaceenabled[] = "X-FaceEnabled";
69 static const char s_signature[] = "Signature";
70 static const char s_emailAliases[] = "Email Aliases";
71 static const char s_attachVcard[] = "Attach Vcard";
72 static const char s_autocorrectionLanguage[] = "Autocorrection Language";
73 static const char s_disabledFcc[] = "Disable Fcc";
74 static const char s_pgpautosign[] = "Pgp Auto Sign";
75 static const char s_defaultDomainName[] = "Default Domain";
76
77 KPIMIDENTITIES_EXPORT QDataStream &operator<<
78 ( QDataStream &stream, const KPIMIdentities::Identity &ident );
79 KPIMIDENTITIES_EXPORT QDataStream &operator>>
80 ( QDataStream &stream, KPIMIdentities::Identity &ident );
81
82/** User identity information */
83class KPIMIDENTITIES_EXPORT Identity
84{
85 // only the identity manager should be able to construct and
86 // destruct us, but then we get into problems with using
87 // QValueList<Identity> and especially qHeapSort().
88 friend class IdentityManager;
89
90 friend KPIMIDENTITIES_EXPORT QDataStream &operator<<
91 ( QDataStream &stream, const KPIMIdentities::Identity &ident );
92 friend KPIMIDENTITIES_EXPORT QDataStream &operator>>
93 ( QDataStream &stream, KPIMIdentities::Identity &ident );
94
95 public:
96 typedef QList<Identity> List;
97
98 /** Constructor */
99 explicit Identity( const QString &id=QString(),
100 const QString &realName=QString(),
101 const QString &emailAddr=QString(),
102 const QString &organization=QString(),
103 const QString &replyToAddress=QString() );
104
105 /** Destructor */
106 ~Identity();
107
108 /** used for comparison */
109 bool operator== ( const Identity &other ) const;
110
111 /** used for comparison */
112 bool operator!= ( const Identity &other ) const;
113
114 /** used for sorting */
115 bool operator< ( const Identity &other ) const;
116
117 /** used for sorting */
118 bool operator> ( const Identity &other ) const;
119
120 /** used for sorting */
121 bool operator<= ( const Identity &other ) const;
122
123 /** used for sorting */
124 bool operator>= ( const Identity &other ) const;
125
126 /** Tests if there are enough values set to allow mailing */
127 bool mailingAllowed() const;
128
129 /** Identity/nickname for this collection */
130 QString identityName() const;
131
132 /** Identity/nickname for this collection */
133 void setIdentityName( const QString &name );
134
135 /** @return whether this identity is the default identity */
136 bool isDefault() const;
137
138 /** Unique Object Identifier for this identity */
139 uint uoid() const;
140
141 /** Full name of the user */
142 QString fullName() const;
143 void setFullName( const QString& );
144
145 /** The user's organization (optional) */
146 QString organization() const;
147 void setOrganization( const QString& );
148
149 /** The user's OpenPGP encryption key */
150 QByteArray pgpEncryptionKey() const;
151 void setPGPEncryptionKey( const QByteArray &key );
152
153 /** The user's OpenPGP signing key */
154 QByteArray pgpSigningKey() const;
155 void setPGPSigningKey( const QByteArray &key );
156
157 /** The user's S/MIME encryption key */
158 QByteArray smimeEncryptionKey() const;
159 void setSMIMEEncryptionKey( const QByteArray &key );
160
161 /** The user's S/MIME signing key */
162 QByteArray smimeSigningKey() const;
163 void setSMIMESigningKey( const QByteArray &key );
164
165 QString preferredCryptoMessageFormat() const;
166 void setPreferredCryptoMessageFormat( const QString& );
167
168 /**
169 * email address (without the user name - only name\@host)
170 * @deprecated Use the primary email address or aliases, depending on your usecase
171 * @sa primaryEmailAddress(), setPrimaryEmailAddress(), emailAliases(), setEmailAliases(),
172 * matchesEmailAddress()
173 */
174 KPIMIDENTITIES_DEPRECATED QString emailAddr() const;
175 KPIMIDENTITIES_DEPRECATED void setEmailAddr( const QString& );
176
177 /**
178 * primary email address (without the user name - only name\@host).
179 * The primary email address is used for all outgoing mail.
180 *
181 * @since 4.6
182 */
183 QString primaryEmailAddress() const;
184 void setPrimaryEmailAddress( const QString & email );
185
186 /**
187 * email address aliases
188 *
189 * @since 4.6
190 */
191 const QStringList emailAliases() const;
192 void setEmailAliases( const QStringList & aliases );
193
194 /**
195 * @param addr the email address to check
196 * @return true if this identity contains the email address @p addr, either as primary address
197 * or as alias
198 *
199 * @since 4.6
200 */
201 bool matchesEmailAddress( const QString & addr ) const;
202
203 /** vCard to attach to outgoing emails */
204 QString vCardFile() const;
205 void setVCardFile( const QString& );
206
207 /** email address in the format "username <name@host>" suitable
208 for the "From:" field of email messages. */
209 QString fullEmailAddr() const;
210
211 /** email address for the ReplyTo: field */
212 QString replyToAddr() const;
213 void setReplyToAddr( const QString& );
214
215 /** email addresses for the BCC: field */
216 QString bcc() const;
217 void setBcc( const QString& );
218
219 /** email addresses for the CC: field
220 * @since 4.9
221 */
222 QString cc() const;
223 void setCc( const QString& );
224
225 /**
226 *
227 * @since 4.10
228 */
229 bool attachVcard() const;
230 void setAttachVcard(bool attach);
231
232 /**
233 * @since 4.10
234 */
235 QString autocorrectionLanguage() const;
236 void setAutocorrectionLanguage(const QString& language);
237
238 /**
239 * @since 4.11
240 */
241 bool disabledFcc() const;
242 void setDisabledFcc(bool);
243
244 /**
245 * @since 4.12
246 */
247 bool pgpAutoSign() const;
248 void setPgpAutoSign(bool);
249
250 /**
251 * @since 4.14
252 */
253 QString defaultDomainName() const;
254 void setDefaultDomainName(const QString &domainName);
255
256
257 void setSignature( const Signature &sig );
258 Signature &signature(); /* _not_ const! */
259
260 /**
261 @return the signature with '-- \n' prepended to it if it is not
262 present already.
263 No newline in front of or after the signature is added.
264 @param ok if a valid bool pointer, it is set to @c true or @c false depending
265 on whether the signature could successfully be obtained.
266 */
267 QString signatureText( bool *ok = 0 ) const;
268
269 /**
270 * @since 4.1
271 * @return true if the inlined signature is html formatted
272 */
273 bool signatureIsInlinedHtml() const;
274
275 /** The transport that is set for this identity. Used to link a
276 transport with an identity. */
277 QString transport() const;
278 void setTransport( const QString& );
279
280 /** The folder where sent messages from this identity will be
281 stored by default. */
282 QString fcc() const;
283 void setFcc( const QString& );
284
285 /** The folder where draft messages from this identity will be
286 stored by default.
287 TODO: KDE5 Change QString to int as the folder is an akonadi collection id.
288 */
289 QString drafts() const;
290 void setDrafts( const QString& );
291
292 /** The folder where template messages from this identity will be
293 stored by default.
294 TODO: KDE5 Change QString to int as the folder is an akonadi collection id.
295 */
296 QString templates() const;
297 void setTemplates( const QString& );
298
299 /**
300 * Dictionary which should be used for spell checking
301 *
302 * Note that this is the localized language name (e.g. "British English"),
303 * _not_ the language code or dictionary name!
304 */
305 QString dictionary() const;
306 void setDictionary( const QString& );
307
308 /** a X-Face header for this identity */
309 QString xface() const;
310 void setXFace( const QString& );
311 bool isXFaceEnabled() const;
312 void setXFaceEnabled( const bool );
313
314 /** Get random properties
315 * @param key the key of the property to get
316 */
317 QVariant property( const QString &key ) const;
318 /** Set random properties, when @p value is empty (for QStrings) or null,
319 the property is deleted. */
320 void setProperty( const QString &key, const QVariant &value );
321
322 static const Identity &null();
323 /** Returns true when the identity contains no values, all null values or
324 only empty values */
325 bool isNull() const;
326
327 static QString mimeDataType();
328 static bool canDecode( const QMimeData* );
329 void populateMimeData( QMimeData* );
330 static Identity fromMimeData( const QMimeData* );
331
332 /** Read configuration from config. Group must be preset (or use
333 KConfigGroup). Called from IdentityManager. */
334 void readConfig( const KConfigGroup & );
335
336 /** Write configuration to config. Group must be preset (or use
337 KConfigGroup). Called from IdentityManager. */
338 void writeConfig( KConfigGroup & ) const;
339
340 /** Set whether this identity is the default identity. Since this
341 affects all other identites, too (most notably, the old default
342 identity), only the IdentityManager can change this.
343 You should use
344 <pre>
345 kmkernel->identityManager()->setAsDefault( name_of_default )
346 </pre>
347 instead. */
348 void setIsDefault( bool flag );
349
350 /** set the uiod
351 * @param aUoid the uoid to set
352 */
353 void setUoid( uint aUoid );
354
355 protected:
356 /** during migration when it failed it can be a string => not a qlonglong akonadi::id => fix it*/
357 /** remove it in kde5 */
358 QString verifyAkonadiId(const QString& str) const;
359
360 /** @return true if the signature is read from the output of a command */
361 bool signatureIsCommand() const;
362
363 /** @return true if the signature is read from a text file */
364 bool signatureIsPlainFile() const;
365
366 /** @return true if the signature was specified directly */
367 bool signatureIsInline() const;
368
369 /** name of the signature file (with path) */
370 QString signatureFile() const;
371 void setSignatureFile( const QString& );
372
373 /** inline signature */
374 QString signatureInlineText() const;
375 void setSignatureInlineText( const QString& );
376
377 /** Inline or signature from a file */
378 bool useSignatureFile() const;
379
380 Signature mSignature;
381 bool mIsDefault;
382 QHash<QString, QVariant> mPropertiesMap;
383};
384
385}
386
387#endif /*kpim_identity_h*/
388