37 #include <QtCore/QRegExp>
38 #include <QtCore/QDataStream>
40 using namespace KCalCore;
47 class KCalCore::Person::Private
50 Private() : mCount(0) {}
62 : d(new KCalCore::
Person::Private)
69 : d(new KCalCore::
Person::Private(*person.d))
81 d->mName == person.d->mName &&
82 d->mEmail == person.d->mEmail;
87 return !(*
this == person);
93 if (&person ==
this) {
103 if (d->mName.isEmpty()) {
106 if (d->mEmail.isEmpty()) {
110 QString
name = d->mName;
111 QRegExp needQuotes(
"[^ 0-9A-Za-z\\x0080-\\xFFFF]");
112 bool weNeedToQuote = name.indexOf(needQuotes) != -1;
114 if (name[0] !=
'"') {
117 if (name[ name.length()-1 ] !=
'"') {
121 return name +
" <" + d->mEmail +
'>';
138 return d->mEmail.isEmpty() && d->mName.isEmpty();
148 if (email.startsWith(QLatin1String(
"mailto:"), Qt::CaseInsensitive)) {
149 d->mEmail = email.mid(7);
157 int pos = email.lastIndexOf(
"@");
158 return (pos > 0) && (email.lastIndexOf(
".") > pos) && ((email.length() - pos) > 4);
178 return stream << person->d->mName
180 << person->d->mCount;
188 stream >> name >> email >> count;
191 person_tmp->setCount(count);
192 person.swap(person_tmp);
199 static bool extractEmailAddressAndName(
const QString &aStr, QString &mail, QString &name)
204 const int len = aStr.length();
205 const char cQuotes =
'"';
207 bool bInComment =
false;
208 bool bInQuotesOutsideOfEmail =
false;
209 int i=0, iAd=0, iMailStart=0, iMailEnd=0;
211 unsigned int commentstack = 0;
223 bInComment = commentstack != 0;
224 if (
'"' == c && !bInComment) {
225 bInQuotesOutsideOfEmail = !bInQuotesOutsideOfEmail;
228 if (!bInComment && !bInQuotesOutsideOfEmail) {
241 for (i = 0; len > i; ++i) {
249 mail = aStr.mid(i + 1);
250 if (mail.endsWith(
'>')) {
251 mail.truncate(mail.length() - 1);
259 bInQuotesOutsideOfEmail =
false;
260 for (i = iAd-1; 0 <= i; --i) {
264 if (!name.isEmpty()) {
271 }
else if (bInQuotesOutsideOfEmail) {
273 bInQuotesOutsideOfEmail =
false;
274 }
else if (c !=
'\\') {
285 bInQuotesOutsideOfEmail =
true;
290 switch (c.toLatin1()) {
295 if (!name.isEmpty()) {
309 name = name.simplified();
310 mail = mail.simplified();
312 if (mail.isEmpty()) {
322 bInQuotesOutsideOfEmail =
false;
323 int parenthesesNesting = 0;
324 for (i = iAd+1; len > i; ++i) {
328 if (--parenthesesNesting == 0) {
330 if (!name.isEmpty()) {
340 ++parenthesesNesting;
344 }
else if (bInQuotesOutsideOfEmail) {
346 bInQuotesOutsideOfEmail =
false;
347 }
else if (c !=
'\\') {
358 bInQuotesOutsideOfEmail =
true;
363 switch (c.toLatin1()) {
368 if (!name.isEmpty()) {
371 if (++parenthesesNesting > 0) {
385 name = name.simplified();
386 mail = mail.simplified();
388 return !(name.isEmpty() || mail.isEmpty());
394 extractEmailAddressAndName(fullName, email, name);