37 #include <QtCore/QRegExp>
39 using namespace KCalCore;
46 class KCalCore::Person::Private
49 Private() : mCount( 0 ) {}
61 : d( new KCalCore::
Person::Private )
68 : d( new KCalCore::
Person::Private( *person.d ) )
80 d->mName == person.d->mName &&
81 d->mEmail == person.d->mEmail;
86 return !( *
this == person );
92 if ( &person ==
this ) {
102 if ( d->mName.isEmpty() ) {
105 if ( d->mEmail.isEmpty() ) {
109 QString
name = d->mName;
110 QRegExp needQuotes(
"[^ 0-9A-Za-z\\x0080-\\xFFFF]" );
111 bool weNeedToQuote = name.indexOf( needQuotes ) != -1;
112 if ( weNeedToQuote ) {
113 if ( name[0] !=
'"' ) {
116 if ( name[ name.length()-1 ] !=
'"' ) {
120 return name +
" <" + d->mEmail +
'>';
137 return d->mEmail.isEmpty() && d->mName.isEmpty();
147 if ( email.startsWith( QLatin1String(
"mailto:" ), Qt::CaseInsensitive ) ) {
148 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 ) {
272 if ( cQuotes == c ) {
273 bInQuotesOutsideOfEmail =
false;
274 }
else if ( c !=
'\\' ) {
284 if ( cQuotes == 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 ) {
345 if ( cQuotes == c ) {
346 bInQuotesOutsideOfEmail =
false;
347 }
else if ( c !=
'\\' ) {
357 if ( cQuotes == 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() );
395 extractEmailAddressAndName( fullName, email, name );