File indexing completed on 2024-11-24 04:39:27
0001 /* 0002 This file is part of Akonadi Contact. 0003 0004 SPDX-FileCopyrightText: 2010 KDAB 0005 SPDX-FileContributor: Tobias Koenig <tokoe@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include "emailaddressselection.h" 0011 #include "emailaddressselection_p.h" 0012 0013 #include <KContacts/ContactGroup> 0014 #include <KMime/HeaderParsing> 0015 0016 using namespace Akonadi; 0017 0018 EmailAddressSelectionPrivate::EmailAddressSelectionPrivate() 0019 : QSharedData() 0020 { 0021 } 0022 0023 EmailAddressSelectionPrivate::EmailAddressSelectionPrivate(const EmailAddressSelectionPrivate &other) 0024 : QSharedData(other) 0025 { 0026 mName = other.mName; 0027 mEmailAddress = other.mEmailAddress; 0028 mItem = other.mItem; 0029 } 0030 0031 EmailAddressSelection::EmailAddressSelection() 0032 : d(new EmailAddressSelectionPrivate) 0033 { 0034 } 0035 0036 EmailAddressSelection::EmailAddressSelection(const EmailAddressSelection &other) = default; 0037 0038 EmailAddressSelection &EmailAddressSelection::operator=(const EmailAddressSelection &other) 0039 { 0040 if (this != &other) { 0041 d = other.d; 0042 } 0043 0044 return *this; 0045 } 0046 0047 EmailAddressSelection::~EmailAddressSelection() = default; 0048 0049 bool EmailAddressSelection::isValid() const 0050 { 0051 return d->mItem.isValid(); 0052 } 0053 0054 QString EmailAddressSelection::name() const 0055 { 0056 return d->mName; 0057 } 0058 0059 void EmailAddressSelection::setName(const QString &name) 0060 { 0061 d->mName = name; 0062 } 0063 0064 QString EmailAddressSelection::email() const 0065 { 0066 return d->mEmailAddress; 0067 } 0068 0069 void EmailAddressSelection::setEmail(const QString &email) 0070 { 0071 d->mEmailAddress = email; 0072 } 0073 0074 QString EmailAddressSelection::quotedEmail() const 0075 { 0076 if (d->mItem.hasPayload<KContacts::ContactGroup>()) { 0077 if (d->mEmailAddress == d->mName) { 0078 return d->mName; 0079 } 0080 } 0081 0082 KMime::Types::Mailbox mailbox; 0083 mailbox.setAddress(d->mEmailAddress.toUtf8()); 0084 mailbox.setName(d->mName); 0085 0086 return mailbox.prettyAddress(KMime::Types::Mailbox::QuoteWhenNecessary); 0087 } 0088 0089 Akonadi::Item EmailAddressSelection::item() const 0090 { 0091 return d->mItem; 0092 } 0093 0094 void EmailAddressSelection::setItem(const Item &item) 0095 { 0096 d->mItem = item; 0097 }