Debian Codegraph @

Dekko/backend/mail/MailAddress.cpp

raw symbols SCIP
1 /* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "MailAddress.h"
19 #include <QStringList>
20 #include <QList>
21 #include <QDebug>
22
23 MailAddress::MailAddress(QObject *parent) : QObject(parent)
24 {
25 }
26
27 MailAddress::MailAddress(QObject *parent, const QMailAddress &address): QObject(parent),
28 m_address(address)
29 {
30 emit addrDataChanged();
31 }
32
33 MailAddress::MailAddress(QObject *parent, const QString &name, const QString &address): QObject(parent),
34 m_address(QMailAddress(name, address))
35 {
36 emit addrDataChanged();
37 }
38
39 MailAddress::MailAddress(QObject *parent, const QString &address) : QObject(parent),
40 m_address(QMailAddress(address))
41 {
42 }
43
44 QString MailAddress::name() const
45 {
46 return m_address.name();
47 }
48
49 QString MailAddress::address() const
50 {
51 return m_address.address();
52 }
53
54 QString MailAddress::completeAddress() const
55 {
56 return m_address.toString();
57 }
58
59 QString MailAddress::initials()
60 {
61 QString name = this->name().trimmed();
62 if (name.isEmpty() || !name.at(0).isLetter()) {
63 // Name is empty so return first character of address. :-/
64 if (address().isEmpty()) {
65 return QString();
66 }
67 return QString(address().at(0).toUpper());
68 }
69 // Intitials string
70 QString initials;
71 // Now break up the name, we have to set the encoding here as QT_NO_CAST_FROM/TO_ASCII is set
72 QStringList parts = name.split(QStringLiteral(" "));
73 if (parts.first().at(0).isLetter()) {
74 initials += parts.first().at(0).toUpper();
75 }
76 if (parts.size() > 1) {
77 if (parts.last().at(0).isLetter()) {
78 initials += parts.last().at(0).toUpper();
79 }
80 }
81 return initials;
82 }
83
84 bool MailAddress::isGroup() const
85 {
86 return m_address.isGroup();
87 }
88
89 bool MailAddress::isNull() const
90 {
91 return m_address.isNull();
92 }
93
94 bool MailAddress::isContact() const
95 {
96 return false; // not implemented yet
97 }
98
99 QString MailAddress::toRfc6068Mailto()
100 {
101 return QStringLiteral("mailto:%1").arg(completeAddress());
102 }
103
104 void MailAddress::setAddress(const QMailAddress &address)
105 {
106 m_address = address;
107 emit addrDataChanged();
108 }
109