• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkdepim

  • sources
  • kde-4.14
  • kdepim
  • libkdepim
  • addressline
  • addresslineedit
baloocompletionemail.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 
19 */
20 
21 #include "baloocompletionemail.h"
22 #include <QMap>
23 #include <KPIMUtils/Email>
24 #include <QDebug>
25 using namespace KPIM;
26 
27 BalooCompletionEmail::BalooCompletionEmail()
28 {
29 
30 }
31 
32 void BalooCompletionEmail::setEmailList(const QStringList &lst)
33 {
34  mListEmail = lst;
35 }
36 
37 void BalooCompletionEmail::setExcludeDomain(const QStringList &lst)
38 {
39  mExcludeDomain = lst;
40 }
41 
42 void BalooCompletionEmail::setBlackList(const QStringList &lst)
43 {
44  mBlackList = lst;
45 }
46 
47 QStringList BalooCompletionEmail::cleanupEmailList()
48 {
49  if (mListEmail.isEmpty())
50  return mListEmail;
51  QMap<QString, QString> hashEmail;
52  Q_FOREACH (QString email, mListEmail) {
53  if (!mBlackList.contains(email)) {
54  QString address;
55  email = stripEmail(email, address);
56  if (address.isEmpty()) {
57  address = email;
58  }
59  bool excludeMail = false;
60  Q_FOREACH(const QString &excludeDomain, mExcludeDomain) {
61  if (!excludeDomain.isEmpty()) {
62  if (address.endsWith(excludeDomain)) {
63  excludeMail = true;
64  continue;
65  }
66  }
67  }
68  if (!excludeMail && !hashEmail.contains(address.toLower())) {
69  hashEmail.insert(address.toLower(), email);
70  }
71  }
72  }
73  return hashEmail.values();
74 }
75 
76 
77 /* stips the name of an email address email
78  *
79  * 'a' <a@example.com> -> a <a@example.com>
80  * "a" <a@example.com> -> a <a@example.com>
81  * "\"'a'\"" <a@example.com> -> a <a@example.com>
82  *
83  * but "\"'a" <a@example.com> -> "\"'a" <a@example.com>
84  * cause the start and end is not the same.
85  */
86 QString BalooCompletionEmail::stripEmail(const QString &email, QString &address)
87 {
88  QString displayName, addrSpec, comment;
89  if ( KPIMUtils::AddressOk == KPIMUtils::splitAddress( email, displayName, addrSpec, comment )) {
90  address = addrSpec;
91  while ((displayName.startsWith(QLatin1Char('\'')) && displayName.endsWith(QLatin1Char('\''))) ||
92  (displayName.startsWith(QLatin1Char('"')) && displayName.endsWith(QLatin1Char('"'))) ||
93  (displayName.startsWith(QLatin1String("\\\"")) && displayName.endsWith(QLatin1String("\\\""))) ) {
94  if (displayName.startsWith(QLatin1String("\\\""))) {
95  displayName = displayName.mid(2, displayName.length()-4).trimmed();
96  } else {
97  displayName = displayName.mid(1, displayName.length()-2).trimmed();
98  }
99  }
100  return KPIMUtils::normalizedAddress(displayName, addrSpec, comment);
101  } else {
102  return email;
103  }
104 }
105 
KPIM::BalooCompletionEmail::setEmailList
void setEmailList(const QStringList &lst)
Definition: baloocompletionemail.cpp:32
QMap::contains
bool contains(const Key &key) const
QMap::values
QList< T > values() const
QMap
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
KPIM::BalooCompletionEmail::BalooCompletionEmail
BalooCompletionEmail()
Definition: baloocompletionemail.cpp:27
KPIM::BalooCompletionEmail::setExcludeDomain
void setExcludeDomain(const QStringList &lst)
Definition: baloocompletionemail.cpp:37
QList::isEmpty
bool isEmpty() const
QString::isEmpty
bool isEmpty() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QString
baloocompletionemail.h
QStringList
QString::toLower
QString toLower() const
QLatin1Char
QString::mid
QString mid(int position, int n) const
QLatin1String
KPIM::BalooCompletionEmail::setBlackList
void setBlackList(const QStringList &lst)
Definition: baloocompletionemail.cpp:42
QString::length
int length() const
QMap::insert
iterator insert(const Key &key, const T &value)
KPIM::BalooCompletionEmail::cleanupEmailList
QStringList cleanupEmailList()
Definition: baloocompletionemail.cpp:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal