summaryrefslogtreecommitdiffstats
path: root/libemailfunctions/tests/testemail.cpp
blob: 4976764b13adef0aec190dca05ef33bb89fc85db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
/* This file is part of the KDE project
   Copyright (C) 2004 David Faure <faure@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

// Test program for libemailfunctions/email.h
#include "email.h"

#include <kcmdlineargs.h>
#include <kapplication.h>
#include <kdebug.h>

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

using namespace KPIM;

static bool check(const TQString& txt, const TQString& a, const TQString& b)
{
  if (a == b) {
    kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
  }
  else {
    kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
    exit(1);
  }
  return true;
}

static bool check(const TQString& txt, const TQStringList& a, const TQStringList& b)
{
  if ( a.join("\n") == b.join("\n") ) {
    kdDebug() << txt << " : checking list [ " << a.join( ", " ) << " ] against expected value [ " << b.join( ", " ) << " ]... " << "ok" << endl;
  }
  else {
    kdDebug() << txt << " : checking list [ " << a.join( ",\n" ) << " ] against expected value [ " << b.join( ",\n" ) << " ]... " << "KO !" << endl;
    exit(1);
  }
  return true;
}

static bool checkGetNameAndEmail(const TQString& input, const TQString& expName, const TQString& expEmail, bool expRetVal)
{
  TQString name, email;
  bool retVal = KPIM::getNameAndMail(input, name, email);
  check( "getNameAndMail " + input + " retVal", retVal?TQString::fromLatin1( "true" ):TQString::fromLatin1( "false" ), expRetVal?TQString::fromLatin1( "true" ):TQString::fromLatin1( "false" ) );
  check( "getNameAndMail " + input + " name", name, expName );
  check( "getNameAndMail " + input + " email", email, expEmail );
  return true;
}

// convert this to a switch instead but hey, nothing speedy in here is needed but still.. it would be nice
static TQString emailTestParseResultToString( EmailParseResult errorCode )
{
  if( errorCode == TooManyAts ) {
    return "TooManyAts";
  } else if( errorCode == TooFewAts ) {
    return "TooFewAts";
  } else if( errorCode == AddressEmpty ) {
    return "AddressEmpty";
  } else if( errorCode == MissingLocalPart ) {
    return "MissingLocalPart";
  } else if( errorCode == MissingDomainPart ) {
    return "MissingDomainPart";
  } else if( errorCode == UnbalancedParens ) {
    return "UnbalancedParens";
  } else if( errorCode == AddressOk ) {
    return "AddressOk";
  } else if( errorCode == UnclosedAngleAddr ) {
    return "UnclosedAngleAddr";
  } else if( errorCode == UnexpectedEnd ) {
    return "UnexpectedEnd";
  } else if( errorCode == UnopenedAngleAddr ) {
    return "UnopenedAngleAddr";
  } else if( errorCode == DisallowedChar ) {
    return "DisallowedChar";
  } else if( errorCode == UnexpectedComma ) {
    return "UnexpectedComma";
  } else if( errorCode == UnbalancedQuote ) {
    return "UnbalancedQuote";
  } else if( errorCode == InvalidDisplayName ) {
    return "InvalidDisplayName";
  }
  return "unknown error code";
}

static TQString simpleEmailTestParseResultToString( bool validEmail )
{
  if ( validEmail ) {
    return "true";
  }
  return "false";
}

static bool checkIsValidEmailAddress( const TQString& input, const TQString&  expErrorCode )
{
  EmailParseResult errorCode = KPIM::isValidEmailAddress( input );
  TQString errorC = emailTestParseResultToString( errorCode );
  check( "isValidEmailAddress " + input + " errorCode ", errorC , expErrorCode );
  return true;
}

static bool checkIsValidSimpleEmailAddress( const TQString& input, const TQString& expResult )
{
  bool validEmail = KPIM::isValidSimpleEmailAddress( input );
  TQString result = simpleEmailTestParseResultToString( validEmail );
  check( "isValidSimpleEmailAddress " + input + " result ", result, expResult );
  return true;
}

static bool checkGetEmailAddress( const TQString& input, const TQString& expResult )
{
  TQString emailAddress = KPIM::getEmailAddress( input );
  TQString result = emailAddress;
  check( "getEmailAddress " + input + " result ", result, expResult );
  return true;
}

static bool checkSplitEmailAddrList( const TQString& input, const TQStringList& expResult )
{
  TQStringList emailAddresses = KPIM::splitEmailAddrList( input );
  check( "splitEmailAddrList( \"" + input + "\" ) result ", emailAddresses, expResult );
  return true;
}

static bool checkNormalizeAddressesAndEncodeIDNs( const TQString& input, const TQString& expResult )
{
  TQString result = KPIM::normalizeAddressesAndEncodeIDNs( input );
  check( "normalizeAddressesAndEncodeIDNs( \"" + input + "\" ) result ", result, expResult );
  return true;
}

static bool checkNormalizeAddressesAndDecodeIDNs( const TQString& input, const TQString& expResult )
{
  TQString result = KPIM::normalizeAddressesAndDecodeIDNs( input );
  check( "normalizeAddressesAndDecodeIDNs( \"" + input + "\" ) result ", result, expResult );
  return true;
}

static bool checkQuoteIfNecessary( const TQString& input, const TQString& expResult )
{
  TQString result = quoteNameIfNecessary( input );
  check( "quoteNameIfNecessary " + input + " result ", result, expResult );
  return true;
}


int main(int argc, char *argv[])
{
  KApplication::disableAutoDcopRegistration();
  TDECmdLineArgs::init( argc, argv, "testemail", 0, 0, 0, 0 );
  KApplication app( false, false );

  // Empty input
  checkGetNameAndEmail( TQString(), TQString(), TQString(), false );

  // Email only
  checkGetNameAndEmail( "faure@kde.org", TQString(), "faure@kde.org", false );

  // Normal case
  checkGetNameAndEmail( "David Faure <faure@kde.org>", "David Faure", "faure@kde.org", true );

  // Double-quotes
  checkGetNameAndEmail( "\"Faure, David\" <faure@kde.org>", "Faure, David", "faure@kde.org", true );
  checkGetNameAndEmail( "<faure@kde.org> \"David Faure\"", "David Faure", "faure@kde.org", true );

  // Parenthesis
  checkGetNameAndEmail( "faure@kde.org (David Faure)", "David Faure", "faure@kde.org", true );
  checkGetNameAndEmail( "(David Faure) faure@kde.org", "David Faure", "faure@kde.org", true );
  checkGetNameAndEmail( "My Name (me) <me@home.net>", "My Name (me)", "me@home.net", true ); // #93513

  // Nested parenthesis as per https://intevation.de/roundup/kolab/issue858
  checkGetNameAndEmail( "faure@kde.org (David (The Man) Faure)", "David (The Man) Faure", "faure@kde.org", true );

  // Double-quotes inside parenthesis
  checkGetNameAndEmail( "faure@kde.org (David \"Crazy\" Faure)", "David \"Crazy\" Faure", "faure@kde.org", true );
  checkGetNameAndEmail( "(David \"Crazy\" Faure) faure@kde.org", "David \"Crazy\" Faure", "faure@kde.org", true );

  // Parenthesis inside double-quotes
  checkGetNameAndEmail( "\"Faure (David)\" <faure@kde.org>", "Faure (David)", "faure@kde.org", true );
  checkGetNameAndEmail( "<faure@kde.org> \"Faure (David)\"", "Faure (David)", "faure@kde.org", true );

  // Space in email
  checkGetNameAndEmail( "David Faure < faure@kde.org >", "David Faure", "faure@kde.org", true );

  // Check that '@' in name doesn't confuse it
  checkGetNameAndEmail( "faure@kde.org (a@b)", "a@b", "faure@kde.org", true );
  // Interestingly, this isn't supported.
  //checkGetNameAndEmail( "\"a@b\" <faure@kde.org>", "a@b", "faure@kde.org", true );

  // While typing, when there's no '@' yet
  checkGetNameAndEmail( "foo", "foo", TQString(), false );
  checkGetNameAndEmail( "foo <", "foo", TQString(), false );
  checkGetNameAndEmail( "foo <b", "foo", "b", true );

  // If multiple emails are there, only return the first one
  checkGetNameAndEmail( "\"Faure, David\" <faure@kde.org>, KHZ <khz@khz.khz>", "Faure, David", "faure@kde.org", true );

  // domain literals also need to work
  checkGetNameAndEmail( "Matt Douhan <matt@[123.123.123.123]>", "Matt Douhan", "matt@[123.123.123.123]", true );

  // @ inside the comment
  checkGetNameAndEmail( "\"Matt@Douhan\" <matt@fruitsalad.org>", "Matt@Douhan", "matt@fruitsalad.org", true );

  // No '@'
  checkGetNameAndEmail(  "foo <distlist>", "foo", "distlist", true );

  // To many @'s
  checkIsValidEmailAddress( "matt@@fruitsalad.org", "TooManyAts" );

  // To few @'s
  checkIsValidEmailAddress( "mattfruitsalad.org", "TooFewAts" );

  // An empty string
  checkIsValidEmailAddress( TQString() , "AddressEmpty" );

  // email address starting with a @
  checkIsValidEmailAddress( "@mattfruitsalad.org", "MissingLocalPart" );

  // make sure that starting @ and an additional @ in the same email address don't conflict
  // trap the starting @ first and break
  checkIsValidEmailAddress( "@matt@fruitsalad.org", "MissingLocalPart" );

  // email address ending with a @
  checkIsValidEmailAddress( "mattfruitsalad.org@", "MissingDomainPart" );

  // make sure that ending with@ and an additional @ in the email address don't conflict
  checkIsValidEmailAddress( "matt@fruitsalad.org@", "MissingDomainPart" );

  // unbalanced Parens
  checkIsValidEmailAddress( "mattjongel)@fruitsalad.org", "UnbalancedParens" );

  // unbalanced Parens the other way around
  checkIsValidEmailAddress( "mattjongel(@fruitsalad.org", "UnbalancedParens" );

  // Correct parens just to make sure it works
  checkIsValidEmailAddress( "matt(jongel)@fruitsalad.org", "AddressOk" );

  // Check that anglebrackets are closed
  checkIsValidEmailAddress( "matt douhan<matt@fruitsalad.org", "UnclosedAngleAddr" );

  // Check that angle brackets are closed the other way around
  checkIsValidEmailAddress( "matt douhan>matt@fruitsalad.org", "UnopenedAngleAddr" );

  // Check that angle brackets are closed the other way around, and anglebrackets in domainpart
  // instead of local part
  checkIsValidEmailAddress( "matt douhan matt@<fruitsalad.org", "UnclosedAngleAddr" );

  // check that a properly formated anglebrackets situation is OK
  checkIsValidEmailAddress( "matt douhan<matt@fruitsalad.org>", "AddressOk" );

  // a full email address with comments angle brackets and the works should be valid too
  checkIsValidEmailAddress( "Matt (jongel) Douhan <matt@fruitsalad.org>", "AddressOk" );

  // Double quotes
  checkIsValidEmailAddress( "\"Matt Douhan\" <matt@fruitsalad.org>", "AddressOk" );

  // Double quotes inside parens
  checkIsValidEmailAddress( "Matt (\"jongel\") Douhan <matt@fruitsalad.org>", "AddressOk" );

  // DOuble quotes not closed
  checkIsValidEmailAddress( "Matt \"jongel Douhan <matt@fruitsalad.org>", "UnbalancedQuote" );

  // Parens inside double quotes
  checkIsValidEmailAddress( "Matt \"(jongel)\" Douhan <matt@fruitsalad.org>", "AddressOk" );

  // Space in email
  checkIsValidEmailAddress( "Matt Douhan < matt@fruitsalad.org >", "AddressOk" );

  // @ is allowed inisde doublequotes
  checkIsValidEmailAddress( "\"matt@jongel\" <matt@fruitsalad.org>", "AddressOk" );

  // anglebrackets inside dbl quotes
  checkIsValidEmailAddress( "\"matt<blah blah>\" <matt@fruitsalad.org>", "AddressOk" );

  // a , inside a double quoted string is OK, how do I know this? well Ingo says so
  // and it makes sense since it is also a seperator of email addresses
  checkIsValidEmailAddress( "\"Douhan, Matt\" <matt@fruitsalad.org>", "AddressOk" );

  // Domains literals also need to work
  checkIsValidEmailAddress( "Matt Douhan <matt@[123.123.123.123]>", "AddressOk" );

  // Typo in domain literal address
  checkIsValidEmailAddress( "Matt Douhan <matt@[123.123.123,123]>", "UnexpectedComma" );

  // Some more insane tests but still valid so they must work
  checkIsValidEmailAddress( "Matt Douhan <\"m@att\"@jongel.com>", "AddressOk" );

  // BUG 99657
  checkIsValidEmailAddress( "matt@jongel.fibbel.com", "AddressOk" );

  // BUG 98720
  checkIsValidEmailAddress( "mailto:@mydomain", "DisallowedChar" );

  // correct error msg when a comma is inside <>
  checkIsValidEmailAddress( "Matt Douhan <matt@fruitsalad,org>", "UnexpectedComma" );

  //several commentlevels
  checkIsValidEmailAddress( "Matt Douhan (hey(jongel)fibbel) <matt@fruitsalad.org>", "AddressOk" );

  // several comment levels and one (the outer) being unbalanced
  checkIsValidEmailAddress( "Matt Douhan (hey(jongel)fibbel <matt@fruitsalad.org>", "UnbalancedParens" );

  // several comment levels and one (the inner) being unbalanced
  checkIsValidEmailAddress( "Matt Douhan (hey(jongelfibbel) <matt@fruitsalad.org>", "UnbalancedParens" );

  // an error inside a double quote is no error
  checkIsValidEmailAddress ( "Matt Douhan \"(jongel\" <matt@fruitsalad.org>", "AddressOk" );

  // inside a quoted string double quotes are only allowed in pairs as per rfc2822
  checkIsValidEmailAddress( "Matt Douhan \"jongel\"fibbel\" <matt@fruitsalad.org>", "UnbalancedQuote" );

  // a questionmark is valid in an atom
  checkIsValidEmailAddress ( "Matt? <matt@fruitsalad.org>", "AddressOk" );

  // weird but OK
  checkIsValidEmailAddress( "\"testing, \\\"testing\" <matt@fruitsalad.org>", "AddressOk" );

  // escape a quote to many to see if it makes it invalid
  checkIsValidEmailAddress( "\"testing, \\\"testing\\\" <matt@fruitsalad.org>", "UnbalancedQuote" );

  // escape a parens and thus make a comma appear
  checkIsValidEmailAddress( "Matt (jongel, fibbel\\) <matt@fruitsalad.org>", "UnbalancedParens" );

  // several errors inside doublequotes
  checkIsValidEmailAddress( "Matt \"(jongel,\\\" < fibbel\\\\)\" <matt@fruitsalad.org>", "AddressOk" );

  // BUG 105705
  checkIsValidEmailAddress( "matt-@fruitsalad.org", "AddressOk" );

  // underscore at the end of local part
  checkIsValidEmailAddress( "matt_@fruitsalad.org", "AddressOk" );

  // how about ( comment ) in the domain part
  checkIsValidEmailAddress( "matt_@(this is a cool host)fruitsalad.org", "AddressOk" );

  // To quote rfc2822 the test below is aesthetically displeasing, but perfectly legal.
  checkIsValidEmailAddress( "Pete(A wonderful \\) chap) <pete(his account)@silly.test(his host)>", "AddressOk" );

  // quoted pair or not quoted pair
  checkIsValidEmailAddress( "\"jongel '\\\" fibbel\" <matt@fruitsalad.org>", "AddressOk" );
  checkIsValidEmailAddress( "\"jongel '\" fibbel\" <matt@fruitsalad.org>", "UnbalancedQuote" );

  // full atext support according to rfc2822
  checkIsValidEmailAddress( "!matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "#matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "$matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "%matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "&matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "'matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "*matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "+matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "/matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "=matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "?matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "^matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "_matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "-matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "`matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "{matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "|matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "}matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "~matt@fruitsalad.org", "AddressOk" );
  checkIsValidEmailAddress( "matt%matt@fruitsalad.org", "AddressOk" );

  //bug 105405
  checkIsValidEmailAddress( "[foobar] <matt@fruitsalad.org>", "InvalidDisplayName" );
  checkIsValidEmailAddress( "matt \"[foobar]\" Douhan <matt@fruitsalad.org>", "AddressOk" );

  checkIsValidEmailAddress( "Matt Douhan <matt\"@@\"fruitsalad.org>", "TooFewAts" );

  // checks for "pure" email addresses in the form of xxx@yyy.tld
  checkIsValidSimpleEmailAddress( "matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( TQString::fromUtf8("test@täst.invalid"), "true" );
  // non-ASCII char as first char of IDN
  checkIsValidSimpleEmailAddress( TQString::fromUtf8("i_want@øl.invalid"), "true" );
  checkIsValidSimpleEmailAddress( "matt@[123.123.123.123]", "true" );
  checkIsValidSimpleEmailAddress( "matt@[3.3.3.3]", "true" );
  checkIsValidSimpleEmailAddress( "matt@[4.4.4.4]", "true" );
  checkIsValidSimpleEmailAddress( "matt@[192.168.254.254]", "true" );
  checkIsValidSimpleEmailAddress( "\"matt\"@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "-matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "\"-matt\"@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "matt@jongel.fibbel.com", "true" );
  checkIsValidSimpleEmailAddress( "Matt Douhan <matt@fruitsalad.org>", "false" );
  // BUG 105705
  checkIsValidSimpleEmailAddress( "matt-@fibbel.com", "true" );
  checkIsValidSimpleEmailAddress( "matt@fibbel-is-a-geek.com", "true" );
  checkIsValidSimpleEmailAddress( "matt_@fibbel.com", "true" );
  // Check the defined chars for atext according to rfc2822
  checkIsValidSimpleEmailAddress( "!matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "#matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "$matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "%matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "&matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "'matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "*matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "+matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "/matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "=matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "?matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "^matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "_matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "-matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "`matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "{matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "|matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "}matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "~matt@fruitsalad.org", "true" );
  // BUG 108476
  checkIsValidSimpleEmailAddress( "foo+matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "bar=matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "jongel-matt@fruitsalad.org", "true" );
  checkIsValidSimpleEmailAddress( "matt-@fruitsalad.org", "true" );

  // check if the pure email address is wrong
  checkIsValidSimpleEmailAddress( "mattfruitsalad.org", "false" );
  checkIsValidSimpleEmailAddress( "matt@[123.123.123.123", "false" );
  checkIsValidSimpleEmailAddress( "matt@123.123.123.123]", "false" );
  checkIsValidSimpleEmailAddress( "\"matt@fruitsalad.org", "false" );
  checkIsValidSimpleEmailAddress( "matt\"@fruitsalad.org", "false" );
  checkIsValidSimpleEmailAddress( TQString(), "false" );

  // and here some insane but still valid cases
  checkIsValidSimpleEmailAddress( "\"m@tt\"@fruitsalad.org", "true" );

  checkIsValidSimpleEmailAddress( "matt\"@@\"fruitsalad.org", "false" );

  // check the getEmailAddress address method
  checkGetEmailAddress( "matt@fruitsalad.org", "matt@fruitsalad.org" );
  checkGetEmailAddress( "Matt Douhan <matt@fruitsalad.org>", "matt@fruitsalad.org" );
  checkGetEmailAddress( "\"Matt Douhan <blah blah>\" <matt@fruitsalad.org>", "matt@fruitsalad.org" );
  checkGetEmailAddress( "\"Matt <blah blah>\" <matt@fruitsalad.org>", "matt@fruitsalad.org" );
  checkGetEmailAddress( "Matt Douhan (jongel) <matt@fruitsalad.org", TQString() );
  checkGetEmailAddress( "Matt Douhan (m@tt) <matt@fruitsalad.org>", "matt@fruitsalad.org" );
  checkGetEmailAddress( "\"Douhan, Matt\" <matt@fruitsalad.org>", "matt@fruitsalad.org" );
  checkGetEmailAddress( "\"Matt Douhan (m@tt)\" <matt@fruitsalad.org>", "matt@fruitsalad.org" );
  checkGetEmailAddress( "\"Matt Douhan\" (matt <matt@fruitsalad.org>", TQString() );
  checkGetEmailAddress( "Matt Douhan <matt@[123.123.123.123]>", "matt@[123.123.123.123]" );

  // check the splitEmailAddrList method
  checkSplitEmailAddrList( "kloecker@kde.org (Kloecker, Ingo)", TQStringList() << "kloecker@kde.org (Kloecker, Ingo)" );
  checkSplitEmailAddrList( "Matt Douhan <matt@fruitsalad.org>, Foo Bar <foo@bar.com>", TQStringList() << "Matt Douhan <matt@fruitsalad.org>" << "Foo Bar <foo@bar.com>" );
  checkSplitEmailAddrList( "\"Matt, Douhan\" <matt@fruitsalad.org>, Foo Bar <foo@bar.com>", TQStringList() << "\"Matt, Douhan\" <matt@fruitsalad.org>" << "Foo Bar <foo@bar.com>" );

  // check checkNormalizeAddressesAndEncodeIDNs
  checkNormalizeAddressesAndEncodeIDNs( "matt@fruitsalad.org", "matt@fruitsalad.org" );
  checkNormalizeAddressesAndEncodeIDNs( "Matt Douhan <matt@fruitsalad.org>", "Matt Douhan <matt@fruitsalad.org>" );
  checkNormalizeAddressesAndEncodeIDNs( "Matt Douhan (jongel) <matt@fruitsalad.org>", "Matt Douhan (jongel) <matt@fruitsalad.org>" );
  checkNormalizeAddressesAndEncodeIDNs( "Matt Douhan (jongel,fibbel) <matt@fruitsalad.org>", "Matt Douhan (jongel,fibbel) <matt@fruitsalad.org>" );
  checkNormalizeAddressesAndEncodeIDNs( "matt@fruitsalad.org (jongel,fibbel)", "\"jongel,fibbel\" <matt@fruitsalad.org>" );
  checkNormalizeAddressesAndEncodeIDNs( "matt@fruitsalad.org (\"jongel,fibbel\")", "\"jongel,fibbel\" <matt@fruitsalad.org>" );

  // check checkNormalizeAddressesAndDecodeIDNs
  checkNormalizeAddressesAndDecodeIDNs( "=?us-ascii?Q?Surname=2C=20Name?= <nobody@example.org>", "\"Surname, Name\" <nobody@example.org>" );
  checkNormalizeAddressesAndDecodeIDNs( "=?iso-8859-1?B?5Hf8b2xmLPZBbmRyZWFz?= <nobody@example.org>", TQString::fromUtf8("\"äwüolf,öAndreas\" <nobody@example.org>") );

  // check the "quote if necessary" method
  checkQuoteIfNecessary( "Matt Douhan", "Matt Douhan");
  checkQuoteIfNecessary( "Douhan, Matt", "\"Douhan, Matt\"");
  checkQuoteIfNecessary( "Matt \"jongel\" Douhan", "\"Matt \\\"jongel\\\" Douhan\"");
  checkQuoteIfNecessary( "Matt \\\"jongel\\\" Douhan", "\"Matt \\\"jongel\\\" Douhan\"");
  checkQuoteIfNecessary( "trailing '\\\\' should never occur \\", "\"trailing '\\\\' should never occur \\\"");
  checkQuoteIfNecessary( "\"don't quote again\"", "\"don't quote again\"" );
  checkQuoteIfNecessary( "\"leading double quote", "\"\\\"leading double quote\"" );
  checkQuoteIfNecessary( "trailing double quote\"", "\"trailing double quote\\\"\"" );

  printf("\nTest OK !\n");

  return 0;
}